当前位置: 首页>>代码示例>>Python>>正文


Python Storage.get_all方法代码示例

本文整理汇总了Python中storage.Storage.get_all方法的典型用法代码示例。如果您正苦于以下问题:Python Storage.get_all方法的具体用法?Python Storage.get_all怎么用?Python Storage.get_all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在storage.Storage的用法示例。


在下文中一共展示了Storage.get_all方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ColorBuilder

# 需要导入模块: from storage import Storage [as 别名]
# 或者: from storage.Storage import get_all [as 别名]
class ColorBuilder(object):
    def __init__(self, seed, kernel, printer):
        self.__seed = seed
        self.__kernel = kernel
        self.__storage = Storage()
        self.__knownTxs = set((seed.txhash,))
        self.__access = rpc_access.fromFile('../data/rpc.ini')
        self.__printer = printer
        coloredTxs = self.__storage.get_all(seed.color_id)
        for tx in coloredTxs:
            self.__knownTxs.add(str(tx[0]))
            
    def isColored(self, tx):
        for inp in tx.inputs:
            if ('txid' in inp) and (inp['txid'] in self.__knownTxs):
                return True
        return False

    def processBlock(self, blockHeight):
        txhashes = self.__access.getblock(self.__access.getblockhash(blockHeight))['tx']
        for txhash in txhashes:
            tx = Transaction(self.__access.getrawtransaction(txhash, 1))
            if not self.isColored(tx):
                continue
            
            colorVals = list()
            self.__printer(txhash + ", inputs: " + str(len(tx.inputs)) + ", outputs: " + str(len(tx.outputs)))

            for inp in tx.inputs:
                prevHash = inp['txid']
                prevTx = Transaction(self.__access.getrawtransaction(prevHash, 1))
#                   print(str(t1.duration_in_seconds())  + ", inputs: " + str(len(prevTx['vin'])) + ", outputs: " + str(len(prevTx['vout'])))
                prevOutIndex = inp['outindx']
                colorVal = self.__storage.get(self.__seed.color_id, prevHash, prevOutIndex)
                colorVals.append((prevTx.outputs[prevOutIndex], colorVal))
            colorOuts = self.__kernel(tx, colorVals)

            colorFound = False
            for i, colorOut in enumerate(colorOuts):
                if colorOut[0] != 0:
                    self.__storage.add(self.__seed.color_id, txhash, i, colorOut[0], colorOut[1])
                    colorFound = True
            if colorFound:
                self.__knownTxs.add(str(txhash))
                

    def build(self):
        seedTransaction = self.__access.getrawtransaction(self.__seed.txhash, 1)
        for i, seedOut in enumerate(self.__seed.outputs):
            self.__storage.add(self.__seed.color_id, self.__seed.txhash, i, seedOut.value, seedOut.label)
            
        block = self.__access.getblock(seedTransaction['blockhash'])
        blockHeight = block['height']
        while blockHeight <= self.__access.getblockcount():
            self.__printer(blockHeight)
            self.processBlock(blockHeight)
            blockHeight += 1
开发者ID:stdset,项目名称:colored-coins,代码行数:59,代码来源:build.py

示例2: simplePrint

# 需要导入模块: from storage import Storage [as 别名]
# 或者: from storage.Storage import get_all [as 别名]
from build import ColorBuilder
from transaction import *
from ordercoloring import orderColoring
from storage import Storage


txhashes = ['b1586cd10b32f78795b86e9a3febe58dcb59189175fad884a7f4a6623b77486e',
            '8f6c8751f39357cd42af97a67301127d497597ae699ad0670b4f649bd9e39abf']

def simplePrint(x):
    print(x)

def silent(x):
    pass

blueColorId = 1
blueSeed = ColoredSeed(txhashes[0], [ColoredOutput(1, ''),], blueColorId)
builder = ColorBuilder(blueSeed, orderColoring, simplePrint)
builder.build()

stor = Storage()
with stor:
    res = stor.get_all(blueColorId)
for i in res:
    print(i)
开发者ID:stdset,项目名称:colored-coins,代码行数:27,代码来源:test.py


注:本文中的storage.Storage.get_all方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。