Ejemplo n.º 1
0
def update(tx):
    if TransactionUtils.isCFTransation(tx):
        CoinSqlite3().exec_sql('Update TransactionInfo set `version`=?,`lock_time`=?,`parentBlockId`=?,`state`=?, `type` = ? ,original_hash = ?, target_amount = ?, pubkey = ?, end_time = ?, pre_hash = ?, lack_amount = ? , cert = ? where hash = ?', tx.version, tx.lock_time, tx.getBlockHash(), tx.state, 2, tx.cf_header.original_hash, tx.cf_header.target_amount, tx.cf_header.pubkey, tx.cf_header.end_time, tx.cf_header.pre_hash, tx.cf_header.lack_amount, tx.cf_header.cert, tx.hash())
    else:    
        CoinSqlite3().exec_sql('Update TransactionInfo set `version`=?,`lock_time`=?,`parentBlockId`=?, `state`=?, `type` = ? where hash = ?', tx.version, tx.lock_time, tx.getBlockHash(), tx.state, 1, tx.hash())

    for index, txIn in enumerate(tx.txs_in):
        TransactionInDao.save(txIn, tx, index)
    for index, txOut in enumerate(tx.txs_out):
        TransactionOutDao.save(txOut, tx, index)  
Ejemplo n.º 2
0
def insert(tx):
    if TransactionUtils.isCFTransation(tx):
        CoinSqlite3().exec_sql('INSERT INTO TransactionInfo(hash, version,lock_time,parentBlockId,state,type,original_hash, target_amount, pubkey, end_time, pre_hash, lack_amount, cert) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)', tx.hash(), tx.version, tx.lock_time, tx.getBlockHash(), tx.state, 2, tx.cf_header.original_hash, tx.cf_header.target_amount, tx.cf_header.pubkey, tx.cf_header.end_time, tx.cf_header.pre_hash, tx.cf_header.lack_amount, tx.cf_header.cert)
    else:
        CoinSqlite3().exec_sql('INSERT INTO TransactionInfo(hash, version,lock_time,parentBlockId,state,type) VALUES (?,?,?,?,?,?)', tx.hash(), tx.version, tx.lock_time, tx.getBlockHash(), tx.state, 1)
        
    for index, txIn in enumerate(tx.txs_in):
        TransactionInDao.save(txIn, tx, index)
    for index, txOut in enumerate(tx.txs_out):
        TransactionOutDao.save(txOut, tx, index)  
Ejemplo n.º 3
0
def searchMySecrets():   
    c = CoinSqlite3()._exec_sql('Select * from SecretKeyInfo Where privateKey != \'\'')
    secrets = []
    for tmp in c.fetchall():
        secret = SecretKey(tmp[1], tmp[3], tmp[2], tmp[4], tmp[0], tmp[5])
        secrets.append(secret)
    return secrets
Ejemplo n.º 4
0
def search():
    c = CoinSqlite3()._exec_sql('Select * from SecretKeyInfo')
    secrets = []
    for tmp in c.fetchall():
        secret = SecretKey(tmp[1], tmp[3], tmp[2], tmp[4], tmp[0])
        secrets.append(secret)
    return secrets
