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
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
// Copyright 2017-2024 @polkadot/types authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { AnyJson, AnyTuple, AnyU8a, ArgsDef, IMethod, Inspect } from '@polkadot/types-codec/types';
|
||||
import type { AnyJson, AnyTuple, AnyU8a, ArgsDef, IMethod, Inspect, IOption } from '@polkadot/types-codec/types';
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
import type { EcdsaSignature, Ed25519Signature, ExtrinsicUnknown, ExtrinsicV4, Sr25519Signature } from '../interfaces/extrinsics/index.js';
|
||||
import type { FunctionMetadataLatest } from '../interfaces/metadata/index.js';
|
||||
import type { Address, Call, CodecHash } from '../interfaces/runtime/index.js';
|
||||
import type { MultiLocation } from '../interfaces/types.js';
|
||||
import type { CallBase, ExtrinsicPayloadValue, ICompact, IExtrinsic, IKeyringPair, INumber, Registry, SignatureOptions } from '../types/index.js';
|
||||
import type { GenericExtrinsicEra } from './ExtrinsicEra.js';
|
||||
import type { ExtrinsicValueV4 } from './v4/Extrinsic.js';
|
||||
@@ -191,6 +192,13 @@ abstract class ExtrinsicBase<A extends AnyTuple> extends AbstractBase<ExtrinsicV
|
||||
return this.inner.signature.tip;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Forward compat
|
||||
*/
|
||||
public get assetId (): IOption<INumber> | IOption<MultiLocation> {
|
||||
return this.inner.signature.assetId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the raw transaction version (not flagged with signing information)
|
||||
*/
|
||||
@@ -316,6 +324,7 @@ export class GenericExtrinsic<A extends AnyTuple = AnyTuple> extends ExtrinsicBa
|
||||
},
|
||||
this.isSigned
|
||||
? {
|
||||
assetId: this.assetId.toHuman(isExpanded, disableAscii),
|
||||
era: this.era.toHuman(isExpanded, disableAscii),
|
||||
nonce: this.nonce.toHuman(isExpanded, disableAscii),
|
||||
signature: this.signature.toHex(),
|
||||
|
||||
@@ -6,7 +6,8 @@ import type { AnyJson, BareOpts, Registry } from '@polkadot/types-codec/types';
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
import type { BlockHash } from '../interfaces/chain/index.js';
|
||||
import type { ExtrinsicPayloadV4 } from '../interfaces/extrinsics/index.js';
|
||||
import type { ExtrinsicPayloadValue, ICompact, IKeyringPair, INumber } from '../types/index.js';
|
||||
import type { MultiLocation } from '../interfaces/types.js';
|
||||
import type { ExtrinsicPayloadValue, ICompact, IKeyringPair, INumber, IOption } from '../types/index.js';
|
||||
import type { GenericExtrinsicEra } from './ExtrinsicEra.js';
|
||||
|
||||
import { AbstractBase } from '@polkadot/types-codec';
|
||||
@@ -109,6 +110,13 @@ export class GenericExtrinsicPayload extends AbstractBase<ExtrinsicPayloadVx> {
|
||||
return this.inner.transactionVersion || this.registry.createTypeUnsafe('u32', []);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The (optional) asset id as a [[u32]] or [[MultiLocation]] for this payload
|
||||
*/
|
||||
public get assetId (): IOption<INumber | IOption<MultiLocation>> {
|
||||
return this.inner.assetId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Compares the value of the input to see if there is a match
|
||||
*/
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
import type { Text, Vec } from '@polkadot/types-codec';
|
||||
import type { AnyJson, Registry } from '@polkadot/types-codec/types';
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
import type { Address, BlockHash, Call, ExtrinsicEra, Hash } from '../interfaces/index.js';
|
||||
import type { Codec, ICompact, INumber, IRuntimeVersion, ISignerPayload, SignerPayloadJSON, SignerPayloadRaw } from '../types/index.js';
|
||||
import type { Address, BlockHash, Call, ExtrinsicEra, Hash, MultiLocation } from '../interfaces/index.js';
|
||||
import type { Codec, ICompact, INumber, IOption, IRuntimeVersion, ISignerPayload, SignerPayloadJSON, SignerPayloadRaw } from '../types/index.js';
|
||||
|
||||
import { Option, Struct } from '@polkadot/types-codec';
|
||||
import { objectProperty, objectSpread, u8aToHex } from '@polkadot/util';
|
||||
@@ -104,6 +104,10 @@ export class GenericSignerPayload extends Struct implements ISignerPayload, Sign
|
||||
return this.getT('tip');
|
||||
}
|
||||
|
||||
get assetId (): IOption<INumber> | IOption<MultiLocation> {
|
||||
return this.getT('assetId');
|
||||
}
|
||||
|
||||
get version (): INumber {
|
||||
return this.getT('version');
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { SignOptions } from '@polkadot/keyring/types';
|
||||
import type { MultiLocation } from '@polkadot/types/interfaces';
|
||||
import type { Bytes } from '@polkadot/types-codec';
|
||||
import type { Inspect, Registry } from '@polkadot/types-codec/types';
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
@@ -104,7 +105,7 @@ export class GenericExtrinsicPayloadV4 extends Struct {
|
||||
/**
|
||||
* @description The (optional) asset id for this signature for chains that support transaction fees in assets
|
||||
*/
|
||||
public get assetId (): IOption<INumber> {
|
||||
public get assetId (): IOption<INumber | IOption<MultiLocation>> {
|
||||
return this.getT('assetId');
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
// Copyright 2017-2024 @polkadot/types authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { MultiLocation } from '@polkadot/types/interfaces';
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
import type { EcdsaSignature, Ed25519Signature, ExtrinsicEra, ExtrinsicSignature, Sr25519Signature } from '../../interfaces/extrinsics/index.js';
|
||||
import type { Address, Call } from '../../interfaces/runtime/index.js';
|
||||
import type { ExtrinsicPayloadValue, ICompact, IExtrinsicSignature, IKeyringPair, INumber, Registry, SignatureOptions } from '../../types/index.js';
|
||||
import type { ExtrinsicPayloadValue, ICompact, IExtrinsicSignature, IKeyringPair, INumber, IOption, Registry, SignatureOptions } from '../../types/index.js';
|
||||
import type { ExtrinsicSignatureOptions } from '../types.js';
|
||||
|
||||
import { Struct } from '@polkadot/types-codec';
|
||||
@@ -118,6 +119,13 @@ export class GenericExtrinsicSignatureV4 extends Struct implements IExtrinsicSig
|
||||
return this.getT('tip');
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The [[u32]] or [[MultiLocation]] assetId
|
||||
*/
|
||||
public get assetId (): IOption<INumber> | IOption<MultiLocation> {
|
||||
return this.getT('assetId');
|
||||
}
|
||||
|
||||
protected _injectSignature (signer: Address, signature: ExtrinsicSignature, payload: GenericExtrinsicPayloadV4): IExtrinsicSignature {
|
||||
// use the fields exposed to guide the getters
|
||||
for (let i = 0, count = this.#signKeys.length; i < count; i++) {
|
||||
|
||||
Reference in New Issue
Block a user