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

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

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

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

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

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

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

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

1. ื›ื™ืฆื“ ืœื”ืฉืชืžืฉ ื‘ืžืžืฉืง ื”-API ืฉืœ ื‘ืœื•ืงืฆ'ื™ื™ืŸ

ื”ืคื ื™ื•ืช ืœืคื•ื ืงืฆื™ื•ืช ืฉืœ ื—ื•ื–ื™ื ื—ื›ืžื™ื ื–ื”ื•ืช ืœื”ืคื ื™ื•ืช ืฉืœ ืคื™ื™ืชื•ืŸ. ื ื™ืชืŸ ืœื”ื–ืจื™ืง ืืช ื”ืคื•ื ืงืฆื™ื•ืช ื”ืžืชืื™ืžื•ืช ืœืคื™ ื”ืฆื•ืจืš. ืœื“ื•ื’ืžื”, ื”ื”ืฆื”ืจื” ื”ื‘ืื” ืžื–ืจื™ืงื” ืืช GetHeight, ืคื•ื ืงืฆื™ื” ืœืื—ื–ื•ืจ ื’ื•ื‘ื” ื”ื‘ืœื•ืง ื”ื ื•ื›ื—ื™, ื•ืืช GetHeader, ืคื•ื ืงืฆื™ื” ืœืื—ื–ื•ืจ ื›ื•ืชืจืช ื”ื‘ืœื•ืง.

from ontology.interop.System.Blockchain import GetHeight, GetHeader

ืงื‘ืœ ื’ื•ื‘ื”

ืคื•ื ืงืฆื™ื™ืช GetHeight ืžืฉืžืฉืช ืœื”ืฉื’ืช ืžืกืคืจ ืจืฆืฃ ื”ื‘ืœื•ืงื™ื ื”ืขื“ื›ื ื™ ื‘ื™ื•ืชืจ ื‘ื‘ืœื•ืงืฆ'ื™ื™ืŸ, ื›ืคื™ ืฉืžื•ืฆื’ ื‘ื“ื•ื’ืžื” ืœืžื˜ื”. ื‘ื“ื•ื’ืžื” ื”ืื—ืจื•ื ื” ื”ื–ื•, ื ืฉืžื™ื˜ ืืช ื”ืคื•ื ืงืฆื™ื” 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 ืžืฉืžืฉ ืœื”ืฉื’ืช ื›ื•ืชืจืช ื‘ืœื•ืง; ื”ืคืจืžื˜ืจ ื”ื•ื ืžืกืคืจ ื”ืจืฆืฃ ืฉืœ ื”ื‘ืœื•ืง ื‘ื‘ืœื•ืงืฆ'ื™ื™ืŸ. ื“ื•ื’ืžื”:

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

ืงื‘ืœ ืขืกืงื” ืขืœ ื™ื“ื™ Hash

GetTransactionByHash ืžืฉืžืฉ ืœืื—ื–ื•ืจ ืขืกืงื” ื‘ืืžืฆืขื•ืช ื’ื™ื‘ื•ื‘ ืขืกืงื”. ื’ื™ื‘ื•ื‘ ื”ืขืกืงื” ื ืฉืœื— ืืœ ืงื‘ืœ ืขืกืงื” ืขืœ ื™ื“ื™ Hash ื›ืคืจืžื˜ืจื™ื ื‘ืคื•ืจืžื˜ bytearray. ื”ืžืคืชื— ืœืคื•ื ืงืฆื™ื” ื–ื• ื”ื•ื ื”ืžืจืช ื’ื™ื‘ื•ื‘ ืขืกืงืช ื”ืงืกื“ืฆื™ืžืœื™ ืœื’ื™ื‘ื•ื‘ ืขืกืงืช bytearray. ื–ื”ื• ืฉืœื‘ ื—ืฉื•ื‘. ืื—ืจืช, ืชืงื‘ืœื• ืฉื’ื™ืื” ื”ืžืฆื™ื™ื ืช ืฉืื™ืŸ ื‘ืœื•ืง ืขื ื’ื™ื‘ื•ื‘ ื”ื‘ืœื•ืง ื”ื–ื”. ื‘ื•ืื• ื ื™ืงื— ื’ื™ื‘ื•ื‘ ืขืกืงืช ื”ืงืกื“ืฆื™ืžืœื™ ื›ื“ื•ื’ืžื” ื•ื ืžื™ืจ ืื•ืชื• ืœืคื•ืจืžื˜ bytearray. ื”ื“ื•ื’ืžื” ื ืจืื™ืช ื›ืš:

