UNPKG

@broxus/locklift-network

Version:

In-memory TVM-blockchain emulator for locklift

123 lines (122 loc) 4.89 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.LockliftTransport = void 0; const nt = __importStar(require("nekoton-wasm")); const constants_1 = require("./constants"); class LockliftTransport { executor; cache = {}; networkConfig; constructor(networkConfig) { if (typeof networkConfig === "object") { this.networkConfig = networkConfig.custom; console.log("Locklift network is using custom blockchain config"); return; } if (networkConfig === "TON") { this.networkConfig = constants_1.TON_CONFIG; console.log("Locklift network is using TON blockchain config"); return; } if (networkConfig === "EVER") { this.networkConfig = constants_1.EVER_MAIN_CONFIG; console.log("Locklift network is using TYCHO blockchain config"); return; } this.networkConfig = constants_1.TYCHO_CONFIG; console.log("Locklift network is using TYCHO-TESTNET blockchain"); } getLibraryCell(hash) { throw new Error("Method not implemented."); } setExecutor(executor) { this.executor = executor; } info() { return { hasKeyBlocks: false, maxTransactionsPerFetch: 255, reliableBehavior: "IntensivePolling", }; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async getAccountsByCodeHash(codeHash, limit, continuation) { if (codeHash === constants_1.TEST_CODE_HASH) { return [constants_1.ZERO_ADDRESS.toString()]; } // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const q = Object.entries(this.executor.getAccounts()) .filter(([_, state]) => state.codeHash === codeHash) .map(([address, _]) => address); return q; } // @ts-ignore getBlockchainConfig() { return Promise.resolve({ boc: this.networkConfig, globalId: 42, }); } // eslint-disable-next-line @typescript-eslint/no-unused-vars async getCapabilities(nowMs) { const config = await this.getBlockchainConfig(); if (this.cache["capabilities"] == null) { const cap = nt.getCapabilitiesFromConfig(config.boc); this.cache["capabilities"] = { globalId: config.globalId, raw: Number(cap), }; } return Promise.resolve(this.cache["capabilities"]); } async getContractState(address) { const state = await this.executor._getAccount(address); return state ? nt.parseShardAccountBoc(state)?.boc || constants_1.EMPTY_STATE : constants_1.EMPTY_STATE; } getDstTransaction(msgHash) { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion return Promise.resolve(this.executor.getDstTransaction(msgHash)?.boc); } getLatestKeyBlock() { return Promise.resolve(""); } getTransaction(id) { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion return Promise.resolve(this.executor.getTransaction(id)?.boc); } getTransactions(address, fromLt, count) { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion return Promise.resolve(this.executor.getTransactions(address, fromLt, count).map(tx => tx.boc)); } async sendMessage(message) { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion this.executor.enqueueMsg(nt.parseMessageBase64Extended(message)); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion await this.executor.processQueue(); return Promise.resolve(); } } exports.LockliftTransport = LockliftTransport;