Skip to content

Commit 591e9b1

Browse files
authored
Add assetId field to to necessary ExtrinsicPayloads (#5839)
* Add assetId field to GenericExtrinsicPayload * Update AssetId usage * update nits * Update packages/types/src/extrinsic/Extrinsic.ts
1 parent caca8ce commit 591e9b1

File tree

5 files changed

+36
-6
lines changed

5 files changed

+36
-6
lines changed

packages/types/src/extrinsic/Extrinsic.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
// Copyright 2017-2024 @polkadot/types authors & contributors
22
// SPDX-License-Identifier: Apache-2.0
33

4-
import type { AnyJson, AnyTuple, AnyU8a, ArgsDef, IMethod, Inspect } from '@polkadot/types-codec/types';
4+
import type { AnyJson, AnyTuple, AnyU8a, ArgsDef, IMethod, Inspect, IOption } from '@polkadot/types-codec/types';
55
import type { HexString } from '@polkadot/util/types';
66
import type { EcdsaSignature, Ed25519Signature, ExtrinsicUnknown, ExtrinsicV4, Sr25519Signature } from '../interfaces/extrinsics/index.js';
77
import type { FunctionMetadataLatest } from '../interfaces/metadata/index.js';
88
import type { Address, Call, CodecHash } from '../interfaces/runtime/index.js';
9+
import type { MultiLocation } from '../interfaces/types.js';
910
import type { CallBase, ExtrinsicPayloadValue, ICompact, IExtrinsic, IKeyringPair, INumber, Registry, SignatureOptions } from '../types/index.js';
1011
import type { GenericExtrinsicEra } from './ExtrinsicEra.js';
1112
import type { ExtrinsicValueV4 } from './v4/Extrinsic.js';
@@ -191,6 +192,13 @@ abstract class ExtrinsicBase<A extends AnyTuple> extends AbstractBase<ExtrinsicV
191192
return this.inner.signature.tip;
192193
}
193194

195+
/**
196+
* @description Forward compat
197+
*/
198+
public get assetId (): IOption<INumber> | IOption<MultiLocation> {
199+
return this.inner.signature.assetId;
200+
}
201+
194202
/**
195203
* @description Returns the raw transaction version (not flagged with signing information)
196204
*/
@@ -316,6 +324,7 @@ export class GenericExtrinsic<A extends AnyTuple = AnyTuple> extends ExtrinsicBa
316324
},
317325
this.isSigned
318326
? {
327+
assetId: this.assetId.toHuman(isExpanded, disableAscii),
319328
era: this.era.toHuman(isExpanded, disableAscii),
320329
nonce: this.nonce.toHuman(isExpanded, disableAscii),
321330
signature: this.signature.toHex(),

packages/types/src/extrinsic/ExtrinsicPayload.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import type { AnyJson, BareOpts, Registry } from '@polkadot/types-codec/types';
66
import type { HexString } from '@polkadot/util/types';
77
import type { BlockHash } from '../interfaces/chain/index.js';
88
import type { ExtrinsicPayloadV4 } from '../interfaces/extrinsics/index.js';
9-
import type { ExtrinsicPayloadValue, ICompact, IKeyringPair, INumber } from '../types/index.js';
9+
import type { MultiLocation } from '../interfaces/types.js';
10+
import type { ExtrinsicPayloadValue, ICompact, IKeyringPair, INumber, IOption } from '../types/index.js';
1011
import type { GenericExtrinsicEra } from './ExtrinsicEra.js';
1112

1213
import { AbstractBase } from '@polkadot/types-codec';
@@ -109,6 +110,13 @@ export class GenericExtrinsicPayload extends AbstractBase<ExtrinsicPayloadVx> {
109110
return this.inner.transactionVersion || this.registry.createTypeUnsafe('u32', []);
110111
}
111112

113+
/**
114+
* @description The (optional) asset id as a [[u32]] or [[MultiLocation]] for this payload
115+
*/
116+
public get assetId (): IOption<INumber | IOption<MultiLocation>> {
117+
return this.inner.assetId;
118+
}
119+
112120
/**
113121
* @description Compares the value of the input to see if there is a match
114122
*/

packages/types/src/extrinsic/SignerPayload.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import type { Text, Vec } from '@polkadot/types-codec';
55
import type { AnyJson, Registry } from '@polkadot/types-codec/types';
66
import type { HexString } from '@polkadot/util/types';
7-
import type { Address, BlockHash, Call, ExtrinsicEra, Hash } from '../interfaces/index.js';
8-
import type { Codec, ICompact, INumber, IRuntimeVersion, ISignerPayload, SignerPayloadJSON, SignerPayloadRaw } from '../types/index.js';
7+
import type { Address, BlockHash, Call, ExtrinsicEra, Hash, MultiLocation } from '../interfaces/index.js';
8+
import type { Codec, ICompact, INumber, IOption, IRuntimeVersion, ISignerPayload, SignerPayloadJSON, SignerPayloadRaw } from '../types/index.js';
99

1010
import { Option, Struct } from '@polkadot/types-codec';
1111
import { objectProperty, objectSpread, u8aToHex } from '@polkadot/util';
@@ -104,6 +104,10 @@ export class GenericSignerPayload extends Struct implements ISignerPayload, Sign
104104
return this.getT('tip');
105105
}
106106

