@ethereumjs/tx
Advanced tools
Comparing version 4.0.0 to 4.0.1
@@ -174,2 +174,5 @@ /// <reference types="node" /> | ||
}, bits?: number, cannotEqual?: boolean): void; | ||
protected static _validateNotArray(values: { | ||
[key: string]: any; | ||
}): void; | ||
/** | ||
@@ -176,0 +179,0 @@ * Return a compact error string representation of the object |
@@ -309,2 +309,26 @@ "use strict"; | ||
} | ||
static _validateNotArray(values) { | ||
const txDataKeys = [ | ||
'nonce', | ||
'gasPrice', | ||
'gasLimit', | ||
'to', | ||
'value', | ||
'data', | ||
'v', | ||
'r', | ||
's', | ||
'type', | ||
'baseFee', | ||
'maxFeePerGas', | ||
'chainId', | ||
]; | ||
for (const [key, value] of Object.entries(values)) { | ||
if (txDataKeys.includes(key)) { | ||
if (Array.isArray(value)) { | ||
throw new Error(`${key} cannot be an array`); | ||
} | ||
} | ||
} | ||
} | ||
/** | ||
@@ -311,0 +335,0 @@ * Returns the shared error postfix part for _error() method |
@@ -53,2 +53,3 @@ "use strict"; | ||
}); | ||
baseTransaction_1.BaseTransaction._validateNotArray(txData); | ||
if (this.gasLimit * this.maxFeePerGas > util_1.MAX_INTEGER) { | ||
@@ -114,2 +115,3 @@ const msg = this._errorMsg('gasLimit * maxFeePerGas cannot exceed MAX_INTEGER (2^256-1)'); | ||
const [chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data, accessList, v, r, s,] = values; | ||
this._validateNotArray({ chainId, v }); | ||
(0, util_1.validateNoLeadingZeroes)({ nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, value, v, r, s }); | ||
@@ -116,0 +118,0 @@ return new FeeMarketEIP1559Transaction({ |
@@ -52,2 +52,3 @@ "use strict"; | ||
}); | ||
baseTransaction_1.BaseTransaction._validateNotArray(txData); | ||
if (this.gasPrice * this.gasLimit > util_1.MAX_INTEGER) { | ||
@@ -109,2 +110,3 @@ const msg = this._errorMsg('gasLimit * gasPrice cannot exceed MAX_INTEGER'); | ||
const [chainId, nonce, gasPrice, gasLimit, to, value, data, accessList, v, r, s] = values; | ||
this._validateNotArray({ chainId, v }); | ||
(0, util_1.validateNoLeadingZeroes)({ nonce, gasPrice, gasLimit, value, v, r, s }); | ||
@@ -111,0 +113,0 @@ const emptyAccessList = []; |
@@ -36,2 +36,3 @@ "use strict"; | ||
this._validateCannotExceedMaxInteger({ gasPrice: this.gasPrice }); | ||
baseTransaction_1.BaseTransaction._validateNotArray(txData); | ||
if (this.common.gteHardfork('spuriousDragon')) { | ||
@@ -38,0 +39,0 @@ if (!this.isSigned()) { |
/// <reference types="node" /> | ||
import { ethers } from 'ethers'; | ||
import type { AccessListEIP2930TxData, FeeMarketEIP1559TxData, TxData, TxOptions, TypedTransaction } from './types'; | ||
@@ -29,3 +30,11 @@ export declare class TransactionFactory { | ||
static fromBlockBodyData(data: Buffer | Buffer[], txOptions?: TxOptions): TypedTransaction; | ||
/** | ||
* Method to retrieve a transaction from the provider | ||
* @param provider - An Ethers JsonRPCProvider | ||
* @param txHash - Transaction hash | ||
* @param txOptions - The transaction options | ||
* @returns the transaction specified by `txHash` | ||
*/ | ||
static fromEthersProvider(provider: string | ethers.providers.JsonRpcProvider, txHash: string, txOptions?: TxOptions): Promise<TypedTransaction>; | ||
} | ||
//# sourceMappingURL=transactionFactory.d.ts.map |
@@ -5,4 +5,6 @@ "use strict"; | ||
const util_1 = require("@ethereumjs/util"); | ||
const ethers_1 = require("ethers"); | ||
const eip1559Transaction_1 = require("./eip1559Transaction"); | ||
const eip2930Transaction_1 = require("./eip2930Transaction"); | ||
const fromRpc_1 = require("./fromRpc"); | ||
const legacyTransaction_1 = require("./legacyTransaction"); | ||
@@ -92,4 +94,17 @@ class TransactionFactory { | ||
} | ||
/** | ||
* Method to retrieve a transaction from the provider | ||
* @param provider - An Ethers JsonRPCProvider | ||
* @param txHash - Transaction hash | ||
* @param txOptions - The transaction options | ||
* @returns the transaction specified by `txHash` | ||
*/ | ||
static async fromEthersProvider(provider, txHash, txOptions) { | ||
const prov = typeof provider === 'string' ? new ethers_1.ethers.providers.JsonRpcProvider(provider) : provider; | ||
const txData = await prov.send('eth_getTransactionByHash', [txHash]); | ||
const normedTx = (0, fromRpc_1.normalizeTxParams)(txData); | ||
return TransactionFactory.fromTxData(normedTx, txOptions); | ||
} | ||
} | ||
exports.TransactionFactory = TransactionFactory; | ||
//# sourceMappingURL=transactionFactory.js.map |
{ | ||
"name": "@ethereumjs/tx", | ||
"version": "4.0.0", | ||
"version": "4.0.1", | ||
"description": "A simple module for creating, manipulating and signing Ethereum transactions", | ||
@@ -47,12 +47,14 @@ "keywords": [ | ||
"tape": "tape -r ts-node/register", | ||
"test": "npm run test:node && npm run test:browser", | ||
"test": "npm run test:node && npm run test:browser && npm run test:txTests", | ||
"test:browser": "karma start karma.conf.js", | ||
"test:node": "tape -r ts-node/register ./test/index.ts", | ||
"test:node": "tape -r ts-node/register -- 'test/**/*.spec.ts'", | ||
"test:txTests": "tape -r ts-node/register ./test/transactionRunner.ts", | ||
"tsc": "../../config/cli/ts-compile.sh" | ||
}, | ||
"dependencies": { | ||
"@ethereumjs/common": "^3.0.0", | ||
"@ethereumjs/common": "^3.0.1", | ||
"@ethereumjs/rlp": "^4.0.0", | ||
"@ethereumjs/util": "^8.0.0", | ||
"ethereum-cryptography": "^1.1.2" | ||
"ethereum-cryptography": "^1.1.2", | ||
"ethers": "^5.7.1" | ||
}, | ||
@@ -59,0 +61,0 @@ "devDependencies": { |
@@ -208,2 +208,3 @@ # @ethereumjs/tx | ||
- `public static fromBlockBodyData(data: Buffer | Buffer[], txOptions: TxOptions = {})` | ||
- `public static async fromEthersProvider(provider: string | ethers.providers.JsonRpcProvider, txHash: string, txOptions?: TxOptions)` | ||
@@ -210,0 +211,0 @@ ### Sending a Transaction |
@@ -454,2 +454,27 @@ import { Chain, Common, Hardfork } from '@ethereumjs/common' | ||
protected static _validateNotArray(values: { [key: string]: any }) { | ||
const txDataKeys = [ | ||
'nonce', | ||
'gasPrice', | ||
'gasLimit', | ||
'to', | ||
'value', | ||
'data', | ||
'v', | ||
'r', | ||
's', | ||
'type', | ||
'baseFee', | ||
'maxFeePerGas', | ||
'chainId', | ||
] | ||
for (const [key, value] of Object.entries(values)) { | ||
if (txDataKeys.includes(key)) { | ||
if (Array.isArray(value)) { | ||
throw new Error(`${key} cannot be an array`) | ||
} | ||
} | ||
} | ||
} | ||
/** | ||
@@ -456,0 +481,0 @@ * Return a compact error string representation of the object |
@@ -120,2 +120,3 @@ import { RLP } from '@ethereumjs/rlp' | ||
this._validateNotArray({ chainId, v }) | ||
validateNoLeadingZeroes({ nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, value, v, r, s }) | ||
@@ -178,2 +179,4 @@ | ||
BaseTransaction._validateNotArray(txData) | ||
if (this.gasLimit * this.maxFeePerGas > MAX_INTEGER) { | ||
@@ -180,0 +183,0 @@ const msg = this._errorMsg('gasLimit * maxFeePerGas cannot exceed MAX_INTEGER (2^256-1)') |
@@ -106,2 +106,3 @@ import { RLP } from '@ethereumjs/rlp' | ||
this._validateNotArray({ chainId, v }) | ||
validateNoLeadingZeroes({ nonce, gasPrice, gasLimit, value, v, r, s }) | ||
@@ -162,2 +163,4 @@ | ||
BaseTransaction._validateNotArray(txData) | ||
if (this.gasPrice * this.gasLimit > MAX_INTEGER) { | ||
@@ -164,0 +167,0 @@ const msg = this._errorMsg('gasLimit * gasPrice cannot exceed MAX_INTEGER') |
@@ -119,2 +119,3 @@ import { RLP } from '@ethereumjs/rlp' | ||
this._validateCannotExceedMaxInteger({ gasPrice: this.gasPrice }) | ||
BaseTransaction._validateNotArray(txData) | ||
@@ -121,0 +122,0 @@ if (this.common.gteHardfork('spuriousDragon')) { |
import { bufferToBigInt, toBuffer } from '@ethereumjs/util' | ||
import { ethers } from 'ethers' | ||
import { FeeMarketEIP1559Transaction } from './eip1559Transaction' | ||
import { AccessListEIP2930Transaction } from './eip2930Transaction' | ||
import { normalizeTxParams } from './fromRpc' | ||
import { Transaction } from './legacyTransaction' | ||
@@ -96,2 +98,21 @@ | ||
} | ||
/** | ||
* Method to retrieve a transaction from the provider | ||
* @param provider - An Ethers JsonRPCProvider | ||
* @param txHash - Transaction hash | ||
* @param txOptions - The transaction options | ||
* @returns the transaction specified by `txHash` | ||
*/ | ||
public static async fromEthersProvider( | ||
provider: string | ethers.providers.JsonRpcProvider, | ||
txHash: string, | ||
txOptions?: TxOptions | ||
) { | ||
const prov = | ||
typeof provider === 'string' ? new ethers.providers.JsonRpcProvider(provider) : provider | ||
const txData = await prov.send('eth_getTransactionByHash', [txHash]) | ||
const normedTx = normalizeTxParams(txData) | ||
return TransactionFactory.fromTxData(normedTx, txOptions) | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
265351
48
4605
362
5
+ Addedethers@^5.7.1
+ Added@ethersproject/abi@5.7.0(transitive)
+ Added@ethersproject/abstract-provider@5.7.0(transitive)
+ Added@ethersproject/abstract-signer@5.7.0(transitive)
+ Added@ethersproject/address@5.7.0(transitive)
+ Added@ethersproject/base64@5.7.0(transitive)
+ Added@ethersproject/basex@5.7.0(transitive)
+ Added@ethersproject/bignumber@5.7.0(transitive)
+ Added@ethersproject/bytes@5.7.0(transitive)
+ Added@ethersproject/constants@5.7.0(transitive)
+ Added@ethersproject/contracts@5.7.0(transitive)
+ Added@ethersproject/hash@5.7.0(transitive)
+ Added@ethersproject/hdnode@5.7.0(transitive)
+ Added@ethersproject/json-wallets@5.7.0(transitive)
+ Added@ethersproject/keccak256@5.7.0(transitive)
+ Added@ethersproject/logger@5.7.0(transitive)
+ Added@ethersproject/networks@5.7.1(transitive)
+ Added@ethersproject/pbkdf2@5.7.0(transitive)
+ Added@ethersproject/properties@5.7.0(transitive)
+ Added@ethersproject/providers@5.7.2(transitive)
+ Added@ethersproject/random@5.7.0(transitive)
+ Added@ethersproject/rlp@5.7.0(transitive)
+ Added@ethersproject/sha2@5.7.0(transitive)
+ Added@ethersproject/signing-key@5.7.0(transitive)
+ Added@ethersproject/solidity@5.7.0(transitive)
+ Added@ethersproject/strings@5.7.0(transitive)
+ Added@ethersproject/transactions@5.7.0(transitive)
+ Added@ethersproject/units@5.7.0(transitive)
+ Added@ethersproject/wallet@5.7.0(transitive)
+ Added@ethersproject/web@5.7.1(transitive)
+ Added@ethersproject/wordlists@5.7.0(transitive)
+ Addedaes-js@3.0.0(transitive)
+ Addedbech32@1.1.4(transitive)
+ Addedbn.js@4.12.05.2.1(transitive)
+ Addedbrorand@1.1.0(transitive)
+ Addedelliptic@6.5.4(transitive)
+ Addedethers@5.7.2(transitive)
+ Addedhash.js@1.1.7(transitive)
+ Addedhmac-drbg@1.0.1(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedjs-sha3@0.8.0(transitive)
+ Addedminimalistic-assert@1.0.1(transitive)
+ Addedminimalistic-crypto-utils@1.0.1(transitive)
+ Addedscrypt-js@3.0.1(transitive)
+ Addedws@7.4.6(transitive)
Updated@ethereumjs/common@^3.0.1