コード例 #1
0
def insert(blockchain):
    if BlockchainDao.isExist(blockchain):
        return

    if BlockchainDao.isPreBlockLinked(blockchain):  #如果前一个区块被链接了  则失效
        return

    for tx in blockchain.txs:
        TransactionUtils.updatePreOutState(tx)

    BlockchainDao.save(blockchain)
コード例 #2
0
def searchParentBlock(tx):
    blockHash = None
    if isinstance(tx, Transaction):
        blockHash = TransactionDao.searchParentBlockHash(tx)
    elif isinstance(tx, TransactionOut):
        blockHash = TransactionOutDao.searchParentBlockHash(tx)
    if blockHash == None:
        return None
    else:
        return BlockchainDao.search(blockHash)
コード例 #3
0
def main():
    parser = argparse.ArgumentParser(
        description="Dump a block in human-readable form.")
    parser.add_argument("block_bin",
                        nargs="+",
                        type=argparse.FileType('rb'),
                        help='The file containing the binary block.')

    args = parser.parse_args()
    #     pbkey = '1693NYwCPZYAdF1pYdVfrfCR6c9acpNGQd'
    #     cf_header = CFHeader(ZERO32, 10, pbkey, time.time()+3600, ZERO32, 10)
    #     TransactionUtils.createCFTransaction([], cf_header, spendValue=0, publicAddrToValueDict=[[]])
    #     TransactionUtils.createFirstTransaction({"17ZaizPFAB76bVXXDZNMHunzeoFjrwGtS2":100})
    for f in args.block_bin:
        for i in range(1, 5):
            SecretKeyUtils.manageKey(10 * i)
        block = Block.parse(f)

        BlockchainDao.save(block)
        print(block.hash())
        tmp = BlockchainDao.search(block.hash())
        print(tmp.hash())
        dump_block(block)
        print('')
コード例 #4
0
def get_block_info(block_hash):
    block = BlockchainDao.search(block_hash)
    wblock = WBlock(block)
    wblock.get_details()
    return wblock
コード例 #5
0
def get_blocks():
    wblocks = []
    blocks = BlockchainDao.searchAll()
    for block in blocks:
        wblocks.append(WBlock(block))
    return wblocks