၎င်းသည် Ontology blockchain ကွန်ရက်ရှိ Python တွင် စမတ်စာချုပ်များဖန်တီးခြင်းဆိုင်ရာ ပညာပေးဆောင်းပါးစီးရီးများ၏ တတိယအပိုင်းဖြစ်သည်။ အရင်ဆောင်းပါးတွေမှာ ကျွန်တော် သိဖူးပါတယ်။
Ontology ကွန်ရက်ပေါ်ရှိ Python ကို အသုံးပြု၍ စမတ်ကျသည့် စာချုပ်တစ်ခုကို တီထွင်သည့်အခါ သင့်လျော်သော မြဲမြံသောသိုလှောင်မှု API ကို မည်သို့ခေါ်ဆိုရမည်ကို စိတ်ကူးရပြီဆိုလျှင်၊ အသုံးပြုနည်းကို လေ့လာကြပါစို့။ Runtime API (Contract Execution API)။ Runtime API တွင် စာချုပ်အကောင်အထည်ဖော်မှုအတွက် ဘုံအင်တာဖေ့စ်များကို ပံ့ပိုးပေးသည့် ဆက်စပ် API 8 ခု ရှိပြီး ဆော့ဖ်ဝဲရေးသားသူများ ဒေတာကို ပြန်လည်ရယူရန်၊ ပြောင်းလဲရန်နှင့် တရားဝင်အောင်ပြုလုပ်ရန် ကူညီပေးသည်။
အောက်တွင် 8 API ဒေတာ၏ အကျဉ်းချုပ် ဖော်ပြချက်ဖြစ်ပါသည်။
8 API ဒေတာကို အသုံးပြုပုံကို အနီးကပ် လေ့လာကြည့်ရအောင်။ ယင်းမတိုင်မီတွင်၊ သင်သည် Ontology စမတ်စာချုပ်ဖွံ့ဖြိုးတိုးတက်ရေးကိရိယာတွင် စာချုပ်အသစ်တစ်ခုကို ဖန်တီးနိုင်သည်။
Runtime API ကိုအသုံးပြုနည်း
တင်သွင်းရန်နည်းလမ်းနှစ်ခုရှိသည်။ Runtime API- ontology.interop.System.Runtime и ontology.interop.Ontology.Runtime. Ontology လမ်းကြောင်းတွင် အသစ်ထည့်ထားသော API များပါရှိသည်။ အောက်ပါလိုင်းများသည် API ဒေတာကို တင်သွင်းသည်။
from ontology.interop.System.Runtime import GetTime, CheckWitness, Log, Notify, Serialize, Deserialize
from ontology.interop.Ontology.Runtime import Base58ToAddress, AddressToBase58, GetCurrentBlockHash
API ကို အသိပေးပါ။
Notify လုပ်ဆောင်ချက်သည် အဖြစ်အပျက်အား ကွန်ရက်တစ်လျှောက် ထုတ်လွှင့်ပေးသည်။ အောက်ဖော်ပြပါ ဥပမာတွင်၊ Notify လုပ်ဆောင်ချက်သည် hex string “hello word” ကို ပြန်ပေးမည်ဖြစ်ပြီး ၎င်းကို ကွန်ရက်တစ်လျှောက် ထုတ်လွှင့်မည်ဖြစ်သည်။
from ontology.interop.System.Runtime import Notify
def demo():
Notify("hello world")
ဤအရာကို မှတ်တမ်းများတွင် သင်တွေ့နိုင်သည်-
GetTime API
GetTime လုပ်ဆောင်ချက်သည် လုပ်ဆောင်ချက်ဟုခေါ်သည့် Unix အချိန်ကို ပြန်ပေးသည့် လက်ရှိအချိန်တံဆိပ်ကို ပြန်ပေးသည်။ တိုင်းတာမှုယူနစ်သည် ဒုတိယဖြစ်သည်။
from ontology.interop.System.Runtime import GetTime
def demo():
time=GetTime()
return time # return a uint num
GetCurrentBlockHash API
GetCurrentBlockHash လုပ်ဆောင်ချက်သည် လက်ရှိ block ၏ hash ကို ပြန်ပေးသည်။
from ontology.interop.Ontology.Runtime import GetCurrentBlockHash
def demo():
block_hash = GetCurrentBlockHash()
return block_hash
Serialize နှင့် Deserialize
၎င်းသည် အမှတ်စဉ်နှင့် ဖယ်ထုတ်ခြင်း လုပ်ဆောင်ချက် တစ်စုံဖြစ်သည်။ Serialize လုပ်ဆောင်ချက်သည် အရာဝတ္ထုတစ်ခုအား bytearray အရာဝတ္ထုတစ်ခုအဖြစ်သို့ ပြောင်းလဲပေးပြီး Deserialize လုပ်ဆောင်ချက်သည် bytearray ကို မူရင်းအရာဝတ္ထုအဖြစ်သို့ ပြောင်းလဲပေးသည်။ အောက်ဖော်ပြပါ ကုဒ်နမူနာသည် ဝင်လာသည့် ကန့်သတ်ချက်များကို ပြောင်းလဲပြီး ၎င်းတို့ကို စာချုပ်၏ မြဲမြံသောသိုလှောင်မှုတွင် သိမ်းဆည်းထားသည်။ ၎င်းသည် စာချုပ်၏ မြဲမြံသောသိုလှောင်မှုမှ ဒေတာကို ထုတ်ယူပြီး မူရင်းအရာဝတ္ထုအဖြစ် ပြောင်းလဲပေးသည်။
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 နှင့် AddressToBase58
ဤလိပ်စာကို ဘာသာပြန်ခြင်း လုပ်ဆောင်ချက်တစ်စုံ။ Base58ToAddress လုပ်ဆောင်ချက်သည် base58 ကုဒ်လုပ်ထားသော လိပ်စာကို bytearray လိပ်စာသို့ ပြောင်းပေးကာ AddressToBase58 သည် bytearray လိပ်စာကို 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)
သက်သေစစ်ဆေးပါ။
CheckWitness(fromAcct) လုပ်ဆောင်ချက်တွင် လုပ်ဆောင်နိုင်စွမ်း နှစ်ခုရှိသည်။
- လက်ရှိလုပ်ဆောင်ချက်၏ခေါ်ဆိုသူသည်Acct မှဟုတ်မဟုတ် အတည်ပြုပါ။ ဟုတ်သည် (ဆိုလိုသည်မှာ၊ လက်မှတ်အတည်ပြုခြင်းအောင်မြင်သွားလျှင်) လုပ်ဆောင်ချက်သည်ပြန်လာသည်။
- လက်ရှိလုပ်ဆောင်ချက်ကို ခေါ်သည့် အရာဝတ္ထုသည် စာချုပ်ဖြစ်မဖြစ် စစ်ဆေးပါ။ အကယ်၍ ၎င်းသည် စာချုပ်တစ်ခုဖြစ်ပြီး အဆိုပါလုပ်ငန်းကို စာချုပ်မှ အကောင်အထည်ဖော်ပါက၊ စိစစ်အတည်ပြုခြင်းကို ကျော်လွန်ပါသည်။ ဆိုလိုသည်မှာ၊ Acct မှ GetCallingScriptHash() ၏ ပြန်လာတန်ဖိုး ဟုတ်မဟုတ် စစ်ဆေးပါ။ GetCallingScriptHash() လုပ်ဆောင်ချက်သည် လက်ရှိစမတ်စာချုပ်၏ စာချုပ် hash တန်ဖိုးကို ရယူနိုင်သည်။
GetCallingScriptHash():
အပေါ်ပိုမိုသောအချက်အလက်များ
from ontology.interop.System.Runtime import CheckWitness
from ontology.interop.Ontology.Runtime import Base58ToAddress
def demo():
addr=Base58ToAddress("AW8hN1KhHE3fLDoPAwrhtjD1P7vfad3v8z")
res=CheckWitness(addr)
return res
အသေးစိတ်အချက်အလက်များကို တွင် ကြည့်ရှုနိုင်ပါသည်။
ဆောင်းပါးကို တည်းဖြတ်သူများမှ ဘာသာပြန်ပါသည်။
Hashrate & မျှဝေမှုများ အထူးသဖြင့် OntologyRussia အတွက်။
သင်က developer တစ်ယောက်လား။ ကျွန်ုပ်တို့၏နည်းပညာအသိုင်းအဝိုင်းတွင် ပါဝင်လိုက်ပါ။
Ontology
source: www.habr.com