9f270aa3a4c13c46891ff0e1a2bdb3ea0525669d414994aadf2606734d0c89c1

ืจืืฉื™ืช, ื”ืคื•ืš ืืช ืงื•ื“ ื”ื’ื™ื‘ื•ื‘ ืฉืœ ื”ืขืกืงื”:

c1890c4d730626dfaa9449419d662505eab3bda2e1f01f89463cc1a4a30a279

ืžืคืชื—ื™ื ื™ื›ื•ืœื™ื ืœื‘ืฆืข ืฉืœื‘ ื–ื” ื‘ืืžืฆืขื•ืช ื›ืœื™ ื”ืžืจืช ืžืกืคืจื™ื ื”ืงืกื“ืฆื™ืžืœื™ (little 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 ื”ืžืกื•ืคืง ืขืœ ื™ื“ื™ 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 ืžืฉืžืฉ ืœืื—ื–ื•ืจ ื’ื•ื‘ื” ื”ืขืกืงื” ื‘ืืžืฆืขื•ืช ืงื•ื“ ื”ื’ื™ื‘ื•ื‘ ืฉืœ ื”ืขืกืงื”. ื‘ื•ืื• ื ืฉืชืžืฉ ื‘ืงื•ื“ ื”ื’ื™ื‘ื•ื‘ ืžื”ื“ื•ื’ืžื” ืœืขื™ืœ:

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 ืฉืœื•. ืชื”ืœื™ืš ื”ืžืจืช ื”-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 ืžืฉืžืฉ ืœื”ืฉื’ืช ื‘ืœื•ืง. ื™ืฉื ืŸ ืฉืชื™ ื“ืจื›ื™ื ืœื”ืฉื™ื’ ื‘ืœื•ืง ืกืคืฆื™ืคื™.

1. ืงื‘ืœ ื’ื•ื‘ื” ื‘ืœื•ืง ืื—ืจ ื‘ืœื•ืง:

from ontology.interop.System.Blockchain import GetBlock
def demo():
    block=GetBlock(1408)
    return block

2. ืงื‘ืœื• ื’ื™ื‘ื•ื‘ ื‘ืœื•ืง ืื—ืจ ื‘ืœื•ืง:

from ontology.interop.System.Blockchain import GetBlock
def demo():    
    block_hash=bytearray(b'x16xe0xc5x40x82x79x77x30x44xeax66xc8xc4x5dx17xf7x17x73x92x33x6dx54xe3x48x46x0bxc3x2fxe2x15x03xe4')
    block=GetBlock(block_hash)

2. ื›ื™ืฆื“ ืœื”ืฉืชืžืฉ ื‘ืžืžืฉืง ื”-API ืฉืœ Block

ื™ืฉื ืŸ ืฉืœื•ืฉ ืคื•ื ืงืฆื™ื•ืช ื–ืžื™ื ื•ืช ื‘-API ืฉืœ Block: ืงื‘ืœ ืขืกืงืื•ืช, ืงื‘ืœ ืžืกืคืจ ืคืขื•ืœื•ืชื• - ืงื‘ืœ ืขืกืงื” ืœืคื™ ืื™ื ื“ืงืกื ื ืชื— ืื•ืชื ืื—ื“ ืื—ื“.

ืงื‘ืœ ืžืกืคืจ ืคืขื•ืœื•ืช

ื”ืคื•ื ืงืฆื™ื” 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 txs

ืงื‘ืœ ืขืกืงื” ืœืคื™ ืื™ื ื“ืงืก

ื”ืคื•ื ืงืฆื™ื” 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.

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

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

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

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

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

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

ืงื ื” ืื™ืจื•ื— ืืžื™ืŸ ืœืืชืจื™ื ืขื ื”ื’ื ืช DDoS, ืฉืจืชื™ VPS VDS ๐Ÿ”ฅ ืงื ื” ืื—ืกื•ืŸ ืืชืจื™ื ืืžื™ืŸ ืขื ื”ื’ื ืช DDoS, ืฉืจืชื™ VPS VDS | ProHoster