-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathindex.ts
115 lines (107 loc) · 3.2 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import {
getRegistryBase,
GetRegistryOptsCore,
getSpecTypes,
PolkadotSS58Format,
TypeRegistry,
} from '@substrate/txwrapper-core';
import { methods as substrateMethods } from '@substrate/txwrapper-substrate';
import * as polkadotMethods from './methods';
// 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 = {
balances: substrateMethods.balances,
utility: substrateMethods.utility,
proxy: substrateMethods.proxy,
democracy: substrateMethods.democracy,
session: substrateMethods.session,
staking: substrateMethods.staking,
system: substrateMethods.system,
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,
// decode function, and types.
export * from '@substrate/txwrapper-core';
/**
* `ChainProperties` for networks that txwrapper-polkadot supports. These are normally returned
* by `system_properties` call, but since they don't change much, it's pretty safe to hardcode them.
*/
const KNOWN_CHAIN_PROPERTIES = {
kusama: {
ss58Format: PolkadotSS58Format.kusama,
tokenDecimals: 12,
tokenSymbol: 'KSM',
},
polkadot: {
ss58Format: PolkadotSS58Format.polkadot,
tokenDecimals: 10,
tokenSymbol: 'DOT',
},
westend: {
ss58Format: PolkadotSS58Format.westend,
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,
// hopefully creating a better experience for users.
/**
* Options for txwrapper-polkadot's `getRegistry` function.
*/
export interface GetRegistryOpts extends GetRegistryOptsCore {
specName: keyof typeof KNOWN_CHAIN_PROPERTIES;
}
/**
* Get a type registry for networks that txwrapper-polkadot supports.
*
* @param GetRegistryOptions specName, chainName, specVersion, and metadataRpc of the current runtime
*/
export function getRegistry({
specName,
chainName,
specVersion,
metadataRpc,
properties,
asCallsOnlyArg,
signedExtensions,
userExtensions,
typesBundle,
additionalTypes,
}: GetRegistryOpts): TypeRegistry {
// 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.
const chainNameAdjusted = chainName === 'Statemine' ? 'Statemint' : chainName;
const specNameAdjusted = specName === 'statemine' ? 'statemint' : specName;
return getRegistryBase({
chainProperties: properties || KNOWN_CHAIN_PROPERTIES[specName],
specTypes: getSpecTypes(
registry,
chainNameAdjusted,
specNameAdjusted,
specVersion
),
metadataRpc,
asCallsOnlyArg,
signedExtensions,
userExtensions,
typesBundle,
additionalTypes,
});
}