Skip to content

Latest commit

 

History

History
671 lines (457 loc) · 12.4 KB

mod_boc.md

File metadata and controls

671 lines (457 loc) · 12.4 KB

Module boc

BOC manipulation module.

Functions

parse_message – Parses message boc into a JSON

parse_transaction – Parses transaction boc into a JSON

parse_account – Parses account boc into a JSON

parse_block – Parses block boc into a JSON

parse_shardstate – Parses shardstate boc into a JSON

get_blockchain_config – Extract blockchain configuration from key block and also from zerostate.

get_boc_hash – Calculates BOC root hash

get_code_from_tvc – Extracts code from TVC contract image

cache_get – Get BOC from cache

cache_set – Save BOC into cache

cache_unpin – Unpin BOCs with specified pin.

encode_boc – Encodes BOC from builder operations.

Types

BocCacheType

BocErrorCode

ParamsOfParse

ResultOfParse

ParamsOfParseShardstate

ParamsOfGetBlockchainConfig

ResultOfGetBlockchainConfig

ParamsOfGetBocHash

ResultOfGetBocHash

ParamsOfGetCodeFromTvc

ResultOfGetCodeFromTvc

ParamsOfBocCacheGet

ResultOfBocCacheGet

ParamsOfBocCacheSet

ResultOfBocCacheSet

ParamsOfBocCacheUnpin

BuilderOp – Cell builder operation.

ParamsOfEncodeBoc

ResultOfEncodeBoc

Functions

parse_message

Parses message boc into a JSON

JSON structure is compatible with GraphQL API message object

type ParamsOfParse = {
    boc: string
}

type ResultOfParse = {
    parsed: any
}

function parse_message(
    params: ParamsOfParse,
): Promise<ResultOfParse>;

Parameters

  • boc: string – BOC encoded as base64

Result

  • parsed: any – JSON containing parsed BOC

parse_transaction

Parses transaction boc into a JSON

JSON structure is compatible with GraphQL API transaction object

type ParamsOfParse = {
    boc: string
}

type ResultOfParse = {
    parsed: any
}

function parse_transaction(
    params: ParamsOfParse,
): Promise<ResultOfParse>;

Parameters

  • boc: string – BOC encoded as base64

Result

  • parsed: any – JSON containing parsed BOC

parse_account

Parses account boc into a JSON

JSON structure is compatible with GraphQL API account object

type ParamsOfParse = {
    boc: string
}

type ResultOfParse = {
    parsed: any
}

function parse_account(
    params: ParamsOfParse,
): Promise<ResultOfParse>;

Parameters

  • boc: string – BOC encoded as base64

Result

  • parsed: any – JSON containing parsed BOC

parse_block

Parses block boc into a JSON

JSON structure is compatible with GraphQL API block object

type ParamsOfParse = {
    boc: string
}

type ResultOfParse = {
    parsed: any
}

function parse_block(
    params: ParamsOfParse,
): Promise<ResultOfParse>;

Parameters

  • boc: string – BOC encoded as base64

Result

  • parsed: any – JSON containing parsed BOC

parse_shardstate

Parses shardstate boc into a JSON

JSON structure is compatible with GraphQL API shardstate object

type ParamsOfParseShardstate = {
    boc: string,
    id: string,
    workchain_id: number
}

type ResultOfParse = {
    parsed: any
}

function parse_shardstate(
    params: ParamsOfParseShardstate,
): Promise<ResultOfParse>;

Parameters

  • boc: string – BOC encoded as base64
  • id: string – Shardstate identificator
  • workchain_id: number – Workchain shardstate belongs to

Result

  • parsed: any – JSON containing parsed BOC

get_blockchain_config

Extract blockchain configuration from key block and also from zerostate.

type ParamsOfGetBlockchainConfig = {
    block_boc: string
}

type ResultOfGetBlockchainConfig = {
    config_boc: string
}

function get_blockchain_config(
    params: ParamsOfGetBlockchainConfig,
): Promise<ResultOfGetBlockchainConfig>;

Parameters

  • block_boc: string – Key block BOC or zerostate BOC encoded as base64

Result

  • config_boc: string – Blockchain config BOC encoded as base64

get_boc_hash

Calculates BOC root hash

