from ontology.interop.System.Blockchain import GetBlock
def demo():
block=GetBlock(1408)
return block
2. 逐块获取哈希值:
from ontology.interop.System.Blockchain import GetBlock
def demo():
block_hash=bytearray(b'x16xe0xc5x40x82x79x77x30x44xeax66xc8xc4x5dx17xf7x17x73x92x33x6dx54xe3x48x46x0bxc3x2fxe2x15x03xe4')
block=GetBlock(block_hash)
2. 如何使用区块API
Block API 中有 XNUMX 个可用函数: 获取交易, 获取交易计数和 按索引获取交易。 我们将一一整理。
获取交易计数
GetTransactionCount 用于获取给定块的交易数量。
from ontology.interop.System.Blockchain import GetBlock
from ontology.interop.System.Block import GetTransactionCount
def demo():
block=GetBlock(1408)
count=GetTransactionCount(block)
return count
获取交易
开发人员可以使用 GetTransactions 函数检索给定区块中的所有交易。
from ontology.interop.System.Blockchain import GetBlock
from ontology.interop.System.Block import GetTransactions
def demo():
block=GetBlock(1408)
txs=GetTransactions(block)
return txs
按索引获取交易
GetTransactionByIndex 用于检索给定块中的特定交易。
from ontology.interop.System.Blockchain import GetBlock
from ontology.interop.System.Block import GetTransactionByIndex
def demo():
block=GetBlock(1408)
tx=GetTransactionByIndex(block,0) # index starts from 0.
return tx