Skip to content

Commit

Permalink
finish
Browse files Browse the repository at this point in the history
  • Loading branch information
avkos committed Oct 12, 2023
1 parent 0311eb6 commit 12d325a
Show file tree
Hide file tree
Showing 10 changed files with 555 additions and 1,027 deletions.
2 changes: 2 additions & 0 deletions packages/web3-eth-accounts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ Documentation:
### Added

- Added public function `privateKeyToPublicKey`
- Added exporting `BaseTransaction` from the package (#6493)
- Added exporting `txUtils` from the package (#6493)

### Fixed

Expand Down
29 changes: 21 additions & 8 deletions packages/web3-eth-accounts/src/tx/baseTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,9 @@ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
import { Numbers } from 'web3-types';
import { bytesToHex } from 'web3-utils';
import { MAX_INTEGER, MAX_UINT64, SECP256K1_ORDER_DIV_2, secp256k1 } from './constants.js';
import {
Chain,
Common,
Hardfork,
toUint8Array,
uint8ArrayToBigInt,
unpadUint8Array,
} from '../common/index.js';
import { toUint8Array, uint8ArrayToBigInt, unpadUint8Array } from '../common/utils.js';
import { Common } from '../common/common.js';
import { Hardfork, Chain } from '../common/enums.js';
import type {
AccessListEIP2930TxData,
AccessListEIP2930ValuesArray,
Expand Down Expand Up @@ -565,4 +560,22 @@ export abstract class BaseTransaction<TransactionObject> {

return { r, s, v };
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
public static fromSerializedTx(
// @ts-expect-error unused variable
serialized: Uint8Array,
// @ts-expect-error unused variable
opts: TxOptions = {},
// eslint-disable-next-line @typescript-eslint/no-empty-function
): any {}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
public static fromTxData(
// @ts-expect-error unused variable
txData: any,
// @ts-expect-error unused variable
opts: TxOptions = {},
// eslint-disable-next-line @typescript-eslint/no-empty-function
): any {}
}
2 changes: 1 addition & 1 deletion packages/web3-eth-accounts/src/tx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ export { AccessListEIP2930Transaction } from './eip2930Transaction.js';
export { Transaction } from './legacyTransaction.js';
export { TransactionFactory } from './transactionFactory.js';
export { BaseTransaction } from './baseTransaction.js';
export * as txUtils from './utils';
export * as txUtils from './utils.js';
export * from './types.js';
20 changes: 8 additions & 12 deletions packages/web3-eth-accounts/src/tx/transactionFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import type {
TxData,
TxOptions,
} from './types.js';
import { BaseTransaction } from './baseTransaction';
import { BaseTransaction } from './baseTransaction.js';

const extraTxTypes: Map<Numbers, typeof BaseTransaction> = new Map();

Expand Down Expand Up @@ -59,8 +59,6 @@ export class TransactionFactory {
txData: TxData | TypedTransaction,
txOptions: TxOptions = {},
): TypedTransaction {
console.log('txData', txData);
console.log('txOptions', txOptions);
if (!('type' in txData) || txData.type === undefined) {
// Assume legacy transaction
return Transaction.fromTxData(txData as TxData, txOptions);
Expand All @@ -85,12 +83,8 @@ export class TransactionFactory {
);
}
const ExtraTransaction = extraTxTypes.get(txType);
if (ExtraTransaction) {
console.log('extra');
// @ts-ignore
console.log('res', ExtraTransaction.fromTxData(txData, txOptions));
// @ts-ignore
return ExtraTransaction.fromTxData(txData, txOptions);
if (ExtraTransaction?.fromTxData) {
return ExtraTransaction.fromTxData(txData, txOptions) as TypedTransaction;
}

throw new Error(`Tx instantiation with type ${txType} not supported`);
Expand All @@ -115,9 +109,11 @@ export class TransactionFactory {
return FeeMarketEIP1559Transaction.fromSerializedTx(data, txOptions);
default: {
const ExtraTransaction = extraTxTypes.get(data[0]);
if (ExtraTransaction) {
// @ts-ignore
return ExtraTransaction.fromSerializedTx(data, txOptions);
if (ExtraTransaction?.fromSerializedTx) {
return ExtraTransaction.fromSerializedTx(
data,
txOptions,
) as TypedTransaction;
}

throw new Error(`TypedTransaction with ID ${data[0]} unknown`);
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-eth/src/utils/get_transaction_gas_pricing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export async function getTransactionGasPricing<ReturnFormat extends DataFormat>(
throw new UnsupportedTransactionTypeError(transactionType);

// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2718.md#transactions
if (transactionType < '0x0' || transactionType > '0x7f')
if (Number(transactionType) < 0 || Number(transactionType) > 127)
throw new UnsupportedTransactionTypeError(transactionType);

if (
Expand Down
1 change: 1 addition & 0 deletions packages/web3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"eslint-config-base-web3": "0.1.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"ethereum-cryptography": "^2.1.2",
"ganache": "^7.5.0",
"hardhat": "^2.12.2",
"in3": "^3.3.3",
Expand Down
Loading

0 comments on commit 12d325a

Please sign in to comment.