Beispiel #1
0
def processSTO(Sender,
               Amount,
               PropertyID,
               Protocol,
               TxDBSerialNum,
               owners=None):
    if owners is None:
        # get list of owners sorted by most held to least held and by address alphabetically
        owners = sortSTO(
            dbSelect(
                "select address, balanceavailable from addressbalances where balanceavailable > 0 "
                "and address != %s and propertyid=%s", (Sender, PropertyID)))
    else:
        # use the addresslist sent to us
        owners = sortSTO(owners)
    # find out how much is actually owned/held in total
    toDistribute = Amount
    sumTotal = sum([holder[1] for holder in owners])
    # prime first position and set role
    AddressTxIndex = 0
    AddressRole = 'payee'
    Ecosystem = getEcosystem(PropertyID)
    LastHash = gettxhash(TxDBSerialNum)
    # process all holders from the sorted ownerslist
    for holder in owners:
        # who gets it
        Address = holder[0]
        # calculate percentage owed to the holder rounding up always
        amountToSend = int(math.ceil((holder[1] / sumTotal) * Amount))
        # if we sent this amount how much will we have left to send after (used to validate later)
        remaining = toDistribute - amountToSend
        # make sure its a valid amount to send
        if amountToSend > 0:
            # make sure amountToSend is actually available
            if remaining >= 0:
                # send/credit amountToSend to the holder
                amountSent = amountToSend
            else:
                # send/credit whatever is left (toDistribute) to the holder
                amountSent = toDistribute
            # Insert the amountSent record into the addressesintx table?
            dbExecute(
                "insert into addressesintxs "
                "(Address, PropertyID, Protocol, TxDBSerialNum, AddressTxIndex, AddressRole, BalanceAvailableCreditDebit)"
                "values(%s, %s, %s, %s, %s, %s, %s)",
                (Address, PropertyID, Protocol, TxDBSerialNum, AddressTxIndex,
                 AddressRole, amountSent))
            # dont update balance table, just fill in txs
            # updateBalance(Address, Protocol, PropertyID, Ecosystem, amountSent, None, None, LastHash)
            # make sure we keep track of how much was sent/left to send
            toDistribute -= amountSent
        # /end if amountToSend > 0
        # relative position of the recipiant
        AddressTxIndex += 1
        # no money left to distribute. Done
        if toDistribute == 0:
            break
Beispiel #2
0
def backupWallets():
    ROWS = dbSelect("select walletid, walletblob from wallets")
    if len(ROWS) == 0:
        print "No Wallets found to backup"
    else:
        directory = os.path.expanduser("~") + '/walletBackups/'

        if not os.path.exists(directory):
            os.makedirs(directory)

        for wallet in ROWS:
            walletid = wallet[0]
            blob = wallet[1]
            walletfile = str(directory) + str(walletid) + '.json'
            file = open(walletfile, "w")
            file.write(str(blob))
            file.close()

        print str(datetime.now()) + " Backed up " + str(len(ROWS)) + " wallets to " + str(directory)
Beispiel #3
0
        if toDistribute == 0:
            break
    # /end for holder in owners


with open('data/owners.data', 'rb') as csvfile:
    fr = csv.reader(csvfile)
    toProcess = {}
    skip = False
    for row in fr:
        if row[0] == 'BLOCK':
            block = row[1]
            txid = row[3]
            sender = row[5]
            if 'not' in dbSelect(
                    "select txstate from transactions where txhash=%s",
                [txid])[0][0]:
                skip = True
            else:
                skip = False
                toProcess[txid] = {
                    'sender': sender,
                    'block': block,
                    'balance': {}
                }
            print "Found", txid, skip
        elif '#' in row[0]:
            if not skip:
                address = row[2]
                balance = row[1]
                toProcess[txid]['balance'].update({address: balance})
Beispiel #4
0
import json
import decimal
from rpcclient import getdivisible_MP
from sql import updateProperty, insertProperty
from sqltools import (dbInit, dbCommit, dbSelect, dbExecute)

dbInit()

txtofix = dbSelect("select txtype, txhash, txdbserialnum from transactions where txtype=-51 or txtype=51 or txtype=53")
Protocol = "Mastercoin"

for tx in txtofix:

    type = tx[0]
    TxHash = tx[1]
    TxDBSerialNum = tx[2]
    rawtx = {'result': json.loads(dbSelect("select txdata from txjson where txdbserialnum=%s", [TxDBSerialNum])[0][0])}
    print type, TxHash, TxDBSerialNum, rawtx

    if type == -51:
        # Credit the buy in to the issuer
        AddressRole = 'issuer'
        Address = rawtx['result']['referenceaddress']

        # Now start updating the crowdsale propertyid balance info
        PropertyID = rawtx['result']['purchasedpropertyid']

        if getdivisible_MP(PropertyID):
            IssuerCreditDebit = int(decimal.Decimal(rawtx['result']['issuertokens']) * decimal.Decimal(1e8))
            BalanceAvailableCreditDebit = int(
                decimal.Decimal(rawtx['result']['purchasedtokens']) * decimal.Decimal(1e8))
Beispiel #5
0
##      'PrevBlock', 'MerkleRoot', 'Bits', 'Nonce', 'Size','TxCount']
##out_file = open('data/blocks.'+appendname+'.csv', "wb")
##blocks_table = csv.DictWriter(out_file, delimiter=',', fieldnames=fieldnames)
##blocks_table.writerow(dict((fn,fn) for fn in fieldnames))

