Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ For example, those looking to construct a transaction offline on Polkadot would

#### Published

- [@substrate/txwrapper-polkadot](/packages/txwrapper-polkadot/README.md) Helper functions for Polkadot, Kusama, Rococo and Westend offline transaction generation.
- [@substrate/txwrapper-polkadot](/packages/txwrapper-polkadot/README.md) Helper functions for offline transaction generation for polkadot relay and system chains; specifically the following chains: Polkadot, Kusama, Rococo, Westend, Statemint and Statemine.
- [@substrate/txwrapper-core](/packages/txwrapper-core/README.md) The essentials for creating a chain specific txwrapper lib.
- [@substrate/txwrapper-registry](/packages/txwrapper-registry/README.md) Registry creation support, catering to chains with types in [@polkadot/apps-config](https://github.com/polkadot-js/apps/tree/master/packages/apps-config/README.md).
- [@substrate/txwrapper-substrate](/packages/txwrapper-substrate/README.md) Selected dispatchables of Substrate pallets, to be re-exported by txwrappers (e.g. @substrate/txwrapper-polkadot).
Expand Down
2 changes: 1 addition & 1 deletion packages/txwrapper-acala/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function getRegistry({
}: GetRegistryOpts): TypeRegistry {
const registry = new TypeRegistry();
registry.setKnownTypes({
typesBundle: (typesBundleForPolkadot as unknown) as OverrideBundleType,
typesBundle: typesBundleForPolkadot as unknown as OverrideBundleType,
});

return getRegistryBase({
Expand Down
4 changes: 2 additions & 2 deletions packages/txwrapper-core/src/core/decode/decode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ describe('decode', () => {
POLKADOT_25_TEST_OPTIONS
);

const decoded = (decode(
const decoded = decode(
signingPayload,
POLKADOT_25_TEST_OPTIONS
) as unknown) as DecodedSigningPayload;
) as unknown as DecodedSigningPayload;

itDecodesSigningPayloadBalancesTransfer(decoded);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ import { itDecodesBalancesTransferCommon } from './test-helpers';
export function itDecodesSigningPayloadBalancesTransfer(
decoded: DecodedSigningPayload
): void {
([
'blockHash',
'genesisHash',
'metadataRpc',
'nonce',
'specVersion',
'tip',
] as const).forEach((key) =>
expect(decoded[key]).toBe(TEST_BASE_TX_INFO[key])
);
(
[
'blockHash',
'genesisHash',
'metadataRpc',
'nonce',
'specVersion',
'tip',
] as const
).forEach((key) => expect(decoded[key]).toBe(TEST_BASE_TX_INFO[key]));
}

describe('decodeSigningPayload', () => {
Expand Down
26 changes: 13 additions & 13 deletions packages/txwrapper-core/src/core/decode/decodeUnsignedTx.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ import { itDecodesBalancesTransferCommon } from './test-helpers';
export function itDecodesUnsignedBalanceTransferTx(
decoded: DecodedUnsignedTx
): void {
([
'address',
'blockHash',
'blockNumber',
'genesisHash',
'metadataRpc',
'nonce',
'specVersion',
'transactionVersion',
'tip',
] as const).forEach((key) =>
expect(decoded[key]).toBe(TEST_BASE_TX_INFO[key])
);
(
[
'address',
'blockHash',
'blockNumber',
'genesisHash',
'metadataRpc',
'nonce',
'specVersion',
'transactionVersion',
'tip',
] as const
).forEach((key) => expect(decoded[key]).toBe(TEST_BASE_TX_INFO[key]));
}

describe('decodeUnsignedTx', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/txwrapper-core/src/core/method/defineMethod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function defineMethod(

const methodFunction =
!!tx[info.method.pallet] &&
((tx[info.method.pallet] as unknown) as ModuleExtrinsics)[info.method.name];
(tx[info.method.pallet] as unknown as ModuleExtrinsics)[info.method.name];
if (!methodFunction) {
throw new Error('pallet or method not found in metadata');
}
Expand Down
2 changes: 1 addition & 1 deletion packages/txwrapper-core/src/core/method/toTxMethod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { Args, TxMethod } from '../../types/method';
export function toTxMethod(registry: TypeRegistry, method: Call): TxMethod {
// Mapping of argName->argType
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const argsDef = JSON.parse((method.Type.args as unknown) as string);
const argsDef = JSON.parse(method.Type.args as unknown as string);
// Mapping of argName->argValue
const args = Object.keys(argsDef).reduce((accumulator, key, index) => {
let codec = createTypeUnsafe(registry, argsDef[key], [method.args[index]]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function getRegistryMandala(
): TypeRegistry {
const registry = new TypeRegistry();
registry.setKnownTypes({
typesBundle: (typesBundleForPolkadot as unknown) as OverrideBundleType,
typesBundle: typesBundleForPolkadot as unknown as OverrideBundleType,
});

return getRegistryBase({
Expand Down
6 changes: 6 additions & 0 deletions packages/txwrapper-polkadot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@

<br /><br />

# About

Txwrapper library for polkadot relay and system chains; specifically Polkadot, Kusama, Rococo, Westend, Statemint and Statemine.

Note: not all methods available apply to all supported chains. To check what methods are supported by a chain consult the pallets included in chain's runtime.


## Get Started

Expand Down
26 changes: 24 additions & 2 deletions packages/txwrapper-polkadot/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { methods as substrateMethods } from '@substrate/txwrapper-substrate';

import * as polkadotMethods from './methods';

// Export methods of pallets included in the Polkadot/ Kusama/ Westend runtimes.
// Export methods of pallets included in the Polkadot, Kusama, Westend, Rococo
// and State{mint, mine} runtimes.
// Note: in the future this may also include methods defined within this package
// that do not exist in Substrate.
export const methods = {
Expand All @@ -23,6 +24,8 @@ export const methods = {
vesting: substrateMethods.vesting,
multisig: substrateMethods.multisig,
crowdloan: polkadotMethods.crowdloan,
// assets is only applicable to State{mint, mine}
assets: substrateMethods.assets,
};

// Re-export all of txwrapper-core so users have access to utilities, construct functions,
Expand All @@ -49,6 +52,16 @@ const KNOWN_CHAIN_PROPERTIES = {
tokenDecimals: 12,
tokenSymbol: 'WND',
},
statemint: {
ss58Format: PolkadotSS58Format.polkadot,
tokenDecimals: 10,
tokenSymbol: 'DOT',
},
statemine: {
ss58Format: PolkadotSS58Format.kusama,
tokenDecimals: 12,
tokenSymbol: 'KSM',
},
};

// We override the `specName` property of `GetRegistryOptsCore` in order to get narrower type specificity,
Expand All @@ -75,9 +88,18 @@ export function getRegistry({
// The default type registry has polkadot types
const registry = new TypeRegistry();

// As of now statemine is not a supported specName in the default polkadot-js/api type registry.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know if there's an issue for that upstream? If there is, maybe link to it here?

const chainNameAdjusted = chainName === 'Statemine' ? 'Statemint' : chainName;
const specNameAdjusted = specName === 'statemine' ? 'statemint' : specName;

return getRegistryBase({
chainProperties: properties || KNOWN_CHAIN_PROPERTIES[specName],
specTypes: getSpecTypes(registry, chainName, specName, specVersion),
specTypes: getSpecTypes(
registry,
chainNameAdjusted,
specNameAdjusted,
specVersion
),
metadataRpc,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface AssetsApproveTransferArgs extends Args {
* The amount of asset that may be transferred by `delegate`. If there is
* already an approval in place, then this acts additively.
*/
amount: number;
amount: number | string;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface AssetsTransferArgs extends Args {
* the case that the transfer would otherwise take the sender balance above zero but below
* the minimum balance. Must be greater than zero.
*/
amount: number;
amount: number | string;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface AssetsTransferApprovedArgs extends Args {
/**
* The amount of assets to transfer.
*/
amount: number;
amount: number | string;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface AssetsTransferKeepAliveArgs extends Args {
* the case that the transfer would otherwise take the sender balance above zero but below
* the minimum balance. Must be greater than zero.
*/
amount: number;
amount: number | string;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,12 @@ export const TEST_METHOD_ARGS = {
delegate: 'HNZata7iMYWmk5RvZRTiAsSDhV8366zq2YGb3tLH5Upf74F', // seed "//Alice"
real: '14E5nqKAp3oAJcmzgZhUD2RcptBeUBScxKHgJKU4HPNcKVf3', // seed "//Bob",
forceProxyType: 'Any',
call:
'0x0500306721211d5404bd9da88e0204360a1a9ab8b87c66c1bc2fcdd37f3c2222cc200f00a0be1c448399',
call: '0x0500306721211d5404bd9da88e0204360a1a9ab8b87c66c1bc2fcdd37f3c2222cc200f00a0be1c448399',
},
proxy: {
real: '14E5nqKAp3oAJcmzgZhUD2RcptBeUBScxKHgJKU4HPNcKVf3', // seed "//Bob",
forceProxyType: 'Any',
call:
'0x0500306721211d5404bd9da88e0204360a1a9ab8b87c66c1bc2fcdd37f3c2222cc200f00a0be1c448399',
call: '0x0500306721211d5404bd9da88e0204360a1a9ab8b87c66c1bc2fcdd37f3c2222cc200f00a0be1c448399',
},
anonymous: {
proxyType: 'Any',
Expand Down Expand Up @@ -178,8 +176,7 @@ export const TEST_METHOD_ARGS = {
height: 123,
index: 3,
},
call:
'0x0500306721211d5404bd9da88e0204360a1a9ab8b87c66c1bc2fcdd37f3c2222cc200f00a0be1c448399',
call: '0x0500306721211d5404bd9da88e0204360a1a9ab8b87c66c1bc2fcdd37f3c2222cc200f00a0be1c448399',
storeCall: false,
maxWeight: '90071992547409910',
},
Expand Down
Loading