107+
get assetId (): IOption<INumber> | IOption<MultiLocation> {
108+
return this.getT('assetId');
109+
}
110+
107111
get version (): INumber {
108112
return this.getT('version');
109113
}

packages/types/src/extrinsic/v4/ExtrinsicPayload.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
import type { SignOptions } from '@polkadot/keyring/types';
5+
import type { MultiLocation } from '@polkadot/types/interfaces';
56
import type { Bytes } from '@polkadot/types-codec';
67
import type { Inspect, Registry } from '@polkadot/types-codec/types';
78
import type { HexString } from '@polkadot/util/types';
@@ -104,7 +105,7 @@ export class GenericExtrinsicPayloadV4 extends Struct {
104105
/**
105106
* @description The (optional) asset id for this signature for chains that support transaction fees in assets
106107
*/
107-
public get assetId (): IOption<INumber> {
108+
public get assetId (): IOption<INumber | IOption<MultiLocation>> {
108109
return this.getT('assetId');
109110
}
110111

packages/types/src/extrinsic/v4/ExtrinsicSignature.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// Copyright 2017-2024 @polkadot/types authors & contributors
22
// SPDX-License-Identifier: Apache-2.0
33

4+
import type { MultiLocation } from '@polkadot/types/interfaces';
45
import type { HexString } from '@polkadot/util/types';
56
import type { EcdsaSignature, Ed25519Signature, ExtrinsicEra, ExtrinsicSignature, Sr25519Signature } from '../../interfaces/extrinsics/index.js';
67
import type { Address, Call } from '../../interfaces/runtime/index.js';
7-
import type { ExtrinsicPayloadValue, ICompact, IExtrinsicSignature, IKeyringPair, INumber, Registry, SignatureOptions } from '../../types/index.js';
8+
import type { ExtrinsicPayloadValue, ICompact, IExtrinsicSignature, IKeyringPair, INumber, IOption, Registry, SignatureOptions } from '../../types/index.js';
89
import type { ExtrinsicSignatureOptions } from '../types.js';
910

1011
import { Struct } from '@polkadot/types-codec';
@@ -118,6 +119,13 @@ export class GenericExtrinsicSignatureV4 extends Struct implements IExtrinsicSig
118119
return this.getT('tip');
119120
}
120121

122+
/**
123+
* @description The [[u32]] or [[MultiLocation]] assetId
124+
*/
125+
public get assetId (): IOption<INumber> | IOption<MultiLocation> {
126+
return this.getT('assetId');
127+
}
128+
121129
protected _injectSignature (signer: Address, signature: ExtrinsicSignature, payload: GenericExtrinsicPayloadV4): IExtrinsicSignature {
122130
// use the fields exposed to guide the getters
123131
for (let i = 0, count = this.#signKeys.length; i < count; i++) {

0 commit comments

Comments
 (0)