diff --git a/packages/decoder/lib/decoders.ts b/packages/decoder/lib/decoders.ts index c175800e92e..fbbe7eb31b2 100644 --- a/packages/decoder/lib/decoders.ts +++ b/packages/decoder/lib/decoders.ts @@ -455,7 +455,8 @@ export class ProjectDecoder { overrideContext?: Contexts.Context, isForSelectorBasedDecoding?: boolean ): Promise { - const block = transaction.blockNumber; + const block = + transaction.blockNumber !== null ? Number(transaction.blockNumber) : null; const blockNumber = await this.regularizeBlock(block); const isConstructor = transaction.to === null; const context = @@ -615,7 +616,7 @@ export class ProjectDecoder { options: DecoderTypes.EventOptions = {}, additionalContexts: Contexts.Contexts = {} ): Promise { - const block = log.blockNumber; + const block = log.blockNumber !== null ? Number(log.blockNumber) : null; const blockNumber = await this.regularizeBlock(block); const data = Conversion.toBytes(log.data); const topics = log.topics.map(Conversion.toBytes); diff --git a/packages/decoder/lib/types.ts b/packages/decoder/lib/types.ts index f89ad1e2a65..36b8497253f 100644 --- a/packages/decoder/lib/types.ts +++ b/packages/decoder/lib/types.ts @@ -125,11 +125,48 @@ export interface ContractState { /** * This type represents a web3 Log object that has been decoded. - * Note that it extends the Log type and just adds an additional field - * with the decoding. + * Note that it has the same fields the Log type. The differences are: + * + * 1. It adds an additional field with the decodings; + * 2. Some fields that in Log are allowed to be strings, + * here are specified as numbers. (Because this type is + * for output and that type is for input.) * @category Results */ -export interface DecodedLog extends Log { +export interface DecodedLog { + /** + * Address of the emitter (as checksummed hex string). + */ + address: string; + /** + * The log's data section (as hex string). + */ + data: string; + /** + * The log's topics; each is a hex string representing 32 bytes. + */ + topics: string[]; + /** + * Index of the log within the block. + */ + logIndex: number; + /** + * Index within the block of the emitting transaction; null if + * block is pending. + */ + transactionIndex: number | null; + /** + * The emitting transaction's hash (as hex string). + */ + transactionHash: string; + /** + * The block hash (as hex string). Null if pending. + */ + blockHash: string | null; + /** + * The block number. Null if pending. + */ + blockNumber: number | null; /** * An array of possible decodings of the given log -- it's an array because logs can be ambiguous. * @@ -247,7 +284,7 @@ export interface ReturnOptions { * * Intended to work like Web3's * [Transaction](https://web3js.readthedocs.io/en/v1.2.1/web3-eth.html#eth-gettransaction-return) - * type. + * type, but with strings allowed where it requires numbers. * @category Inputs */ export interface Transaction { @@ -258,7 +295,7 @@ export interface Transaction { /** * The nonce of the sender before this transaction was sent. */ - nonce?: number; + nonce?: number | string | bigint; /** * Hash of this transaction's block as hex string; null if pending. */ @@ -266,11 +303,11 @@ export interface Transaction { /** * This transaction's block number; null if pending. */ - blockNumber: number | null; + blockNumber: number | string | bigint | null; /** * Index of transaction in block; null if block is pending. */ - transactionIndex?: number | null; + transactionIndex?: number | string | bigint | null; /** * Address of the sender (as checksummed hex string). */ @@ -299,7 +336,7 @@ export interface Transaction { /** * A positive unsigned 8-bit number between 0 and 0x7f that represents the type of the transaction. */ - type?: number; + type?: number | string | bigint; /** * The maximum fee per gas that the transaction is willing to pay in total. */ @@ -317,7 +354,7 @@ export interface Transaction { * * Intended to work like Web3's * [Log](https://web3js.readthedocs.io/en/v1.2.1/web3-eth.html#eth-getpastlogs-return) - * type. + * type, but with strings allowed where it requires numbers. * @category Inputs */ export interface Log { @@ -336,12 +373,12 @@ export interface Log { /** * Index of the log within the block. */ - logIndex?: number; + logIndex?: number | string | bigint; /** * Index within the block of the emitting transaction; null if * block is pending. */ - transactionIndex?: number | null; + transactionIndex?: number | string | bigint | null; /** * The emitting transaction's hash (as hex string). */ @@ -353,7 +390,7 @@ export interface Log { /** * The block number. Null if pending. */ - blockNumber: number | null; + blockNumber: number | string | bigint | null; } //HACK diff --git a/packages/decoder/test/current/test/compatible-nativize.js b/packages/decoder/test/current/test/compatible-nativize.js index 57b2bf9bd56..1f40c6f2f53 100644 --- a/packages/decoder/test/current/test/compatible-nativize.js +++ b/packages/decoder/test/current/test/compatible-nativize.js @@ -117,7 +117,8 @@ describe("nativize (ethers format)", function () { }); const logs = receipt.logs; assert.lengthOf(logs, 1); - const log = logs[0]; + let log = logs[0]; + log.blockNumber = String(log.blockNumber); //while we're here, let's test the ability to take strings :P const decodings = await decoder.decodeLog(log); assert.lengthOf(decodings, 1); const decoding = decodings[0]; diff --git a/packages/decoder/test/current/test/wire-test.js b/packages/decoder/test/current/test/wire-test.js index 07f91eea5b4..2c403a65f60 100644 --- a/packages/decoder/test/current/test/wire-test.js +++ b/packages/decoder/test/current/test/wire-test.js @@ -126,6 +126,20 @@ describe("Over-the-wire decoding", function () { defaultConstructorHash ); + for (let tx of [ + constructorTx, + emitStuffTx, + moreStuffTx, + globalTestTx, + inheritedTx, + getterTx1, + getterTx2, + defaultConstructorTx + ]) { + //while we're here, let's test string input to the decoder + tx.blockNumber = String(tx.blockNumber); + } + let constructorDecoding = await decoder.decodeTransaction(constructorTx); let emitStuffDecoding = await decoder.decodeTransaction(emitStuffTx); let moreStuffDecoding = await decoder.decodeTransaction(moreStuffTx);