Me pehea te tuhi kirimana atamai ki Python i runga i te whatunga Ontology. Wāhanga 3: API Wāhaere

Me pehea te tuhi kirimana atamai ki Python i runga i te whatunga Ontology. Wāhanga 3: API Wāhaere

Koinei te wahanga tuatoru i roto i te raupapa tuhinga matauranga mo te hanga kirimana atamai i roto i te Python i runga i te whatunga poraka Ontology. I nga tuhinga o mua i mohio tatou

  1. Poraka & Paraka API
  2. API rokiroki.

Inaianei kei a koe te whakaaro me pehea te karanga i te API rokiroki pumau e tika ana i te wa e whakawhanake ana i tetahi kirimana atamai ma te whakamahi i te Python i runga i te whatunga Ontology, me haere tonu ki te ako me pehea te whakamahi. API Wāhaere (API Whakaoti kirimana). Kei te Runtime API nga API e 8 e whakarato ana i nga hononga noa mo te mahi kirimana me te awhina i nga kaihanga ki te tiki, ki te huri, ki te whakamana i nga raraunga.

Kei raro nei he whakamaarama poto mo nga raraunga API 8:

Me pehea te tuhi kirimana atamai ki Python i runga i te whatunga Ontology. Wāhanga 3: API Wāhaere

Kia ata tirohia me pehea te whakamahi i nga raraunga API 8. I mua i tenei, ka taea e koe te hanga kirimana hou i roto i te taputapu whakawhanake kirimana atamai Ontology SmartX ka whai i nga tohutohu i raro nei.

Me pehea te whakamahi i te Runtime API

E rua nga huarahi ki te kawemai API Wāhaere: ontology.interop.System.Runtime и ontology.interop.Ontology.Runtime. Kei te ara Ontology nga API katahi ano ka taapirihia. Ko nga raina i raro nei ka kawemai i nga raraunga API.

from ontology.interop.System.Runtime import GetTime, CheckWitness, Log, Notify, Serialize, Deserialize
from ontology.interop.Ontology.Runtime import Base58ToAddress, AddressToBase58, GetCurrentBlockHash

Whakamōhiotia API

Ko te mahi Whakamōhiotanga ka whakapaoho i te huihuinga puta noa i te whatunga. I roto i te tauira i raro nei, ka whakahokia e te mahi Whakamōhio te aho hex "kia ora" ka paoho puta noa i te whatunga.

from ontology.interop.System.Runtime import Notify
def demo():
    Notify("hello world")

Ka kite koe i tenei i nga raarangi:

Me pehea te tuhi kirimana atamai ki Python i runga i te whatunga Ontology. Wāhanga 3: API Wāhaere

API GetTime

Ko te mahi GetTime ka whakahoki i te tohu wa o naianei, e whakahoki ana i te wa Unix i karangahia ai te mahi. He tuarua te waeine ine.

from ontology.interop.System.Runtime import GetTime
def demo():
    time=GetTime()
    return time # return a uint num

GetCurrentBlockHash API

Ko te mahi GetCurrentBlockHash ka whakahoki i te hash o te poraka o naianei.

from ontology.interop.Ontology.Runtime import GetCurrentBlockHash
def demo():
    block_hash = GetCurrentBlockHash()
    return block_hash

Whakaraupapa me te Deserialize

He takirua tenei o nga mahi whakahiato me te whakakore. Ko te mahi Serialize ka huri i tetahi mea ki te ahanoa bytearray, a ko te Deserialize mahi he huri i te bytearray ki te ahanoa taketake. Ko te tauira waehere i raro nei ka huri i nga tawhā taumai me te penapena i roto i te rokiroki pumau o te kirimana. Ka tikina ano e ia nga raraunga mai i te rokiroki pumau o te kirimana me te huri hei taonga taketake.

from ontology.interop.System.Runtime import GetTime, CheckWitness, Log, Notify, Serialize, Deserialize
from ontology.interop.System.Storage import Put, Get, GetContext

def Main(operation, args):
    if operation == 'serialize_to_bytearray':
        data = args[0]
        return serialize_to_bytearray(data)
    if operation == 'deserialize_from_bytearray':
        key = args[0]
        return deserialize_from_bytearray(key)
    return False


def serialize_to_bytearray(data):
    sc = GetContext()
    key = "1"
    byte_data = Serialize(data)
    Put(sc, key, byte_data)


def deserialize_from_bytearray(key):
    sc = GetContext()
    byte_data = Get(sc, key)
    data = Deserialize(byte_data)
    return data

Base58ToAddress and AddressToBase58

Ko tenei takirua o nga mahi whakamaori wahitau. Ko te mahi Base58ToAddress ka huri i tetahi wahitau kua whakawaeheretia base58 ki te wahitau taurangi, a ka huri a AddressToBase58 i tetahi wahitau bytearray ki tetahi wahitau kua whakawaeheretia base58.

from ontology.interop.Ontology.Runtime import Base58ToAddress, AddressToBase58
def demo():
    base58_addr="AV1GLfVzw28vtK3d1kVGxv5xuWU59P6Sgn"
    addr=Base58ToAddress(base58_addr)
    Log(addr)
    base58_addr=AddressToBase58(addr)
    Log(base58_addr)

Tirohia te kaiwhakaatu

Ko te mahi CheckWitness(fromAcct) e rua nga mahi:

  • Manatoko mena noAcct te kaiwaea o te mahi o naianei. Mena ae (ara, kua paahitia te hainatanga hainatanga), ka hoki mai te mahi.
  • Tirohia mehemea he kirimana te mea e karanga ana i te mahi o naianei. Mena he kirimana me te mahi i mahia mai i te kirimana, ka paahitia te manatoko. Arā, tirohia mēnā ko fromAcct te uara whakahoki o GetCallingScriptHash(). Ka taea e te mahi GetCallingScriptHash() te tango i te uara hash kirimana o te kirimana atamai o naianei.

GetCallingScriptHash():

Ētahi atu Guthub

from ontology.interop.System.Runtime import CheckWitness
from ontology.interop.Ontology.Runtime import Base58ToAddress
def demo():
    addr=Base58ToAddress("AW8hN1KhHE3fLDoPAwrhtjD1P7vfad3v8z")
    res=CheckWitness(addr)
    return res

Ka kitea etahi atu korero i Guthub. I roto i te tuhinga ka whai ake ka whakaatu API Maoriki te ako me pehea te whakawhiti rawa i roto i nga kirimana atamai Ontology.

I whakamaoritia te tuhinga e nga kaiwhakatikatika Hashrate&Shares rawa mo OntologyRussia.

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

Tuwhera nga mahi mo nga kaihanga. Whakaotia te mahi ka whiwhi utu.

Tonoa inaianei mo te kaupapa Ontology talent mo nga tauira

Tuhinga

pae tukutuku Ontology - GitHub - Korero - Telegram English - Twitter - Reddit

Source: will.com

Tāpiri i te kōrero