ืื™ืš ื›ื•ืชื‘ื™ื ื—ื•ื–ื” ื—ื›ื ื‘ืคื™ื™ืชื•ืŸ ื‘ืจืฉืช ืื•ื ื˜ื•ืœื•ื’ื™ื”. ื—ืœืง 1: Blockchain & Block API

ืื™ืš ื›ื•ืชื‘ื™ื ื—ื•ื–ื” ื—ื›ื ื‘ืคื™ื™ืชื•ืŸ ื‘ืจืฉืช ืื•ื ื˜ื•ืœื•ื’ื™ื”. ื—ืœืง 1: Blockchain & Block API

ื–ื”ื• ื”ื—ืœืง ื”ืจืืฉื•ืŸ ื‘ืกื“ืจืช ื”ื“ืจื›ื•ืช ืœื™ืฆื™ืจืช ื—ื•ื–ื™ื ื—ื›ืžื™ื ืฉืœ Python ื‘ืจืฉืช ื”ื‘ืœื•ืงืฆ'ื™ื™ืŸ ืื•ื ื˜ื•ืœื•ื’ื™ื” ื‘ืืžืฆืขื•ืช ื›ืœื™ ืคื™ืชื•ื— ื—ื•ื–ื™ื ื—ื›ืžื™ื. SmartX.

ื‘ืžืืžืจ ื–ื”, ื ืชื—ื™ืœ ืืช ื”ื”ื™ื›ืจื•ืช ืฉืœื ื• ืขื API ืฉืœ ื—ื•ื–ื” ื—ื›ื ืฉืœ Ontology. ืžืžืฉืง API ืฉืœ ื—ื•ื–ื” ื—ื›ื ืฉืœ Ontology ืžื—ื•ืœืง ืœ-7 ืžื•ื“ื•ืœื™ื:

  1. Blockchain & Block API,
  2. API ืฉืœ ื–ืžืŸ ืจื™ืฆื”,
  3. API ืœืื—ืกื•ืŸ,
  4. API ืžืงื•ืจื™,
  5. ืฉื“ืจื•ื’ API,
  6. ืžื ื•ืข ื‘ื™ืฆื•ืข API ื•
  7. ืžืžืฉืง API ืœืฉื™ื—ื•ืช ืกื˜ื˜ื™ื•ืช ื•ื“ื™ื ืžื™ื•ืช.

Blockchain & Block API ื”ื•ื ื”ื—ืœืง ื”ืขื™ืงืจื™ ืฉืœ ืžืขืจื›ืช ื”ื—ื•ื–ื™ื ื”ื—ื›ืžื™ื Ontology. ื”-Blockchain API ืชื•ืžืš ื‘ืคืขื•ืœื•ืช ืฉืื™ืœืชื•ืช ื‘ืกื™ืกื™ื•ืช ืฉืœ ื‘ืœื•ืงืฆ'ื™ื™ืŸ, ื›ื’ื•ืŸ ืงื‘ืœืช ื’ื•ื‘ื” ื”ื‘ืœื•ืง ื”ื ื•ื›ื—ื™, ื‘ืขื•ื“ ืฉื”-Block API ืชื•ืžืš ื‘ืคืขื•ืœื•ืช ืฉืื™ืœืชืช ื‘ืœื•ืง ื‘ืกื™ืกื™ื•ืช, ื›ื’ื•ืŸ ืฉืื™ืœืชืช ืžืกืคืจ ื”ืขืกืงืื•ืช ืขื‘ื•ืจ ื‘ืœื•ืง ื ืชื•ืŸ.

ื‘ื•ืื• ื ืชื—ื™ืœ!

ืจืืฉื™ืช, ืฆื•ืจ ื—ื•ื–ื” ื—ื“ืฉ ื‘ SmartXื•ืœืื—ืจ ืžื›ืŸ ื‘ืฆืข ืืช ื”ื”ื•ืจืื•ืช ืฉืœื”ืœืŸ.

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

ืžื“ืจื™ืš ืžืœื ื ื™ืชืŸ ืœืžืฆื•ื ืืฆืœื ื• GitHub.

ืื—ืจื™ืช ื“ื‘ืจ

ื”-Blockchain & Block API ื”ื•ื ื—ืœืง ื”ื›ืจื—ื™ ื‘ื—ื•ื–ื™ื ื—ื›ืžื™ื, ืžื›ื™ื•ื•ืŸ ืฉืืชื” ื™ื›ื•ืœ ืœื”ืฉืชืžืฉ ื‘ื”ื ื›ื“ื™ ืœื‘ืงืฉ ื ืชื•ื ื™ ื‘ืœื•ืงืฆ'ื™ื™ืŸ ื•ืœื—ืกื•ื ื ืชื•ื ื™ื ื‘ื—ื•ื–ื™ื ื—ื›ืžื™ื. ื‘ืžืืžืจื™ื ื”ื‘ืื™ื, ื ื“ื•ืŸ ื›ื™ืฆื“ ืœื”ืฉืชืžืฉ ื‘ืฉืืจ ืžืžืฉืงื™ ื”-API ื•ื ื’ืœื” ื›ื™ืฆื“ ื”ื ืžืงื™ื™ืžื™ื ืื™ื ื˜ืจืืงืฆื™ื” ืขื ื”ื‘ืœื•ืงืฆ'ื™ื™ืŸ ืฉืœ ืื•ื ื˜ื•ืœื•ื’ื™ื”.

ื”ืžืืžืจ ืชื•ืจื’ื ืขืœ ื™ื“ื™ ืขื•ืจื›ื™ Hashrate&Shares ื‘ืžื™ื•ื—ื“ ืขื‘ื•ืจ OntologyRussia. ืœื—ืฅ ืขืœ

ื”ืื ืืชื” ืžืคืชื—? ื”ืฆื˜ืจืฃ ืœืงื”ื™ืœืช ื”ื˜ื›ื ื•ืœื•ื’ื™ื” ืฉืœื ื• ื‘- ืžื—ืœื•ืงืช. ื›ืžื• ื›ืŸ, ืชืกืชื›ืœ ืขืœ ืžืจื›ื– ืžืคืชื—ื™ื ื‘ืืชืจ ื”ืื™ื ื˜ืจื ื˜ ืฉืœื ื•, ืฉื ืชื•ื›ืœ ืœืžืฆื•ื ื›ืœื™ื ืœืžืคืชื—ื™ื, ืชื™ืขื•ื“ ื•ืขื•ื“.

ืื•ื ื˜ื•ืœื•ื’ื™ื”

ืžืงื•ืจ: www.habr.com

ื”ื•ืกืคืช ืชื’ื•ื‘ื”