ืื™ืš ื›ื•ืชื‘ื™ื ื—ื•ื–ื” ื—ื›ื ื‘ืคื™ื™ืชื•ืŸ ื‘ืจืฉืช ืื•ื ื˜ื•ืœื•ื’ื™ื”. ื—ืœืง 3: ืจื™ืฆื” API

ืื™ืš ื›ื•ืชื‘ื™ื ื—ื•ื–ื” ื—ื›ื ื‘ืคื™ื™ืชื•ืŸ ื‘ืจืฉืช ืื•ื ื˜ื•ืœื•ื’ื™ื”. ื—ืœืง 3: ืจื™ืฆื” API

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

  1. Blockchain & Block API
  2. ืžืžืฉืง API ืœืื—ืกื•ืŸ.

ื›ืขืช, ืœืื—ืจ ืฉื™ืฉ ืœืš ืจืขื™ื•ืŸ ื›ื™ืฆื“ ืœืงืจื•ื ืœ-API ื”ืื—ืกื•ืŸ ื”ืžืชืžืฉืš ื”ืžืชืื™ื ื‘ืขืช ืคื™ืชื•ื— ื—ื•ื–ื” ื—ื›ื ื‘ืืžืฆืขื•ืช Python ื‘ืจืฉืช ืื•ื ื˜ื•ืœื•ื’ื™ื”, ื‘ื•ืื• ื ืขื‘ื•ืจ ืœืœืžื•ื“ ื›ื™ืฆื“ ืœื”ืฉืชืžืฉ API ืฉืœ ื–ืžืŸ ืจื™ืฆื” (API ืœื‘ื™ืฆื•ืข ื—ื•ื–ื”). ืœ-Runtime API ื™ืฉ 8 ืžืžืฉืงื™ API ืงืฉื•ืจื™ื ื”ืžืกืคืงื™ื ืžืžืฉืงื™ื ื ืคื•ืฆื™ื ืœื‘ื™ืฆื•ืข ื—ื•ื–ื” ื•ืขื•ื–ืจื™ื ืœืžืคืชื—ื™ื ืœืื—ื–ืจ, ืœืฉื ื•ืช ื•ืœืืžืช ื ืชื•ื ื™ื.

ืœื”ืœืŸ ืชื™ืื•ืจ ืงืฆืจ ืฉืœ 8 ื ืชื•ื ื™ ื”-API:

ืื™ืš ื›ื•ืชื‘ื™ื ื—ื•ื–ื” ื—ื›ื ื‘ืคื™ื™ืชื•ืŸ ื‘ืจืฉืช ืื•ื ื˜ื•ืœื•ื’ื™ื”. ื—ืœืง 3: ืจื™ืฆื” API

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

ื›ื™ืฆื“ ืœื”ืฉืชืžืฉ ื‘- Runtime API

ื™ืฉื ืŸ ืฉืชื™ ื“ืจื›ื™ื ืœื™ื™ื‘ื ื–ืžืŸ ืจื™ืฆื” API: ontology.interop.System.Runtime ะธ ืื•ื ื˜ื•ืœื•ื’ื™ื”.ืื™ื ื˜ืจื•ืค.ืื•ื ื˜ื•ืœื•ื’ื™ื”.ื–ืžืŸ ืจื™ืฆื”. ื ืชื™ื‘ ื”ืื•ื ื˜ื•ืœื•ื’ื™ื” ืžื›ื™ืœ ืืช ืžืžืฉืงื™ ื”-API ื”ื—ื“ืฉื™ื ืฉื ื•ืกืคื•. ื”ืฉื•ืจื•ืช ืœืžื˜ื” ืžื™ื™ื‘ืื•ืช ืืช ื ืชื•ื ื™ ื”-API.

from ontology.interop.System.Runtime import GetTime, CheckWitness, Log, Notify, Serialize, Deserialize
from ontology.interop.Ontology.Runtime import Base58ToAddress, AddressToBase58, GetCurrentBlockHash

ื”ื•ื“ืข ืœ-API

ื”ืคื•ื ืงืฆื™ื” Notify ืžืฉื“ืจืช ืืช ื”ืื™ืจื•ืข ื‘ืจื—ื‘ื™ ื”ืจืฉืช. ื‘ื“ื•ื’ืžื” ืฉืœืžื˜ื”, ื”ืคื•ื ืงืฆื™ื” Notify ืชื—ื–ื™ืจ ืืช ืžื—ืจื•ื–ืช ื”hex "hello word" ื•ืชืฉื“ืจ ืื•ืชื” ื‘ืจื—ื‘ื™ ื”ืจืฉืช.

from ontology.interop.System.Runtime import Notify
def demo():
    Notify("hello world")

ืืชื” ื™ื›ื•ืœ ืœืจืื•ืช ืืช ื–ื” ื‘ื™ื•ืžื ื™ื:

ืื™ืš ื›ื•ืชื‘ื™ื ื—ื•ื–ื” ื—ื›ื ื‘ืคื™ื™ืชื•ืŸ ื‘ืจืฉืช ืื•ื ื˜ื•ืœื•ื’ื™ื”. ื—ืœืง 3: ืจื™ืฆื” API

GetTime API

ื”ืคื•ื ืงืฆื™ื” GetTime ืžื—ื–ื™ืจื” ืืช ื—ื•ืชืžืช ื”ื–ืžืŸ ื”ื ื•ื›ื—ื™ืช, ื”ืžื—ื–ื™ืจื” ืืช ื–ืžืŸ ื”-Unix ืฉื‘ื• ื ืงืจืื” ื”ืคื•ื ืงืฆื™ื”. ื™ื—ื™ื“ืช ื”ืžื™ื“ื” ื”ื™ื ืฉื ื™ื™ื”.

