Methods

pytoniq's LiteClient supports all methods from the lite_api.tl. The following describes the non-obvious specifics of some of the methods:

  • raw methods

For almost all raw methods which require providing block specify block as instance of TL class BlockIdExt. If block in function arguments default value is None then last (trusted) masterchain block will be taken.

  • raw_get_account_state

Returns 2 values: instances of Account and ShardAccount TLB wrappers. The ShardAccount value is needed to take last account transaction lt and hash to get last account transactions. If Full node doesn't have account (for e.g. it's uninitilized and has zero balance) returns (None, None).

  • get_account_state

Returns instance of class SimpleAccount. The SimpleAccount is a wrapper for TLB scheme with friendly account state representation:

account_none$0 = SimpleAccount;
account$1 addr:Address balance:Grams state:SimpleAccountState = SimpleAccount;

uninitialized$00 = SimpleAccountState;
frozen$01 state_hash:bits256 = SimpleAccountState;
active$10 state_init:StateInit = SimpleAccountState;

SimpleAccount is a custom TLB Scheme and not used anywhere outside of the library

  • run_get_method

For stack argument provide just a list with get method arguments. Returns list with deserialized values.

  • raw_get_mc_block_proof

This method is used inside more high-level get_mc_block_proof method. Asks a Liteserver for block proof link and checks it. If the proof is invalid raises exceptions. If the proof is valid returns is_complete - is the proof was complete from known block to target one, last proved mc block and can return best key block and its gen_utime.

For blockLinkForward checks validators signatures of to_block

For blockLinkBack if to_key_block checks if prev key block hash in trusted block matches with to_block hash, otherwise checks if prev block hash in OldMcBlocksInfo of trusted block matches with to_block hash.

If provided return_best_key_block=True compares every key block ttl it receives with last stored (it's needed to store key block with big persistent state ttl):

def choose_key_block(blk: BlockIdExt, blk_ts: int, other_blk: typing.Optional[BlockIdExt], other_ts: typing.Optional[int]):
    if other_blk is None:
        return blk, blk_ts
    if blk is None:
        return other_blk, other_ts
    p1 = persistent_state_ttl(blk_ts)
    p2 = persistent_state_ttl(other_ts)
    c_t = time.time()
    if p1 < c_t < p2:
        return other_blk, other_ts
    if p2 < c_t < p1:
        return blk, blk_ts

    # p1 and p2 > time.time
    d1 = c_t - p1
    d2 = c_t - p2

    min_time = 21 * 3600 * 24  # 3 weeks

    if d2 >= min_time and other_blk.seqno > blk.seqno:
        return other_blk, other_ts
    elif d2 < min_time and other_blk.seqno > blk.seqno:
        if d1 >= min_time:
            return blk, blk_ts
        else:
            return other_blk, other_ts
    else:
        return blk, blk_ts

Last updated