@eliseev_s/tolk-tlb-transpiler
Version:
Transpile Tolk structs to TLB definitions and generate TypeScript wrappers for TON blockchain smart contracts
146 lines • 5.04 kB
TypeScript
import { Address, Cell } from '@ton/core';
/**
* Parameters passed to caption handlers for parsing message bodies
*/
export interface CaptionHandlerParams {
body: Cell;
src?: Address | null;
dst?: Address | null;
}
/**
* Handler function that parses a message body and returns caption data
*/
export type CaptionHandler = (params: CaptionHandlerParams) => Record<string, any>;
/**
* Handler function that parses contract storage
*/
export type StorageParser = (cell: Cell) => Record<string, any>;
/**
* Result of the TolkGraphAdapter
*/
export interface TolkGraphAdapterResult {
/** Maps opcode (number) to message name */
opMap: Map<number, string>;
/** Maps error code (number) to error name */
errMap: Map<number, string>;
/** Maps opcode (number) to caption handler for parsing message bodies */
captionsMap: Map<number, CaptionHandler>;
/** Maps contract name to storage parser */
contractToParserMap: Map<string, StorageParser>;
}
/**
* Configuration options for TolkGraphAdapter
*/
export interface TolkGraphAdapterOptions {
/**
* List of parameters to exclude from captions
* @defaultValue ['query_id', 'excesses']
*/
blacklistParams?: string[] | null;
/**
* Whether to hide address fields in captions
* @defaultValue false
*/
hideAddresses?: boolean;
/**
* Whether to show all fields including blacklisted ones
* @defaultValue false
*/
showAll?: boolean;
/**
* Prefix for opcode constants (e.g., 'OP_', 'op::')
* If not provided, opcodes are extracted from message struct prefixes
*/
opcodeConstantPrefix?: string;
/**
* Prefix for error constants
* @defaultValue 'ERROR_'
*/
errorConstantPrefix?: string;
}
/**
* Adapter class for generating transaction visualization helpers from Tolk code
*
* @remarks
* This class generates:
* - `opMap`: Maps operation codes to their names
* - `errMap`: Maps error codes to their names
* - `captionsMap`: Contains handlers for parsing message bodies
* - `contractToParserMap`: Contains handlers for parsing contract storage
*
* @example
* ```typescript
* const result = await TolkGraphAdapter.fromFiles({
* structuresPath: 'contracts/structures.tolk',
* errorsPath: 'contracts/errors.tolk',
* contractName: 'MyContract',
* internalMessageType: 'MyContractInternalMessage',
* });
*
* // Use the adapter for transaction visualization
* const { opMap, errMap, captionsMap, contractToParserMap } = result;
* ```
*/
export declare class TolkGraphAdapter {
/**
* Create adapter from Tolk file paths
*
* @param config - Configuration with file paths and contract info
* @param options - Additional options for caption generation
* @returns Promise resolving to adapter result with all maps
*/
static fromFiles(config: {
/** Path to Tolk file with struct definitions */
structuresPath: string;
/** Optional path to Tolk file with error constants */
errorsPath?: string;
/** Optional path to additional Tolk file with opcode constants */
opcodesPath?: string;
/** Name of the contract (used for storage parser) */
contractName: string;
/** Type name for internal messages (e.g., "MyContractInternalMessage") */
internalMessageType: string;
}, options?: TolkGraphAdapterOptions): Promise<TolkGraphAdapterResult>;
/**
* Create adapter from Tolk source code strings
*
* @param config - Configuration with source code and contract info
* @param options - Additional options for caption generation
* @returns Promise resolving to adapter result with all maps
*/
static fromContent(config: {
/** Tolk code containing struct definitions */
structuresCode: string;
/** Optional Tolk code with error constants */
errorsCode?: string;
/** Optional Tolk code with opcode constants */
opcodesCode?: string;
/** Name of the contract */
contractName: string;
/** Type name for internal messages */
internalMessageType: string;
}, options?: TolkGraphAdapterOptions): Promise<TolkGraphAdapterResult>;
/**
* Extract opcodes from message structs that have prefixes
*/
private static extractOpcodesFromStructs;
/**
* Format TLB definitions to string
*/
private static formatTlbDefinitions;
}
/**
* Merge multiple TolkGraphAdapterResult objects into one
*
* @param results - Array of adapter results to merge
* @returns Merged result with all maps combined
*
* @example
* ```typescript
* const result1 = await TolkGraphAdapter.fromFiles({ ... });
* const result2 = await TolkGraphAdapter.fromFiles({ ... });
* const merged = mergeGraphAdapterResults([result1, result2]);
* ```
*/
export declare function mergeGraphAdapterResults(results: TolkGraphAdapterResult[]): TolkGraphAdapterResult;
//# sourceMappingURL=graph-adapter.d.ts.map