from ontology.interop.System.Runtime import GetTime
def demo():
    time=GetTime()
    return time # return a uint num

ืžืžืฉืง API ืฉืœ GetCurrentBlockHash

ื”ืคื•ื ืงืฆื™ื” GetCurrentBlockHash ืžื—ื–ื™ืจื” ืืช ื”-hash ืฉืœ ื”ื‘ืœื•ืง ื”ื ื•ื›ื—ื™.

from ontology.interop.Ontology.Runtime import GetCurrentBlockHash
def demo():
    block_hash = GetCurrentBlockHash()
    return block_hash

ืกื™ื“ื•ืจ ื•ื‘ื™ื˜ื•ืœ ืกื“ืจื”

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

from ontology.interop.System.Runtime import GetTime, CheckWitness, Log, Notify, Serialize, Deserialize
from ontology.interop.System.Storage import Put, Get, GetContext

def Main(operation, args):
    if operation == 'serialize_to_bytearray':
        data = args[0]
        return serialize_to_bytearray(data)
    if operation == 'deserialize_from_bytearray':
        key = args[0]
        return deserialize_from_bytearray(key)
    return False


def serialize_to_bytearray(data):
    sc = GetContext()
    key = "1"
    byte_data = Serialize(data)
    Put(sc, key, byte_data)


def deserialize_from_bytearray(key):
    sc = GetContext()
    byte_data = Get(sc, key)
    data = Deserialize(byte_data)
    return data

Base58ToAddress ื•-AddressToBase58

ืฆืžื“ ื–ื” ืฉืœ ืคื•ื ืงืฆื™ื•ืช ืชืจื’ื•ื ื›ืชื•ื‘ื•ืช. ื”ืคื•ื ืงืฆื™ื” Base58ToAddress ืžืžื™ืจื” ื›ืชื•ื‘ืช ืžืงื•ื“ื“ืช base58 ืœื›ืชื•ื‘ืช bytearray, ื•-AddressToBase58 ืžืžื™ืจื” ื›ืชื•ื‘ืช bytearray ืœื›ืชื•ื‘ืช ืžืงื•ื“ื“ืช base58.

from ontology.interop.Ontology.Runtime import Base58ToAddress, AddressToBase58
def demo():
    base58_addr="AV1GLfVzw28vtK3d1kVGxv5xuWU59P6Sgn"
    addr=Base58ToAddress(base58_addr)
    Log(addr)
    base58_addr=AddressToBase58(addr)
    Log(base58_addr)

ื‘ื“ื•ืง ืขื“

ืœืคื•ื ืงืฆื™ื” CheckWitness(fromAcct) ื™ืฉ ืฉืชื™ ืคื•ื ืงืฆื™ื•ืช:

  • ื•ื“ื ืื ื”ืžืชืงืฉืจ ืฉืœ ื”ืคื•ื ืงืฆื™ื” ื”ื ื•ื›ื—ื™ืช ื”ื•ื ืž-Act. ืื ื›ืŸ (ื›ืœื•ืžืจ, ืื™ืžื•ืช ื”ื—ืชื™ืžื” ืขื‘ืจ), ื”ืคื•ื ืงืฆื™ื” ื—ื•ื–ืจืช.
  • ื‘ื“ื•ืง ืื ื”ืื•ื‘ื™ื™ืงื˜ ื”ืงื•ืจื ืœืคื•ื ืงืฆื™ื” ื”ื ื•ื›ื—ื™ืช ื”ื•ื ื—ื•ื–ื”. ืื ืžื“ื•ื‘ืจ ื‘ื—ื•ื–ื” ื•ื”ืคื•ื ืงืฆื™ื” ืžื‘ื•ืฆืขืช ืžืชื•ืš ื”ื—ื•ื–ื”, ื”ืื™ืžื•ืช ืžื•ืขื‘ืจ. ื›ืœื•ืžืจ, ื•ื“ื ืื fromAcct ื”ื•ื ืขืจืš ื”ื”ื—ื–ืจื” ืฉืœ GetCallingScriptHash(). ื”ืคื•ื ืงืฆื™ื” GetCallingScriptHash() ื™ื›ื•ืœื” ืœืงื—ืช ืืช ืขืจืš ื”ื’ื™ื‘ื•ื‘ ืฉืœ ื”ื—ื•ื–ื” ืฉืœ ื”ื—ื•ื–ื” ื”ื—ื›ื ื”ื ื•ื›ื—ื™.

GetCallingScriptHash():

ืงืจื ืขื•ื“ ื‘ื ื•ืฉื Guthub

from ontology.interop.System.Runtime import CheckWitness
from ontology.interop.Ontology.Runtime import Base58ToAddress
def demo():
    addr=Base58ToAddress("AW8hN1KhHE3fLDoPAwrhtjD1P7vfad3v8z")
    res=CheckWitness(addr)
    return res

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

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

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

ืžืฉื™ืžื•ืช ืคืชื•ื—ื•ืช ืœืžืคืชื—ื™ื. ื”ืฉืœื ืืช ื”ืžืฉื™ืžื” ื•ืงื‘ืœ ืคืจืก.

ืœื”ื’ื™ืฉ ืžื•ืขืžื“ื•ืช ืขื‘ื•ืจ ืชื•ื›ื ื™ืช ื”ื›ื™ืฉืจื•ื ื•ืช ืื•ื ื˜ื•ืœื•ื’ื™ื” ืœืกื˜ื•ื“ื ื˜ื™ื

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

ืืชืจ ืื•ื ื˜ื•ืœื•ื’ื™ื” - GitHub - ืžื—ืœื•ืงืช - ื˜ืœื’ืจื ืจื•ืกื™ืช - ื˜ื•ื™ื˜ืจ - reddit

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

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