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

TransactionExtension, ExtrinsicV5 #5976

Merged
merged 73 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
1684e53
TransactionExtension Start
TarikGul Sep 6, 2024
9078754
Add V5_VERSION logic to necessary classes
TarikGul Sep 6, 2024
52ad227
Fix latest version to 5
TarikGul Sep 6, 2024
55b0499
Add v5 dir
TarikGul Sep 10, 2024
fb3a3f5
Merge branch 'master' of github.com:polkadot-js/api into tg-v5-ext
TarikGul Sep 19, 2024
34e4a02
Add v5 types to interfaces
TarikGul Sep 19, 2024
2e28c3f
Cleanup paths
TarikGul Sep 19, 2024
17993bf
Update ExtrinsicSignature V5
TarikGul Sep 19, 2024
9169647
Cleanup v5 folders
TarikGul Sep 19, 2024
159d01c
nits
TarikGul Sep 19, 2024
38768e3
signed works
bee344 Sep 19, 2024
c7a86bc
general works?
bee344 Sep 19, 2024
437b885
Clean linter, and imports
TarikGul Sep 20, 2024
378949c
fix typing
TarikGul Sep 20, 2024
2c3e285
Change sign in v5 to hash all payloads
TarikGul Sep 20, 2024
72de8df
remove SignV5Options
TarikGul Sep 20, 2024
13b40c5
Remove SignatureV5Options
TarikGul Sep 20, 2024
d92fa6e
Change versioning
TarikGul Sep 20, 2024
b4a2f0f
added bitmasks
bee344 Sep 20, 2024
6a9a432
cleanup
TarikGul Sep 20, 2024
e1baccf
change version to constant
TarikGul Sep 20, 2024
fd2a35c
Add tests
TarikGul Sep 20, 2024
9a37194
Decouple payload v5 from v4
TarikGul Sep 21, 2024
d77053b
Add helper fn to get signed extension version from the registry
TarikGul Sep 21, 2024
f277d82
Add version to encoding
TarikGul Sep 23, 2024
d7fb11c
Cleanup tests
TarikGul Sep 23, 2024
ae43b6e
renamed getSignedExtensionVersion to getTransactionExtensionVersion
bee344 Sep 23, 2024
721054d
removed this.type for v5
bee344 Sep 23, 2024
a40afb4
undo this.type removal
bee344 Sep 23, 2024
7c1b641
replaced signedExtensionVersion by transactionExtensionVersion for v5…
bee344 Sep 23, 2024
0b1c350
unfinished Preamble Class
bee344 Sep 24, 2024
072f69a
Revert "unfinished Preamble Class"
bee344 Sep 24, 2024
4667ebd
Added test for decoding
TarikGul Sep 24, 2024
a10fa71
Fix test
TarikGul Sep 24, 2024
0f93298
preamble typo
bee344 Sep 24, 2024
d6ac60b
updated GeneralExtrinsic [WIP]
bee344 Sep 24, 2024
bac50e8
added generalExtrinsic
bee344 Sep 25, 2024
e2592e9
General Extrinsic
bee344 Sep 27, 2024
d235092
linting and renaming
bee344 Sep 27, 2024
278a09a
renaming
bee344 Sep 27, 2024
a2dcbb0
Extend the v5 signed extrinsic test
TarikGul Sep 29, 2024
e916ee0
Unmask preamble
TarikGul Sep 29, 2024
4210edb
Set payload to GeneralExtrinsicPayload
TarikGul Sep 30, 2024
6266b73
Add test for GeneralExtrinsicPayload
TarikGul Sep 30, 2024
00b23b2
Start GeneralExtrinsicEncoded tests
TarikGul Sep 30, 2024
418859a
Add GeneralExt as a replacement class
TarikGul Oct 1, 2024
798d595
Export GeneralExt
TarikGul Oct 1, 2024
edd536d
Fix nits
TarikGul Oct 1, 2024
ed80794
Start decodeu8a
TarikGul Oct 1, 2024
ad0d6c3
GeneralExt tests
TarikGul Oct 1, 2024
11bb801
GeneralExt fix
TarikGul Oct 1, 2024
583d7e0
updated decodeu8a
bee344 Oct 1, 2024
24fa6b0
Fix decoding
TarikGul Oct 1, 2024
e11f955
Add error handling for invalid version
TarikGul Oct 1, 2024
6032f09
remove fluff
TarikGul Oct 2, 2024
0ae6edf
Fix version in GeneralExtrinsic
TarikGul Oct 2, 2024
ccd38d4
fixes
TarikGul Oct 2, 2024
aefc3df
add parent class methods as errors
TarikGul Oct 2, 2024
0d908bf
Reorg some types
TarikGul Oct 2, 2024
4485585
Add test for GeneralExtrinsic
TarikGul Oct 2, 2024
104c58e
Fix compatibility with GeneralExtrinsic
TarikGul Oct 2, 2024
7601b94
fix structure of GeneralExtrinsic
TarikGul Oct 2, 2024
10b81c1
Add another test
TarikGul Oct 2, 2024
6d8baed
cleanup
bee344 Oct 2, 2024
eb7b309
Fix decoding bug for bare
TarikGul Oct 2, 2024
70d298b
fix change from bare to signed
bee344 Oct 2, 2024
7a919cb
linting
bee344 Oct 2, 2024
98290cc
Fix encodinglength
TarikGul Oct 2, 2024
51d7232
Set default to preamble to bre
TarikGul Oct 2, 2024
67b2370
Fix tests
TarikGul Oct 2, 2024
9bcca0b
fixed version setting
bee344 Oct 2, 2024
54a18a2
Add test
TarikGul Oct 2, 2024
a54fd9e
Merge branch 'tg-v5-ext' of github.com:polkadot-js/api into tg-v5-ext
TarikGul Oct 2, 2024
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
5 changes: 4 additions & 1 deletion packages/types-augment/src/registry/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import type { ApprovalFlag, DefunctVoter, Renouncing, SetIndex, Vote, VoteIndex,
import type { CreatedBlock, ImportedAux } from '@polkadot/types/interfaces/engine';
import type { BlockV0, BlockV1, BlockV2, EIP1559Transaction, EIP2930Transaction, EthAccessList, EthAccessListItem, EthAccount, EthAddress, EthBlock, EthBloom, EthCallRequest, EthFeeHistory, EthFilter, EthFilterAddress, EthFilterChanges, EthFilterTopic, EthFilterTopicEntry, EthFilterTopicInner, EthHeader, EthLog, EthReceipt, EthReceiptV0, EthReceiptV3, EthRichBlock, EthRichHeader, EthStorageProof, EthSubKind, EthSubParams, EthSubResult, EthSyncInfo, EthSyncStatus, EthTransaction, EthTransactionAction, EthTransactionCondition, EthTransactionRequest, EthTransactionSignature, EthTransactionStatus, EthWork, EthereumAccountId, EthereumAddress, EthereumLookupSource, EthereumSignature, LegacyTransaction, TransactionV0, TransactionV1, TransactionV2 } from '@polkadot/types/interfaces/eth';
import type { EvmAccount, EvmCallInfo, EvmCallInfoV2, EvmCreateInfo, EvmCreateInfoV2, EvmLog, EvmVicinity, EvmWeightInfo, 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 { AnySignature, EcdsaSignature, Ed25519Signature, Era, Extrinsic, ExtrinsicEra, ExtrinsicPayload, ExtrinsicPayloadUnknown, ExtrinsicPayloadV4, ExtrinsicPayloadV5, ExtrinsicSignature, ExtrinsicSignatureV4, ExtrinsicSignatureV5, ExtrinsicUnknown, ExtrinsicV4, ExtrinsicV5, ImmortalEra, MortalEra, MultiSignature, Signature, SignerPayload, Sr25519Signature } from '@polkadot/types/interfaces/extrinsics';
import type { FungiblesAccessError } from '@polkadot/types/interfaces/fungibles';
import type { AssetOptions, Owner, PermissionLatest, PermissionVersions, PermissionsV1 } from '@polkadot/types/interfaces/genericAsset';
import type { GenesisBuildErr } from '@polkadot/types/interfaces/genesisBuilder';
Expand Down Expand Up @@ -504,12 +504,15 @@ declare module '@polkadot/types/types/registry' {
ExtrinsicPayload: ExtrinsicPayload;
ExtrinsicPayloadUnknown: ExtrinsicPayloadUnknown;
ExtrinsicPayloadV4: ExtrinsicPayloadV4;
ExtrinsicPayloadV5: ExtrinsicPayloadV5;
ExtrinsicSignature: ExtrinsicSignature;
ExtrinsicSignatureV4: ExtrinsicSignatureV4;
ExtrinsicSignatureV5: ExtrinsicSignatureV5;
ExtrinsicStatus: ExtrinsicStatus;
ExtrinsicsWeight: ExtrinsicsWeight;
ExtrinsicUnknown: ExtrinsicUnknown;
ExtrinsicV4: ExtrinsicV4;
ExtrinsicV5: ExtrinsicV5;
f32: f32;
F32: F32;
f64: f64;
Expand Down
1 change: 1 addition & 0 deletions packages/types-codec/src/types/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export interface Registry {
getClassName (clazz: CodecClass): string | undefined;
getOrThrow <T extends Codec = Codec, K extends string = string> (name: K, msg?: string): CodecClass<T>;
getOrUnknown <T extends Codec = Codec, K extends string = string> (name: K): CodecClass<T>;
getTransactionExtensionVersion (): number;
getSignedExtensionExtra (): Record<string, string>;
getSignedExtensionTypes (): Record<string, string>;

Expand Down
5 changes: 5 additions & 0 deletions packages/types/src/create/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,11 @@ export class TypeRegistry implements Registry {
return this.get<T, K>(name, true) as unknown as CodecClass<R>;
}

// Only used in extrinsic version 5
public getTransactionExtensionVersion (): number {
return 0;
}

public getSignedExtensionExtra (): Record<string, string> {
return expandExtensionTypes(this.#signedExtensions, 'payload', this.#userExtensions);
}
Expand Down
77 changes: 77 additions & 0 deletions packages/types/src/extrinsic/Extrinsic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,81 @@ describe('Extrinsic', (): void => {
expect(extrinsic.toPrimitive()).toEqual({ method: { args: { dest: { id: '5DiuK2zR4asj2CEh77SKtUgTswTLkD8eiAKrByg5G3wL5w9b' }, value: 104560923320000 }, callIndex: '0x0600' }, signature: { era: { mortalEra: [1024, 186] }, nonce: 68, signature: { ed25519: '0xd99ffe3e610ad234e1414bda5831395a6df9098bf80b01561ce89a5065ae89d5c10e1619c6c99131b0bea4fb73ef04d07c07770e2ae9df5c325c331769ccb300' }, signer: { id: '5Hn8KKEp8qruCGWaN9MEsjTs4FXB4wv9xn7g1RWkNeKKNXCr' }, tip: 30000000000 } });
});
});

describe('V5', () => {
// Ensure it does not have its registry modified by the fallback extensions.
const registry = new TypeRegistry();
const metadata = new Metadata(registry, rpcMetadata);

registry.setMetadata(metadata);

describe('SignedExtrinsic', () => {
it('Should work when the version and preamble is passed in', () => {
const extrinsic = new Extrinsic(
registry,
'0x51028500d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d011e0b7d9438899333c50121f8e10144952d51c3bb8d0ea11dd1f24940d8ff615ad351d95ed9f41f078748ed7cf182864a20b38eebfaef6629433365eb90c0148c007502000000000603008eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a480b00a0724e1809',
{ preamble: 'signed', version: 5 }
);

expect(extrinsic.signer.toString()).toEqual('5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY');
expect(extrinsic.era.toHuman()).toEqual({ MortalEra: { period: '64', phase: '39' } });
expect(extrinsic.nonce.toNumber()).toEqual(0);
expect(extrinsic.tip.toHuman()).toEqual('0');
expect(extrinsic.callIndex).toEqual(new Uint8Array([6, 3]));
expect(extrinsic.args[0].toHex()).toEqual('0x008eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48');
expect(extrinsic.args[1].toHuman()).toEqual('10,000,000,000,000');
});

it('Should work when the version and preamble is not passed in', () => {
const extrinsic = new Extrinsic(
registry,
'0x51028500d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d011e0b7d9438899333c50121f8e10144952d51c3bb8d0ea11dd1f24940d8ff615ad351d95ed9f41f078748ed7cf182864a20b38eebfaef6629433365eb90c0148c007502000000000603008eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a480b00a0724e1809'
);

expect(extrinsic.version).toEqual(133);
expect(extrinsic.signer.toString()).toEqual('5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY');
expect(extrinsic.era.toHuman()).toEqual({ MortalEra: { period: '64', phase: '39' } });
expect(extrinsic.nonce.toNumber()).toEqual(0);
expect(extrinsic.tip.toHuman()).toEqual('0');
expect(extrinsic.callIndex).toEqual(new Uint8Array([6, 3]));
expect(extrinsic.args[0].toHex()).toEqual('0x008eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48');
expect(extrinsic.args[1].toHuman()).toEqual('10,000,000,000,000');
});
});

describe('GeneralExtrinsic', () => {
it('Should work when the version and preamble is passed in', () => {
const extrinsic = new Extrinsic(
registry,
'0xc44500650000000000060000d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d0700e40b5402',
{ preamble: 'general', version: 5 }
);

expect(extrinsic.version).toEqual(69);
// expect(extrinsic.transactionExtensionVersion.toNumber()).toEqual(0);
expect(extrinsic.method.toHuman()).toEqual({ args: { dest: { Id: '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY' }, value: '10,000,000,000' }, method: 'transferAllowDeath', section: 'balances' });
expect(extrinsic.era.toHuman()).toEqual({ MortalEra: { period: '64', phase: '6' } });
expect(extrinsic.tip.toNumber()).toEqual(0);
expect(extrinsic.mode.toNumber()).toEqual(0);
expect(extrinsic.assetId.toHuman()).toEqual(null);
expect(extrinsic.nonce.toNumber()).toEqual(0);
});

it('Should work when there is no version and preamble is passed in', () => {
const extrinsic = new Extrinsic(
registry,
'0xc44500650000000000060000d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d0700e40b5402'
);

expect(extrinsic.version).toEqual(69);
// expect(extrinsic.transactionExtensionVersion.toNumber()).toEqual(0);
expect(extrinsic.method.toHuman()).toEqual({ args: { dest: { Id: '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY' }, value: '10,000,000,000' }, method: 'transferAllowDeath', section: 'balances' });
expect(extrinsic.era.toHuman()).toEqual({ MortalEra: { period: '64', phase: '6' } });
expect(extrinsic.tip.toNumber()).toEqual(0);
expect(extrinsic.mode.toNumber()).toEqual(0);
expect(extrinsic.assetId.toHuman()).toEqual(null);
expect(extrinsic.nonce.toNumber()).toEqual(0);
});
});
});
});
Loading