Me pehea te tuhi kirimana atamai ki Python i runga i te whatunga Ontology. Wāhanga 1: Poraka & Poraka API

Me pehea te tuhi kirimana atamai ki Python i runga i te whatunga Ontology. Wāhanga 1: Poraka & Poraka API

Koinei te waahanga tuatahi o te raupapa tuhinga matauranga mo te hanga kirimana atamai i roto i te Python i runga i te whatunga poraka Ontology ma te whakamahi i te taputapu whakawhanake kirimana atamai. SmartX.

I roto i tenei tuhinga, ka timata taatau ki te mohio ki te API kirimana atamai Ontology. Kua wehea te API kirimana atamai Ontology ki nga waahanga e 7:

  1. Poraka & Paraka API,
  2. API Wāhaere
  3. API rokiroki
  4. API Maori
  5. Whakapai API,
  6. Execution Engine API me
  7. API Waea Hangarau me te Hihiko.

Ko te Blockchain & Block API te waahanga matua o te punaha kirimana atamai Ontology. Ka tautokohia e te Blockchain API nga mahinga uiui poraka matua, penei i te whiwhi i te teitei o naianei o te poraka, i te wa e tautoko ana te Blockchain API i nga mahi uiui poraka taketake, penei i te uiui i te maha o nga whakawhitinga mo tetahi poraka.

Kia timata tatou!

Hei timata, hanga he kirimana hou ki roto SmartX, ka whai i nga tohutohu i raro nei.

1. Me pehea te whakamahi Blockchain API

He rite nga tohutoro mahi kirimana atamai ki nga tohutoro Python. Ka taea e koe te whakauru i nga mahi e tika ana ina hiahiatia. Hei tauira, ko te korero e whai ake nei e whakaatu ana i a GetHeight, he mahi hei tiki i te teitei o te poraka, me te GetHeader, he mahi hei tiki i te taitara o te poraka.

from ontology.interop.System.Blockchain import GetHeight, GetHeader

TikinaTeitei

Ka whakamahia a GetHeight ki te tiki i te tau raupapa poraka whakamutunga i roto i te poraka, penei i te tauira i raro nei. I te tauira whakamutunga, mo te waatea, ka pekehia e matou te mahi Matua, engari ka taea e koe te taapiri mena e tika ana.

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

Tikina Panepoko

Ka whakamahia te GetHeader ki te tiki i te pane paraka; ko te tawhā ko te tau rangatū o te poraka i roto i te poraka. Tauira:

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

TikinaTransactionByHash

Ka whakamahia te GetTransactionByHash ki te tiki i tetahi tauwhitinga ma te whakamahi i te hash tauwhitinga. Ka tukuna te hash tauwhitinga ki TikinaTransactionByHash hei tawhā i roto i te whakatakotoranga taarua. Ko te matua ki tenei mahi ko te huri i te hash tauwhitinga i te whakatakotoranga hex ki te hash tauwhitinga i roto i te whakatakotoranga bytearray. He taahiraa nui tenei. Ki te kore ka puta he hapa e tohu ana karekau he paraka me taua hash poraka. Me tango te hash tauwhitinga i roto i te whakatakotoranga hex hei tauira hei huri ki te whakatakotoranga bytearray. He penei te ahua o te tauira:

9f270aa3a4c13c46891ff0e1a2bdb3ea0525669d414994aadf2606734d0c89c1

Whakahokia tuatahi te Hash tauwhitinga:

c1890c4d730626dfaa9449419d662505eab3bda2e1f01f89463cc1a4a30a279

Ka taea e nga kaiwhakawhanake te mahi i tenei mahi ma te whakamahi i te Hex Number(iti iti) taputapu hurihanga Tau na SmartX.

Na ka huri i te hua ka puta ki te whakatakotoranga bytearray:

{0xc1,0x89,0x0c,0x4d,0x73,0x06,0x26,0xdf,0xaa,0x94,0x49,0x41,0x9d,0x66,0x25,0x05,0xea,0xb3,0xbd,0xa2,0xe1,0xf0,0x1f,0x89,0x46,0x3c,0xc1,0xa4,0xa3,0x0a,0x27,0x9f}

Ka taea tenei ma te whakamahi i te taputapu hurihanga String Byte Array e whakaratohia ana e SmartX. Hei whakamutunga, huri i te bytearray ka puta hei aho penei:

xc1x89x0cx4dx73x06x26xdfxaax94x49x41x9dx66x25x05xeaxb3xbdxa2xe1xf0x1fx89x46x3cxc1xa4xa3x0ax27x9f

Kei raro nei he tauira o te mahi GetTransactionByHash, e tango ana i te tauwhitinga ma te hash tauwhitinga:

