Skip to content

Commit

Permalink
modified types to use new ChargeAssetTxPayment
Browse files Browse the repository at this point in the history
  • Loading branch information
bee344 committed Nov 21, 2023
1 parent 1bd1b38 commit cd2a8e9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
13 changes: 8 additions & 5 deletions packages/txwrapper-core/src/core/decode/decodeSigningPayload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,18 @@ export function decodeSigningPayload(
? payload.era.asMortalEra.period.toNumber()
: 0;

let assetId: number | undefined;
let assetId: number | object | undefined;
if (payload.inner.assetId) {
assetId = payload.inner.assetId.isSome
? parseInt(payload.inner.assetId.toString())
: undefined;
assetId = payload.inner.assetId.isSome ? payload.inner.assetId : undefined;
}

return {
assetId,
assetId:
typeof assetId === 'object'
? assetId
: typeof assetId === 'number'
? parseInt(assetId.toString())
: undefined,
blockHash: payload.blockHash.toHex(),
eraPeriod,
genesisHash: payload.genesisHash.toHex(),
Expand Down
9 changes: 5 additions & 4 deletions packages/txwrapper-core/src/core/decode/decodeUnsignedTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ export function decodeUnsignedTx(
const eraPeriod = isImmortalEra
? hexToNumber(registry.createType('ImmortalEra', unsigned.era).toHex())
: registry.createType('MortalEra', unsigned.era).period.toNumber();

const assetId = unsigned.assetId;
return {
address: unsigned.address,
assetId: registry
.createType('Compact<AssetId>', unsigned.assetId)
.toNumber(),
assetId:
typeof assetId === 'object'
? registry.createType('MultiLocation', assetId)
: registry.createType('Compact<AssetId>', assetId).toNumber(),
blockHash: unsigned.blockHash,
blockNumber: registry
.createType('BlockNumber', unsigned.blockNumber)
Expand Down
6 changes: 5 additions & 1 deletion packages/txwrapper-core/src/core/method/defineMethod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,14 @@ export function defineMethod(
const extrinsicEra = createEra(registry, eraOptions);
const blockHash = info.blockHash as `0x${string}`;
const genesisHash = info.genesisHash as `0x${string}`;
const assetId = info.assetId;

return {
address: info.address,
assetId: registry.createType('Compact<AssetId>', info.assetId).toNumber(),
assetId:
typeof assetId === 'object'
? registry.createType('MultiLocation', assetId)
: registry.createType('Compact<AssetId>', assetId).toNumber(),
blockHash,
blockNumber: registry.createType('BlockNumber', info.blockNumber).toHex(),
era: extrinsicEra.toHex(),
Expand Down
6 changes: 2 additions & 4 deletions packages/txwrapper-core/src/types/method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ export interface UnsignedTransaction extends SignerPayloadJSON {
/**
* The assetId used in ChargeAssetTxPayment
*
* @default 0
*/
assetId?: number;
assetId?: number | object;
/**
* The SCALE-encoded metadata, as a hex string. Can be retrieved via the RPC
* call `state_getMetadata`.
Expand All @@ -90,9 +89,8 @@ export interface BaseTxInfo {
/**
* The assetId used in ChargeAssetTxPayment
*
* @default 0
*/
assetId?: number;
assetId?: number | object;
/**
* The checkpoint hash of the block, in hex.
*/
Expand Down

0 comments on commit cd2a8e9

Please sign in to comment.