UNPKG

@signumjs/contracts

Version:

Smart Contracts package for Signum Network

88 lines (87 loc) 2.9 kB
/** * Copyright (c) 2019 Burst Apps Team */ import { Contract } from './typings/contract'; /** * Helper class for contracts * * A contract owns additional data, which is split in 8 byte blocks. * The content is encoded in hexadecimal representation and big endianness. * This class facilitates access to these data. The term "index" is used to address * these 8 byte blocks * * @example * A contract may have the following data * * ``` * 010000000000000000e1f5050000000000000000000000003eba832d8f2c82fe0048e80100000000 * ``` * * Then it can be split into five data sections each 8 bytes (16 chars in hex) and indexed like shown * * ``` * 0100000000000000 00e1f50500000000 0000000000000000 3eba832d8f2c82fe 0048e80100000000 * * |------ 0 ------|------ 1 -------|------ 2 -------|------ 3 -------|------ 4 ------| = Indices * * ``` * * @example Usage * * ```ts * const client = LedgerClientFactory.createClient({nodehost: "https://europe.signum.network"}); * const nft = await client.contracts.getContract("9482276719950823724"); * const dataView - new ContractDataView(nft); * const ownerId = dataView.getVariableAsDecimal(0); * const currentPrice = Amount.fromPlanck(dataview.getVariableAsDecimal(2)); * ``` * */ export declare class ContractDataView { private readonly _contract; /** * The length of a contracts variable (considering Hex notation) */ static VariableLength: number; constructor(_contract: Contract); /** * @return Get the contract */ getContract(): Contract; /** * @return The number of code pages */ countCodePages(): number; /** * Get a variable as string * @param index The index of variable (starting at 0) * @return The data as string (Utf-8) */ getVariableAsString(index: number): string; /** * Get multiple data blocks as string * @param index The index of variable (starting at 0) * @param count Number of blocks * @return The data as string (Utf-8) */ getDataBlocksAsString(index: number, count?: number): string; /** * Get a variable as decimal (string) * @param index The index of variable (starting at 0) * @return The data as a decimal string sequence */ getVariableAsDecimal(index: number): string; /** * Get a variable at given position/index * @param index The index of variable (starting at 0) * @return The data as hexadecimal string (in little endianness) */ getVariable(index: number): string; /** * Get a hexadecimal data block of arbitrary length at given position/index * @param index The index of variable (starting at 0) * @param length The length of the data block (must be a multiple of 2) * @return The data as hexadecimal string (in little endianness) */ getHexDataAt(index: number, length?: number): string; }