Ejemplo n.º 5
0
def searchCertByPubAddr(pubkey_addr):
    c = CoinSqlite3()._exec_sql('Select cert from SecretKeyInfo where pubicAddress = ?', pubkey_addr)
    tmp = c.fetchone()
    if tmp == None:
        return ''
    else:
        return '''-----BEGIN CERTIFICATE-----
Ejemplo n.º 6
0
def isPreCFlinked(cf):
    if cf.cf_header.pre_hash == '' or cf.cf_header.pre_hash == Constants.ZERO_HASH:
        return False
    else:
        c = CoinSqlite3()._exec_sql('Select * from TransactionInfo where pre_hash = ?', cf.cf_header.pre_hash)
        s = c.fetchone()
        return s != None
Ejemplo n.º 7
0
def searchParentBlockHash(tx):
    c = CoinSqlite3()._exec_sql('Select parentBlockId from TransactionInfo where hash = ?', tx.hash())
    tmp = c.fetchone()
    if tmp == None:
        return None
    else:
        parentBlockId = tmp[0]
        return parentBlockId
Ejemplo n.º 8
0
def __update(blockChain, preHeight):
    CoinSqlite3().exec_sql(
        'Update BlockInfo set `version`=?,`previous_block_hash`=?,`merkle_root`=?,`timestamp`=?,`difficulty`=?,`nonce`=?,`state`=?,`height`=? where hash = ?',
        blockChain.version, blockChain.previous_block_hash,
        blockChain.merkle_root, blockChain.timestamp, blockChain.difficulty,
        blockChain.nonce, blockChain.state, preHeight + 1, blockChain.hash())
    for tx in blockChain.txs:
        TransactionDao.save(tx)
Ejemplo n.º 9
0
def __insert(blockChain, preHeight):
    CoinSqlite3().exec_sql(
        'INSERT INTO BlockInfo(hash, version,previous_block_hash,merkle_root,timestamp,difficulty,nonce,state,height) VALUES (?,?,?,?,?,?,?,?,?)',
        blockChain.hash(), blockChain.version, blockChain.previous_block_hash,
        blockChain.merkle_root, blockChain.timestamp, blockChain.difficulty,
        blockChain.nonce, blockChain.state, preHeight + 1)
    for tx in blockChain.txs:
        TransactionDao.save(tx)
Ejemplo n.º 10
0
def searchParentTransactionHash(txout):
    c = CoinSqlite3()._exec_sql(
        'Select parentTxId from TransactionInfoOut where `id` = ?', txout.uid)
    tmp = c.fetchone()
    if tmp == None:
        return None
    else:
        parentTxId = tmp[0]
        return parentTxId
Ejemplo n.º 11
0
def searchAllCFDict():
    c = CoinSqlite3()._exec_sql(
        'Select * from TransactionInfo where type =2 and target_amount = lack_amount and  parentBlockId != \'\''
    )
    src_cfs = __getSearchResult(c)
    allCFDict = {}
    for src_cf in src_cfs:
        cfs = searchCFTcsByOriginal_hash(src_cf.hash())
        cfs.insert(0, src_cf)
        allCFDict[src_cf.hash()] = cfs
    return allCFDict
Ejemplo n.º 12
0
def search(hash):
    c = CoinSqlite3()._exec_sql('Select * from BlockInfo where hash = ?', hash)
    tmp = c.fetchone()
    if tmp != None:
        txs = TransactionDao.search(hash)
        sort_txs = __sort_txs(txs)
        block = Block(tmp[2], tmp[3], tmp[4], tmp[5], tmp[6], tmp[7], sort_txs,
                      tmp[8], tmp[9], tmp[10], tmp[0])
        for tx in txs:
            tx.block = block
        return block
Ejemplo n.º 13
0
def searchAll():
    c = CoinSqlite3()._exec_sql('Select * from BlockInfo')
    blocks = []
    for tmp in c.fetchall():
        txs = TransactionDao.search(tmp[1])
        sort_txs = __sort_txs(txs)
        block = Block(tmp[2], tmp[3], tmp[4], tmp[5], tmp[6], tmp[7], sort_txs,
                      tmp[8], tmp[9], tmp[10], tmp[0])
        for tx in txs:
            tx.block = block
        blocks.append(block)
    return blocks
Ejemplo n.º 14
0
def searchUnlinkedBlock():
    c = CoinSqlite3()._exec_sql('Select previous_block_hash from BlockInfo')
    preBlockHashs = []
    for tmp in c.fetchall():
        preBlockHashs.append(tmp[0])

    blocks = searchAll()
    unlinkedBlocks = []
    for block in blocks:
        if block.hash() not in preBlockHashs:
            unlinkedBlocks.append(block)
    return unlinkedBlocks
Ejemplo n.º 15
0
def save(txOut, tx, index):
    deleteOld(tx, index)
    pubicAddress = txOut.address()
    end_time = 0
    if TransactionUtils.isCFTransation(tx):
        if 0 == index:
            end_time = tx.cf_header.end_time
    CoinSqlite3().exec_sql(
        'INSERT INTO TransactionInfoOut(coin_value, script, parentBlockId, parentTxId, state, `index`, pubicAddress, isToMe, usedState, end_time, isMyTx) VALUES (?,?,?,?,?,?,?,?,?,?,?)',
        txOut.coin_value, txOut.script, tx.getBlockHash(), tx.hash(),
        txOut.state, index, pubicAddress,
        SecretKeyDao.isMypubicAddress(pubicAddress), 0, end_time,
        SecretKeyDao.isMypubicAddress(txOut.address()))
Ejemplo n.º 16
0
def searchByIndex(parentTxId, index):
    c = CoinSqlite3()._exec_sql(
        'Select * from TransactionInfoOut where parentTxId = ? And `index` = ?',
        parentTxId, index)
    return __getSearchResultSingle(c)
Ejemplo n.º 17
0
def search(parentBlockId, parentTxId):
    c = CoinSqlite3()._exec_sql(
        'Select * from TransactionInfoOut where parentTxId = ?', parentTxId)
    return __getSearchResult(c)
Ejemplo n.º 18
0
def searchById(id):
    c = CoinSqlite3()._exec_sql(
        'Select * from TransactionInfoOut where id = ? ', id)
    return __getSearchResultSingle(c)
Ejemplo n.º 19
0
def searchSpendById(id):
    c = CoinSqlite3()._exec_sql(
        'Select * from TransactionInfoOut where id = ? ', id)
    tmp = c.fetchone()
    spend = Spendable(tmp[1], tmp[2], tmp[4], tmp[6])
    return spend
Ejemplo n.º 20
0
def searchMyUnUsedNomalTxOuts():  #不包含未用的众筹交易
    c = CoinSqlite3()._exec_sql(
        'Select * from TransactionInfoOut where isMyTx = 1 and usedState = 0')
    return __getSearchResult(c)
Ejemplo n.º 21
0
def searchMyTotalTxOuts():  #包含未成功的众筹交易
    c = CoinSqlite3()._exec_sql(
        'Select * from TransactionInfoOut where end_time < ? and isToMe = 1 and parentBlockId != \'\'',
        int(time.time()))
    return __getSearchResult(c)
Ejemplo n.º 22
0
def insert(secret):
    CoinSqlite3().exec_sql('INSERT INTO SecretKeyInfo(publicKey, privateKey,pubicAddress, cert, sec_num) VALUES (?,?,?,?,?)', str(secret.publicKey), str(secret.privateKey), str(secret.pubicAddress), str(secret.cert), int(secret.sec_num)) 
Ejemplo n.º 23
0
def searchMyTxOuts():
    c = CoinSqlite3()._exec_sql(
        'Select * from TransactionInfoOut where isMyTx = 1')
    return __getSearchResult(c)
Ejemplo n.º 24
0
def updateEndTimeToZero(tx):
    CoinSqlite3().exec_sql(
        'Update TransactionInfoOut set `end_time`= ? where `parentTxId` = ? and `index` = 0',
        int(time.time()), tx.hash())
Ejemplo n.º 25
0
def searchAll():
    c = CoinSqlite3()._exec_sql('Select * from TransactionInfoOut')
    return __getSearchResult(c)
Ejemplo n.º 26
0
def updateAllLinkedCFTransationOut(hash):
    CoinSqlite3().exec_sql(
        'Update TransactionInfoOut set `usedState` = 1 where `parentTxId` = ? and `index` = 0',
        hash)
Ejemplo n.º 27
0
def deleteOld(tx, index):
    CoinSqlite3().exec_sql(
        'Delete from TransactionInfoOut where parentTxId = ? And `Index` = ?',
        tx.hash(), index)
Ejemplo n.º 28
0
def setStateUsed(hash, index):
    CoinSqlite3().exec_sql(
        'Update TransactionInfoOut set `usedState`=1 where `parentTxId` = ? and `index` = ?',
        hash, index)
Ejemplo n.º 29
0
def updateState(tx_out, tx_out_id):
    CoinSqlite3().exec_sql(
        'Update TransactionInfoOut set `usedState`=? where `id` = ?',
        tx_out.usedState, tx_out_id)
Ejemplo n.º 30
0
def isExist(secret):
    tmp = CoinSqlite3()._exec_sql('Select * from SecretKeyInfo where publicKey = ?', str(secret.publicKey))
    s = tmp.fetchone()
    return s != None