from ontology.interop.System.Blockchain import GetTransactionByHash
def demo():
    # tx_hash="9f270aa3a4c13c46891ff0e1a2bdb3ea0525669d414994aadf2606734d0c89c1"    
    tx_hash=bytearray(b"xc1x89x0cx4dx73x06x26xdfxaax94x49x41x9dx66x25x05xeaxb3xbdxa2xe1xf0x1fx89x46x3cxc1xa4xa3x0ax27x9f")
    tx=GetTransactionByHash(tx_hash)
    return tx

TikinaTransactionHeight

Ka whakamahia te GetTransactionHeight ki te tiki i te teitei tauwhitinga ma te whakamahi i te hash tauwhitinga. Me tango te hash mai i te tauira i runga ake nei:

from ontology.interop.System.Blockchain import  GetTransactionHeight
def demo():
    #   tx_hash="9f270aa3a4c13c46891ff0e1a2bdb3ea0525669d414994aadf2606734d0c89c1"    
    tx_hash=bytearray(b"xc1x89x0cx4dx73x06x26xdfxaax94x49x41x9dx66x25x05xeaxb3xbdxa2xe1xf0x1fx89x46x3cxc1xa4xa3x0ax27x9f")
    height=GetTransactionHeight(tx_hash)
    return height

TikinaContract

Ka taea e nga kaiwhakawhanake te whakamahi i te mahi GetContract ki te tiki i tetahi kirimana ma te haina kirimana. Ko te tukanga whakawhiti hash kirimana he rite tonu ki te tukanga whakawhiti hash whakawhitinga kua whakahuahia i runga ake nei.

from ontology.interop.System.Blockchain import GetContract
def demo():
    # contract_hash="d81a75a5ff9b95effa91239ff0bb3232219698fa"    
    contract_hash=bytearray(b"xfax98x96x21x32x32xbbxf0x9fx23x91xfaxefx95x9bxffxa5x75x1axd8")
    contract=GetContract(contract_hash)
    return contract

GetPoraka

Ka whakamahia te GetBlock ki te tiki poraka. E rua nga huarahi ki te tiki poraka motuhake.

1. Tikina he poraka ma ia poraka teitei:

from ontology.interop.System.Blockchain import GetBlock
def demo():
    block=GetBlock(1408)
    return block

2. Tikina he poraka ma ia poraka Hash:

from ontology.interop.System.Blockchain import GetBlock
def demo():    
    block_hash=bytearray(b'x16xe0xc5x40x82x79x77x30x44xeax66xc8xc4x5dx17xf7x17x73x92x33x6dx54xe3x48x46x0bxc3x2fxe2x15x03xe4')
    block=GetBlock(block_hash)

2. Me pehea te whakamahi Poraka API

E toru nga mahi e waatea ana i te API Poraka: Tikina Tauwhitinga, TikinaKauteKautea TikinaTransactionByIndex. Ma tatou e whakariterite takitahi.

TikinaKauteKaute

Ka whakamahia te GetTransactionCount ki te tiki i te maha o nga tauwhitinga mo tetahi poraka.

from ontology.interop.System.Blockchain import GetBlock
from ontology.interop.System.Block import GetTransactionCount
def demo():
    block=GetBlock(1408)
    count=GetTransactionCount(block)
    return count

Tikina Tauwhitinga

Ka taea e nga Kaihanga te whakamahi i te mahi GetTransactions ki te tiki i nga whakawhitinga katoa i roto i tetahi poraka kua tohua.

from ontology.interop.System.Blockchain import GetBlock
from ontology.interop.System.Block import GetTransactions 
def demo():
    block=GetBlock(1408)
    txs=GetTransactions(block)
    return txs

TikinaTransactionByIndex

Ka whakamahia te GetTransactionByIndex ki te tiki i tetahi tauwhitinga motuhake i roto i tetahi poraka kua tohua.

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

Ko te aratohu katoa ka kitea i runga i ta maatau GitHub.

Afterword

Ko te Blockchain & Block API tetahi waahanga nui o nga kirimana atamai na te mea ka taea e koe te whakamahi ki te uiui i nga raraunga poraka me te aukati i nga raraunga i roto i nga kirimana atamai. I roto i nga tuhinga a muri ake nei, ka matapakihia me pehea te whakamahi i nga API e toe ana me te mohio me pehea te taunekeneke me te Ontology blockchain.

I whakamaoritia te tuhinga e nga kaiwhakatikatika o Hashrate&Shares ina koa mo OntologyRussia. tangi

He kaiwhakawhanake koe? Hono mai ki ta maatau hapori hangarau i Korero. Ano, tirohia Pokapū Kaiwhakawhanake i runga i ta maatau paetukutuku, ka kitea e koe nga taputapu kaiwhakawhanake, tuhinga, me etahi atu.

Tuhinga

Source: will.com

Tāpiri i te kōrero