UNPKG

deth

Version:

Ethereum node focused on Developer Experience

65 lines (64 loc) 3.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const ethers_1 = require("ethers"); const TestChain_1 = require("./TestChain"); const model_1 = require("./model"); const TestProviderOptions_1 = require("./TestProviderOptions"); const WalletManager_1 = require("./WalletManager"); const primitives_1 = require("./primitives"); const config_1 = require("./config/config"); class TestProvider extends ethers_1.providers.BaseProvider { constructor(logger, chainOrOptions) { // note this file should not rely on NODE/config super({ name: config_1.DEFAULT_NODE_CONFIG.blockchain.chainName, chainId: config_1.DEFAULT_NODE_CONFIG.blockchain.chainId }); if (chainOrOptions instanceof TestChain_1.TestChain) { this.chain = chainOrOptions; this.walletManager = new WalletManager_1.WalletManager(undefined, this); } else { this.chain = new TestChain_1.TestChain(logger, TestProviderOptions_1.toTestChainOptions(chainOrOptions)); this.walletManager = new WalletManager_1.WalletManager(this.chain.options.value.accounts.privateKeys, this); } } async init() { await this.chain.init(); } async mineBlock() { return this.chain.mineBlock(); } // eslint-disable-next-line @typescript-eslint/no-explicit-any async perform(method, params) { var _a; switch (method) { case 'getBlockNumber': return this.chain.getBlockNumber(); case 'getGasPrice': return this.chain.getGasPrice(); case 'getBalance': return this.chain.getBalance(primitives_1.makeAddress(params.address), params.blockTag); case 'getTransactionCount': return this.chain.getTransactionCount(primitives_1.makeAddress(params.address), params.blockTag); case 'getCode': return this.chain.getCode(primitives_1.makeAddress(params.address), params.blockTag); case 'getStorageAt': return this.chain.getStorageAt(primitives_1.makeAddress(params.address), primitives_1.makeQuantity(params.position), params.blockTag); case 'sendTransaction': return this.chain.sendTransaction(params.signedTransaction); case 'call': return this.chain.call(model_1.toRpcTransactionRequest(params.transaction), params.blockTag); case 'estimateGas': return this.chain.estimateGas(model_1.toRpcTransactionRequest(params.transaction)); case 'getBlock': return this.chain.getBlock((_a = params.blockTag, (_a !== null && _a !== void 0 ? _a : params.blockHash)), params.includeTransactions); case 'getTransaction': return this.chain.getTransaction(params.transactionHash); case 'getTransactionReceipt': return this.chain.getTransactionReceipt(params.transactionHash); case 'getLogs': return this.chain.getLogs(params.filter); default: return super.perform(method, params); } } } exports.TestProvider = TestProvider;