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