예제 #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)  
예제 #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)  
예제 #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
예제 #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
예제 #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-----
예제 #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
예제 #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
예제 #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)
예제 #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)
예제 #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
예제 #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
예제 #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
예제 #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
예제 #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
예제 #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()))
예제 #16
0
def searchByIndex(parentTxId, index):
    c = CoinSqlite3()._exec_sql(
        'Select * from TransactionInfoOut where parentTxId = ? And `index` = ?',
        parentTxId, index)
    return __getSearchResultSingle(c)
예제 #17
0
def search(parentBlockId, parentTxId):
    c = CoinSqlite3()._exec_sql(
        'Select * from TransactionInfoOut where parentTxId = ?', parentTxId)
    return __getSearchResult(c)
예제 #18
0
def searchById(id):
    c = CoinSqlite3()._exec_sql(
        'Select * from TransactionInfoOut where id = ? ', id)
    return __getSearchResultSingle(c)
예제 #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
예제 #20
0
def searchMyUnUsedNomalTxOuts():  #不包含未用的众筹交易
    c = CoinSqlite3()._exec_sql(
        'Select * from TransactionInfoOut where isMyTx = 1 and usedState = 0')
    return __getSearchResult(c)
예제 #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)
예제 #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)) 
예제 #23
0
def searchMyTxOuts():
    c = CoinSqlite3()._exec_sql(
        'Select * from TransactionInfoOut where isMyTx = 1')
    return __getSearchResult(c)
예제 #24
0
def updateEndTimeToZero(tx):
    CoinSqlite3().exec_sql(
        'Update TransactionInfoOut set `end_time`= ? where `parentTxId` = ? and `index` = 0',
        int(time.time()), tx.hash())
예제 #25
0
def searchAll():
    c = CoinSqlite3()._exec_sql('Select * from TransactionInfoOut')
    return __getSearchResult(c)
예제 #26
0
def updateAllLinkedCFTransationOut(hash):
    CoinSqlite3().exec_sql(
        'Update TransactionInfoOut set `usedState` = 1 where `parentTxId` = ? and `index` = 0',
        hash)
예제 #27
0
def deleteOld(tx, index):
    CoinSqlite3().exec_sql(
        'Delete from TransactionInfoOut where parentTxId = ? And `Index` = ?',
        tx.hash(), index)
예제 #28
0
def setStateUsed(hash, index):
    CoinSqlite3().exec_sql(
        'Update TransactionInfoOut set `usedState`=1 where `parentTxId` = ? and `index` = ?',
        hash, index)
예제 #29
0
def updateState(tx_out, tx_out_id):
    CoinSqlite3().exec_sql(
        'Update TransactionInfoOut set `usedState`=? where `id` = ?',
        tx_out.usedState, tx_out_id)
예제 #30
0
def isExist(secret):
    tmp = CoinSqlite3()._exec_sql('Select * from SecretKeyInfo where publicKey = ?', str(secret.publicKey))
    s = tmp.fetchone()
    return s != None