type ParamsOfGetBocHash = {
    boc: string
}

type ResultOfGetBocHash = {
    hash: string
}

function get_boc_hash(
    params: ParamsOfGetBocHash,
): Promise<ResultOfGetBocHash>;

Parameters

  • boc: string – BOC encoded as base64

Result

  • hash: string – BOC root hash encoded with hex

get_code_from_tvc

Extracts code from TVC contract image

type ParamsOfGetCodeFromTvc = {
    tvc: string
}

type ResultOfGetCodeFromTvc = {
    code: string
}

function get_code_from_tvc(
    params: ParamsOfGetCodeFromTvc,
): Promise<ResultOfGetCodeFromTvc>;

Parameters

  • tvc: string – Contract TVC image encoded as base64

Result

  • code: string – Contract code encoded as base64

cache_get

Get BOC from cache

type ParamsOfBocCacheGet = {
    boc_ref: string
}

type ResultOfBocCacheGet = {
    boc?: string
}

function cache_get(
    params: ParamsOfBocCacheGet,
): Promise<ResultOfBocCacheGet>;

Parameters

  • boc_ref: string – Reference to the cached BOC

Result

  • boc?: string – BOC encoded as base64.

cache_set

Save BOC into cache

type ParamsOfBocCacheSet = {
    boc: string,
    cache_type: BocCacheType
}

type ResultOfBocCacheSet = {
    boc_ref: string
}

function cache_set(
    params: ParamsOfBocCacheSet,
): Promise<ResultOfBocCacheSet>;

Parameters

  • boc: string – BOC encoded as base64 or BOC reference
  • cache_type: BocCacheType – Cache type

Result

  • boc_ref: string – Reference to the cached BOC

cache_unpin

Unpin BOCs with specified pin.

BOCs which don't have another pins will be removed from cache

type ParamsOfBocCacheUnpin = {
    pin: string,
    boc_ref?: string
}

function cache_unpin(
    params: ParamsOfBocCacheUnpin,
): Promise<void>;

Parameters

  • pin: string – Pinned name
  • boc_ref?: string – Reference to the cached BOC.
    If it is provided then only referenced BOC is unpinned

encode_boc

Encodes BOC from builder operations.

type ParamsOfEncodeBoc = {
    builder: BuilderOp[],
    boc_cache?: BocCacheType
}

type ResultOfEncodeBoc = {
    boc: string
}

function encode_boc(
    params: ParamsOfEncodeBoc,
): Promise<ResultOfEncodeBoc>;

Parameters

  • builder: BuilderOp[] – Cell builder operations.
  • boc_cache?: BocCacheType – Cache type to put the result. The BOC itself returned if no cache type provided.

Result

  • boc: string – Encoded cell BOC or BOC cache key.

Types

BocCacheType

type BocCacheType = {
    type: 'Pinned'
    pin: string
} | {
    type: 'Unpinned'
}

Depends on value of the type field.

When type is 'Pinned'

Pin the BOC with pin name.

Such BOC will not be removed from cache until it is unpinned

  • pin: string

When type is 'Unpinned'

Variant constructors:

function bocCacheTypePinned(pin: string): BocCacheType;
function bocCacheTypeUnpinned(): BocCacheType;

BocErrorCode

enum BocErrorCode {
    InvalidBoc = 201,
    SerializationError = 202,
    InappropriateBlock = 203,
    MissingSourceBoc = 204,
    InsufficientCacheSize = 205,
    BocRefNotFound = 206,
    InvalidBocRef = 207
}

One of the following value:

  • InvalidBoc = 201
  • SerializationError = 202
  • InappropriateBlock = 203
  • MissingSourceBoc = 204
  • InsufficientCacheSize = 205
  • BocRefNotFound = 206
  • InvalidBocRef = 207

ParamsOfParse

type ParamsOfParse = {
    boc: string
}
  • boc: string – BOC encoded as base64

ResultOfParse

type ResultOfParse = {
    parsed: any
}
  • parsed: any – JSON containing parsed BOC

ParamsOfParseShardstate

type ParamsOfParseShardstate = {
    boc: string,
    id: string,
    workchain_id: number
}
  • boc: string – BOC encoded as base64
  • id: string – Shardstate identificator
  • workchain_id: number – Workchain shardstate belongs to

