UNPKG

deth

Version:

Ethereum node focused on Developer Experience

74 lines (73 loc) 2.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const primitives_1 = require("../primitives"); const ethereumjs_tx_1 = require("ethereumjs-tx"); const ethers_1 = require("ethers"); function toFakeTransaction(tx) { var _a; return new ethereumjs_tx_1.FakeTransaction({ from: (_a = tx.from, (_a !== null && _a !== void 0 ? _a : '0x0000000000000000000000000000000000000000')), to: tx.to, data: tx.data, gasLimit: tx.gas, gasPrice: tx.gasPrice, nonce: tx.nonce, value: tx.value, }); } exports.toFakeTransaction = toFakeTransaction; const toQuantity = (value) => primitives_1.makeQuantity(ethers_1.utils.hexStripZeros(ethers_1.utils.hexlify(value))); const toAddress = (value) => primitives_1.makeAddress(ethers_1.utils.hexlify(value)); const toHexData = (value) => primitives_1.makeHexData(ethers_1.utils.hexlify(value)); function toRpcTransactionRequest(transaction) { const result = {}; if (transaction.gasLimit) { result.gas = toQuantity(transaction.gasLimit); } if (transaction.gasPrice) { result.gasPrice = toQuantity(transaction.gasPrice); } if (transaction.nonce) { result.nonce = toQuantity(transaction.nonce); } if (transaction.value) { result.value = toQuantity(transaction.value); } if (transaction.from) { result.from = toAddress(transaction.from); } if (transaction.to) { result.to = toAddress(transaction.to); } if (transaction.data) { result.data = toHexData(transaction.data); } return result; } exports.toRpcTransactionRequest = toRpcTransactionRequest; function toEthersTransaction(tx) { const result = {}; if (tx.data) { result.data = tx.data; } if (tx.from) { result.from = tx.from; } if (tx.gas) { result.gasLimit = tx.gas; } if (tx.gasPrice) { result.gasPrice = tx.gasPrice; } if (tx.nonce) { result.nonce = tx.nonce; } if (tx.to) { result.to = tx.to; } if (tx.value) { result.value = tx.value; } return result; } exports.toEthersTransaction = toEthersTransaction;