Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4693/transaction receipt effective gas price 4.x #4866

Merged
merged 5 commits into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/web3-common/src/eth_execution_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export interface ReceiptInfo {
readonly logsBloom: HexString256Bytes;
readonly root: HexString32Bytes;
readonly status: '0x1' | '0x0';
readonly effectiveGasPrice: Uint;
nazarhussain marked this conversation as resolved.
Show resolved Hide resolved
}

// https://github.com/ethereum/execution-apis/blob/main/src/schemas/client.json#L2
Expand Down
4 changes: 4 additions & 0 deletions packages/web3-common/src/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,10 @@ export const outputTransactionReceiptFormatter = (receipt: ReceiptInput): Receip
modifiedReceipt.logs = receipt.logs.map(outputLogFormatter);
}

if (receipt.effectiveGasPrice) {
modifiedReceipt.effectiveGasPrice = hexToNumber(receipt.effectiveGasPrice);
}

if (receipt.contractAddress) {
modifiedReceipt.contractAddress = toChecksumAddress(receipt.contractAddress);
}
Expand Down
2 changes: 2 additions & 0 deletions packages/web3-common/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export interface ReceiptInput {
readonly logs?: LogsInput[];
readonly contractAddress?: HexString;
readonly status?: string;
readonly effectiveGasPrice?: HexString;
}

export interface ReceiptOutput {
Expand All @@ -184,6 +185,7 @@ export interface ReceiptOutput {
readonly logs?: LogsOutput[];
readonly contractAddress?: HexString;
readonly status: boolean;
readonly effectiveGasPrice?: bigint | number;
}

export interface PostInput {
Expand Down
14 changes: 14 additions & 0 deletions packages/web3-common/test/unit/formatters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,20 @@ describe('formatters', () => {

expect(result.status).toBeFalsy();
});

it('should convert "effectiveGasPrice" from hex to number', () => {
const effectiveGasPrice = '0x80d9594d23495b';

const result = outputTransactionReceiptFormatter({
...validReceipt,
effectiveGasPrice,
});

expect(utils.hexToNumber).toHaveBeenCalledWith(effectiveGasPrice);
expect(result).toEqual(
expect.objectContaining({ effectiveGasPrice: hexToNumberResult }),
);
});
});

describe('outputBlockFormatter', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/web3-eth/src/convertible_properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const convertibleReceiptInfoProperties: (keyof ReceiptInfo)[] = [
'cumulativeGasUsed',
'gasUsed',
'status',
'effectiveGasPrice',
];

export const convertibleFeeHistoryResultProperties: (keyof FeeHistoryResult)[] = [
Expand Down
1 change: 1 addition & 0 deletions packages/web3-eth/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ export interface ReceiptInfoFormatted<
readonly logsBloom: HexString256Bytes;
readonly root: HexString32Bytes;
readonly status: ReturnType;
readonly effectiveGasPrice: ReturnType;
}

export interface BlockFormatted<
Expand Down
4 changes: 4 additions & 0 deletions packages/web3-eth/test/fixtures/rpc_methods_wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,7 @@ const receiptInfo: ReceiptInfo = {
logsBloom: '0xe21194c9509beb01be7e90c2bcefff2804cd85836ae12134f22ad4acda0fc547',
root: '0xe21194c9509beb01be7e90c2bcefff2804cd85836ae12134f22ad4acda0fc547',
status: '0x1',
effectiveGasPrice: '0x4dc4', // 19908
};
const receiptInfoNumberString: ReceiptInfoFormatted<ValidTypes.NumberString> = {
...receiptInfo,
Expand All @@ -1347,6 +1348,7 @@ const receiptInfoNumberString: ReceiptInfoFormatted<ValidTypes.NumberString> = {
cumulativeGasUsed: '13244',
gasUsed: '1244',
status: '1',
effectiveGasPrice: '19908',
};
const receiptInfoNumber: ReceiptInfoFormatted<ValidTypes.Number> = {
...receiptInfo,
Expand All @@ -1355,6 +1357,7 @@ const receiptInfoNumber: ReceiptInfoFormatted<ValidTypes.Number> = {
cumulativeGasUsed: 13244,
gasUsed: 1244,
status: 1,
effectiveGasPrice: 19908,
};
const receiptInfoBigInt: ReceiptInfoFormatted<ValidTypes.BigInt> = {
...receiptInfo,
Expand All @@ -1363,6 +1366,7 @@ const receiptInfoBigInt: ReceiptInfoFormatted<ValidTypes.BigInt> = {
cumulativeGasUsed: BigInt('13244'),
gasUsed: BigInt('1244'),
status: BigInt('1'),
effectiveGasPrice: BigInt('19908'),
};
/**
* Array consists of:
Expand Down