ParamsOfGetBlockchainConfig

type ParamsOfGetBlockchainConfig = {
    block_boc: string
}
  • block_boc: string – Key block BOC or zerostate BOC encoded as base64

ResultOfGetBlockchainConfig

type ResultOfGetBlockchainConfig = {
    config_boc: string
}
  • config_boc: string – Blockchain config BOC encoded as base64

ParamsOfGetBocHash

type ParamsOfGetBocHash = {
    boc: string
}
  • boc: string – BOC encoded as base64

ResultOfGetBocHash

type ResultOfGetBocHash = {
    hash: string
}
  • hash: string – BOC root hash encoded with hex

ParamsOfGetCodeFromTvc

type ParamsOfGetCodeFromTvc = {
    tvc: string
}
  • tvc: string – Contract TVC image encoded as base64

ResultOfGetCodeFromTvc

type ResultOfGetCodeFromTvc = {
    code: string
}
  • code: string – Contract code encoded as base64

ParamsOfBocCacheGet

type ParamsOfBocCacheGet = {
    boc_ref: string
}
  • boc_ref: string – Reference to the cached BOC

ResultOfBocCacheGet

type ResultOfBocCacheGet = {
    boc?: string
}
  • boc?: string – BOC encoded as base64.

ParamsOfBocCacheSet

type ParamsOfBocCacheSet = {
    boc: string,
    cache_type: BocCacheType
}
  • boc: string – BOC encoded as base64 or BOC reference
  • cache_type: BocCacheType – Cache type

ResultOfBocCacheSet

type ResultOfBocCacheSet = {
    boc_ref: string
}
  • boc_ref: string – Reference to the cached BOC

ParamsOfBocCacheUnpin

type ParamsOfBocCacheUnpin = {
    pin: string,
    boc_ref?: string
}
  • pin: string – Pinned name
  • boc_ref?: string – Reference to the cached BOC.
    If it is provided then only referenced BOC is unpinned

BuilderOp

Cell builder operation.

type BuilderOp = {
    type: 'Integer'
    size: number,
    value: any
} | {
    type: 'BitString'
    value: string
} | {
    type: 'Cell'
    builder: BuilderOp[]
} | {
    type: 'CellBoc'
    boc: string
}

Depends on value of the type field.

When type is 'Integer'

Append integer to cell data.

  • size: number – Bit size of the value.
  • value: any – Value: - Number containing integer number.
    e.g. 123, -123. - Decimal string. e.g. "123", "-123".
    - 0x prefixed hexadecimal string.
    e.g 0x123, 0X123, -0x123.

When type is 'BitString'

Append bit string to cell data.

  • value: string – Bit string content using bitstring notation. See TON VM specification 1.0.
    Contains hexadecimal string representation:
    - Can end with _ tag.
    - Can be prefixed with x or X.
    - Can be prefixed with x{ or X{ and ended with }.

    Contains binary string represented as a sequence
    of 0 and 1 prefixed with n or N.

    Examples:
    1AB, x1ab, X1AB, x{1abc}, X{1ABC}
    2D9_, x2D9_, X2D9_, x{2D9_}, X{2D9_}
    n00101101100, N00101101100

When type is 'Cell'

Append ref to nested cells

  • builder: BuilderOp[] – Nested cell builder

When type is 'CellBoc'

Append ref to nested cell

  • boc: string – Nested cell BOC encoded with base64 or BOC cache key.

Variant constructors:

function builderOpInteger(size: number, value: any): BuilderOp;
function builderOpBitString(value: string): BuilderOp;
function builderOpCell(builder: BuilderOp[]): BuilderOp;
function builderOpCellBoc(boc: string): BuilderOp;

ParamsOfEncodeBoc

type ParamsOfEncodeBoc = {
    builder: BuilderOp[],
    boc_cache?: BocCacheType
}
  • builder: BuilderOp[] – Cell builder operations.
  • boc_cache?: BocCacheType – Cache type to put the result. The BOC itself returned if no cache type provided.

ResultOfEncodeBoc

type ResultOfEncodeBoc = {
    boc: string
}
  • boc: string – Encoded cell BOC or BOC cache key.