diff --git a/CHANGELOG.md b/CHANGELOG.md index f3a04a3faf..0a6451b90b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Changes: +- Add Ethereum `BlockV{0, 1, 2}` types, aligning with latest Frontier - Additional tests for metadata serialization/de-serialization diff --git a/packages/types/src/augment/registry.ts b/packages/types/src/augment/registry.ts index a4459b7d7a..d03e832c33 100644 --- a/packages/types/src/augment/registry.ts +++ b/packages/types/src/augment/registry.ts @@ -23,7 +23,7 @@ import type { ConfigData, MessageId, OverweightIndex, PageCounter, PageIndexData import type { AccountVote, AccountVoteSplit, AccountVoteStandard, Conviction, Delegations, PreimageStatus, PreimageStatusAvailable, PriorLock, PropIndex, Proposal, ProxyState, ReferendumIndex, ReferendumInfo, ReferendumInfoFinished, ReferendumInfoTo239, ReferendumStatus, Tally, Voting, VotingDelegating, VotingDirect, VotingDirectVote } from '@polkadot/types/interfaces/democracy'; import type { ApprovalFlag, DefunctVoter, Renouncing, SetIndex, Vote, VoteIndex, VoteThreshold, VoterInfo } from '@polkadot/types/interfaces/elections'; import type { CreatedBlock, ImportedAux } from '@polkadot/types/interfaces/engine'; -import type { EthAccount, EthBlock, EthBloom, EthCallRequest, EthFilter, EthFilterAddress, EthFilterChanges, EthFilterTopic, EthFilterTopicEntry, EthFilterTopicInner, EthHeader, EthLog, EthReceipt, EthRichBlock, EthRichHeader, EthStorageProof, EthSubKind, EthSubParams, EthSubResult, EthSyncInfo, EthSyncStatus, EthTransaction, EthTransactionAction, EthTransactionCondition, EthTransactionRequest, EthTransactionSignature, EthTransactionStatus, EthWork, EthereumAccountId, EthereumLookupSource, EthereumSignature } from '@polkadot/types/interfaces/eth'; +import type { BlockV0, BlockV1, BlockV2, EIP1559Transaction, EIP2930Transaction, EthAccessList, EthAccessListItem, EthAccount, EthAddress, EthBlock, EthBloom, EthCallRequest, EthFilter, EthFilterAddress, EthFilterChanges, EthFilterTopic, EthFilterTopicEntry, EthFilterTopicInner, EthHeader, EthLog, EthReceipt, EthRichBlock, EthRichHeader, EthStorageProof, EthSubKind, EthSubParams, EthSubResult, EthSyncInfo, EthSyncStatus, EthTransaction, EthTransactionAction, EthTransactionCondition, EthTransactionRequest, EthTransactionSignature, EthTransactionStatus, EthWork, EthereumAccountId, EthereumLookupSource, EthereumSignature, LegacyTransaction, TransactionV0, TransactionV1, TransactionV2 } from '@polkadot/types/interfaces/eth'; import type { EvmAccount, EvmLog, EvmVicinity, ExitError, ExitFatal, ExitReason, ExitRevert, ExitSucceed } from '@polkadot/types/interfaces/evm'; import type { AnySignature, EcdsaSignature, Ed25519Signature, Era, Extrinsic, ExtrinsicEra, ExtrinsicPayload, ExtrinsicPayloadUnknown, ExtrinsicPayloadV4, ExtrinsicSignature, ExtrinsicSignatureV4, ExtrinsicUnknown, ExtrinsicV4, ImmortalEra, MortalEra, MultiSignature, Signature, SignerPayload, Sr25519Signature } from '@polkadot/types/interfaces/extrinsics'; import type { AssetOptions, Owner, PermissionLatest, PermissionVersions, PermissionsV1 } from '@polkadot/types/interfaces/genericAsset'; @@ -155,6 +155,9 @@ declare module '@polkadot/types/types/registry' { BlockTraceEvent: BlockTraceEvent; BlockTraceEventData: BlockTraceEventData; BlockTraceSpan: BlockTraceSpan; + BlockV0: BlockV0; + BlockV1: BlockV1; + BlockV2: BlockV2; BlockWeights: BlockWeights; BodyId: BodyId; BodyPart: BodyPart; @@ -293,6 +296,8 @@ declare module '@polkadot/types/types/registry' { DownwardMessage: DownwardMessage; EcdsaSignature: EcdsaSignature; Ed25519Signature: Ed25519Signature; + EIP1559Transaction: EIP1559Transaction; + EIP2930Transaction: EIP2930Transaction; ElectionCompute: ElectionCompute; ElectionPhase: ElectionPhase; ElectionResult: ElectionResult; @@ -314,7 +319,10 @@ declare module '@polkadot/types/types/registry' { ErrorMetadataV13: ErrorMetadataV13; ErrorMetadataV14: ErrorMetadataV14; ErrorMetadataV9: ErrorMetadataV9; + EthAccessList: EthAccessList; + EthAccessListItem: EthAccessListItem; EthAccount: EthAccount; + EthAddress: EthAddress; EthBlock: EthBlock; EthBloom: EthBloom; EthCallRequest: EthCallRequest; @@ -522,6 +530,7 @@ declare module '@polkadot/types/types/registry' { LastRuntimeUpgradeInfo: LastRuntimeUpgradeInfo; LeasePeriod: LeasePeriod; LeasePeriodOf: LeasePeriodOf; + LegacyTransaction: LegacyTransaction; Limits: Limits; LimitsTo264: LimitsTo264; LocalValidationData: LocalValidationData; @@ -951,6 +960,9 @@ declare module '@polkadot/types/types/registry' { TransactionInfo: TransactionInfo; TransactionPriority: TransactionPriority; TransactionStorageProof: TransactionStorageProof; + TransactionV0: TransactionV0; + TransactionV1: TransactionV1; + TransactionV2: TransactionV2; TransactionValidityError: TransactionValidityError; TransientValidationData: TransientValidationData; TreasuryProposal: TreasuryProposal; diff --git a/packages/types/src/interfaces/eth/definitions.ts b/packages/types/src/interfaces/eth/definitions.ts index b1a69cdac8..4eeb3c8927 100644 --- a/packages/types/src/interfaces/eth/definitions.ts +++ b/packages/types/src/interfaces/eth/definitions.ts @@ -10,12 +10,94 @@ import type { DefinitionsTypes } from '../../types'; import { rpc } from './rpc'; +const V0: DefinitionsTypes = { + BlockV0: { + header: 'EthHeader', + transactions: 'Vec', + ommers: 'Vec' + }, + LegacyTransaction: { + nonce: 'U256', + gasPrice: 'U256', + gasLimit: 'U256', + action: 'EthTransactionAction', + value: 'U256', + input: 'Bytes', + signature: 'EthTransactionSignature' + }, + TransactionV0: 'LegacyTransaction' +}; + +const V1: DefinitionsTypes = { + BlockV1: { + header: 'EthHeader', + transactions: 'Vec', + ommers: 'Vec' + }, + EIP2930Transaction: { + chainId: 'u64', + nonce: 'U256', + gasPrice: 'U256', + gasLimit: 'U256', + action: 'EthTransactionAction', + value: 'U256', + input: 'Bytes', + accessList: 'EthAccessList', + oddYParity: 'bool', + r: 'H256', + s: 'H256' + }, + TransactionV1: { + _enum: { + Legacy: 'LegacyTransaction', + EIP2930: 'EIP2930Transaction' + } + } +}; + +const V2: DefinitionsTypes = { + BlockV2: { + header: 'EthHeader', + transactions: 'Vec', + ommers: 'Vec' + }, + EIP1559Transaction: { + chainId: 'u64', + nonce: 'U256', + maxPriorityFeePerGas: 'U256', + maxFeePerGas: 'U256', + gasLimit: 'U256', + action: 'EthTransactionAction', + value: 'U256', + input: 'Bytes', + accessList: 'EthAccessList', + oddYParity: 'bool', + r: 'H256', + s: 'H256' + }, + TransactionV2: { + _enum: { + Legacy: 'LegacyTransaction', + EIP2930: 'EIP2930Transaction', + EIP1559: 'EIP1559Transaction' + } + } +}; + const types: DefinitionsTypes = { + ...V0, + ...V1, + ...V2, EthereumAccountId: 'GenericEthereumAccountId', EthereumLookupSource: 'GenericEthereumLookupSource', EthereumSignature: '[u8; 65]', + EthAccessListItem: { + address: 'EthAddress', + slots: 'Vec' + }, + EthAccessList: 'Vec', EthAccount: { - address: 'H160', + address: 'EthAddress', balance: 'U256', nonce: 'U256', codeHash: 'H256', @@ -23,6 +105,7 @@ const types: DefinitionsTypes = { accountProof: 'Vec', storageProof: 'Vec' }, + EthAddress: 'H160', EthBlock: { header: 'EthHeader', transactions: 'Vec', @@ -31,7 +114,7 @@ const types: DefinitionsTypes = { EthHeader: { parentHash: 'H256', ommersHash: 'H256', - beneficiary: 'H160', + beneficiary: 'EthAddress', stateRoot: 'H256', transactionsRoot: 'H256', receiptsRoot: 'H256', @@ -53,8 +136,8 @@ const types: DefinitionsTypes = { blockHash: 'Option', parentHash: 'H256', sha3Uncles: 'H256', - author: 'H160', - miner: 'H160', + author: 'EthAddress', + miner: 'EthAddress', stateRoot: 'H256', transactionsRoot: 'H256', receiptsRoot: 'H256', @@ -73,8 +156,8 @@ const types: DefinitionsTypes = { }, EthBloom: 'H2048', EthCallRequest: { - from: 'Option', - to: 'Option', + from: 'Option', + to: 'Option', gasPrice: 'Option', gas: 'Option', value: 'Option', @@ -90,8 +173,8 @@ const types: DefinitionsTypes = { }, EthFilterAddress: { _enum: { - Single: 'H160', - Multiple: 'Vec', + Single: 'EthAddress', + Multiple: 'Vec', Null: 'Null' } }, @@ -125,8 +208,8 @@ const types: DefinitionsTypes = { blockHash: 'Option', parentHash: 'H256', sha3Uncles: 'H256', - author: 'H160', - miner: 'H160', + author: 'EthAddress', + miner: 'EthAddress', stateRoot: 'H256', transactionsRoot: 'H256', receiptsRoot: 'H256', @@ -141,7 +224,7 @@ const types: DefinitionsTypes = { blockSize: 'Option' }, EthLog: { - address: 'H160', + address: 'EthAddress', topics: 'Vec', data: 'Bytes', blockHash: 'Option', @@ -156,12 +239,12 @@ const types: DefinitionsTypes = { transactionHash: 'Option', transactionIndex: 'Option', blockHash: 'Option', - from: 'Option', - to: 'Option', + from: 'Option', + to: 'Option', blockNumber: 'Option', cumulativeGasUsed: 'U256', gasUsed: 'Option', - contractAddress: 'Option', + contractAddress: 'Option', logs: 'Vec', root: 'Option', logsBloom: 'EthBloom', @@ -202,15 +285,7 @@ const types: DefinitionsTypes = { None: 'Null' } }, - EthTransaction: { - nonce: 'U256', - gasPrice: 'U256', - gasLimit: 'U256', - action: 'EthTransactionAction', - value: 'U256', - input: 'Bytes', - signature: 'EthTransactionSignature' - }, + EthTransaction: 'LegacyTransaction', EthTransactionSignature: { v: 'u64', r: 'H256', @@ -229,8 +304,8 @@ const types: DefinitionsTypes = { } }, EthTransactionRequest: { - from: 'Option', - to: 'Option', + from: 'Option', + to: 'Option', gasPrice: 'Option', gas: 'Option', value: 'Option', @@ -240,9 +315,9 @@ const types: DefinitionsTypes = { EthTransactionStatus: { transactionHash: 'H256', transactionIndex: 'u32', - from: 'H160', - to: 'Option', - contractAddress: 'Option', + from: 'EthAddress', + to: 'Option', + contractAddress: 'Option', logs: 'Vec', logsBloom: 'EthBloom' }, diff --git a/packages/types/src/interfaces/eth/types.ts b/packages/types/src/interfaces/eth/types.ts index e5c43006e2..819fe68299 100644 --- a/packages/types/src/interfaces/eth/types.ts +++ b/packages/types/src/interfaces/eth/types.ts @@ -4,9 +4,70 @@ import type { Bytes, Enum, GenericEthereumAccountId, GenericEthereumLookupSource, Option, Struct, U256, U64, U8aFixed, Vec, bool, u32, u64 } from '@polkadot/types'; import type { BlockNumber, H160, H2048, H256, H64 } from '@polkadot/types/interfaces/runtime'; +/** @name BlockV0 */ +export interface BlockV0 extends Struct { + readonly header: EthHeader; + readonly transactions: Vec; + readonly ommers: Vec; +} + +/** @name BlockV1 */ +export interface BlockV1 extends Struct { + readonly header: EthHeader; + readonly transactions: Vec; + readonly ommers: Vec; +} + +/** @name BlockV2 */ +export interface BlockV2 extends Struct { + readonly header: EthHeader; + readonly transactions: Vec; + readonly ommers: Vec; +} + +/** @name EIP1559Transaction */ +export interface EIP1559Transaction extends Struct { + readonly chainId: u64; + readonly nonce: U256; + readonly maxPriorityFeePerGas: U256; + readonly maxFeePerGas: U256; + readonly gasLimit: U256; + readonly action: EthTransactionAction; + readonly value: U256; + readonly input: Bytes; + readonly accessList: EthAccessList; + readonly oddYParity: bool; + readonly r: H256; + readonly s: H256; +} + +/** @name EIP2930Transaction */ +export interface EIP2930Transaction extends Struct { + readonly chainId: u64; + readonly nonce: U256; + readonly gasPrice: U256; + readonly gasLimit: U256; + readonly action: EthTransactionAction; + readonly value: U256; + readonly input: Bytes; + readonly accessList: EthAccessList; + readonly oddYParity: bool; + readonly r: H256; + readonly s: H256; +} + +/** @name EthAccessList */ +export interface EthAccessList extends Vec {} + +/** @name EthAccessListItem */ +export interface EthAccessListItem extends Struct { + readonly address: EthAddress; + readonly slots: Vec; +} + /** @name EthAccount */ export interface EthAccount extends Struct { - readonly address: H160; + readonly address: EthAddress; readonly balance: U256; readonly nonce: U256; readonly codeHash: H256; @@ -15,6 +76,9 @@ export interface EthAccount extends Struct { readonly storageProof: Vec; } +/** @name EthAddress */ +export interface EthAddress extends H160 {} + /** @name EthBlock */ export interface EthBlock extends Struct { readonly header: EthHeader; @@ -27,8 +91,8 @@ export interface EthBloom extends H2048 {} /** @name EthCallRequest */ export interface EthCallRequest extends Struct { - readonly from: Option; - readonly to: Option; + readonly from: Option; + readonly to: Option; readonly gasPrice: Option; readonly gas: Option; readonly value: Option; @@ -57,9 +121,9 @@ export interface EthFilter extends Struct { /** @name EthFilterAddress */ export interface EthFilterAddress extends Enum { readonly isSingle: boolean; - readonly asSingle: H160; + readonly asSingle: EthAddress; readonly isMultiple: boolean; - readonly asMultiple: Vec; + readonly asMultiple: Vec; readonly isNull: boolean; } @@ -97,7 +161,7 @@ export interface EthFilterTopicInner extends Enum { export interface EthHeader extends Struct { readonly parentHash: H256; readonly ommersHash: H256; - readonly beneficiary: H160; + readonly beneficiary: EthAddress; readonly stateRoot: H256; readonly transactionsRoot: H256; readonly receiptsRoot: H256; @@ -114,7 +178,7 @@ export interface EthHeader extends Struct { /** @name EthLog */ export interface EthLog extends Struct { - readonly address: H160; + readonly address: EthAddress; readonly topics: Vec; readonly data: Bytes; readonly blockHash: Option; @@ -131,12 +195,12 @@ export interface EthReceipt extends Struct { readonly transactionHash: Option; readonly transactionIndex: Option; readonly blockHash: Option; - readonly from: Option; - readonly to: Option; + readonly from: Option; + readonly to: Option; readonly blockNumber: Option; readonly cumulativeGasUsed: U256; readonly gasUsed: Option; - readonly contractAddress: Option; + readonly contractAddress: Option; readonly logs: Vec; readonly root: Option; readonly logsBloom: EthBloom; @@ -148,8 +212,8 @@ export interface EthRichBlock extends Struct { readonly blockHash: Option; readonly parentHash: H256; readonly sha3Uncles: H256; - readonly author: H160; - readonly miner: H160; + readonly author: EthAddress; + readonly miner: EthAddress; readonly stateRoot: H256; readonly transactionsRoot: H256; readonly receiptsRoot: H256; @@ -172,8 +236,8 @@ export interface EthRichHeader extends Struct { readonly blockHash: Option; readonly parentHash: H256; readonly sha3Uncles: H256; - readonly author: H160; - readonly miner: H160; + readonly author: EthAddress; + readonly miner: EthAddress; readonly stateRoot: H256; readonly transactionsRoot: H256; readonly receiptsRoot: H256; @@ -239,15 +303,7 @@ export interface EthSyncStatus extends Enum { } /** @name EthTransaction */ -export interface EthTransaction extends Struct { - readonly nonce: U256; - readonly gasPrice: U256; - readonly gasLimit: U256; - readonly action: EthTransactionAction; - readonly value: U256; - readonly input: Bytes; - readonly signature: EthTransactionSignature; -} +export interface EthTransaction extends LegacyTransaction {} /** @name EthTransactionAction */ export interface EthTransactionAction extends Enum { @@ -266,8 +322,8 @@ export interface EthTransactionCondition extends Enum { /** @name EthTransactionRequest */ export interface EthTransactionRequest extends Struct { - readonly from: Option; - readonly to: Option; + readonly from: Option; + readonly to: Option; readonly gasPrice: Option; readonly gas: Option; readonly value: Option; @@ -286,9 +342,9 @@ export interface EthTransactionSignature extends Struct { export interface EthTransactionStatus extends Struct { readonly transactionHash: H256; readonly transactionIndex: u32; - readonly from: H160; - readonly to: Option; - readonly contractAddress: Option; + readonly from: EthAddress; + readonly to: Option; + readonly contractAddress: Option; readonly logs: Vec; readonly logsBloom: EthBloom; } @@ -301,4 +357,36 @@ export interface EthWork extends Struct { readonly number: Option; } +/** @name LegacyTransaction */ +export interface LegacyTransaction extends Struct { + readonly nonce: U256; + readonly gasPrice: U256; + readonly gasLimit: U256; + readonly action: EthTransactionAction; + readonly value: U256; + readonly input: Bytes; + readonly signature: EthTransactionSignature; +} + +/** @name TransactionV0 */ +export interface TransactionV0 extends LegacyTransaction {} + +/** @name TransactionV1 */ +export interface TransactionV1 extends Enum { + readonly isLegacy: boolean; + readonly asLegacy: LegacyTransaction; + readonly isEip2930: boolean; + readonly asEip2930: EIP2930Transaction; +} + +/** @name TransactionV2 */ +export interface TransactionV2 extends Enum { + readonly isLegacy: boolean; + readonly asLegacy: LegacyTransaction; + readonly isEip2930: boolean; + readonly asEip2930: EIP2930Transaction; + readonly isEip1559: boolean; + readonly asEip1559: EIP1559Transaction; +} + export type PHANTOM_ETH = 'eth';