၎င်းသည် စမတ်ကန်ထရိုက်ဖွံ့ဖြိုးတိုးတက်ရေးကိရိယာကို အသုံးပြု၍ Ontology blockchain ကွန်ရက်တွင် Python စမတ်စာချုပ်များဖန်တီးခြင်းဆိုင်ရာ သင်ခန်းစာစီးရီးများ၏ ပထမပိုင်းဖြစ်သည်။
ဤဆောင်းပါးတွင်၊ ကျွန်ုပ်တို့သည် Ontology စမတ်စာချုပ် API နှင့် ကျွန်ုပ်တို့၏အသိအကျွမ်းကို စတင်ပါမည်။ Ontology စမတ်စာချုပ် API ကို module 7 ခု ခွဲထားသည်။
- Blockchain & Block API၊
- runtime API၊
- သိုလှောင်မှု API၊
- မူရင်း API၊
- API အဆင့်မြှင့်ခြင်း၊
- Execution Engine API နှင့်
- Static & Dynamic Call API။
Blockchain & Block API သည် Ontology စမတ်စာချုပ်စနစ်၏ အဓိကအစိတ်အပိုင်းဖြစ်သည်။ Blockchain API သည် လက်ရှိ block အမြင့်ကို ရယူခြင်းကဲ့သို့သော အခြေခံ blockchain query operations များကို ပံ့ပိုးပေးထားပြီး Block API သည် ပေးထားသော block တစ်ခုအတွက် ငွေပေးငွေယူအရေအတွက်ကို မေးမြန်းခြင်းကဲ့သို့သော အခြေခံလုပ်ကွက်မေးမြန်းခြင်းလုပ်ငန်းဆောင်တာများကို ပံ့ပိုးပေးပါသည်။
စလိုက်ကြစို့!
ပထမဦးစွာ စာချုပ်အသစ်ဖန်တီးပါ။
1. Blockchain API ကိုအသုံးပြုနည်း
စမတ်စာချုပ်လုပ်ဆောင်ချက်များသို့ လင့်ခ်များသည် Python လင့်ခ်များနှင့် တူညီပါသည်။ လိုအပ်သလို သက်ဆိုင်ရာ Functions များကို ထည့်သွင်းနိုင်ပါတယ်။ ဥပမာအားဖြင့်၊ အောက်ပါထုတ်ပြန်ချက်သည် လက်ရှိဘလောက်အမြင့်ကိုရရန် GetHeight လုပ်ဆောင်ချက်ကို မိတ်ဆက်ပေးပြီး ဘလောက်၏ခေါင်းစီးကိုရယူရန် GetHeader လုပ်ဆောင်ချက်ကို မိတ်ဆက်ပေးသည်။
from ontology.interop.System.Blockchain import GetHeight, GetHeader
GetHeight
GetHeight ကိုအောက်ပါဥပမာတွင်ပြထားသည့်အတိုင်း blockchain တွင်နောက်ဆုံးပိတ်ဆို့နံပါတ်ကိုရရန်အသုံးပြုသည်။ နောက်ဆုံးဥပမာတွင်၊ အဆင်ပြေစေရန်အတွက် Main function ကို ချန်လှပ်ထားမည်ဖြစ်သော်လည်း လိုအပ်ပါက ၎င်းကိုသင်ထည့်နိုင်ပါသည်။
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 ကို block header ကိုရယူရန်အသုံးပြုသည်၊ parameter သည် blockchain ရှိ block ၏နံပါတ်စဉ်ဖြစ်သည်။ ဥပမာ-
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 ကို ငွေပေးငွေယူ hash မှတဆင့် ငွေပေးငွေယူရယူရန် အသုံးပြုပါသည်။ ငွေပေးငွေယူ hash ကို ပေးပို့သည်။ GetTransactionByHash bytearray ဖော်မတ်တွင် ဘောင်များအဖြစ်။ ဤလုပ်ဆောင်ချက်အတွက် သော့ချက်မှာ ငွေပေးငွေယူ hash ကို hex ဖော်မတ်တွင် bytearray ဖော်မတ်ဖြင့် ငွေပေးငွေယူ hash သို့ ပြောင်းရန်ဖြစ်သည်။ ဒါက အရေးကြီးတဲ့ အဆင့်တစ်ခုပါ။ မဟုတ်ပါက၊ ထိုဘလော့ဂ် hash တွင် ပိတ်ဆို့ခြင်း မရှိကြောင်း ညွှန်ပြသော အမှားတစ်ခု သင်ရရှိလိမ့်မည်။ ၎င်းကို bytearray ဖော်မတ်သို့ ပြောင်းရန် ဥပမာတစ်ခုအနေဖြင့် ငွေပေးငွေယူ hash ကို hex ဖော်မတ်ဖြင့် ယူကြပါစို့။ ဥပမာတစ်ခုသည် ဤကဲ့သို့ဖြစ်သည်-
9f270aa3a4c13c46891ff0e1a2bdb3ea0525669d414994aadf2606734d0c89c1
ပထမဦးစွာ ငွေပေးငွေယူ hash ကို ပြောင်းပြန်လှန်ပါ။
c1890c4d730626dfaa9449419d662505eab3bda2e1f01f89463cc1a4a30a279
Developer များသည် SmartX မှပံ့ပိုးပေးသော Hex Number(little endian)Number conversion tool ကိုအသုံးပြု၍ ဤအဆင့်ကို ပြီးမြောက်အောင်မြင်နိုင်ပါသည်။
ထို့နောက်ရလဒ်ကို 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}
SmartX မှပေးသော String Byte Array ပြောင်းလဲခြင်းတူးလ်ကို အသုံးပြု၍ ၎င်းကိုလုပ်ဆောင်နိုင်သည်။ နောက်ဆုံးတွင်၊ ရရှိလာသော bytearray ကို အလားတူစာကြောင်းအဖြစ် ပြောင်းပါ-
xc1x89x0cx4dx73x06x26xdfxaax94x49x41x9dx66x25x05xeaxb3xbdxa2xe1xf0x1fx89x46x3cxc1xa4xa3x0ax27x9f
အောက်ဖော်ပြပါသည် ငွေပေးငွေယူ၏ hash ကို အသုံးပြု၍ ငွေပေးငွေယူပြုလုပ်သည့် GetTransactionByHash လုပ်ဆောင်ချက်၏ ဥပမာတစ်ခုဖြစ်သည်။
from ontology.interop.System.Blockchain import GetTransactionByHash
def demo():
# tx_hash="9f270aa3a4c13c46891ff0e1a2bdb3ea0525669d414994aadf2606734d0c89c1"
tx_hash=bytearray(b"xc1x89x0cx4dx73x06x26xdfxaax94x49x41x9dx66x25x05xeaxb3xbdxa2xe1xf0x1fx89x46x3cxc1xa4xa3x0ax27x9f")
tx=GetTransactionByHash(tx_hash)
return tx
GetTransactionHeight
GetTransactionHeight ကို ငွေပေးငွေယူ hash မှတစ်ဆင့် ငွေပေးငွေယူ အမြင့်ကို ရယူရန် အသုံးပြုသည်။ အပေါ်က ဥပမာကနေ hash ကို ယူကြည့်ရအောင်။
from ontology.interop.System.Blockchain import GetTransactionHeight
def demo():
# tx_hash="9f270aa3a4c13c46891ff0e1a2bdb3ea0525669d414994aadf2606734d0c89c1"
tx_hash=bytearray(b"xc1x89x0cx4dx73x06x26xdfxaax94x49x41x9dx66x25x05xeaxb3xbdxa2xe1xf0x1fx89x46x3cxc1xa4xa3x0ax27x9f")
height=GetTransactionHeight(tx_hash)
return height
GetContract
စာချုပ်၏ hash မှတစ်ဆင့် စာချုပ်တစ်ခုရယူရန် Developer များသည် GetContract လုပ်ဆောင်ချက်ကို အသုံးပြုနိုင်သည်။ စာချုပ် hash ပြောင်းလဲခြင်းလုပ်ငန်းစဉ်သည် အထက်တွင်ဖော်ပြထားသော ငွေပေးငွေယူ hash ပြောင်းလဲခြင်းလုပ်ငန်းစဉ်နှင့် အတူတူပင်ဖြစ်ပါသည်။
from ontology.interop.System.Blockchain import GetContract
def demo():
# contract_hash="d81a75a5ff9b95effa91239ff0bb3232219698fa"
contract_hash=bytearray(b"xfax98x96x21x32x32xbbxf0x9fx23x91xfaxefx95x9bxffxa5x75x1axd8")
contract=GetContract(contract_hash)
return contract
GetBlock
GetBlock သည် block တစ်ခုရရှိရန်အသုံးပြုသည်။ တိကျသော block တစ်ခုရရန် နည်းလမ်းနှစ်ခုရှိသည်။
1. ဘလောက်အမြင့်ဖြင့် ပိတ်ဆို့ရယူပါ-
from ontology.interop.System.Blockchain import GetBlock
def demo():
block=GetBlock(1408)
return block
2. block hash ဖြင့် block တစ်ခုကို ရယူပါ-
from ontology.interop.System.Blockchain import GetBlock
def demo():
block_hash=bytearray(b'x16xe0xc5x40x82x79x77x30x44xeax66xc8xc4x5dx17xf7x17x73x92x33x6dx54xe3x48x46x0bxc3x2fxe2x15x03xe4')
block=GetBlock(block_hash)
2. Block API ကိုအသုံးပြုနည်း
Block API တွင် ရရှိနိုင်သော လုပ်ဆောင်ချက်များ သုံးခုရှိသည်။ လွှဲပြောင်းရယူပါ။, GetTransactionCountနှင့် GetTransactionByIndex. ငါတို့က သူတို့ကို တစ်ခုပြီးတစ်ခု ဖြိုခွဲမယ်။
GetTransactionCount
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
လွှဲပြောင်းရယူပါ။
Developer များသည် ပေးထားသော block တစ်ခုတွင် ငွေပေးငွေယူများအားလုံးကို ရယူရန် 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
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
ကျွန်ုပ်တို့၏လမ်းညွှန်ချက်အပြည့်အစုံကို တွေ့ရှိနိုင်ပါသည်။
afterword
Blockchain & Block API သည် ၎င်းတို့ကို blockchain ဒေတာနှင့် စမတ်စာချုပ်များတွင် block data များတောင်းဆိုရန်အတွက် ၎င်းတို့ကို အသုံးပြု၍ စမတ်စာချုပ်များ၏ မရှိမဖြစ်အစိတ်အပိုင်းတစ်ခုဖြစ်သည်။ အောက်ပါဆောင်းပါးများတွင်၊ ကျန်ရှိသော APIs များကိုမည်သို့အသုံးပြုရမည်ကိုကျွန်ုပ်တို့ဆွေးနွေးပြီး Ontology blockchain နှင့်မည်သို့အပြန်အလှန်အကျိုးသက်ရောက်သည်ကိုရှာဖွေပါ။
ဆောင်းပါးကို OntologyRussia အတွက် အထူးသဖြင့် Hashrate&Shares ၏ တည်းဖြတ်သူများမှ ဘာသာပြန်ထားပါသည်။
ငိုပါ။
သင်က developer တစ်ယောက်လား။ ကျွန်ုပ်တို့၏နည်းပညာအသိုင်းအဝိုင်းတွင် ပါဝင်လိုက်ပါ။
Ontology
Ontology ဝဘ်ဆိုဒ် GitHub /စိတ်တိုးပွား - ကွေးနနျးစာ
အဂၤလိပ္ /ရုရွား တွစ်တာ /Reddit
source: www.habr.com