ืืื ืืืืง ืืจืืฉืื ืืกืืจืช ืืืจืืืช ืืืฆืืจืช ืืืืื ืืืืื ืฉื Python ืืจืฉืช ืืืืืงืฆ'ืืื ืืื ืืืืืืื ืืืืฆืขืืช ืืื ืคืืชืื ืืืืื ืืืืื.
ืืืืืจ ืื, ื ืชืืื ืืช ืืืืืจืืช ืฉืื ื ืขื API ืฉื ืืืื ืืื ืฉื Ontology. ืืืฉืง API ืฉื ืืืื ืืื ืฉื Ontology ืืืืืง ื-7 ืืืืืืื:
- Blockchain & Block API,
- API ืฉื ืืื ืจืืฆื,
- API ืืืืกืื,
- API ืืงืืจื,
- ืฉืืจืื API,
- ืื ืืข ืืืฆืืข API ื
- ืืืฉืง API ืืฉืืืืช ืกืืืืืช ืืืื ืืืืช.
Blockchain & Block API ืืื ืืืืง ืืขืืงืจื ืฉื ืืขืจืืช ืืืืืื ืืืืืื Ontology. ื-Blockchain API ืชืืื ืืคืขืืืืช ืฉืืืืชืืช ืืกืืกืืืช ืฉื ืืืืงืฆ'ืืื, ืืืื ืงืืืช ืืืื ืืืืืง ืื ืืืื, ืืขืื ืฉื-Block API ืชืืื ืืคืขืืืืช ืฉืืืืชืช ืืืืง ืืกืืกืืืช, ืืืื ืฉืืืืชืช ืืกืคืจ ืืขืกืงืืืช ืขืืืจ ืืืืง ื ืชืื.
ืืืื ื ืชืืื!
ืจืืฉืืช, ืฆืืจ ืืืื ืืืฉ ื
1. ืืืฆื ืืืฉืชืืฉ ื-Blockchain API
ืงืืฉืืจืื ืืคืื ืงืฆืืืช ืืืื ืืื ืืืื ืืงืืฉืืจื Python. ื ืืชื ืืืืื ืืช ืืคืื ืงืฆืืืช ืืืชืืืืืช ืืคื ืืฆืืจื. ืืืืืื, ืืืฆืืจื ืืืื ืืฆืืื ืคืื ืงืฆืื GetHeight ืืื ืืงืื ืืช ืืืื ืืืืืง ืื ืืืื, ืืคืื ืงืฆืื GetHeader ืืื ืืงืื ืืช ืืืืชืจืช ืฉื ืืืืืง.
from ontology.interop.System.Blockchain import GetHeight, GetHeader
GetHeight
GetHeight ืืฉืืฉ ืืื ืืงืื ืืช ืืกืคืจ ืจืฆืฃ ืืืืืง ืืืืจืื ื- blockchain, ืืคื ืฉืืืฆื ืืืืืื ืืืื. ืืืืืื ืืืืจืื ื ื ืฉืืื ืืช ืืคืื ืงืฆืื Main ืืืขืื ื ืืืืช, ืื ื ืืชื ืืืืกืืฃ ืืืชื ืืืืืช ืืฆืืจื.
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 ืืฉืืฉ ืืื ืืงืื ืืช ืืืชืจืช ืืืืืง, ืืคืจืืืจ ืืื ืืืกืคืจ ืืกืืืืจื ืฉื ืืืืืง ืืืืืงืฆ'ืืื. ืืืืื:
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 ื-transaction hash ืืคืืจืื bytearray. ืืื ืฆืขื ืืฉืื. ืืืจืช, ืชืงืื ืฉืืืื ืฉืืฆืืื ืช ืฉืืื ืืกืืื ืขื ื-hash ืฉื ืืืืืง ืืื. ื ืืงื ืืช ื-hash ืฉื ืืขืกืงื ืืคืืจืื hex ืืืืืื ืืื ืืืืืจ ืืืชื ืืคืืจืื bytearray. ืืืืื ื ืจืืืช ืื:
9f270aa3a4c13c46891ff0e1a2bdb3ea0525669d414994aadf2606734d0c89c1
ืจืืฉืืช, ืืคืื ืืช ื-hash ืฉื ืืขืกืงื:
c1890c4d730626dfaa9449419d662505eab3bda2e1f01f89463cc1a4a30a279
ืืคืชืืื ืืืืืื ืืืฆืข ืืช ืืฉืื ืืื ืืืืฆืขืืช ืืื ืืืืจื ืฉื ืืกืคืจ Hex Number(Endian ืืงืื) ืืืกืืคืง ืขื ืืื SmartX.
ืืืืจ ืืื ืืืจ ืืช ืืชืืฆืื ืืคืืจืื 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}
ื ืืชื ืืขืฉืืช ืืืช ืืืืฆืขืืช ืืื ืืืืจื ืฉื String Byte Array ืืืกืืคืง ืขื ืืื SmartX. ืืืกืืฃ, ืืืจ ืืช ืืขืจื ืืืืืื ืืืชืงืื ืืืืจืืืช ืืืื:
xc1x89x0cx4dx73x06x26xdfxaax94x49x41x9dx66x25x05xeaxb3xbdxa2xe1xf0x1fx89x46x3cxc1xa4xa3x0ax27x9f
ืืืื ืืืืื ืืคืื ืงืฆืื GetTransactionByHash, ืืฉืจ ืืืงืืช ืขืกืงื ืืืืฆืขืืช ื-hash ืฉื ืืขืกืงื:
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
ืืคืชืืื ืืืืืื ืืืฉืชืืฉ ืืคืื ืงืฆืื GetContract ืืื ืืงืื ืืืื ืืจื ื-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 ืืฉืืฉ ืืื ืืงืื ืืกืืื. ืืฉื ื ืฉืชื ืืจืืื ืืืฉืื ืืืืง ืกืคืฆืืคื.
1. ืงืื ืืืืง ืืืจ ืืืื ืืืืง:
from ontology.interop.System.Blockchain import GetBlock
def demo():
block=GetBlock(1408)
return block
2. ืงืื hash ืืืืง ืืืจ ืืืืง:
from ontology.interop.System.Blockchain import GetBlock
def demo():
block_hash=bytearray(b'x16xe0xc5x40x82x79x77x30x44xeax66xc8xc4x5dx17xf7x17x73x92x33x6dx54xe3x48x46x0bxc3x2fxe2x15x03xe4')
block=GetBlock(block_hash)
2. ืืืฆื ืืืฉืชืืฉ ื- Block API
ืืฉื ื ืฉืืืฉ ืคืื ืงืฆืืืช ืืืื ืืช ื-Block API: GetTransactions, 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
GetTransactions
ืืคืชืืื ืืืืืื ืืืฉืชืืฉ ืืคืื ืงืฆืื 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
ืืืจืื ืืื ื ืืชื ืืืฆืื ืืฆืื ื
ืืืจืืช ืืืจ
ื-Blockchain & Block API ืืื ืืืง ืืืจืื ืืืืืื ืืืืื, ืืืืืื ืฉืืชื ืืืื ืืืฉืชืืฉ ืืื ืืื ืืืงืฉ ื ืชืื ื ืืืืงืฆ'ืืื ืืืืกืื ื ืชืื ืื ืืืืืื ืืืืื. ืืืืืจืื ืืืืื, ื ืืื ืืืฆื ืืืฉืชืืฉ ืืฉืืจ ืืืฉืงื ื-API ืื ืืื ืืืฆื ืื ืืงืืืืื ืืื ืืจืืงืฆืื ืขื ืืืืืงืฆ'ืืื ืฉื ืืื ืืืืืืื.
ืืืืืจ ืชืืจืื ืขื ืืื ืขืืจืื Hashrate&Shares ืืืืืื ืขืืืจ OntologyRussia.
ืืืฅ ืขื
ืืื ืืชื ืืคืชื? ืืฆืืจืฃ ืืงืืืืช ืืืื ืืืืืื ืฉืื ื ื-
ืืื ืืืืืืื
ืืชืจ ืืื ืืืืืืื GitHub /ืืืืืงืช - ืืืจืง
ืื ืืืืช /ืจืืกื ืืืืืจ /reddit
ืืงืืจ: www.habr.com