Hauv tsab xov xwm no, peb yuav pib peb cov kev paub nrog Ontology ntse daim ntawv cog lus API. Ontology ntse daim ntawv cog lus API muab faib ua 7 modules:
Blockchain & Block API,
runtime API,
API cia khoom,
Native API
Txhim kho API,
Execution Engine API thiab
Static & Dynamic Hu API.
Blockchain & Block API yog qhov tseem ceeb ntawm Ontology ntse daim ntawv cog lus. Blockchain API txhawb nqa kev ua haujlwm ntawm blockchain cov lus nug, xws li tau txais qhov siab tam sim no, thaum Block API txhawb nqa cov lus nug yooj yim, xws li nug tus lej ntawm kev lag luam rau ib qho thaiv.
Cia peb pib!
Ua ntej, tsim ib daim ntawv cog lus tshiab hauv SmartXthiab tom qab ntawd ua raws li cov lus qhia hauv qab no.
1. Yuav siv Blockchain API li cas
Txuas mus rau cov ntawv cog lus ntse ua haujlwm zoo ib yam rau Python txuas. Koj tuaj yeem nkag mus rau cov haujlwm sib xws raws li xav tau. Piv txwv li, nqe lus hauv qab no qhia txog GetHeight muaj nuj nqi kom tau txais qhov siab tam sim no, thiab GetHeader muaj nuj nqi kom tau txais lub block header.
from ontology.interop.System.Blockchain import GetHeight, GetHeader
GetHeight
GetHeight yog siv kom tau txais tus lej ntu ntu kawg hauv blockchain, raws li qhia hauv qhov piv txwv hauv qab no. Hauv qhov piv txwv kawg, peb yuav tshem tawm Cov Haujlwm Tseem Ceeb kom yooj yim, tab sis koj tuaj yeem ntxiv nws yog tias tsim nyog.
from ontology.interop.System.Runtime import Notify
from ontology.interop.System.Blockchain import GetHeight
def Main(operation):
if operation == 'demo':
return demo()
return False
def demo():
height=GetHeight()
Notify(height) # print height
return height #return height after running the function
GetHeader
GetHeader yog siv kom tau lub block header, parameter yog tus naj npawb ntawm cov block hauv blockchain. Piv txwv:
from ontology.interop.System.Runtime import Notify
from ontology.interop.System.Blockchain import GetHeader
def demo():
block_height=10
header=GetHeader(block_height)
Notify(header)
return header
GetTransactionByHash
GetTransactionByHash yog siv kom tau txais kev sib pauv ntawm kev sib pauv hash. Kev hloov pauv hash raug xa mus rau GetTransactionByHash raws li tsis muaj nyob rau hauv bytearray hom. Tus yuam sij rau txoj haujlwm no yog hloov pauv cov kev sib pauv hash hauv hom hex rau kev sib pauv hash hauv hom ntawv bytearray. Qhov no yog ib kauj ruam tseem ceeb. Txwv tsis pub, koj yuav tau txais qhov yuam kev uas qhia tias tsis muaj qhov thaiv nrog qhov thaiv qhov thaiv ntawd. Cia peb coj cov kev sib pauv hash hauv hex hom ua piv txwv los hloov nws mus rau hom ntawv bytearray. Ib qho piv txwv zoo li no:
GetTransactionCount yog siv kom tau txais tus lej ntawm kev hloov pauv rau qhov muab thaiv.
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
Cov neeg tsim khoom tuaj yeem siv GetTransactions muaj nuj nqi kom tau txais tag nrho cov kev lag luam hauv ib qho thaiv.
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
GetTransactionByIndex yog siv kom tau txais ib qho kev lag luam tshwj xeeb hauv ib qho thaiv.
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
Daim ntawv qhia ua tiav tuaj yeem pom ntawm peb GitHub.
Tom qab ntawd
Blockchain & Block API yog ib qho tseem ceeb ntawm cov ntawv cog lus ntse raws li koj tuaj yeem siv lawv los thov cov ntaub ntawv blockchain thiab thaiv cov ntaub ntawv hauv cov ntawv cog lus ntse. Hauv cov ntawv yav tom ntej, peb yuav tham txog yuav ua li cas siv lwm tus APIs thiab nrhiav seb lawv cuam tshuam li cas nrog Ontology blockchain.