# There are 2 bitcoin transactions that have duplicate hashes in different blocks.
# We skip them here to avoid database issues
# We don't need to skip them, the index will tolerate them now.
# skip={'d5d27987d2a3dfc724e359870c6644b40e497bdc0589a033220fe15429d88599': 91842,
#      'e3bf3d07d4b0375638d5f1db5255fe07ba2c4cb067cd81b84ee974b6585fb468': 91880}

# block with first MP transaction
firstMPtxBlock = 249948

# get last known block processed from db
initialBlock = dbSelect("select max(blocknumber) from blocks", None)[0][0] + 1

# initialBlock=firstMPtxBlock
# initialBlock=253056

endBlock = getinfo()['result']['blocks']
# endBlock=253060

# get highest TxDBSerialNum (number of rows in the Transactions table)
TxDBSerialNum = dbSelect('select last_value from transactions_txdbserialnum_seq', None)[0][0] + 1

# Start at 1 since block 0 is special case
# 21479844 btc tx's before block 249948
# TxDBSerialNum=21479844

currentBlock = initialBlock
Beispiel #6
0
import json
import decimal
from rpcclient import getdivisible_MP
from sqltools import (dbExecute, dbCommit, dbSelect)

txtofix = dbSelect(
    "select atx.txdbserialnum from addressesintxs atx inner join transactions tx on atx.txdbserialnum=tx.txdbserialnum where tx.txtype=50 and tx.txstate='valid'"
)
# txtofix=dbSelect("select atx.txdbserialnum from addressesintxs atx inner join transactions tx on atx.txdbserialnum=tx.txdbserialnum where tx.txtype=3 and tx.txstate='valid'")
Protocol = "Mastercoin"

for tx in txtofix:

    TxDBSerialNum = tx[0]
    rawtx = {
        'result':
        json.loads(
            dbSelect("select txdata from txjson where txdbserialnum=%s",
                     [TxDBSerialNum])[0][0])
    }

    Address = rawtx['result']['sendingaddress']

    # Now start updating the crowdsale propertyid balance info
    PropertyID = rawtx['result']['propertyid']

    if getdivisible_MP(PropertyID):
        BalanceAvailableCreditDebit = int(
            decimal.Decimal(rawtx['result']['amount']) * decimal.Decimal(1e8))
    else:
        BalanceAvailableCreditDebit = int(rawtx['result']['amount'])
Beispiel #7
0
           "048559218ff32a2afe153b4db4c0a24c8e315130472e94f737f47c69e80fe28f",
           "7c26b67f12cbfcd583ceb861c3fcfa92d5bc037f71a2d2e8efbac823c4b45eb9",
           "4ea05d85ab401b7382f69b7a0d34dc38d50ea58b20f0d0386ffa2cd5e26e5c69",
           "fa91b1baadfa47d48c7ab73dfb7ed6927d503add024211fb521f660470f353f9",
           "2dad05c732b3f555d3ff7da4167a50f22a39ab3d92712e013aa1140fb75afab4",
           "eb9797769cb61b1f4313062c2a6d45a8787a171406e3f546ffab57725fcee6f7",
           "788e2ff5fee14245466745279ee03b68b4f3fda6387721bf56f5c447f40c2a27",
           "5acf11630be5373f708f70ff7bf9d842311c78190ce5dd70d208f47a7f23a860",
           "f83d643563932bb181457b3d3dd64de56515d938dc345eaa72ea945869b6d848",
           "5256991ce6bdf40f068de1a46d5800bb63e1a0f3a580b6344496b32848c495e2"]

Protocol = "Mastercoin"

for tx in missing:

    x = dbSelect("select txblocknumber,txdbserialnum,txtype from transactions where txhash=%s order by txdbserialnum",
                 [tx])

    Block = x[0][0]
    TxDBSerialNum = x[0][1]
    type = x[0][2]
    print "Processing", TxDBSerialNum

    rawtx = {'result': json.loads(dbSelect("select txdata from txjson where txdbserialnum=%s", [TxDBSerialNum])[0][0])}

    print "Block:", Block, ", TxDbSerialNum:", TxDBSerialNum, ", type:", type, ", rawtx:", json.dumps(rawtx, indent=2)

    expireAccepts(Block)

    if type == 20:
        if rawtx['result']['valid']:
            updatedex(rawtx, TxDBSerialNum)
Beispiel #8
0
from sql import sendToOwners
from sqltools import dbSelect, dbCommit

txs = dbSelect(
    "select tx.txblocknumber,tx.txdbserialnum,atx.address,atx.propertyid,atx.balanceavailablecreditdebit from transactions tx, addressesintxs atx "
    "where tx.txdbserialnum=atx.txdbserialnum and tx.txtype =3 and atx.addressrole='sender' and txstate='valid' order by txdbserialnum desc"
)

Protocol = "Mastercoin"

# check/calculate the address outputs for each valid tx from sendtoowners
for x in txs:

    TxBlockNum = x[0]
    TxDBSerialNum = x[1]
    Sender = x[2]
    PropertyID = x[3]
    SentAmount = x[4] * -1

    print "Processing:", TxDBSerialNum, "Property:", PropertyID, "Sender:", Sender

    # get the current address balances to walk back from
    addressbalances = dbSelect(
        "select address,balanceavailable,balancereserved,balanceaccepted from addressbalances where propertyid=%s",
        [PropertyID])
    balance = {}
    for _x in addressbalances:
        if _x[1] is None:
            dbBalanceAvailable = 0
        else:
            dbBalanceAvailable = _x[1]