
ืืึธืก ืืื ืืขืจ ืขืจืฉืืขืจ ืืืื ืคืื ืึท ืกืขืจืืข ืคืื โโืืืืืื ืืงืจืืื ืึทืจืืืงืืขื ืืืขืื ืงืจืืืืืื ื ืกืืึทืจื ืงืึทื ืืจืึทืงืฅ ืืื ืคึผืืืืึธื ืืืืฃ ืื ืึธื ืืึธืืึธืื ืืืึธืงืืฉืืื ื ืขืฅ ื ืืฆื ืื ืกืืึทืจื ืงืึธื ืืจืึทืงื ืึทื ืืืืืงืืื ื ืืขืฆืืึทื .
ืืื ืืขื ืึทืจืืืงื, ืืืจ ืืืขืื ืึธื ืืืืื ืืื ืืืขืจ ืืึทืงืึทื ืืขืจ ืืื ืื ืึธื ืืึธืืึธืื ืงืืื ืงืึธื ืืจืึทืงื ืึทืคึผื. ืื ืึธื ืืึธืืึธืื ืงืืื ืงืึธื ืืจืึทืงื ืึทืคึผื ืืื ืฆืขืืืืื ืืื 7 ืืึทืืืฉืืื:
- Blockchain & Block API,
- ืจืื ืืืืข ืึทืคึผื
- ืกืืึธืจืืืืฉ API
- ืืขืืืืจื ืึทืคึผื
- ืึทืคึผืืจืืื API,
- ืืืจืืคืืจืื ื ืขื ืืื ืข ืึทืคึผื ืืื
- ืกืืึทืืืง ืืื ืืื ืึทืืืฉ ืจืืคื ืึทืคึผื.
Blockchain & Block API ืืื ืื ืืึทืจืฅ ืืืื ืคืื ืื ืึธื ืืึธืืึธืื ืงืืื ืงืึธื ืืจืึทืงื ืกืืกืืขื. ืื ืืืึธืงืืฉืืื ืึทืคึผื ืฉืืืฆื ืืงืขืจืืืง ืืืึทืงืืืืืืึทื ืึธื ืคึฟืจืขื ืึทืคึผืขืจืืืฉืึทื ื, ืึทืืึท ืืื ืืึทืงืืืขื ืื ืงืจืึทื ื ืืืื ืคืื ืึท ืืืึธืง, ืืฉืขืช ืื ืืืึทืง ืึทืคึผื ืฉืืืฆื ืืงืขืจืืืง ืืืึธืง ืึธื ืคึฟืจืขื ืึทืคึผืขืจืืืฉืึทื ื, ืึทืืึท ืืื ืื ื ืืืขืจ ืคืื ืืจืึทื ืืึทืงืฉืึทื ื ืคึฟืึทืจ ืึท ืืขืืขืื ืืืึธืง.
ืืืืืจ ืื ืืืืืขื!
ืฆื ืึธื ืืืืื, ืฉืึทืคึฟื ืึท ื ืืึทืข ืงืึธื ืืจืึทืงื ืืื , ืืื ืืขืืึธืื ื ืึธืืืืื ืื ืื ืกืืจืึทืงืฉืึทื ื ืืื ืื.
1. ืืื ืฆื ื ืืฆื Blockchain API
ืกืืึทืจื ืงืึธื ืืจืึทืงื ืคืื ืงืฆืืข ืืึทืืืืึทืื ืืขื ืขื ืืืืขื ืืงืึทื ืฆื ืคึผืืืืึธื ืจืขืคืขืจืขื ืฆื. ืืืจ ืงืขื ืขื ืึทืจืืึทื ืืึทืืืึทืืืง ืคืึทื ืืงืฉืึทื ื ืืื ืืืจืฃ. ืคึฟืึทืจ ืืืึทืฉืคึผืื, ืื ืคืืืืขื ืืข ืืขืจืงืืขืจืื ื ืื ืืจืึทืืืกืื GetHeight, ืึท ืคึฟืื ืงืฆืืข ืฆื ืืึทืงืืืขื ืื ืงืจืึทื ื ืืืื ืคืื ืึท ืืืึธืง, ืืื GetHeader, ืึท ืคึฟืื ืงืฆืืข ืฆื ืืึทืงืืืขื ืืขื ืืืื ืคืื ืืขื ืืืึธืง.
from ontology.interop.System.Blockchain import GetHeight, GetHeaderGetHeight
GetHeight ืืื ืืขื ืืฆื ืฆื ืืึทืงืืืขื ืื ืืขืฆืืข ืืืึธืง ืกืืงืืืึทื ืก ื ืืืขืจ ืืื ืื ืืืึทืงืืืืืืึทื, ืืื ืืขืืืืื ืืื ืื ืืืืฉืคึผืื ืืื ืื. ืืื ืื ืืขืฆืืข ืืืึทืฉืคึผืื, ืคึฟืึทืจ ืงืึทื ืืืื ืืึทื ืก, ืืืจ ืืืขืื ืืึธืคึผืงืขื ืื ืืืืคึผื ืคึฟืื ืงืฆืืข, ืึธืืขืจ ืืืจ ืงืขื ืขื ืืืืื ืขืก ืืืื ื ืืืืืง.
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 functionGetHeader
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 headerGetTransactionByHash
GetTransactionByHash ืืื ืืขื ืืฆื ืฆื ืฆืืจืืงืงืจืืื ืึท ืืจืึทื ืกืึทืงืืืึธื ื ืืฆื ืึท ืืจืึทื ืกืึทืงืืืึธื ืืึทืฉ. ืื ืืจืึทื ืกืึทืงืืืึธื ืืึทืฉ ืืื ืืขืฉืืงื ืฆื GetTransactionByHash ืืื ืคึผืึทืจืึทืืขืืขืจืก ืืื ืืืืืขืึทืจืจืืึท ืคึฟืึธืจืืึทื. ืืขืจ ืฉืืืกื ืฆื ืืขื ืคึฟืื ืงืฆืืข ืืื ืฆื ืืขืจ ืื ืืจืึทื ืกืึทืงืืืึธื ืืึทืฉ ืืื ืืขืงืก ืคึฟืึธืจืืึทื ืฆื ืื ืืจืึทื ืกืึทืงืืืึธื ืืึทืฉ ืืื ืืืืืขืึทืจืจืืึท ืคึฟืึธืจืืึทื. ืืึธืก ืืื ืึท ืืืืืืืง ืฉืจืื. ืึทื ืืขืจืฉ ืืืจ ืืืึธืื ืืึทืงืืืขื ืึท ืืขืืช ืืืึธืก ืื ืืืงืืืฅ ืึทื ืขืก ืืื ืงืืื ืืืึธืง ืืื ืืขื ืืืึธืง ืืึทืฉ. ืืึธืืืจ ื ืขืืขื ืื ืืจืึทื ืกืึทืงืืืึธื ืืึทืฉ ืืื ืืขืงืก ืคึฟืึธืจืืึทื ืืื ืึท ืืืืฉืคึผืื ืฆื ืืขืจ ืขืก ืฆื ืืืืืขืึทืจืจืืึท ืคึฟืึธืจืืึทื. ืื ืืืืฉืคึผืื ืงืืงื ืืื ืืึธืก:
9f270aa3a4c13c46891ff0e1a2bdb3ea0525669d414994aadf2606734d0c89c1ืขืจืฉืืขืจ ืคืึทืจืงืขืจื ืื ืืจืึทื ืกืึทืงืืืึธื ืืึทืฉ:
c1890c4d730626dfaa9449419d662505eab3bda2e1f01f89463cc1a4a30a279ืืขืืืขืืึธืคึผืขืจืก ืงืขื ืขื ืืืกืคืืจื ืืขื ืฉืจืื ืืื ืื ืืขืงืก ื ืืืขืจ (ืงืืืื ืขื ืืืึทื) ื ืืืขืจ ืงืึทื ืืืขืจืืฉืึทื ืืขืฆืืึทื ืฆืืืขืฉืืขืื ืืืจื 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}ืืขื ืงืขื ืขื ืืืื ืืขืืื ืืื ืื ืกืืจืื ื ืืืืืข ืึทืจืจืืึท ืงืึทื ืืืขืจืืฉืึทื ืืขืฆืืึทื ืฆืืืขืฉืืขืื ืืืจื SmartX. ืฆืื ืกืืฃ, ืืขืจ ืื ืจืืืึทืืืื ื ืืืืืขืจืจืืึท ืืื ืึท ืฉืืจืืงื ืืื ืืึธืก:
xc1x89x0cx4dx73x06x26xdfxaax94x49x41x9dx66x25x05xeaxb3xbdxa2xe1xf0x1fx89x46x3cxc1xa4xa3x0ax27x9fืื ืืขืจ ืืื ืึท ืืืืฉืคึผืื ืคืื ืื GetTransactionByHash ืคืื ืงืฆืืข, ืืืึธืก ื ืขืื ืึท ืืจืึทื ืกืึทืงืืืึธื ืืืจื ืื ืืจืึทื ืกืึทืงืืืึธื ืืึทืฉ:
from ontology.interop.System.Blockchain import GetTransactionByHash
def demo():
# tx_hash="9f270aa3a4c13c46891ff0e1a2bdb3ea0525669d414994aadf2606734d0c89c1"
tx_hash=bytearray(b"xc1x89x0cx4dx73x06x26xdfxaax94x49x41x9dx66x25x05xeaxb3xbdxa2xe1xf0x1fx89x46x3cxc1xa4xa3x0ax27x9f")
tx=GetTransactionByHash(tx_hash)
return txGetTransactionHeight
GetTransactionHeight ืืื ืืขื ืืฆื ืฆื ืืึทืงืืืขื ืื ืืจืึทื ืกืึทืงืืืึธื ืืืื ืืื ืื ืืจืึทื ืกืึทืงืืืึธื ืืึทืฉ. ืืึธืืืจ ื ืขืืขื ืื ืืึทืฉ ืคืื ืื ืืืืฉืคึผืื ืืืืื:
from ontology.interop.System.Blockchain import GetTransactionHeight
def demo():
# tx_hash="9f270aa3a4c13c46891ff0e1a2bdb3ea0525669d414994aadf2606734d0c89c1"
tx_hash=bytearray(b"xc1x89x0cx4dx73x06x26xdfxaax94x49x41x9dx66x25x05xeaxb3xbdxa2xe1xf0x1fx89x46x3cxc1xa4xa3x0ax27x9f")
height=GetTransactionHeight(tx_hash)
return heightืืึทืงืืืขื ืงืึธื ืืจืึทืงื
ืืขืืืขืืึธืคึผืขืจืก ืงืขื ืขื ื ืืฆื ืื GetContract ืคืื ืงืฆืืข ืฆื ืฆืืจืืงืงืจืืื ืึท ืงืึธื ืืจืึทืงื ืืืจื ืึท ืงืึธื ืืจืึทืงื ืืึทืฉ. ืืขืจ ืงืึธื ืืจืึทืงื ืืึทืฉ ืงืึทื ืืืขืจืืฉืึทื ืคึผืจืึธืฆืขืก ืืื ืื ืืขืืืข ืืื ืื ืืจืึทื ืกืึทืงืืืึธื ืืึทืฉ ืงืึทื ืืืขืจืืฉืึทื ืคึผืจืึธืฆืขืก ืืขืจืืื ื ืืืืื.
from ontology.interop.System.Blockchain import GetContract
def demo():
# contract_hash="d81a75a5ff9b95effa91239ff0bb3232219698fa"
contract_hash=bytearray(b"xfax98x96x21x32x32xbbxf0x9fx23x91xfaxefx95x9bxffxa5x75x1axd8")
contract=GetContract(contract_hash)
return contractGetBlock
GetBlock ืืื ืืขื ืืฆื ืฆื ืืึทืงืืืขื ืึท ืืืึธืง. ืขืก ืืขื ืขื ืฆืืืื ืืืขืื ืฆื ืืึทืงืืืขื ืึท ืกืคึผืขืฆืืคืืฉ ืืืึธืง.
1. ืืึทืงืืืขื ืึท ืืืึธืง ืืืจื ืืืึธืง ืืืื:
from ontology.interop.System.Blockchain import GetBlock
def demo():
block=GetBlock(1408)
return block2. ืืึทืงืืืขื ืึท ืืืึธืง ืืืจื ืืืึธืง ืืึทืฉ:
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ืืึทืงืืืขื ืืจืึทื ืืึทืงืฉืึทื ื
ืืขืืืขืืึธืคึผืขืจืก ืงืขื ืขื ื ืืฆื ืื GetTransactions ืคืื ืงืฆืืข ืฆื ืฆืืจืืงืงืจืืื ืึทืืข ืืจืึทื ืืึทืงืฉืึทื ื ืืื ืึท ืืขืืขืื ืืืึธืง.
from ontology.interop.System.Blockchain import GetBlock
from ontology.interop.System.Block import GetTransactions
def demo():
block=GetBlock(1408)
txs=GetTransactions(block)
return txsGetTransactionByIndex
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 ืืื ืึท ืื ืืืกืคึผืขื ืกืึทืืึทื ืืืื ืคืื ืกืืึทืจื ืงืึทื ืืจืึทืงืฅ ืืืืึทื ืืืจ ืงืขื ืขื ื ืืฆื ืขืก ืฆื ืึธื ืคืจืขื ืืืึทืงืืืืืืึทื ืืึทืื ืืื ืคืึทืจืฉืคึผืึทืจื ืืึทืื ืืื ืกืืึทืจื ืงืึทื ืืจืึทืงืฅ. ืืื ืฆืืงืื ืคึฟื ืึทืจืืืงืืขื, ืืืจ ืืืขืื ืืืกืงืืืืจื ืืื ืฆื ื ืืฆื ืื ืจืืขื ืึทืคึผืืก ืืื ืคึฟืึทืจืฉืืืื ืืื ืืื ืื ืืขืจืึทืงื ืืื ืื ืึธื ืืึธืืึธืื ืืืึธืงืืฉืืื.
ืืขืจ ืึทืจืืืงื ืืื ืืืืขืจืืขืืขืฆื ืืืจื ืื ืจืขืืืงืฆืืข ืคืื โโHashrate&Shares ืกืคึผืึทืกืืคืืงืื ืคึฟืึทืจ ืึธื ืืึธืืึธืื ืจืืกืืึทื ื.
ืืขื ื ืืืจ ืึท ืืขืืืขืืึธืคึผืขืจ? ืคืึทืจืืื ืื ืืื ืืืขืจ ืืขืง ืงืื ืืื . ืืืื, ื ืขืืขื ืึท ืงืืง ืืืึท ืืืืฃ ืืื ืืืขืจ ืืืขืืืืืื, ืืื ืืืจ ืงืขื ืขื ืืขืคึฟืื ืขื ืืขืืืขืืึธืคึผืขืจ ืืืฉืืจืื, ืืึทืงืืืืขื ืืืืฉืึทื ืืื ืคืื ืืขืจ.
ืึธื ืืึธืืึธืืึธืื
- /
- ืืขืืขืืจืึทื /
- /
ืืงืืจ: www.habr.com
