Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d958ef8f15 | ||
|
|
97527871d6 | ||
|
|
0317f28e5a | ||
|
|
ebe6d03762 | ||
|
|
59e92fa344 | ||
|
|
cab338e26d | ||
|
|
743ea431b4 | ||
|
|
533f9ce249 | ||
|
|
797ee9c24a | ||
|
|
2f5e2537a3 | ||
|
|
dd52ea4b32 | ||
|
|
5e8ae793c3 | ||
|
|
8713a1f2b6 | ||
|
|
6e6fa4a97c | ||
|
|
ac2a0a34ca | ||
|
|
45fb6d44ad | ||
|
|
6d2265d4ff | ||
|
|
4ec42f1750 | ||
|
|
01166b9684 | ||
|
|
0075dce720 | ||
|
|
7fbb30066e | ||
|
|
637069d723 | ||
|
|
d639a7ee8c | ||
|
|
28ef291c40 | ||
|
|
48ddd0b0d4 | ||
|
|
e88ebf7b2e | ||
|
|
72700e6baf | ||
|
|
f748fcd46d | ||
|
|
7876bb9ced | ||
|
|
a83980b213 | ||
|
|
c4323d5e94 | ||
|
|
11694f1393 | ||
|
|
3989ae67b2 | ||
|
|
b78df57907 | ||
|
|
2f78329738 | ||
|
|
6063054712 | ||
|
|
e42af97928 | ||
|
|
d05ccdb5d7 | ||
|
|
c33334b72b | ||
|
|
94e9fd2b17 | ||
|
|
9c1327ea22 | ||
|
|
9f195e9402 | ||
|
|
3e5e089c68 | ||
|
|
35c37aa66c | ||
|
|
f1aeb564e3 | ||
|
|
c2ff1b32ae | ||
|
|
288427cbb8 | ||
|
|
d099ccedad | ||
|
|
79c7983199 | ||
|
|
80c578fe76 | ||
|
|
de90c048bf | ||
|
|
01a36a994d | ||
|
|
b1ce22d51d | ||
|
|
fe951c2645 | ||
|
|
5a17c542a7 | ||
|
|
59bb5f864f | ||
|
|
abcba20f90 | ||
|
|
014f08c7cc | ||
|
|
7ecd00a4e6 | ||
|
|
6239818c26 | ||
|
|
6af22f41c7 | ||
|
|
77c3a701d0 | ||
|
|
46b17a466c | ||
|
|
e592c6c878 | ||
|
|
ef37586dfc | ||
|
|
5856ce24cc | ||
|
|
8b79056bf9 | ||
|
|
70e0f19ade | ||
|
|
cf1e242c17 | ||
|
|
68856e9692 | ||
|
|
e0626c3dad | ||
|
|
277ea92fda | ||
|
|
aec6694028 | ||
|
|
533abb76f7 | ||
|
|
7660bab86b | ||
|
|
f7c1b6e81b | ||
|
|
b6e9b29570 | ||
|
|
519d9c8fa9 | ||
|
|
ad905db53b | ||
|
|
0a0aa742b4 | ||
|
|
dfbb06a4d6 | ||
|
|
82e71fd51e | ||
|
|
a8b88af97a | ||
|
|
eee36537de | ||
|
|
20a75eafb6 | ||
|
|
00d3a1174b | ||
|
|
e293c7c1cf | ||
|
|
3c8cd499c4 | ||
|
|
cb3816df78 | ||
|
|
fcfcbb2d97 | ||
|
|
321b80ed63 | ||
|
|
73eaa9fe17 | ||
|
|
4d8910f3da | ||
|
|
e6806ed7f9 | ||
|
|
218abf9568 | ||
|
|
a1df864681 | ||
|
|
45640edcff | ||
|
|
53655019b5 | ||
|
|
a1f8bedb6d | ||
|
|
9d1af1eaeb | ||
|
|
38bfd26511 | ||
|
|
1beaf9f208 | ||
|
|
29c29978dd | ||
|
|
a8d1dd0637 | ||
|
|
74571dcd26 | ||
|
|
54b4c2620a | ||
|
|
da05828e74 | ||
|
|
fa935156e1 |
+3
-1
@@ -13,6 +13,8 @@ module.exports = {
|
||||
// add override for any (a metric ton of them, initial conversion)
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
// these should be removed, there are 8 of them as errors
|
||||
'@typescript-eslint/no-non-null-assertion': 'off'
|
||||
'@typescript-eslint/no-non-null-assertion': 'off',
|
||||
// this seems very broken atm, false positives
|
||||
'@typescript-eslint/unbound-method': 'off'
|
||||
}
|
||||
};
|
||||
|
||||
+86
File diff suppressed because one or more lines are too long
Vendored
-56
File diff suppressed because one or more lines are too long
+1
-1
@@ -8,4 +8,4 @@ plugins:
|
||||
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.js
|
||||
spec: "@yarnpkg/plugin-interactive-tools"
|
||||
|
||||
yarnPath: .yarn/releases/yarn-rc.js
|
||||
yarnPath: .yarn/releases/yarn-2.1.1.cjs
|
||||
|
||||
+154
-2
@@ -1,27 +1,104 @@
|
||||
# CHANGELOG
|
||||
|
||||
## 1.31.1 Aug 31, 2020
|
||||
|
||||
Upgrade priority: Medium, especially for staking users on Polkadot, Kusama & Westend (type updates applied for v23 onwards) or if transparent `.at(hash)` queries are required/used
|
||||
|
||||
- **Important** Substrate changed the `RewardDestination` enum with an extra field for payout-to-any account for staking preferences. If on an older chain consider adding `RewardDestination: 'RewardDestinationTo257'`
|
||||
- **Important** Substrate changed the `CompactAssignment` type enhanced types for session solution submissions. If on an older chain consider adding `CompactAssignments: 'CompactAssignmentsTo257'`
|
||||
|
||||
- Fix documentation language and typos (Thanks to https://github.com/Meuko)
|
||||
- Add missing `TransactionPriority` type (Thanks to https://github.com/aniiantt)
|
||||
- Update definitions for new `CompactAssignments`, including tests (Thanks to https://github.com/kianenigma)
|
||||
|
||||
- Add transparent support for types/metadata, i.e. hash queries such as `rpc.chain.getBlock(<hash>)` & `query.system.events.at(<hash>)` now works out-of-the-box injecting the correct metadata & types.
|
||||
- Optimize RPC-layer calls with detection of short-term cacheable calls (in the same way subscriptions are done)
|
||||
- Additional checks on `AccountId` for valid sizes
|
||||
- Add `toBigInt()` (JS built-in `BigInt`) on `Int/Uint`, & `Compact<*>` types
|
||||
- Support for `.concat` on Codec arrays
|
||||
- Support for serialization with `isBare` flag on enums
|
||||
- Add `api.getBlockRegistry(blockHash?)` to create registry/types for a specific block
|
||||
- `derive.democracy.locks` now returns delegated locks for an account as well
|
||||
- Adjust unlocking derives with appropriate in-place additions (less object allocations)
|
||||
- `.sign` on submittables is marked deprecated (not due for removal, but rather use `.signAsync` for consistency with `.signAndSend`)
|
||||
- Adjust types for `CompactAssignments` & `RewardDestination` for Polkadot, Kusama & Westend
|
||||
- `@polkadot/util` 3.4
|
||||
- `@polkadot/wasm-crypto` 1.4
|
||||
|
||||
|
||||
## 1.30.1 Aug 24, 2020
|
||||
|
||||
Upgrade priority: Low, unless using the `proposeParachain` module.
|
||||
|
||||
- Adjust balance retrievals to check for `system.account` for new/old determination
|
||||
- Add types for the new `proposeParachain` module (as per Rococo)
|
||||
- Adjust `Address` <-> `LookupSource` definitions (no external impact, both in existence)
|
||||
- Add Ethereum-compatible `Ethereum{AccountId, LookupSource}` types, underlying `H160`
|
||||
- Allow for configurable hashers via `registry.setHasher(...)` (defaults to `blake2AsU8a`)
|
||||
- `@polkadot/util` 3.3
|
||||
|
||||
|
||||
## 1.29.1 Aug 17, 2020
|
||||
|
||||
Upgrade priority: Low, unless on bleeding-edge chain with new compact `CompactAssignments`.
|
||||
|
||||
- **Important** The Substrate `CompactAssignments` type has changed for better space utilization. On older chains, supply `CompactAssignments: 'CompactAssignmentsTo257'`
|
||||
|
||||
- Clean tx cookbook param expansion (Thanks to https://github.com/swswsw)
|
||||
|
||||
- Add additional `Fixed{I,U}{64,128}` and `{I,U}32F32` types
|
||||
- Add `desiredRunnersUp` to council derives
|
||||
- Cleanup indices/AccountId combination derive lookups
|
||||
- `@polkadot/util` 3.2
|
||||
|
||||
|
||||
## 1.28.1 Aug 10, 2020
|
||||
|
||||
Upgrade priority: Low, unless using Centrifuge or parachains
|
||||
|
||||
- Update Centrifuge types to latest (Thanks to https://github.com/mikiquantum)
|
||||
|
||||
- Add cookbook entry for viewing block extrinsics
|
||||
- Support types for time-delay proxies
|
||||
- Update types for parachains
|
||||
- `@polkadot/util` 3.1
|
||||
- `@polkadot/wasm-crypto` 1.3
|
||||
|
||||
|
||||
## 1.27.1 Aug 3, 2020
|
||||
|
||||
Upgrade priority: Low, unless using the Rococo chain
|
||||
|
||||
- Remove outdated example poc-3 RPC reference (Thanks to https://github.com/swswsw)
|
||||
|
||||
- Raw/Bytes `toHuman` detects ASCII sequence for text output
|
||||
- Add know types for the Rococo chain
|
||||
|
||||
|
||||
## 1.26.1 Jul 27, 2020
|
||||
|
||||
Upgrade priority: Low
|
||||
|
||||
- Update docs for the new `system.accountNextIndex` (Thanks to https://github.com/shawntabrizi)
|
||||
- Update contracts call parameter typing (Thanks to https://github.com/kwingram25)
|
||||
|
||||
- Adjust votingBalance to only return `freeBalance` (only council voting is free + reserved)
|
||||
- Additional checks for referenced Vec sub-type deconstruction in typegen
|
||||
- Allow for API `typesBundle` option to inject a group of chain versions types
|
||||
- Update metadata static tests for latest Substrate
|
||||
- `@polkadot/util` 3.0
|
||||
|
||||
|
||||
## 1.25.1 Jul 20, 2020
|
||||
|
||||
Upgrade priority: Medium, especially if using contracts.
|
||||
|
||||
- **Important** Contract RPC result updated on Substrate, on older chains supply `ContractExecResult: 'ContractExecResultTo255'`
|
||||
|
||||
- Support for custom HTTP headers in providers (Thanks to https://github.com/brad-larson)
|
||||
- Update known types for Centrifuge (Thanks to https://github.com/philipstanislaus)
|
||||
- Update API users with Registrar #1 (Thanks to https://github.com/chevdor)
|
||||
|
||||
- Raw/Bytes `toHuman()` displays utf-8 as available
|
||||
- Add fallback for `setImmediate` when not polyfilled
|
||||
- Update `NetworkState` reputation type for `system_networkState` RPC
|
||||
@@ -29,15 +106,18 @@
|
||||
- Fix class prototype for (basically-deprecated) Linkage type
|
||||
- Add Polkadot types for `purchase` pallet
|
||||
|
||||
|
||||
## 1.24.1 Jul 13, 2020
|
||||
|
||||
- Added `isAscii` & `isUtf8` getters to `Bytes` & `Raw` types
|
||||
- Added `toUtf8()` helper to `Bytes` & `Raw` types
|
||||
- `@polkadot/util` 2.18
|
||||
|
||||
|
||||
## 1.23.1 Jul 6, 2020
|
||||
|
||||
- Small README typo fix (Thanks to https://github.com/woss)
|
||||
|
||||
- Add latest Substrate master types
|
||||
- Adjust `<Codec>.toRawType()` to use registry name as available
|
||||
- Update `ProxyType` for Kusama, Polkadot & Westend with `IdentityJudgement`
|
||||
@@ -45,27 +125,34 @@
|
||||
- Remove core codec dependencies on Base class (with proper TS encapsulation)
|
||||
- `@polkadot/util` 2.17
|
||||
|
||||
|
||||
## 1.22.1 Jun 30, 2020
|
||||
|
||||
- **Important** Substrate changed the treasury tip structure, on older chains supply `OpenTip: 'OpenTipTo225'`
|
||||
|
||||
- Allow for `[u8; 33]` in U8aFixed (Thanks to https://github.com/akru)
|
||||
|
||||
- Improve derive accountId -> accountIndex lookups (optimize entries queries)
|
||||
- Vesting balance calculations via `derive.balances.all` has been updated for locks
|
||||
- Add derive for multi staking rewards with specified eras
|
||||
- `@polkadot/util` 2.16
|
||||
|
||||
|
||||
## 1.21.1 Jun 23, 2020
|
||||
|
||||
- Fix subscriptions never unsubscribing after the id swap in 1.18.1 (Thanks to https://github.com/dillu24 for testing iterations)
|
||||
|
||||
- Add support for `CheckMortality` signed extension (old `CheckEra` is now an alias)
|
||||
- Promise API will default to using `getStorage` on non-subscription calls, reducing RPC overhead
|
||||
- Optimize derive BN allocations, using in-place operators as applicable
|
||||
- Add new Substrate types for Babe `EquivocationProof`
|
||||
- Adjust `Releases` enum to use a shared instance
|
||||
|
||||
|
||||
## 1.20.1 Jun 22, 2020
|
||||
|
||||
- **Important** RPC for `account_nextIndex` has been moved to `system_accountNextIndex` (Aligning with Substrate as a primary alias)
|
||||
|
||||
- Cleanup map entries support with only Substrate 2.0-era RPCs (when introduced)
|
||||
- Add `system_dryRun` RPC
|
||||
- Optimize `derive.staking.queryMulti` retrievals with additional per-type batching
|
||||
@@ -73,33 +160,40 @@
|
||||
- Adjust types & metadata for latest Substrate
|
||||
- `@polkadot/util` 2.15
|
||||
|
||||
|
||||
## 1.19.1 Jun 16, 2020
|
||||
|
||||
- Improve typing on `.entries()` queries (Thanks to https://github.com/monitz87)
|
||||
|
||||
- Align metadata and types with latest Substrate
|
||||
- Update Polkadot types for current evolution of parachains
|
||||
- Allow for type aliasing on events (aligning with calls & queries)
|
||||
- `@polkadot/util` 2.14
|
||||
|
||||
|
||||
## 1.18.1 Jun 8, 2020
|
||||
|
||||
- Expand docs on node-template types (Thanks to https://github.com/g2udevelopment)
|
||||
- Update contract fees to current impl. (Thanks to https://github.com/djuanit0x)
|
||||
- Allow `Option` types in enum/Result type generation (Thanks to http://github.com/xlc)
|
||||
- Add `.entriesPaged` and `.keysPaged` methods for state maps (https://github.com/monitz87)
|
||||
|
||||
- Add types for new Substrate proxy module
|
||||
- Adjust types for new Substrate (renamed) npos-elections module
|
||||
- `Call` now exposes `method` & `section` fields (aligned with `toHuman()` representation)
|
||||
- Cater for new Substrate string subscription ids (with backwards compatibility)
|
||||
- `@polkadot/util` 2.13
|
||||
|
||||
|
||||
## 1.17.2 Jun 2, 2020
|
||||
|
||||
- Ensure subscription promise resolves before first result
|
||||
|
||||
|
||||
## 1.17.1 Jun 2, 2020
|
||||
|
||||
- Fix `ElectionSize` type (Thanks to https://github.com/arjanz)
|
||||
|
||||
- Allow `BTreeSet` decoding from Array/JSON inputs
|
||||
- Adjust Call-only metadata output to trim documentation to first full line
|
||||
- Safeguard against divide-by-zero for total era points (expired reward eras)
|
||||
@@ -107,6 +201,7 @@
|
||||
- Support for latest Substrate types & metadata
|
||||
- `@polkadot/util` 2.12
|
||||
|
||||
|
||||
## 1.16.1 May 26, 2020
|
||||
|
||||
- Support for Polkadot CC1 types & signed extensions
|
||||
@@ -116,6 +211,7 @@
|
||||
- Update to latest TypeScript, eslint & typescript-eslint
|
||||
- `@polkadot/util` 2.11
|
||||
|
||||
|
||||
## 1.15.1 May 23, 2020
|
||||
|
||||
- Adjust `keyPrefix()` with DoubleMap args (Thanks to https://github.com/KiChjang)
|
||||
@@ -123,17 +219,20 @@
|
||||
- Spelling fixes for console logs (Thanks to https://github.com/JoshOrndorff)
|
||||
- Spelling fixes in cookbook (Thanks to https://github.com/pawelnguyen)
|
||||
- Add `transactionVersion` getter in payloads (Thanks to https://github.com/amaurymartiny)
|
||||
|
||||
- Adjust `stakerRewards` derive ordering for improved on-payout refreshes
|
||||
- Baseline implementation for derive caching infrastructure
|
||||
- Adjust `Multiplier` type to `Fixed128` (as per latest Substrate)
|
||||
- Updated to latest Substrate metadata & add new types
|
||||
|
||||
|
||||
## 1.14.1 May 14, 2020
|
||||
|
||||
- **Important** `DispatchInfo` changed `paysFee` to an enum, if using an older version use, `DispatchInfo: 'DispatchInfoTo244'`
|
||||
|
||||
- Align imOnline `Heartbeat` with Substrate (Thanks to https://github.com/arjanz)
|
||||
- Adust EVM types to include `Vicinity` (Thanks to https://github.com/drewstone)
|
||||
- Add `derive.democracy.locks` to return extended lock info based on votes
|
||||
|
||||
- Ensure metadata is only requested once upon startup (bypass on upgrade subscriptions)
|
||||
- Expand testing around `ExtrinsicEra` construction
|
||||
- Expand `Registry` to direct access to available signed extensions (in addition to exposed types)
|
||||
@@ -145,6 +244,7 @@
|
||||
- Extends types for Polkadot claims
|
||||
- Update `@polkadot/util` to 2.10
|
||||
|
||||
|
||||
## 1.13.1 May 6, 2020
|
||||
|
||||
- Add support for ECDSA keypairs in extrinsic signers (Thanks to https://github.com/akru)
|
||||
@@ -152,38 +252,46 @@
|
||||
- Adjust extrinsic `sign/signAsync` signature to optional options (Thanks to https://github.com/KiChjang)
|
||||
- Support round-robin endpoints in the `WsProvider` with array of urls (Thanks to https://github.com/hoani)
|
||||
- Remove static test-only metadata for Polkadot dev chains (not updated regularly, Substrate dev to remain)
|
||||
|
||||
- Revert error swallow for wrong preimage data (temp. override for Kusama upgrade with no migration)
|
||||
- Fix `.encodedLength` calculation on `[Type; N]` types
|
||||
- Add new `rpc.grandpa.roundState` RPC
|
||||
- Update types & metadata as per latest Substrate master
|
||||
- Adjust Centrifuge starting version
|
||||
|
||||
|
||||
## 1.12.2 Apr 30, 2020
|
||||
|
||||
- Update `@polkadot/util` to stable 2.9.1 (sadly missed in the previous version, stable should match to stable)
|
||||
|
||||
|
||||
## 1.12.1 Apr 29, 2020
|
||||
|
||||
- Fix `CompactAssignments` types (Thanks to https://github.com/arjanz)
|
||||
- Provider ayo-connect now allows for interval config (Thanks to https://github.com/jnaviask)
|
||||
- Cleanup generation for c-like enums (Thanks to https://github.com/monitz87)
|
||||
- Allow subscription to all storage keys, alignment with Substrate (Thanks to https://github.com/xlc)
|
||||
|
||||
- Cater for vote delegations in democracy derives
|
||||
- Cleanup account derive flags where to allow for optional council modules
|
||||
- Allow generic types in ApiPromise.combineLatest
|
||||
- Update to latest substrate metadata
|
||||
|
||||
|
||||
## 1.11.2 Apr 22, 2020
|
||||
|
||||
- Small patch to add missing Polkadot master types (will be in next Kusama update)
|
||||
|
||||
|
||||
## 1.11.1 Apr 21, 2020
|
||||
|
||||
- **Important** Substrate master has an updated `Weight` (to `u64`), on older chains apply `Weight: 'u32'` (This does affect event decoding if wrongly set)
|
||||
|
||||
- Allow user type augmentation to work with different versions of rxjs (Thanks to https://github.com/monitz87)
|
||||
- Align augmented generation with camelCase (Thanks to https://github.com/monitz87)
|
||||
- Fix bitfield endian encoding (Thanks to investigation by https://github.com/xlc)
|
||||
- Add account flag derives via `accounts.flags(accountId)` (Thanks to https://github.com/kwingram25)
|
||||
|
||||
- Fix entries decoding for `Option<Number>` (& simplify, decoding correctly on rpc layer)
|
||||
- Add `system.{localPeerId, localListenAddresses}` & `state.getReadProof` RPCs
|
||||
- Ensure proper propagation of `api.runtimeVersion` (used for signing) after upgrade
|
||||
@@ -196,9 +304,11 @@
|
||||
- Enhance API support for non-subscription providers (skip subscription to runtimeVersion)
|
||||
- Adjust types for Kusama 1057 (notably the new `StakingLedger`)
|
||||
|
||||
|
||||
## 1.10.1 Apr 13, 2020
|
||||
|
||||
- **Important** Substrate master has updated staking, on older chains apply `StakingLedger: 'StakingLedgerTo240'`
|
||||
|
||||
- Add `rpc.system.chainType` to retrieve the chain type (Development. Local, Live & Custom)
|
||||
- Adjust types for Westend after the reset
|
||||
- Adjust democracy derives, including the support of the frame-scheduler for scheduled deployments
|
||||
@@ -209,10 +319,12 @@
|
||||
- Internally all private/protected methods/variables are now `_` prefixed (Aligning with the `private/protected` indicators in the TS definitions)
|
||||
- Update metadata/docs-from-metadata to the latest Substrate
|
||||
|
||||
|
||||
## 1.9.1 Apr 1, 2020
|
||||
|
||||
- **Breaking change** (TypeScript with derives only) The return type names for `api.derive.*` have been adjusted for consistency, all starting with `Derive*` (previously a mixture of `Derived*` and `Derive*`)
|
||||
- **Breaking change** (derives only) Additional cleanups of democracy proposal & referenda derives, including support for new Polkadot/Substrate vote retrievals
|
||||
|
||||
- Tx signing via `signAndSend` & `signAsync` now tries to use the last finalized block (depending on finalized drift)
|
||||
- Add support for `api.rpc.childstate.*` Substrate RPCs, older nodes with still populate `api.rpc.state.*` with the child methods
|
||||
- Adjust `Error.message` on RPC failures to not include the (already known) method signature
|
||||
@@ -224,11 +336,13 @@
|
||||
- Fix encoding for `Vec<u8>`-related types as part of constants
|
||||
- Internal adjustment of interface type locations (no impact on imports via `@polkadot/types/interfaces`)
|
||||
|
||||
|
||||
## 1.8.1 Mar 22, 2020
|
||||
|
||||
- **Breaking change** The format for any custom RPCs have been changed (alongside API-internal changes) to allow for better RPC management. If you are currently using custom RPCs (or planning to do so), look at the [updated documentation](https://polkadot.js.org/api/start/rpc.custom.html)
|
||||
- **Breaking change** Alongside API RPC changes, the `@polkadot/jsonrpc` package has been removed. Since it was never documented and only used internally, this should not have adverse impacts. All RPC definitions itself has now been moved to the relevant modules inside `@polkadot/types/interfaces`
|
||||
- **Important** Substrate has an updated democracy module. If using an older chain add the `ReferendumInfo: 'ReferendumInfoTo239'` type when using referendums
|
||||
|
||||
- The `isRetracted` Extrinsic status is now a warning, not a fatal error, correctly aligning with Polkadot/Substrate
|
||||
- The Substrate extrinsic phase definitions has been expanded with `Initialization` to align with the latest versions
|
||||
- Add support for all known substrate RPC methods
|
||||
@@ -236,9 +350,11 @@
|
||||
- Adjusted referendum derives to cater for bot new/old democracy. Derived `referendumInfo` now includes `status` field, not `info`
|
||||
- Add `initWasm` flag to API options. When set to `false` does not init the WASM portion (leaving it to the user elsewhere)
|
||||
|
||||
|
||||
## 1.7.1 Mar 17, 2020
|
||||
|
||||
- **Important** Current versions of Polkadot/Substrate have dropped support for linked maps on storage entries. If you are using these queries to retrieve all entries, for instance `staking.{nominators,validators}()` and using an upgraded chain, you need to swap to retrieving entries via `.entries()` or `.keys()` for the keys.
|
||||
|
||||
- Pull in support and types for latest Polkadot/Substrate
|
||||
- Add support for the new Substrate `state_getKeysPaged` RPC, including use in storage keys
|
||||
- Move `derive.staking.controllers` to `derive.staking.stashes`, reflecting actual content
|
||||
@@ -246,13 +362,16 @@
|
||||
- Expanded `derive.staking.*` derives, including addition of `derive.staking.own*`
|
||||
- Re-add fixed (with tests) checks for query args, previously disabled in 1.6.2
|
||||
|
||||
|
||||
## 1.6.2 Mar 12, 2020
|
||||
|
||||
- Revert checks for query args, not working on `.at()` queries (proper fix in next version)
|
||||
|
||||
|
||||
## 1.6.1 Mar 12, 2020
|
||||
|
||||
- **Breaking change** `api.rpc.state.queryStorage(...)` now fully decodes the `Vec<StorageChangeSet>` and returns a decoded `[Hash, Codec[]][]` when using this RPC.
|
||||
|
||||
- `StorageKey` now has an `.args` property, decoded from meta where `twox64_concat` or `blake128_concat` are used on maps
|
||||
- Fix `api.query.*.*.entries` type conversions to return exact types (not `Option` in some cases)
|
||||
- Add `api.query.*.*.keys` to retrieve only the storage keys, similar to `.entries`
|
||||
@@ -264,13 +383,16 @@
|
||||
- Add runtime validation for map arguments to `api.query.*`
|
||||
- TypeScript interfaces for linked maps now correctly generates as `[Type, Linkage<Next>]`
|
||||
|
||||
|
||||
## 1.5.1 Mar 06, 2020
|
||||
|
||||
- **Important** Substrate master has updated staking, on older chains supply `StakingLedger: 'StakingLedgerTo223'`
|
||||
- **Important** Substrate master has updated collective, on older chains supply `Votes: 'VotesTo230'`
|
||||
|
||||
- Add proper support for type generation with an Enum containing an Tuple (Thanks to https://github.com/monitz87)
|
||||
- Fix storage parsing not resulting in rejected Promises (Fix from https://github.com/aniiantt applied)
|
||||
- Remove use of deprecated `Observable.create` (Thanks to https://github.com/Himself65)
|
||||
|
||||
- Add types & metadata for the latest Polkadot/Substrate runtime versions (master branches)
|
||||
- Type extraction will now allow the same sub-module name across packages, i.e. `@polkadot/types/interfaces/runtime` & `@mine/interfaces/runtime` will be valid
|
||||
- Add `.range([from, to]: [Hash, Hash?], ...args: any[]): [Hash, Codec][]` on all storage entries
|
||||
@@ -284,17 +406,21 @@
|
||||
- Add additional derives to `api.derive.staking` to handle lazy-payout retrievals
|
||||
- Update `@polkadot/{util, util-crypto, keyring}` to 1.6.1 & `@polkadot/wasm` to 1.2.1
|
||||
|
||||
|
||||
## 1.4.2 Feb 27, 2020
|
||||
|
||||
- Fix `api.tx(<extrinsic>): Submittable` decoration (non-working in 1.4.1, now with proper test)
|
||||
|
||||
|
||||
## 1.4.1 Feb 26, 2020
|
||||
|
||||
- **Breaking change** (TypeScript only) The `*.d.ts` files now contain TypeScript 3.8 features (specifically `#private`), which is not usable in TS versions < 3.8
|
||||
- **Breaking change** - `api.derive.staking.*` has updated result types and detects support for lazy payouts queries
|
||||
|
||||
- Rework type generation for `api.{query, tx}` to properly handle complex type inputs (Thanks to https://github.com/monitz87)
|
||||
- Rework metadata `--strict` mode to effectively decorate chain metadata (Thanks to https://github.com/monitz87)
|
||||
- Add `api.rpc.chain.subscribeAllHeads` (not just best) (Thanks to https://github.com/jak-pan)
|
||||
|
||||
- Add `api.rpc.engine.*` for manual seal support
|
||||
- Add `api.injectMetadata(metadata)` to initialize API with a specific metadata version
|
||||
- The api now checks for runtime upgrades, augmenting the interfaces with new metadata when found
|
||||
@@ -314,18 +440,23 @@
|
||||
- Cleanup augmentation and generation scripts for type definitions, aligning with api augmentation
|
||||
- Bump to `@polkadot/{util, util-crypto, keyring}` 2.5.1
|
||||
|
||||
|
||||
## 1.3.1 Feb 18, 2020
|
||||
|
||||
- Add `@types/bn.js` as a normal dependency, exposed in `*.d.ts` (Thanks to https://github.com/monitz87)
|
||||
|
||||
- Type generation scripts (including `polkadot-types-from-{chain,defs}`) has been moved to the `@polkadot/typegen` package
|
||||
- The `@polkadot/types/codec/create` has been moved to `@polkadot/types/create`, imports from `@polkadot/types` are unaffected
|
||||
- Expose chain properties on registry (and use for API type formatting)
|
||||
- Add `toHuman(isExtended?: boolean)` to all codec types, formatting into a human-readable structure
|
||||
|
||||
|
||||
## 1.2.1 Feb 16, 2020
|
||||
|
||||
- **Important** Update RPC status codes (latest Substrate 2), with the `isInBlock` (`isFinalized` now indicates finality)
|
||||
|
||||
- Storage `.entries(arg?: any)` now has the correct argument type for DoubleMap (Thanks to https://github.com/monitz87)
|
||||
|
||||
- Swap Kusama and Polkadot aliases for `Address` to `AccountId` (future update)
|
||||
- Add `LookupSource` and `LookupTarget` types instead of mapping these directly for aliasing
|
||||
- Add `BitVec` type primitive
|
||||
@@ -340,9 +471,11 @@
|
||||
- Cleanup `codec/Date` tests to make it run properly on all timezones
|
||||
- Add explicit dependencies to all packages and move TypeScript `@types/*` to dev deps
|
||||
|
||||
|
||||
## 1.1.1 Feb 06, 2020
|
||||
|
||||
- **Important** Chains without `balances.account` or `system.account` should supply `"BalanceLock": "BalanceLockTo212"` to their types to use the previous-generation `BalanceLock` (when querying locks)
|
||||
|
||||
- Add support for `balances.account` in all applicable derives (incl. `vesting` module)
|
||||
- Inject and use SignedExtensions by name from V11 metadata (V4 extrinsics only)
|
||||
- Add typings for `api.tx.*.*` - the `polkadot-types-from-chain` now also generates these
|
||||
@@ -354,11 +487,14 @@
|
||||
- Adjust balances fees derivation with optional transfer and creation fees (removed in Substrate)
|
||||
- Adjust enum `.toJSON()` to return type name as specified
|
||||
|
||||
|
||||
## 1.0.1 Jan 30, 2020
|
||||
|
||||
- **Breaking change** Drop support for Substrate v1 chain in all derives
|
||||
|
||||
- Return unsub functions from provider .on emitters (Thanks to https://github.com/jak-pan)
|
||||
- `ApiPromise.isReady` now rejects on unrecoverable errors (Thanks to https://github.com/laec)
|
||||
|
||||
- Add `polkadot-types-from-chain` & `polkadot-types-from-defs` TypeScript generators to `@polkadot/types`
|
||||
- Only decorate derives where relevant parent `api.query.*` is available
|
||||
- Support `.entries(arg?: any)` lookups on DoubleMaps (in addition to previously supported maps)
|
||||
@@ -373,9 +509,11 @@
|
||||
- Remove support for un-deployed metadata
|
||||
- Remove old known types for Substrate V1
|
||||
|
||||
|
||||
## 0.100.1 Jan 13, 2020
|
||||
|
||||
- **Important** This will the the last API version with Substrate 1.x support. Although you will still be able to use subsequent versions with older chains, dependent libraries such as sr25519 may not be compatible.
|
||||
|
||||
- Add support for the Substrate identity module
|
||||
- Remove the `codec/Data` type, to remove a conflict with Substrate. This type is now named `Raw`
|
||||
- Fix for linked maps using `Option`
|
||||
@@ -384,36 +522,43 @@
|
||||
- Add support for latest Polkadot/Substrate types
|
||||
- Add `paymentInfo` to submittables to calculate fees
|
||||
|
||||
|
||||
## 0.99.1 Dec 13, 2019
|
||||
|
||||
- **Breaking change** The `Data` and `U8a` type has been renamed and just replaced with the `Raw` type
|
||||
- **Breaking change** The `api.derive.staking.info` has been split into 2 - `staking.query` for non-balance related information (more effective) and `staking.account` that enhances query for all the information previously found `.info`
|
||||
|
||||
- Cleanup `DoubleMap` hashing to always hash over the full value (in the case of `Vec<T>`, this includes the length)
|
||||
- Update democracy derives to take care of nextTally and lowestUnbaked
|
||||
- Add additional derives for both council & treasury
|
||||
- Alignment with latest Polkadot/Substrate master branch types
|
||||
|
||||
|
||||
## 0.98.1 Dec 04, 2019
|
||||
|
||||
- Make the TypeScript generation script mor re-usable (Thanks to https://github.com/xlc)
|
||||
- Add `.entries()` for all map-types, returning storage keys and values
|
||||
- Add `.signAsync` to submittable extrinsics (Thanks to https://github.com/c410-f3r)
|
||||
|
||||
- Cleanup circular references between internal dependencies
|
||||
- Support for new Substrate democracy with preimages in derive
|
||||
- Alignment of types with Substrate/Polkadot master branches
|
||||
|
||||
|
||||
## 0.97.1 Nov 29, 2019
|
||||
|
||||
- **Breaking change** Add the passing on an explicit `Registry` to all calls to `createType` as well as all codec classes. If you are upgrading form an older version, use the [migration guide](UPGRADING.md) to walk through the changes required.
|
||||
- **Breaking change** The metadata classes have been moved from `@polkadot/types` into `@polkadot/metadata`. If you explicitly create `Metadata` classes, you now would need to do so with the `import Metadata from '@polkadot/metadata';` This is a decorated class, where the previous metadata is now available on `Metadata.metadata`, alongside decorated `consts.*`', `tx.*` and `query.*`.
|
||||
- **Breaking change** Session `Keys` defaults to 4 keys now (Substrate master), depending on your node config, you would want to override with e.g. `Keys: 'SessionKeys3'` (1, 2, 3, 4, 5 & 6)
|
||||
- **Breaking change** `ValidatorPrefs` now default to the new percentage commission model, to use the previous `validatorPayment`, you can override with `ValidatorPrefs: 'ValidatorPrefsTo196'`
|
||||
|
||||
- `api.derive.*` now has built-in memomization
|
||||
- Various fixes and cleanups to `api.derive.*` including era length progress and vesting calculations
|
||||
- Aligned all types with the latest Polkadot & Substrate, including Kusama CC3
|
||||
- Support for Metadata V9, which adjusts the hashing methods of storage entries
|
||||
- Support for Metadata V10 (still un-released), which includes prefixed map support
|
||||
|
||||
|
||||
## 0.96.1 Nov 09, 2019
|
||||
|
||||
- Updated types for latest Kusama
|
||||
@@ -424,10 +569,12 @@
|
||||
- Update council derives for the latest Substrate master support (with constants)
|
||||
- Derive cleanups, including sharing of instances between the API and internal to derives
|
||||
|
||||
|
||||
## 0.95.2 Oct 25, 2019
|
||||
|
||||
- Temporary removal of `account_nextIndex` use, will be re-added in a future release
|
||||
|
||||
|
||||
## 0.95.1 Oct 25, 2019
|
||||
|
||||
- Support Extrinsic V4 with additional signature indicator (Latest Polkadot/Substrate/Kusama)
|
||||
@@ -438,6 +585,7 @@
|
||||
- All latest Polkadot & Substrate types (as per master branches)
|
||||
- **Breaking change** `Call.injectMethods` is moved to `Call.injectMetadata` to align with `Events` (This _should_ not be used externally, however mentioned as breaking here)
|
||||
|
||||
|
||||
## 0.94.1 Oct 07, 2019
|
||||
|
||||
- Add handling of `Result<Ok, Error>` definitions
|
||||
@@ -450,6 +598,7 @@
|
||||
- Add documentation for custom extrinsic formats (advanced chains)
|
||||
- Update to latest substrate master metadata
|
||||
|
||||
|
||||
## 0.93.1 Sep 26, 2019
|
||||
|
||||
- Support for Kusama CC2
|
||||
@@ -460,6 +609,7 @@
|
||||
- Support recursive type registration (self-referencing via `Box`) in addition to better sanitation of user-defined-types
|
||||
- Documentation and example updates (thanks mostly to contributions)
|
||||
|
||||
|
||||
## 0.92.1 Sep 12, 2019
|
||||
|
||||
- The API now correctly sets the ss58 prefix as retrieved from the chain properties via `ss58Format`
|
||||
@@ -468,6 +618,7 @@
|
||||
- Support the latest Polkadot & Substrate master branches (incl. metadata updates)
|
||||
- Getting started documentation has been made available
|
||||
|
||||
|
||||
## 0.91.1 Sep 09, 2019
|
||||
|
||||
- This release was focussed on stability, with a number of cleanups and bug-fixes
|
||||
@@ -482,6 +633,7 @@
|
||||
- **Breaking change** `SignerPayload` is renamed to `SignerPayloadJSON`
|
||||
- **Breaking change** `SignerPayloadJSON`, `SignerPayloadRawBase` and `SignerPayloadRaw` are all moved to `@polkadot/types`
|
||||
|
||||
|
||||
## 0.90.1 Aug 24, 2019
|
||||
|
||||
If you are upgrading form an older version, use the CHANGELOG hand-in-hand with the [migration guide](UPGRADING.md).
|
||||
@@ -495,6 +647,7 @@ If you are upgrading form an older version, use the CHANGELOG hand-in-hand with
|
||||
- For creation of types, it is recommended to use `createType(<TypeName>, <value>)` instead of e.g. `new Proposal(...)`. When passing these to methods/queries, construction should not be needed, the raw value can be passed.
|
||||
- For moved types, a previous import would have been from `@polkadot/types`, i.e. `import { SetIndex } from '@polkadot/types`, now just the interfaces (TypeScript) are available via `import { SetIndex } from '@polkadot/types/interfaces`
|
||||
- `usize` is now a blacklisted type that will throw on construction. Since it is platform-specific, it creates incompatibilities between native (generally `u64`) and WASM (always `u32`) code. Use one of the `u32` or `u64` types explicitly.
|
||||
|
||||
- Support substrate v7 metadata
|
||||
- The `Method.findFunction(callIndex)` (allowing decoding of raw data), is now available on `api.findCall(callIndex)`. To keep backwards compatibility, it is still available on `GenericCall.findMethod` but the `api.findCall` is recommended and suggested.
|
||||
- The `types/codec/createType` has been moved to `types/codec/create` with the same exports. If you explicitly imported from here (and not doing the suggested `import { createType } from '@polkadot/types`), the reference needs to be updated
|
||||
@@ -596,7 +749,6 @@ If you are upgrading form an older version, use the CHANGELOG hand-in-hand with
|
||||
- Change spelling to US English as per substrate master (1.0-rc1). Breaking changes as a result:
|
||||
- For extrinsic status results, if you have checked the type returns, i.e. `result.type === 'Finalised'` now check on the status for `result.status.isFinalized` or `result.status.isBroadcast`, ... (the `type` property is now accessible only on `result.status.type`)
|
||||
- If using `subscribeFinalisedHeads` update this to `subscribeFinalizedHeads` (likewise `getFinalisedHead` should be updated to `getFinalizedHead` and `derive.bestNumberFinalized`)
|
||||
|
||||
- The underlying ss58 address checksums have changed
|
||||
- The updated keyring with support for this has been made available
|
||||
- All examples have been updated with sr25519 addresses (with the new checksums)
|
||||
|
||||
Executable
+23
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
function copy_folder () {
|
||||
SRC="packages/$1/build"
|
||||
DST="../test/js-test/node_modules/@polkadot/$1"
|
||||
|
||||
echo "** Copying $SRC to $DST"
|
||||
|
||||
rm -rf $DST
|
||||
cp -r $SRC $DST
|
||||
}
|
||||
|
||||
yarn polkadot-dev-build-ts
|
||||
|
||||
copy_folder "api"
|
||||
copy_folder "api-contract"
|
||||
copy_folder "api-derive"
|
||||
copy_folder "metadata"
|
||||
copy_folder "rpc-core"
|
||||
copy_folder "rpc-provider"
|
||||
copy_folder "types"
|
||||
copy_folder "types-known"
|
||||
copy_folder "typegen"
|
||||
@@ -42,3 +42,20 @@ const header = await api.derive.chain.getHeader();
|
||||
|
||||
console.log(`#${header.number}: ${header.author}`);
|
||||
```
|
||||
|
||||
## How do I view block extrinsic information?
|
||||
|
||||
The transactions are included in a signed block as part of the extrinsics - some of these will be unsigned and generated by the block author and some of these may be submitted from external sources and be signed. (Some palettes do use unsigned transactions, so signed/unsigned is not an indication of origin). To retrieve the block and display the transaction information, we can do the following -
|
||||
|
||||
```js
|
||||
// no blockHash is specified, so we retrieve the latest
|
||||
const signedBlock = await this.api.rpc.chain.getBlock();
|
||||
|
||||
// the information for each of the contained extrinsics
|
||||
signedBlock.block.extrinsics.forEach((ex, index) => {
|
||||
// the extrinsics are decoded by the API
|
||||
console.log(index, ex.toHuman());
|
||||
});
|
||||
```
|
||||
|
||||
In the above `.toHuman()` is used to format into a human-readable representation. You can inspect/extract specific fields from the decoded extrinsic as required, for instance `ex.method.section` would return the pallete that executed this transaction.
|
||||
|
||||
+3
-3
@@ -16,9 +16,9 @@ const info = await api.tx.balances
|
||||
|
||||
// log relevant info, partialFee is Balance, estimated for current
|
||||
console.log(`
|
||||
class=${class.toString()},
|
||||
weight=${weight.toString()},
|
||||
partialFee=${partialFee.toHuman()}
|
||||
class=${info.class.toString()},
|
||||
weight=${info.weight.toString()},
|
||||
partialFee=${info.partialFee.toHuman()}
|
||||
`);
|
||||
```
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ Looking at the example in this repo, it also has `augment*`, `index.ts` and `typ
|
||||
|
||||
## Generating
|
||||
|
||||
Now that both the metadata nd types setup is completed, we just run the build command via `yarn build` and magically (assuming you didn't have the `augment*` and other generated files), these files will be added. When running this command, the console should display something like -
|
||||
Now that both the metadata and types setup is completed, we just run the build command via `yarn build` and magically (assuming you didn't have the `augment*` and other generated files), these files will be added. When running this command, the console should display something like -
|
||||
|
||||
```
|
||||
> yarn build
|
||||
@@ -166,7 +166,7 @@ As mentioned earlier, here you will notice the `import { VoteStage }`, the gener
|
||||
|
||||
## TypeScript config
|
||||
|
||||
Now that we have files generated, it is time to make TypeScript aware of the types and add an explicit override into out `tsconfig.json`. After some changes, the paths in the config looks as follow (comments are in teh actual config file here) -
|
||||
Now that we have files generated, it is time to make TypeScript aware of the types and add an explicit override into out `tsconfig.json`. After some changes, the paths in the config looks as follow (comments are in the actual config file here) -
|
||||
|
||||
```json
|
||||
{
|
||||
|
||||
@@ -22,7 +22,6 @@ To fix this, you should look at the specific `api.tx.*` params and adjust the ty
|
||||
|
||||
If you are using a node-template based version of substrate and you changed the specName you need to add these typings(In addition to other custom types) `{"Address": "AccountId","LookupSource": "AccountId"}`. This is also the case when you use [polkadot-js/apps](https://github.com/polkadot-js/apps) to connect to your node. When the specName stays node-template the API is smart enough to add the custom typings.
|
||||
|
||||
|
||||
## I would like to sign transactions offline
|
||||
|
||||
The API itself is independent on where the signature comes from and how it is injected. Additionally it implements a signer interface, that can be used for external signing - an example of this is the [polkadot-js/apps](https://github.com/polkadot-js/apps) support for signing via extensions and even the [polkadot-js/extension](https://github.com/polkadot-js/extension) support for tools such as the [Parity Signer](https://github.com/paritytech/parity-signer).
|
||||
@@ -66,16 +65,3 @@ Due to these customizations and differences that bleed through to the transactio
|
||||
Recently Substrate master updated the `Weight` type from `u32` -> `u64`. This type is used in the `DispatchInfo` struct in the `system.ExtrinsicSuccess` events, to return the applied call weights as well as the resulting fees. Since the API master branch tracks Substrate master, this means the change has been applied by default, with the default set to `u64`.
|
||||
|
||||
If you are on a chain that has not been upgraded yet, you need to add `Weight: 'u32'` to your types to allow for successful parsing of all events. Without this override, parsing will fail. As soon as one event in the `Vec<EventRecord>` structure from `system.events` fails to parse, all subsequent events are affected and the decoding will return an error.
|
||||
|
||||
## When querying older blocks & events, it fails on parsing
|
||||
|
||||
Upon initialization, the API is decorated with the [current on-chain metadata](basics.md#metadata) and (if [available](https://github.com/polkadot-js/api/tree/master/packages/types-known/src)) the specific types for the runtime version is added. This allows the API to decode all current (as per the on-chain info) state and extrinsics.
|
||||
|
||||
When the chain is upgraded, new metadata (indicating new events, storage and extrinsics) is added on-chain. Additionally this generally goes hand in-hand with changes in types, i.e. fields may be addedd or removed or state that was used could now be migrated to new locations. In most cases, this would mean that the current chain information cannot be used to parse older entries pre-upgrade. A typical consequence of this is that any `.at(...)` or `.range(...)` queries pre-upgrade may fail.
|
||||
|
||||
As of the current time, there is no automatic injection of older metadata (based on the runtime version at a specific block) nor decoration of older types if they are available. It can be emulated with what the API will do to handle these cases when it adds a `.historic(...)` query type -
|
||||
|
||||
- querying the runtime version at the parent of older block you wish to retrieve
|
||||
- retrieving and injecting the metadata from the parent block (if the runtime version has changed)
|
||||
- inject any specific older types for the state at that point
|
||||
- finally retrieve the actual entry via an `.at(...)` query
|
||||
|
||||
@@ -42,7 +42,7 @@ Be aware that while defined, the method will only appear on the API if it is in
|
||||
|
||||
## Definition breakdown
|
||||
|
||||
While the above example should be self-explanatory, it is important to understand teh structure. The `rpc: { ... }` definitions are keyed first and foremost by the name of the module exposing the RPC. This means that when we have 2 modules `firstModule` & `testModule`, the first-level structure would follow the following pattern,
|
||||
While the above example should be self-explanatory, it is important to understand the structure. The `rpc: { ... }` definitions are keyed first and foremost by the name of the module exposing the RPC. This means that when we have 2 modules `firstModule` & `testModule`, the first-level structure would follow the following pattern,
|
||||
|
||||
```js
|
||||
...
|
||||
|
||||
@@ -20,7 +20,7 @@ With the conversions done in the API, there are limited reasons to create types
|
||||
import type { Balance } from '@polkadot/types/interfaces';
|
||||
|
||||
...
|
||||
// unwrap out option into a zero Balance whn not found
|
||||
// unwrap out option into a zero Balance when not found
|
||||
// (This can be done via `.unwrapOrDefault()`, which does the same underlying)
|
||||
const balance: Balance = balanceOpt.unwrapOr(api.createType('Balance'));
|
||||
```
|
||||
|
||||
@@ -6,7 +6,7 @@ Therefore to cater for all types, a mapping in done on the [@polkadot/types libr
|
||||
|
||||
Additionally, the API contains some logic for chain type detection, for instance in the case of Substrate 1.x based chains, it will define `BlockNumber` & `Index` (nonce) as a `u64`, while for current-generation chains, these will be defined as `u32`. Some of the work in maintaining the API for Polkadot/Substrate is the addition of types as they appear and gets used in the Rust codebase.
|
||||
|
||||
There is a the [recommendation](install.md#betas) to use a `@polkadot/api@beta` should you wish to track the master branches of Polkadot or Substrate, since master changes for the addition of new types do not make it into a stable release immediately.
|
||||
There is the [recommendation](install.md#betas) to use a `@polkadot/api@beta` should you wish to track the master branches of Polkadot or Substrate, since master changes for the addition of new types do not make it into a stable release immediately.
|
||||
|
||||
## Extension
|
||||
|
||||
@@ -87,7 +87,7 @@ Document: {
|
||||
|
||||
## User-defined enum
|
||||
|
||||
One form of types that appear regularly is enums, these can be defined as follow -
|
||||
One form of types that appear regularly is enums, these can be defined as follows -
|
||||
|
||||
```js
|
||||
...
|
||||
@@ -212,4 +212,4 @@ Always look at customization and understand the impacts, replicating these chang
|
||||
|
||||
## Custom RPC
|
||||
|
||||
In addition to customizing modules and types on your node, you can also add custom RPC definitions. Like the type definitions in ths section, [these can be defined and passed to the API](rpc.custom.md) for decoration.
|
||||
In addition to customizing your node's modules and types, you can also add custom RPC definitions. Like the type definitions in this section, [these can be defined and passed to the API](rpc.custom.md) for decoration.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# TypeScript user generated
|
||||
|
||||
In the previous section we looked at the TypeScript definitions that are available and is generated from both the chain and definitions. Here we will expand upon the use of the infrastructure created to define types as part of the `@polkadot/types` library and see how to use them to generate your own definitions and chain types.
|
||||
In the previous section we looked at the TypeScript definitions that are available and are generated from both the chain and definitions. Here we will expand upon the use of the infrastructure created to define types as part of the `@polkadot/types` library and see how to use them to generate your own definitions and chain types.
|
||||
|
||||
## Definitions
|
||||
|
||||
@@ -17,7 +17,7 @@ In the root of your project (with the `@polkadot/typegen` package installed), yo
|
||||
|
||||
## Chain modules
|
||||
|
||||
In the same way as the type library provides defaults from a substrate-base chain, you can also, directly from chain from metadata, generate a complete `api.{consts,query}.*` definition for your specific chain. The command will create 2 files, `{consts, query}.types.ts` which you can either use to augment the TypeScript definitions, or replace those in `@polkadot/api/*` with your versions (copy, TypeScript replacement or browser/node aliasing).
|
||||
In the same way as the type library provides defaults from a substrate-base chain, you can also, directly from the chain's metadata, generate a complete `api.{consts,query}.*` definition for your specific chain. The command will create 2 files, `{consts, query}.types.ts` which you can either use to augment the TypeScript definitions, or replace those in `@polkadot/api/*` with your versions (copy, TypeScript replacement or browser/node aliasing).
|
||||
|
||||
In the root of your project, you can run `yarn polkadot-types-from-chain --endpoint wss://<url> --output ./stuff` and it will create the required output. (Here you can specify an optional `--package @MeInc/stuff` to read definitions for the targeted output folder with the specified package name.)
|
||||
|
||||
@@ -27,4 +27,4 @@ The [TypeScript augmentation example](../examples/promise/90_typegen/) example p
|
||||
|
||||
## And that's a wrap
|
||||
|
||||
This brings us to the end of our overview and jump through the API. While the documentation is still very much and ever evolving item, we can encourage you to try out what you have learned with some [examples](../examples). As we [indicated right at the start of this journey](README.md#help-us-help-others), if there are areas for improvement, let us know.
|
||||
This brings us to the end of our overview and jump through the API. While the documentation is still very much an ever evolving item, we can encourage you to try out what you have learned with some [examples](../examples). As we [indicated right at the start of this journey](README.md#help-us-help-others), if there are areas for improvement, let us know.
|
||||
|
||||
+1
-1
@@ -9,5 +9,5 @@
|
||||
"packages": [
|
||||
"packages/*"
|
||||
],
|
||||
"version": "1.27.1"
|
||||
"version": "1.31.1"
|
||||
}
|
||||
|
||||
+11
-8
@@ -24,15 +24,18 @@
|
||||
"test:watch": "polkadot-dev-run-test --watch"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.11.0",
|
||||
"@babel/core": "^7.11.4",
|
||||
"@babel/register": "^7.10.5",
|
||||
"@babel/runtime": "^7.11.0",
|
||||
"@polkadot/dev": "^0.55.30",
|
||||
"@polkadot/ts": "^0.3.31",
|
||||
"@babel/runtime": "^7.11.2",
|
||||
"@polkadot/dev": "^0.55.43",
|
||||
"@polkadot/ts": "^0.3.40",
|
||||
"@polkadot/typegen": "workspace:packages/typegen",
|
||||
"@types/jest": "^26.0.8",
|
||||
"@vuepress/plugin-search": "^1.5.2",
|
||||
"copyfiles": "^2.3.0"
|
||||
"@types/jest": "^26.0.10",
|
||||
"@vuepress/plugin-search": "^1.5.4",
|
||||
"copyfiles": "^2.3.0",
|
||||
"typedoc": "^0.18.0",
|
||||
"typedoc-plugin-markdown": "^2.4.2",
|
||||
"typedoc-plugin-no-inherit": "^1.1.10"
|
||||
},
|
||||
"version": "1.27.1"
|
||||
"version": "1.31.1"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/api-contract",
|
||||
"version": "1.27.1",
|
||||
"version": "1.31.1",
|
||||
"description": "Interfaces for interacting with contracts and contract ABIs",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
@@ -26,12 +26,12 @@
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-contract#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.11.0",
|
||||
"@polkadot/api": "1.27.1",
|
||||
"@polkadot/rpc-core": "1.27.1",
|
||||
"@polkadot/types": "1.27.1",
|
||||
"@polkadot/util": "^3.0.1",
|
||||
"bn.js": "^5.1.2",
|
||||
"@babel/runtime": "^7.11.2",
|
||||
"@polkadot/api": "1.31.1",
|
||||
"@polkadot/rpc-core": "1.31.1",
|
||||
"@polkadot/types": "1.31.1",
|
||||
"@polkadot/util": "^3.4.1",
|
||||
"bn.js": "^5.1.3",
|
||||
"rxjs": "^6.6.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/api-derive",
|
||||
"version": "1.27.1",
|
||||
"version": "1.31.1",
|
||||
"description": "Common functions used across Polkadot, derived from RPC calls and storage queries.",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
@@ -27,18 +27,18 @@
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-derive#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.11.0",
|
||||
"@polkadot/api": "1.27.1",
|
||||
"@polkadot/rpc-core": "1.27.1",
|
||||
"@polkadot/rpc-provider": "1.27.1",
|
||||
"@polkadot/types": "1.27.1",
|
||||
"@polkadot/util": "^3.0.1",
|
||||
"@polkadot/util-crypto": "^3.0.1",
|
||||
"bn.js": "^5.1.2",
|
||||
"@babel/runtime": "^7.11.2",
|
||||
"@polkadot/api": "1.31.1",
|
||||
"@polkadot/rpc-core": "1.31.1",
|
||||
"@polkadot/rpc-provider": "1.31.1",
|
||||
"@polkadot/types": "1.31.1",
|
||||
"@polkadot/util": "^3.4.1",
|
||||
"@polkadot/util-crypto": "^3.4.1",
|
||||
"bn.js": "^5.1.3",
|
||||
"memoizee": "^0.4.14",
|
||||
"rxjs": "^6.6.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^3.0.1"
|
||||
"@polkadot/keyring": "^3.4.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ function retrieve (api: ApiInterfaceRx, address: Address | AccountId | AccountIn
|
||||
|
||||
const accountIndex = api.registry.createType('AccountIndex', decoded);
|
||||
|
||||
return api.derive.accounts.indexToId(accountIndex).pipe(
|
||||
return api.derive.accounts.indexToId(accountIndex.toString()).pipe(
|
||||
map((accountId): AccountIdAndIndex => [accountId, accountIndex])
|
||||
);
|
||||
} catch (error) {
|
||||
|
||||
@@ -17,6 +17,8 @@ import { memo } from '../util';
|
||||
type ResultBalance = [VestingInfo | null, (BalanceLock | BalanceLockTo212)[]];
|
||||
type Result = [DeriveBalancesAccount, BlockNumber, ResultBalance];
|
||||
|
||||
const VESTING_ID = '0x76657374696e6720';
|
||||
|
||||
function calcBalances (api: ApiInterfaceRx, [{ accountId, accountNonce, freeBalance, frozenFee, frozenMisc, reservedBalance, votingBalance }, bestNumber, [vesting, locks]]: Result): DeriveBalancesAll {
|
||||
let lockedBalance = api.registry.createType('Balance');
|
||||
let lockedBreakdown: (BalanceLock | BalanceLockTo212)[] = [];
|
||||
@@ -30,7 +32,7 @@ function calcBalances (api: ApiInterfaceRx, [{ accountId, accountNonce, freeBala
|
||||
const notAll = lockedBreakdown.filter(({ amount }) => !amount.isMax());
|
||||
|
||||
allLocked = lockedBreakdown.some(({ amount }) => amount.isMax());
|
||||
vestingLocked = api.registry.createType('Balance', lockedBreakdown.filter(({ id }) => id.eq('0x76657374696e6720')).reduce((result: BN, { amount }) => result.iadd(amount), new BN(0)));
|
||||
vestingLocked = api.registry.createType('Balance', lockedBreakdown.filter(({ id }) => id.eq(VESTING_ID)).reduce((result: BN, { amount }) => result.iadd(amount), new BN(0)));
|
||||
|
||||
// get the maximum of the locks according to https://github.com/paritytech/substrate/blob/master/srml/balances/src/lib.rs#L699
|
||||
if (notAll.length) {
|
||||
@@ -131,7 +133,7 @@ export function all (api: ApiInterfaceRx): (address: AccountIndex | AccountId |
|
||||
? combineLatest([
|
||||
of(account),
|
||||
api.derive.chain.bestNumber(),
|
||||
isFunction(api.query.balances.account)
|
||||
isFunction(api.query.system.account) || isFunction(api.query.balances.account)
|
||||
? queryCurrent(api, account.accountId)
|
||||
: queryOld(api, account.accountId)
|
||||
])
|
||||
|
||||
@@ -11,7 +11,7 @@ import { HeaderExtended } from '../type';
|
||||
import { memo } from '../util';
|
||||
|
||||
/**
|
||||
* @name bestNumberFinalized
|
||||
* @name getHeader
|
||||
* @param {( Uint8Array | string )} hash - A block hash as U8 array or string.
|
||||
* @returns An array containing the block header and the block author
|
||||
* @description Get a specific block header and extend it with the author
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { AccountId, ReferendumInfo, ReferendumInfoTo239, VotingDirect, VotingDirectVote } from '@polkadot/types/interfaces';
|
||||
import { AccountId, ReferendumInfo, ReferendumInfoTo239, VotingDelegating, VotingDirect, VotingDirectVote } from '@polkadot/types/interfaces';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { DeriveDemocracyLock } from '../types';
|
||||
|
||||
@@ -20,16 +20,37 @@ const ZERO = new BN(0);
|
||||
function parseLock (api: ApiInterfaceRx, [referendumId, accountVote]: VotingDirectVote, referendum: ReferendumInfo): DeriveDemocracyLock {
|
||||
const { balance, vote } = accountVote.asStandard;
|
||||
let unlockAt = ZERO;
|
||||
let referendumEnd = ZERO;
|
||||
|
||||
if (referendum.isFinished) {
|
||||
const { approved, end } = referendum.asFinished;
|
||||
|
||||
referendumEnd = end;
|
||||
|
||||
if ((approved.isTrue && vote.isAye) || (approved.isFalse && vote.isNay)) {
|
||||
unlockAt = end.add(api.consts.democracy.enactmentPeriod.muln(LOCKUPS[vote.conviction.index]));
|
||||
}
|
||||
}
|
||||
|
||||
return { balance, isFinished: referendum.isFinished, referendumId, unlockAt, vote };
|
||||
return { balance, isDelegated: false, isFinished: referendum.isFinished, referendumEnd, referendumId, unlockAt, vote };
|
||||
}
|
||||
|
||||
function delegateLocks (api: ApiInterfaceRx, { balance, conviction, target }: VotingDelegating): Observable<DeriveDemocracyLock[]> {
|
||||
return api.derive.democracy.locks(target).pipe(
|
||||
map((available): DeriveDemocracyLock[] =>
|
||||
available.map(({ isFinished, referendumEnd, referendumId, unlockAt, vote }): DeriveDemocracyLock => ({
|
||||
balance,
|
||||
isDelegated: true,
|
||||
isFinished,
|
||||
referendumEnd,
|
||||
referendumId,
|
||||
unlockAt: unlockAt.isZero()
|
||||
? unlockAt
|
||||
: referendumEnd.add(api.consts.democracy.enactmentPeriod.muln(LOCKUPS[conviction.index])),
|
||||
vote: api.registry.createType('Vote', { aye: vote.isAye, conviction })
|
||||
}))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function directLocks (api: ApiInterfaceRx, { votes }: VotingDirect): Observable<DeriveDemocracyLock[]> {
|
||||
@@ -59,7 +80,9 @@ export function locks (api: ApiInterfaceRx): (accountId: string | AccountId) =>
|
||||
switchMap((voting): Observable<DeriveDemocracyLock[]> =>
|
||||
voting.isDirect
|
||||
? directLocks(api, voting.asDirect)
|
||||
: of([])
|
||||
: voting.isDelegating
|
||||
? delegateLocks(api, voting.asDelegating)
|
||||
: of([])
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
@@ -9,7 +9,9 @@ import { Vec } from '@polkadot/types';
|
||||
|
||||
export interface DeriveDemocracyLock {
|
||||
balance: Balance;
|
||||
isDelegated: boolean;
|
||||
isFinished: boolean;
|
||||
referendumEnd: BN;
|
||||
referendumId: ReferendumIndex;
|
||||
unlockAt: BN;
|
||||
vote: Vote;
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
|
||||
import { AccountId, Balance, BlockNumber } from '@polkadot/types/interfaces';
|
||||
import { ITuple } from '@polkadot/types/types';
|
||||
import { DeriveElectionsInfo } from './types';
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { Vec, u32 } from '@polkadot/types';
|
||||
|
||||
import { DeriveElectionsInfo } from '../types';
|
||||
import { memo } from '../util';
|
||||
|
||||
function sortAccounts ([, balanceA]: ITuple<[AccountId, Balance]>, [, balanceB]: ITuple<[AccountId, Balance]>): number {
|
||||
@@ -30,6 +30,7 @@ function queryElections (api: ApiInterfaceRx): Observable<DeriveElectionsInfo> {
|
||||
candidacyBond: api.consts[section].candidacyBond as Balance,
|
||||
candidateCount: api.registry.createType('u32', candidates.length),
|
||||
candidates,
|
||||
desiredRunnersUp: api.consts[section].desiredRunnersUp as u32,
|
||||
desiredSeats: api.consts[section].desiredMembers as u32,
|
||||
members: members.length
|
||||
? members.sort(sortAccounts)
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { AccountId, Balance, BlockNumber, SetIndex, VoteIndex } from '@polkadot/types/interfaces';
|
||||
|
||||
import { u32 } from '@polkadot/types';
|
||||
|
||||
export interface DeriveElectionsInfo {
|
||||
candidates: AccountId[];
|
||||
candidateCount: u32;
|
||||
candidacyBond?: Balance;
|
||||
desiredRunnersUp: u32;
|
||||
desiredSeats: u32;
|
||||
members: [AccountId, Balance][];
|
||||
nextVoterSet?: SetIndex;
|
||||
runnersUp: [AccountId, Balance][];
|
||||
termDuration: BlockNumber;
|
||||
voteCount?: VoteIndex;
|
||||
voterCount?: SetIndex;
|
||||
votingBond?: Balance;
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import { Observable, of, combineLatest } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { Bytes, Option, u32 } from '@polkadot/types';
|
||||
import { BN_ZERO } from '@polkadot/util';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
@@ -34,7 +35,7 @@ export function receivedHeartbeats (api: ApiInterfaceRx): () => Observable<Deriv
|
||||
[validator.toString()]: {
|
||||
blockCount: numBlocks[index],
|
||||
hasMessage: !heartbeats[index].isEmpty,
|
||||
isOnline: !heartbeats[index].isEmpty || numBlocks[index].gtn(0)
|
||||
isOnline: !heartbeats[index].isEmpty || numBlocks[index].gt(BN_ZERO)
|
||||
}
|
||||
}), {})
|
||||
)
|
||||
|
||||
@@ -9,43 +9,29 @@ import { DeriveSessionInfo, DeriveStakingAccount, DeriveStakingQuery, DeriveUnlo
|
||||
import BN from 'bn.js';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
|
||||
import { isUndefined } from '@polkadot/util';
|
||||
import { BN_ZERO } from '@polkadot/util';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
// groups the supplied chunks by era, i.e. { [era]: BN(total of values) }
|
||||
function groupByEra (list: UnlockChunk[]): Record<string, BN> {
|
||||
return list.reduce((map: Record<string, BN>, { era, value }): Record<string, BN> => {
|
||||
const key = era.toString();
|
||||
|
||||
map[key] = !map[key]
|
||||
? value.unwrap()
|
||||
: map[key].iadd(value.unwrap());
|
||||
map[key] = (map[key] || BN_ZERO).add(value.unwrap());
|
||||
|
||||
return map;
|
||||
}, {});
|
||||
}
|
||||
|
||||
function calculateUnlocking (api: ApiInterfaceRx, stakingLedger: StakingLedger | undefined, sessionInfo: DeriveSessionInfo): DeriveUnlocking[] | undefined {
|
||||
if (isUndefined(stakingLedger)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const unlockingChunks = stakingLedger.unlocking.filter(({ era }) =>
|
||||
era.unwrap().gt(sessionInfo.activeEra)
|
||||
);
|
||||
|
||||
if (!unlockingChunks.length) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// group the unlock chunks that have the same era and sum their values
|
||||
const groupedResult = groupByEra(unlockingChunks);
|
||||
const results = Object.entries(groupedResult).map(([eraString, value]): DeriveUnlocking => ({
|
||||
remainingEras: new BN(eraString).isub(sessionInfo.activeEra),
|
||||
value: api.registry.createType('Balance', value)
|
||||
}));
|
||||
const results = Object
|
||||
.entries(groupByEra(
|
||||
(stakingLedger?.unlocking || []).filter(({ era }) => era.unwrap().gt(sessionInfo.activeEra))
|
||||
))
|
||||
.map(([eraString, value]): DeriveUnlocking => ({
|
||||
remainingEras: new BN(eraString).isub(sessionInfo.activeEra),
|
||||
value: api.registry.createType('Balance', value)
|
||||
}));
|
||||
|
||||
return results.length
|
||||
? results
|
||||
@@ -53,11 +39,7 @@ function calculateUnlocking (api: ApiInterfaceRx, stakingLedger: StakingLedger |
|
||||
}
|
||||
|
||||
function redeemableSum (api: ApiInterfaceRx, stakingLedger: StakingLedger | undefined, sessionInfo: DeriveSessionInfo): Balance {
|
||||
if (isUndefined(stakingLedger)) {
|
||||
return api.registry.createType('Balance');
|
||||
}
|
||||
|
||||
return api.registry.createType('Balance', stakingLedger.unlocking.reduce((total, { era, value }): BN => {
|
||||
return api.registry.createType('Balance', (stakingLedger?.unlocking || [] as UnlockChunk[]).reduce((total, { era, value }): BN => {
|
||||
return sessionInfo.activeEra.gte(era.unwrap())
|
||||
? total.iadd(value.unwrap())
|
||||
: total;
|
||||
|
||||
@@ -8,6 +8,7 @@ import { DeriveEraPoints, DeriveEraValPoints } from '../types';
|
||||
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { BN_ZERO } from '@polkadot/util';
|
||||
|
||||
import { deriveCache, memo } from '../util';
|
||||
|
||||
@@ -15,7 +16,7 @@ const CACHE_KEY = 'eraPoints';
|
||||
|
||||
function mapValidators ({ individual }: EraRewardPoints): DeriveEraValPoints {
|
||||
return [...individual.entries()]
|
||||
.filter(([, points]): boolean => points.gtn(0))
|
||||
.filter(([, points]) => points.gt(BN_ZERO))
|
||||
.reduce((result: DeriveEraValPoints, [validatorId, points]): DeriveEraValPoints => {
|
||||
result[validatorId.toString()] = points;
|
||||
|
||||
|
||||
@@ -3,13 +3,14 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import type BN from 'bn.js';
|
||||
import { AccountId, Balance, BalanceLock, BalanceLockTo212, BalanceOf, Bid, BidKind, BlockNumber, Hash, Index, Proposal, ProposalIndex, SetIndex, SocietyVote, StrikeCount, TreasuryProposal, Votes, VoteIndex, VouchingStatus } from '@polkadot/types/interfaces';
|
||||
import { AccountId, Balance, BalanceLock, BalanceLockTo212, BalanceOf, Bid, BidKind, BlockNumber, Hash, Index, Proposal, ProposalIndex, SetIndex, SocietyVote, StrikeCount, TreasuryProposal, Votes, VouchingStatus } from '@polkadot/types/interfaces';
|
||||
|
||||
import { u32 } from '@polkadot/types';
|
||||
|
||||
export * from './accounts/types';
|
||||
export * from './council/types';
|
||||
export * from './democracy/types';
|
||||
export * from './elections/types';
|
||||
export * from './parachains/types';
|
||||
export * from './session/types';
|
||||
export * from './staking/types';
|
||||
@@ -59,20 +60,6 @@ export interface DeriveCollectiveProposal {
|
||||
|
||||
export type DeriveCollectiveProposals = DeriveCollectiveProposal[];
|
||||
|
||||
export interface DeriveElectionsInfo {
|
||||
candidates: AccountId[];
|
||||
candidateCount: u32;
|
||||
candidacyBond?: Balance;
|
||||
desiredSeats: u32;
|
||||
members: [AccountId, Balance][];
|
||||
nextVoterSet?: SetIndex;
|
||||
runnersUp: [AccountId, Balance][];
|
||||
termDuration: BlockNumber;
|
||||
voteCount?: VoteIndex;
|
||||
voterCount?: SetIndex;
|
||||
votingBond?: Balance;
|
||||
}
|
||||
|
||||
export interface DeriveFees {
|
||||
creationFee: Balance;
|
||||
existentialDeposit: Balance;
|
||||
|
||||
+14
-14
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/api",
|
||||
"version": "1.27.1",
|
||||
"version": "1.31.1",
|
||||
"description": "Promise and RxJS wrappers around the Polkadot JS RPC",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
@@ -26,21 +26,21 @@
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.11.0",
|
||||
"@polkadot/api-derive": "1.27.1",
|
||||
"@polkadot/keyring": "^3.0.1",
|
||||
"@polkadot/metadata": "1.27.1",
|
||||
"@polkadot/rpc-core": "1.27.1",
|
||||
"@polkadot/rpc-provider": "1.27.1",
|
||||
"@polkadot/types": "1.27.1",
|
||||
"@polkadot/types-known": "1.27.1",
|
||||
"@polkadot/util": "^3.0.1",
|
||||
"@polkadot/util-crypto": "^3.0.1",
|
||||
"bn.js": "^5.1.2",
|
||||
"eventemitter3": "^4.0.4",
|
||||
"@babel/runtime": "^7.11.2",
|
||||
"@polkadot/api-derive": "1.31.1",
|
||||
"@polkadot/keyring": "^3.4.1",
|
||||
"@polkadot/metadata": "1.31.1",
|
||||
"@polkadot/rpc-core": "1.31.1",
|
||||
"@polkadot/rpc-provider": "1.31.1",
|
||||
"@polkadot/types": "1.31.1",
|
||||
"@polkadot/types-known": "1.31.1",
|
||||
"@polkadot/util": "^3.4.1",
|
||||
"@polkadot/util-crypto": "^3.4.1",
|
||||
"bn.js": "^5.1.3",
|
||||
"eventemitter3": "^4.0.6",
|
||||
"rxjs": "^6.6.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^3.0.1"
|
||||
"@polkadot/keyring": "^3.4.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,9 @@ import { SetId, StoredPendingChange, StoredState } from '@polkadot/types/interfa
|
||||
import { RegistrarInfo, Registration } from '@polkadot/types/interfaces/identity';
|
||||
import { AuthIndex } from '@polkadot/types/interfaces/imOnline';
|
||||
import { DeferredOffenceOf, Kind, OffenceDetails, OpaqueTimeSlot, ReportIdOf } from '@polkadot/types/interfaces/offences';
|
||||
import { ProxyType } from '@polkadot/types/interfaces/proxy';
|
||||
import { ActiveRecovery, RecoveryConfig } from '@polkadot/types/interfaces/recovery';
|
||||
import { AccountId, AccountIndex, Balance, BalanceOf, BlockNumber, ExtrinsicsWeight, Hash, KeyTypeId, Moment, OpaqueCall, Perbill, ProxyType, Releases, ValidatorId } from '@polkadot/types/interfaces/runtime';
|
||||
import { AccountId, AccountIndex, Balance, BalanceOf, BlockNumber, ExtrinsicsWeight, Hash, KeyTypeId, Moment, OpaqueCall, Perbill, Releases, ValidatorId } from '@polkadot/types/interfaces/runtime';
|
||||
import { Scheduled, TaskAddress } from '@polkadot/types/interfaces/scheduler';
|
||||
import { Keys, SessionIndex } from '@polkadot/types/interfaces/session';
|
||||
import { Bid, BidKind, SocietyVote, StrikeCount, VouchingStatus } from '@polkadot/types/interfaces/society';
|
||||
|
||||
@@ -13,7 +13,8 @@ import { Extrinsic, Signature } from '@polkadot/types/interfaces/extrinsics';
|
||||
import { GrandpaEquivocationProof, KeyOwnerProof } from '@polkadot/types/interfaces/grandpa';
|
||||
import { IdentityFields, IdentityInfo, IdentityJudgement, RegistrarIndex } from '@polkadot/types/interfaces/identity';
|
||||
import { Heartbeat } from '@polkadot/types/interfaces/imOnline';
|
||||
import { AccountId, AccountIndex, Address, Balance, BalanceOf, BlockNumber, Call, ChangesTrieConfiguration, Hash, Header, KeyValue, LookupSource, Moment, OpaqueCall, Perbill, Percent, ProxyType, Weight } from '@polkadot/types/interfaces/runtime';
|
||||
import { ProxyType } from '@polkadot/types/interfaces/proxy';
|
||||
import { AccountId, AccountIndex, Address, Balance, BalanceOf, BlockNumber, Call, ChangesTrieConfiguration, Hash, Header, KeyValue, LookupSource, Moment, OpaqueCall, Perbill, Percent, Weight } from '@polkadot/types/interfaces/runtime';
|
||||
import { Period, Priority } from '@polkadot/types/interfaces/scheduler';
|
||||
import { Keys } from '@polkadot/types/interfaces/session';
|
||||
import { SocietyJudgement } from '@polkadot/types/interfaces/society';
|
||||
@@ -63,7 +64,7 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* not assumed to be in the overlay.
|
||||
* # </weight>
|
||||
**/
|
||||
forceTransfer: AugmentedSubmittable<(source: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array, dest: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array, value: Compact<Balance> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
forceTransfer: AugmentedSubmittable<(source: LookupSource | Address | AccountId | AccountIndex | LookupSource | string | Uint8Array, dest: LookupSource | Address | AccountId | AccountIndex | LookupSource | string | Uint8Array, value: Compact<Balance> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Set the balances of a given account.
|
||||
*
|
||||
@@ -84,7 +85,7 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* - DB Weight: 1 Read, 1 Write to `who`
|
||||
* # </weight>
|
||||
**/
|
||||
setBalance: AugmentedSubmittable<(who: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array, newFree: Compact<Balance> | AnyNumber | Uint8Array, newReserved: Compact<Balance> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
setBalance: AugmentedSubmittable<(who: LookupSource | Address | AccountId | AccountIndex | LookupSource | string | Uint8Array, newFree: Compact<Balance> | AnyNumber | Uint8Array, newReserved: Compact<Balance> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Transfer some liquid free balance to another account.
|
||||
*
|
||||
@@ -114,7 +115,7 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* - Origin account is already in memory, so no DB operations for them.
|
||||
* # </weight>
|
||||
**/
|
||||
transfer: AugmentedSubmittable<(dest: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array, value: Compact<Balance> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
transfer: AugmentedSubmittable<(dest: LookupSource | Address | AccountId | AccountIndex | LookupSource | string | Uint8Array, value: Compact<Balance> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Same as the [`transfer`] call, but with a check that the transfer will not kill the
|
||||
* origin account.
|
||||
@@ -128,7 +129,7 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* - DB Weight: 1 Read and 1 Write to dest (sender is in overlay already)
|
||||
* #</weight>
|
||||
**/
|
||||
transferKeepAlive: AugmentedSubmittable<(dest: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array, value: Compact<Balance> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
transferKeepAlive: AugmentedSubmittable<(dest: LookupSource | Address | AccountId | AccountIndex | LookupSource | string | Uint8Array, value: Compact<Balance> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
};
|
||||
contracts: {
|
||||
[index: string]: SubmittableExtrinsicFunction<ApiType>;
|
||||
@@ -141,7 +142,7 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* * If no account exists and the call value is not less than `existential_deposit`,
|
||||
* a regular account will be created and any value will be transferred.
|
||||
**/
|
||||
call: AugmentedSubmittable<(dest: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array, value: Compact<BalanceOf> | AnyNumber | Uint8Array, gasLimit: Compact<Gas> | AnyNumber | Uint8Array, data: Bytes | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
call: AugmentedSubmittable<(dest: LookupSource | Address | AccountId | AccountIndex | LookupSource | string | Uint8Array, value: Compact<BalanceOf> | AnyNumber | Uint8Array, gasLimit: Compact<Gas> | AnyNumber | Uint8Array, data: Bytes | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Allows block producers to claim a small reward for evicting a contract. If a block producer
|
||||
* fails to do so, a regular users will be allowed to claim the reward.
|
||||
@@ -739,7 +740,7 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* Else, since this is a root call and will go into phragmen, we assume full block for now.
|
||||
* # </weight>
|
||||
**/
|
||||
removeMember: AugmentedSubmittable<(who: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array, hasReplacement: bool | boolean | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
removeMember: AugmentedSubmittable<(who: LookupSource | Address | AccountId | AccountIndex | LookupSource | string | Uint8Array, hasReplacement: bool | boolean | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Remove `origin` as a voter. This removes the lock and returns the bond.
|
||||
*
|
||||
@@ -947,7 +948,7 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* The dispatch origin for this call must be _Signed_ and the sender must have a registered
|
||||
* sub identity of `sub`.
|
||||
**/
|
||||
addSub: AugmentedSubmittable<(sub: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array, data: Data | { None: any } | { Raw: any } | { BlakeTwo256: any } | { Sha256: any } | { Keccak256: any } | { ShaThree256: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
addSub: AugmentedSubmittable<(sub: LookupSource | Address | AccountId | AccountIndex | LookupSource | string | Uint8Array, data: Data | { None: any } | { Raw: any } | { BlakeTwo256: any } | { Sha256: any } | { Keccak256: any } | { ShaThree256: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Cancel a previous request.
|
||||
*
|
||||
@@ -1010,7 +1011,7 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* - One event.
|
||||
* # </weight>
|
||||
**/
|
||||
killIdentity: AugmentedSubmittable<(target: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
killIdentity: AugmentedSubmittable<(target: LookupSource | Address | AccountId | AccountIndex | LookupSource | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Provide a judgement for an account's identity.
|
||||
*
|
||||
@@ -1032,7 +1033,7 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* - One event.
|
||||
* # </weight>
|
||||
**/
|
||||
provideJudgement: AugmentedSubmittable<(regIndex: Compact<RegistrarIndex> | AnyNumber | Uint8Array, target: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array, judgement: IdentityJudgement | { Unknown: any } | { FeePaid: any } | { Reasonable: any } | { KnownGood: any } | { OutOfDate: any } | { LowQuality: any } | { Erroneous: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
provideJudgement: AugmentedSubmittable<(regIndex: Compact<RegistrarIndex> | AnyNumber | Uint8Array, target: LookupSource | Address | AccountId | AccountIndex | LookupSource | string | Uint8Array, judgement: IdentityJudgement | { Unknown: any } | { FeePaid: any } | { Reasonable: any } | { KnownGood: any } | { OutOfDate: any } | { LowQuality: any } | { Erroneous: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Remove the sender as a sub-account.
|
||||
*
|
||||
@@ -1055,14 +1056,14 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* The dispatch origin for this call must be _Signed_ and the sender must have a registered
|
||||
* sub identity of `sub`.
|
||||
**/
|
||||
removeSub: AugmentedSubmittable<(sub: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
removeSub: AugmentedSubmittable<(sub: LookupSource | Address | AccountId | AccountIndex | LookupSource | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Alter the associated name of the given sub-account.
|
||||
*
|
||||
* The dispatch origin for this call must be _Signed_ and the sender must have a registered
|
||||
* sub identity of `sub`.
|
||||
**/
|
||||
renameSub: AugmentedSubmittable<(sub: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array, data: Data | { None: any } | { Raw: any } | { BlakeTwo256: any } | { Sha256: any } | { Keccak256: any } | { ShaThree256: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
renameSub: AugmentedSubmittable<(sub: LookupSource | Address | AccountId | AccountIndex | LookupSource | string | Uint8Array, data: Data | { None: any } | { Raw: any } | { BlakeTwo256: any } | { Sha256: any } | { Keccak256: any } | { ShaThree256: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Request a judgement from a registrar.
|
||||
*
|
||||
@@ -2164,7 +2165,7 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* Total Complexity: O(M + logM + C)
|
||||
* # </weight>
|
||||
**/
|
||||
vote: AugmentedSubmittable<(candidate: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array, approve: bool | boolean | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
vote: AugmentedSubmittable<(candidate: LookupSource | Address | AccountId | AccountIndex | LookupSource | string | Uint8Array, approve: bool | boolean | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* As a member, vouch for someone to join society by placing a bid on their behalf.
|
||||
*
|
||||
@@ -2239,7 +2240,7 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* - Write: Bonded, Payee, [Origin Account], Locks, Ledger
|
||||
* # </weight>
|
||||
**/
|
||||
bond: AugmentedSubmittable<(controller: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array, value: Compact<BalanceOf> | AnyNumber | Uint8Array, payee: RewardDestination | 'Staked'|'Stash'|'Controller' | number | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
bond: AugmentedSubmittable<(controller: LookupSource | Address | AccountId | AccountIndex | LookupSource | string | Uint8Array, value: Compact<BalanceOf> | AnyNumber | Uint8Array, payee: RewardDestination | { Staked: any } | { Stash: any } | { Controller: any } | { Account: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Add some extra amount that have appeared in the stash `free_balance` into the balance up
|
||||
* for staking.
|
||||
@@ -2384,7 +2385,7 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* - Writes: Validators, Nominators
|
||||
* # </weight>
|
||||
**/
|
||||
nominate: AugmentedSubmittable<(targets: Vec<LookupSource> | (LookupSource | Address | AccountId | AccountIndex | string | Uint8Array)[]) => SubmittableExtrinsic<ApiType>>;
|
||||
nominate: AugmentedSubmittable<(targets: Vec<LookupSource> | (LookupSource | Address | AccountId | AccountIndex | LookupSource | string | Uint8Array)[]) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Pay out all the stakers behind a single validator for a single era.
|
||||
*
|
||||
@@ -2479,7 +2480,7 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* - Write: Bonded, Ledger New Controller, Ledger Old Controller
|
||||
* # </weight>
|
||||
**/
|
||||
setController: AugmentedSubmittable<(controller: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
setController: AugmentedSubmittable<(controller: LookupSource | Address | AccountId | AccountIndex | LookupSource | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Set `HistoryDepth` value. This function will delete any history information
|
||||
* when `HistoryDepth` is reduced.
|
||||
@@ -2534,7 +2535,7 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* - Write: Payee
|
||||
* # </weight>
|
||||
**/
|
||||
setPayee: AugmentedSubmittable<(payee: RewardDestination | 'Staked'|'Stash'|'Controller' | number | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
setPayee: AugmentedSubmittable<(payee: RewardDestination | { Staked: any } | { Stash: any } | { Controller: any } | { Account: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Sets the ideal number of validators.
|
||||
*
|
||||
@@ -2710,7 +2711,7 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* - One DB change.
|
||||
* # </weight>
|
||||
**/
|
||||
setKey: AugmentedSubmittable<(updated: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
setKey: AugmentedSubmittable<(updated: LookupSource | Address | AccountId | AccountIndex | LookupSource | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Authenticates the sudo key and dispatches a function call with `Root` origin.
|
||||
*
|
||||
@@ -2737,7 +2738,7 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* - Weight of derivative `call` execution + 10,000.
|
||||
* # </weight>
|
||||
**/
|
||||
sudoAs: AugmentedSubmittable<(who: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array, call: Call | { callIndex?: any; args?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
sudoAs: AugmentedSubmittable<(who: LookupSource | Address | AccountId | AccountIndex | LookupSource | string | Uint8Array, call: Call | { callIndex?: any; args?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Authenticates the sudo key and dispatches a function call with `Root` origin.
|
||||
* This function does not check the weight of the call, and instead allows the
|
||||
@@ -3121,7 +3122,7 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* - DbWrites: `ProposalCount`, `Proposals`, `origin account`
|
||||
* # </weight>
|
||||
**/
|
||||
proposeSpend: AugmentedSubmittable<(value: Compact<BalanceOf> | AnyNumber | Uint8Array, beneficiary: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
proposeSpend: AugmentedSubmittable<(value: Compact<BalanceOf> | AnyNumber | Uint8Array, beneficiary: LookupSource | Address | AccountId | AccountIndex | LookupSource | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Reject a proposed spend. The original deposit will be slashed.
|
||||
*
|
||||
@@ -3302,7 +3303,7 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* - Using 100 µs fixed. Assuming less than 50 locks on any user, else we may want factor in number of locks.
|
||||
* # </weight>
|
||||
**/
|
||||
forceVestedTransfer: AugmentedSubmittable<(source: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array, target: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array, schedule: VestingInfo | { locked?: any; perBlock?: any; startingBlock?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
forceVestedTransfer: AugmentedSubmittable<(source: LookupSource | Address | AccountId | AccountIndex | LookupSource | string | Uint8Array, target: LookupSource | Address | AccountId | AccountIndex | LookupSource | string | Uint8Array, schedule: VestingInfo | { locked?: any; perBlock?: any; startingBlock?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Unlock any vested funds of the sender account.
|
||||
*
|
||||
@@ -3344,7 +3345,7 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* - Using 50 µs fixed. Assuming less than 50 locks on any user, else we may want factor in number of locks.
|
||||
* # </weight>
|
||||
**/
|
||||
vestOther: AugmentedSubmittable<(target: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
vestOther: AugmentedSubmittable<(target: LookupSource | Address | AccountId | AccountIndex | LookupSource | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Create a vested transfer.
|
||||
*
|
||||
@@ -3365,7 +3366,7 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* - Using 100 µs fixed. Assuming less than 50 locks on any user, else we may want factor in number of locks.
|
||||
* # </weight>
|
||||
**/
|
||||
vestedTransfer: AugmentedSubmittable<(target: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array, schedule: VestingInfo | { locked?: any; perBlock?: any; startingBlock?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
vestedTransfer: AugmentedSubmittable<(target: LookupSource | Address | AccountId | AccountIndex | LookupSource | string | Uint8Array, schedule: VestingInfo | { locked?: any; perBlock?: any; startingBlock?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ const PAGE_SIZE_VALS = PAGE_SIZE_KEYS;
|
||||
const l = logger('api/init');
|
||||
|
||||
export default abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
public readonly registry: Registry;
|
||||
#registry: Registry;
|
||||
|
||||
// HACK Use BN import so decorateDerive works... yes, wtf.
|
||||
protected __phantom = new BN(0);
|
||||
@@ -127,7 +127,7 @@ export default abstract class Decorate<ApiType extends ApiTypes> extends Events
|
||||
constructor (options: ApiOptions, type: ApiTypes, decorateMethod: DecorateMethod<ApiType>) {
|
||||
super();
|
||||
|
||||
this.registry = options.registry || new TypeRegistry();
|
||||
this.#registry = options.registry || new TypeRegistry();
|
||||
|
||||
const thisProvider = options.source
|
||||
? options.source._rpcCore.provider.clone()
|
||||
@@ -136,24 +136,31 @@ export default abstract class Decorate<ApiType extends ApiTypes> extends Events
|
||||
this._decorateMethod = decorateMethod;
|
||||
this._options = options;
|
||||
this._type = type;
|
||||
this._rpcCore = new RpcCore(this.registry, thisProvider, this._options.rpc);
|
||||
this._rpcCore = new RpcCore(this.#registry, thisProvider, this._options.rpc);
|
||||
this._isConnected = new BehaviorSubject(this._rpcCore.provider.isConnected());
|
||||
this._rx.hasSubscriptions = this._rpcCore.provider.hasSubscriptions;
|
||||
this._rx.registry = this.registry;
|
||||
this._rx.registry = this.#registry;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Return the current used registry
|
||||
*/
|
||||
public get registry (): Registry {
|
||||
return this.#registry;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Creates an instance of a type as registered
|
||||
*/
|
||||
public createType <K extends keyof InterfaceTypes> (type: K, ...params: unknown[]): InterfaceTypes[K] {
|
||||
return this.registry.createType(type, ...params);
|
||||
return this.#registry.createType(type, ...params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Register additional user-defined of chain-specific types in the type registry
|
||||
*/
|
||||
public registerTypes (types?: RegistryTypes): void {
|
||||
types && this.registry.register(types);
|
||||
types && this.#registry.register(types);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -163,8 +170,8 @@ export default abstract class Decorate<ApiType extends ApiTypes> extends Events
|
||||
return this._rpcCore.provider.hasSubscriptions;
|
||||
}
|
||||
|
||||
public injectMetadata (metadata: Metadata, fromEmpty?: boolean): void {
|
||||
const decoratedMeta = new DecoratedMeta(this.registry, metadata);
|
||||
public injectMetadata (metadata: Metadata, fromEmpty?: boolean, registry?: Registry): void {
|
||||
const decoratedMeta = new DecoratedMeta(registry || this.#registry, metadata);
|
||||
|
||||
if (fromEmpty || !this._extrinsics) {
|
||||
this._extrinsics = this._decorateExtrinsics(decoratedMeta.tx, this._decorateMethod);
|
||||
@@ -461,8 +468,8 @@ export default abstract class Decorate<ApiType extends ApiTypes> extends Events
|
||||
}
|
||||
|
||||
const nextResult = vals.length
|
||||
? new LinkageResult(this.registry, [keys[0].constructor as any, keys], [vals[0].constructor as any, vals])
|
||||
: new LinkageResult(this.registry, [Null, []], [Null, []]);
|
||||
? new LinkageResult(this.#registry, [keys[0].constructor as any, keys], [vals[0].constructor as any, vals])
|
||||
: new LinkageResult(this.#registry, [Null, []], [Null, []]);
|
||||
|
||||
// we set our result into a subject so we have a single observable for
|
||||
// which the value changes over time. Initially create, follow-up next
|
||||
|
||||
@@ -3,25 +3,37 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { SignedBlock, RuntimeVersion } from '@polkadot/types/interfaces';
|
||||
import { Registry } from '@polkadot/types/types';
|
||||
import { ApiBase, ApiOptions, ApiTypes, DecorateMethod } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { Observable, Subscription, of } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { Metadata, Text } from '@polkadot/types';
|
||||
import { Metadata, Text, TypeRegistry } from '@polkadot/types';
|
||||
import { LATEST_EXTRINSIC_VERSION } from '@polkadot/types/extrinsic/Extrinsic';
|
||||
import { getMetadataTypes, getSpecAlias, getSpecTypes } from '@polkadot/types-known';
|
||||
import { logger } from '@polkadot/util';
|
||||
import { getMetadataTypes, getSpecAlias, getSpecTypes, getUpgradeVersion } from '@polkadot/types-known';
|
||||
import { BN_ZERO, assert, logger, u8aEq, u8aToU8a } from '@polkadot/util';
|
||||
import { cryptoWaitReady } from '@polkadot/util-crypto';
|
||||
|
||||
import Decorate from './Decorate';
|
||||
|
||||
interface VersionedRegistry {
|
||||
isDefault: boolean;
|
||||
lastBlockHash: Uint8Array | null;
|
||||
registry: Registry;
|
||||
specVersion: BN;
|
||||
}
|
||||
|
||||
const KEEPALIVE_INTERVAL = 15000;
|
||||
const DEFAULT_BLOCKNUMBER = { unwrap: () => BN_ZERO };
|
||||
|
||||
const l = logger('api/init');
|
||||
|
||||
export default abstract class Init<ApiType extends ApiTypes> extends Decorate<ApiType> {
|
||||
#healthTimer: NodeJS.Timeout | null = null;
|
||||
|
||||
#registries: VersionedRegistry[] = [];
|
||||
|
||||
#updateSub?: Subscription;
|
||||
|
||||
constructor (options: ApiOptions, type: ApiTypes, decorateMethod: DecorateMethod<ApiType>) {
|
||||
@@ -32,13 +44,7 @@ export default abstract class Init<ApiType extends ApiTypes> extends Decorate<Ap
|
||||
}
|
||||
|
||||
// all injected types added to the registry for overrides
|
||||
this.registry.setKnownTypes({
|
||||
types: options.types,
|
||||
typesAlias: options.typesAlias,
|
||||
typesBundle: options.typesBundle,
|
||||
typesChain: options.typesChain,
|
||||
typesSpec: options.typesSpec
|
||||
});
|
||||
this.registry.setKnownTypes(options);
|
||||
|
||||
// We only register the types (global) if this is not a cloned instance.
|
||||
// Do right up-front, so we get in the user types before we are actually
|
||||
@@ -55,6 +61,7 @@ export default abstract class Init<ApiType extends ApiTypes> extends Decorate<Ap
|
||||
this._rx.queryMulti = this._decorateMulti(this._rxDecorateMethod);
|
||||
this._rx.signer = options.signer;
|
||||
|
||||
this._rpcCore.setRegistrySwap((hash?: string | Uint8Array | null) => this.getBlockRegistry(hash));
|
||||
this._rpcCore.provider.on('disconnected', this.#onProviderDisconnect);
|
||||
this._rpcCore.provider.on('error', this.#onProviderError);
|
||||
this._rpcCore.provider.on('connected', this.#onProviderConnect);
|
||||
@@ -68,6 +75,71 @@ export default abstract class Init<ApiType extends ApiTypes> extends Decorate<Ap
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Sets up a registry based on the block hash defined
|
||||
*/
|
||||
public async getBlockRegistry (blockHash?: string | Uint8Array | null): Promise<Registry> {
|
||||
if (!blockHash) {
|
||||
return this.registry;
|
||||
}
|
||||
|
||||
// shortcut in the case where we have an immediate-same request
|
||||
const lastBlockHash = u8aToU8a(blockHash);
|
||||
const existingViaHash = this.#registries.find((r) => r.lastBlockHash && u8aEq(lastBlockHash, r.lastBlockHash));
|
||||
|
||||
if (existingViaHash) {
|
||||
return existingViaHash.registry;
|
||||
}
|
||||
|
||||
// ensure we have everything required
|
||||
assert(this._genesisHash && this._runtimeVersion, 'Cannot retrieve data on an uninitialized chain');
|
||||
|
||||
// We have to assume that on the RPC layer the calls used here does not call back into
|
||||
// the registry swap, so getHeader & getRuntimeVersion should not be historic
|
||||
const header = this._genesisHash.eq(blockHash)
|
||||
? { number: DEFAULT_BLOCKNUMBER, parentHash: this._genesisHash }
|
||||
: await this._rpcCore.chain.getHeader(blockHash).toPromise();
|
||||
|
||||
assert(header?.parentHash && !header.parentHash.isEmpty, 'Unable to retrieve header and parent from supplied hash');
|
||||
|
||||
// get the runtime version, either on-chain or via an known upgrade history
|
||||
const [firstVersion, lastVersion] = getUpgradeVersion(this._genesisHash, header.number.unwrap());
|
||||
const version = (firstVersion && (lastVersion || firstVersion.specVersion.eq(this._runtimeVersion.specVersion)))
|
||||
? { specName: this._runtimeVersion.specName, specVersion: firstVersion.specVersion }
|
||||
: await this._rpcCore.state.getRuntimeVersion(header.parentHash).toPromise();
|
||||
|
||||
// check for pre-existing registries
|
||||
const existingViaVersion = this.#registries.find((r) => r.specVersion.eq(version.specVersion));
|
||||
|
||||
if (existingViaVersion) {
|
||||
existingViaVersion.lastBlockHash = lastBlockHash;
|
||||
|
||||
return existingViaVersion.registry;
|
||||
}
|
||||
|
||||
// nothing has been found, construct new
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
registry.setChainProperties(this.registry.getChainProperties());
|
||||
registry.setKnownTypes(this._options);
|
||||
registry.register(getSpecTypes(registry, this._runtimeChain as Text, version.specName, version.specVersion));
|
||||
|
||||
if (registry.knownTypes.typesBundle) {
|
||||
this._adjustBundleTypes(registry, this._runtimeChain as Text, version.specName);
|
||||
}
|
||||
|
||||
// retrieve the metadata now that we have all types set
|
||||
const metadata = await this._rpcCore.state.getMetadata(header.parentHash).toPromise();
|
||||
|
||||
// TODO: Not convinced (yet) that we really want to re-decorate, keep on ice since it does muddle-up
|
||||
// this.injectMetadata(metadata, false);
|
||||
registry.setMetadata(metadata);
|
||||
|
||||
this.#registries.push({ isDefault: false, lastBlockHash, registry, specVersion: version.specVersion });
|
||||
|
||||
return registry;
|
||||
}
|
||||
|
||||
protected async _loadMeta (): Promise<boolean> {
|
||||
const genesisHash = await this._rpcCore.chain.getBlockHash(0).toPromise();
|
||||
|
||||
@@ -138,8 +210,14 @@ export default abstract class Init<ApiType extends ApiTypes> extends Decorate<Ap
|
||||
this._runtimeVersion = version;
|
||||
this._rx.runtimeVersion = version;
|
||||
|
||||
this.registerTypes(getSpecTypes(this.registry, this._runtimeChain as Text, version.specName, version.specVersion));
|
||||
this.injectMetadata(metadata, false);
|
||||
// update the default registry version
|
||||
const thisRegistry = this.#registries.find(({ isDefault }) => isDefault);
|
||||
|
||||
assert(thisRegistry, 'Initialization error, cannot find the default registry');
|
||||
|
||||
thisRegistry.specVersion = version.specVersion;
|
||||
thisRegistry.registry.register(getSpecTypes(thisRegistry.registry, this._runtimeChain as Text, version.specName, version.specVersion));
|
||||
this.injectMetadata(metadata, false, thisRegistry.registry);
|
||||
|
||||
return true;
|
||||
})
|
||||
@@ -148,9 +226,9 @@ export default abstract class Init<ApiType extends ApiTypes> extends Decorate<Ap
|
||||
).subscribe();
|
||||
}
|
||||
|
||||
private _adjustBundleTypes (chain: Text, specName: Text): void {
|
||||
private _adjustBundleTypes (registry: Registry, chain: Text, specName: Text): void {
|
||||
// adjust known type aliases
|
||||
this.registry.knownTypes.typesAlias = getSpecAlias(this.registry, chain, specName);
|
||||
registry.knownTypes.typesAlias = getSpecAlias(registry, chain, specName);
|
||||
|
||||
// FIXME For the first round, we are not adjusting the user-injected RPCs
|
||||
// inject any user-level RPCs now that we have the chain/spec
|
||||
@@ -187,9 +265,14 @@ export default abstract class Init<ApiType extends ApiTypes> extends Decorate<Ap
|
||||
this._runtimeVersion = runtimeVersion;
|
||||
this._rx.runtimeVersion = runtimeVersion;
|
||||
|
||||
// setup the initial registry, when we have none
|
||||
if (!this.#registries.length) {
|
||||
this.#registries.push({ isDefault: true, lastBlockHash: null, registry: this.registry, specVersion: runtimeVersion.specVersion });
|
||||
}
|
||||
|
||||
// adjust types based on bundled info
|
||||
if (this.registry.knownTypes.typesBundle) {
|
||||
this._adjustBundleTypes(chain, runtimeVersion.specName);
|
||||
this._adjustBundleTypes(this.registry, chain, runtimeVersion.specName);
|
||||
}
|
||||
|
||||
// do the setup for the specific chain
|
||||
@@ -219,7 +302,7 @@ export default abstract class Init<ApiType extends ApiTypes> extends Decorate<Ap
|
||||
const metaExtrinsic = metadata.asLatest.extrinsic;
|
||||
|
||||
// only inject if we are not a clone (global init)
|
||||
if (metaExtrinsic.version.gtn(0)) {
|
||||
if (metaExtrinsic.version.gt(BN_ZERO)) {
|
||||
this._extrinsicType = metaExtrinsic.version.toNumber();
|
||||
} else if (!this._options.source) {
|
||||
// detect the extrinsic version in-use based on the last block
|
||||
|
||||
@@ -60,16 +60,19 @@ export default function createClass <ApiType extends ApiTypes> ({ api, apiType,
|
||||
)();
|
||||
}
|
||||
|
||||
// sign a transaction, returning the this to allow chaining, i.e. .sign(...).send()
|
||||
/**
|
||||
* @description Sign a transaction, returning the this to allow chaining, i.e. .sign(...).send(). When options, e.g. nonce/blockHash are not specified, it will be inferred. To retrieve eg. nonce use `signAsync` (the preferred interface, this is provided for backwards compatibility)
|
||||
* @deprecated
|
||||
*/
|
||||
public sign (account: IKeyringPair, optionsOrNonce?: Partial<SignerOptions>): this {
|
||||
super.sign(account, this.#makeSignOptions(this.#optionsOrNonce(optionsOrNonce), {}));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
// signs a transaction, returning `this` to allow chaining. E.g.: `sign(...).send()`
|
||||
//
|
||||
// also supports signing through external signers
|
||||
/**
|
||||
* @description Signs a transaction, returning `this` to allow chaining. E.g.: `sign(...).send()`. Like `.signAndSend` this will retrieve the nonce and blockHash to send the tx with.
|
||||
*/
|
||||
public signAsync (account: AddressOrPair, optionsOrNonce?: Partial<SignerOptions>): SubmittableThis<ApiType, this> {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return,@typescript-eslint/no-unsafe-call
|
||||
return decorateMethod(
|
||||
|
||||
@@ -50,6 +50,9 @@ export interface SubmittableExtrinsic<ApiType extends ApiTypes> extends Extrinsi
|
||||
|
||||
send(statusCb: Callback<ISubmittableResult>): SubmittableResultSubscription<ApiType>;
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
sign(account: IKeyringPair, _options?: Partial<SignerOptions>): this;
|
||||
|
||||
signAsync(account: AddressOrPair, _options?: Partial<SignerOptions>): SubmittableThis<ApiType, this>;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/metadata",
|
||||
"version": "1.27.1",
|
||||
"version": "1.31.1",
|
||||
"description": "Helpers to extract information from runtime metadata",
|
||||
"main": "index.js",
|
||||
"publishConfig": {
|
||||
@@ -26,14 +26,14 @@
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/type-metadata#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.11.0",
|
||||
"@polkadot/types": "1.27.1",
|
||||
"@polkadot/types-known": "1.27.1",
|
||||
"@polkadot/util": "^3.0.1",
|
||||
"@polkadot/util-crypto": "^3.0.1",
|
||||
"bn.js": "^5.1.2"
|
||||
"@babel/runtime": "^7.11.2",
|
||||
"@polkadot/types": "1.31.1",
|
||||
"@polkadot/types-known": "1.31.1",
|
||||
"@polkadot/util": "^3.4.1",
|
||||
"@polkadot/util-crypto": "^3.4.1",
|
||||
"bn.js": "^5.1.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^3.0.1"
|
||||
"@polkadot/keyring": "^3.4.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/rpc-core",
|
||||
"version": "1.27.1",
|
||||
"version": "1.31.1",
|
||||
"description": "A JavaScript wrapper for the Polkadot JsonRPC interface",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
@@ -26,15 +26,15 @@
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/rpc-core#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.11.0",
|
||||
"@polkadot/metadata": "1.27.1",
|
||||
"@polkadot/rpc-provider": "1.27.1",
|
||||
"@polkadot/types": "1.27.1",
|
||||
"@polkadot/util": "^3.0.1",
|
||||
"@babel/runtime": "^7.11.2",
|
||||
"@polkadot/metadata": "1.31.1",
|
||||
"@polkadot/rpc-provider": "1.31.1",
|
||||
"@polkadot/types": "1.31.1",
|
||||
"@polkadot/util": "^3.4.1",
|
||||
"memoizee": "^0.4.14",
|
||||
"rxjs": "^6.6.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^3.0.1"
|
||||
"@polkadot/keyring": "^3.4.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,10 +91,25 @@ describe('Cached Observables', (): void => {
|
||||
expect(observable2).not.toBe(observable1);
|
||||
});
|
||||
|
||||
it('creates multiple observables for one-shots', (): void => {
|
||||
it('creates single observables for subsequent one-shots', (): void => {
|
||||
const observable1 = rpc.chain.getBlockHash(123);
|
||||
const observable2 = rpc.chain.getBlockHash(123);
|
||||
|
||||
expect(observable2).not.toBe(observable1);
|
||||
expect(observable2).toBe(observable1);
|
||||
});
|
||||
|
||||
it('creates multiple observables for subsequent one-shots delayed', (done): void => {
|
||||
const observable1 = rpc.chain.getBlockHash(123);
|
||||
|
||||
const sub = observable1.subscribe((): void => {
|
||||
sub.unsubscribe();
|
||||
});
|
||||
|
||||
expect(rpc.chain.getBlockHash(123)).toBe(observable1);
|
||||
|
||||
setTimeout((): void => {
|
||||
expect(rpc.chain.getBlockHash(123)).not.toBe(observable1);
|
||||
done();
|
||||
}, 3500);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -8,13 +8,13 @@ import { AnyJson, Codec, DefinitionRpc, DefinitionRpcExt, DefinitionRpcSub, Regi
|
||||
import { RpcInterface, RpcInterfaceMethod } from './types';
|
||||
|
||||
import memoizee from 'memoizee';
|
||||
import { combineLatest, from, Observable, Observer, of, throwError } from 'rxjs';
|
||||
import { catchError, map, publishReplay, refCount, switchMap } from 'rxjs/operators';
|
||||
import { Observable, Observer } from 'rxjs';
|
||||
import { publishReplay, refCount } from 'rxjs/operators';
|
||||
import jsonrpc from '@polkadot/types/interfaces/jsonrpc';
|
||||
import { Option, StorageKey, Vec, createClass, createTypeUnsafe } from '@polkadot/types';
|
||||
import { assert, hexToU8a, isFunction, isNull, isUndefined, logger, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
import { drr } from './rxjs';
|
||||
import { drr, refCountDelay } from './rxjs';
|
||||
|
||||
interface StorageChangeSetJSON {
|
||||
block: string;
|
||||
@@ -66,14 +66,16 @@ function logErrorMessage (method: string, { params, type }: DefinitionRpc, error
|
||||
* ```
|
||||
*/
|
||||
export default class Rpc implements RpcInterface {
|
||||
#registryDefault: Registry;
|
||||
|
||||
#getBlockRegistry?: (blockHash?: string | Uint8Array | null) => Promise<Registry>;
|
||||
|
||||
readonly #storageCache = new Map<string, string | null>();
|
||||
|
||||
public readonly mapping = new Map<string, DefinitionRpcExt>();
|
||||
|
||||
public readonly provider: ProviderInterface;
|
||||
|
||||
public readonly registry: Registry;
|
||||
|
||||
public readonly sections: string[] = [];
|
||||
|
||||
// Ok, this is quite horrible - we really should not be using the ! here, but we are actually assigning
|
||||
@@ -113,7 +115,7 @@ export default class Rpc implements RpcInterface {
|
||||
// eslint-disable-next-line @typescript-eslint/unbound-method
|
||||
assert(provider && isFunction(provider.send), 'Expected Provider to API create');
|
||||
|
||||
this.registry = registry;
|
||||
this.#registryDefault = registry;
|
||||
this.provider = provider;
|
||||
|
||||
const sectionNames = Object.keys(jsonrpc);
|
||||
@@ -131,6 +133,13 @@ export default class Rpc implements RpcInterface {
|
||||
this.provider.disconnect();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Sets a registry swap (typically from Api)
|
||||
*/
|
||||
public setRegistrySwap (registrySwap: (blockHash?: string | Uint8Array | null) => Promise<Registry>): void {
|
||||
this.#getBlockRegistry = registrySwap;
|
||||
}
|
||||
|
||||
public addUserInterfaces<Section extends keyof RpcInterface> (userRpc: Record<string, Record<string, DefinitionRpc | DefinitionRpcSub>>): void {
|
||||
// add any extra user-defined sections
|
||||
this.sections.push(...Object.keys(userRpc).filter((key) => !this.sections.includes(key)));
|
||||
@@ -192,41 +201,60 @@ export default class Rpc implements RpcInterface {
|
||||
|
||||
private _createMethodSend (section: string, method: string, def: DefinitionRpc): RpcInterfaceMethod {
|
||||
const rpcName = `${section}_${method}`;
|
||||
const hashIndex = def.params.findIndex(({ isHistoric }) => isHistoric);
|
||||
const cacheIndex = def.params.findIndex(({ isCached }) => isCached);
|
||||
let memoized: null | RpcInterfaceMethod & memoizee.Memoized<RpcInterfaceMethod> = null;
|
||||
|
||||
// execute the RPC call, doing a registry swap for historic as applicable
|
||||
const callWithRegistry = async (isRaw: boolean, values: any[]): Promise<Codec | Codec[]> => {
|
||||
const hash = hashIndex === -1
|
||||
? undefined
|
||||
: values[hashIndex] as Uint8Array;
|
||||
const registry = hash && this.#getBlockRegistry
|
||||
? await this.#getBlockRegistry(hash)
|
||||
: this.#registryDefault;
|
||||
const params = this._formatInputs(registry, def, values);
|
||||
const data = await this.provider.send(rpcName, params.map((param): AnyJson => param.toJSON())) as AnyJson;
|
||||
|
||||
return isRaw
|
||||
? registry.createType('Raw', data)
|
||||
: this._formatOutput(registry, method, def, params, data);
|
||||
};
|
||||
|
||||
const creator = (isRaw: boolean) => (...values: any[]): Observable<any> => {
|
||||
// Here, logically, it should be `of(this.formatInputs(method, values))`.
|
||||
// However, formatInputs can throw, and when it does, the above way
|
||||
// doesn't throw in the "Observable loop" (which is internally wrapped in
|
||||
// a try/catch block). So we:
|
||||
// - first do `of(1)` - won't throw
|
||||
// - then do `map(()=>this.formatInputs)` - might throw, but inside Observable.
|
||||
return of(1).pipe(
|
||||
map(() => this._formatInputs(def, values)),
|
||||
switchMap((params): Observable<[Codec[], any]> =>
|
||||
combineLatest([
|
||||
of(params),
|
||||
from(this.provider.send(rpcName, params.map((param): AnyJson => param.toJSON())))
|
||||
])
|
||||
),
|
||||
map(([params, result]) =>
|
||||
isRaw
|
||||
? this.registry.createType('Raw', result)
|
||||
: this._formatOutput(method, def, params, result)
|
||||
),
|
||||
catchError((error): any => {
|
||||
logErrorMessage(method, def, error);
|
||||
const isDelayed = (hashIndex !== -1 && !!values[hashIndex]) || (cacheIndex !== -1 && !!values[cacheIndex]);
|
||||
|
||||
return throwError(error);
|
||||
}),
|
||||
return new Observable((observer: Observer<any>): VoidCallback => {
|
||||
callWithRegistry(isRaw, values)
|
||||
.then((value): void => {
|
||||
observer.next(value);
|
||||
observer.complete();
|
||||
})
|
||||
.catch((error): void => {
|
||||
logErrorMessage(method, def, error);
|
||||
|
||||
observer.error(error);
|
||||
observer.complete();
|
||||
});
|
||||
|
||||
return (): void => {
|
||||
// delete old results from cache
|
||||
memoized?.delete(...values);
|
||||
};
|
||||
}).pipe(
|
||||
publishReplay(1), // create a Replay(1)
|
||||
refCount() // Unsubscribe WS when there are no more subscribers
|
||||
isDelayed
|
||||
? refCountDelay() // Unsubscribe after delay
|
||||
: refCount()
|
||||
);
|
||||
};
|
||||
|
||||
// We voluntarily don't cache the "one-shot" RPC calls. For example,
|
||||
// `getStorage('123')` returns the current value, but this value can change
|
||||
// over time, so we wouldn't want to cache the Observable.
|
||||
return this._createMethodWithRaw(creator);
|
||||
memoized = memoizee(this._createMethodWithRaw(creator), {
|
||||
length: false,
|
||||
normalizer: JSON.stringify
|
||||
});
|
||||
|
||||
return memoized;
|
||||
}
|
||||
|
||||
// create a subscriptor, it subscribes once and resolves with the id as subscribe
|
||||
@@ -253,6 +281,7 @@ export default class Rpc implements RpcInterface {
|
||||
return new Observable((observer: Observer<any>): VoidCallback => {
|
||||
// Have at least an empty promise, as used in the unsubscribe
|
||||
let subscriptionPromise: Promise<number | string | null> = Promise.resolve(null);
|
||||
const registry = this.#registryDefault;
|
||||
|
||||
const errorHandler = (error: Error): void => {
|
||||
logErrorMessage(method, def, error);
|
||||
@@ -261,7 +290,7 @@ export default class Rpc implements RpcInterface {
|
||||
};
|
||||
|
||||
try {
|
||||
const params = this._formatInputs(def, values);
|
||||
const params = this._formatInputs(registry, def, values);
|
||||
const paramsJson = params.map((param): AnyJson => param.toJSON());
|
||||
|
||||
const update = (error?: Error | null, result?: any): void => {
|
||||
@@ -274,8 +303,8 @@ export default class Rpc implements RpcInterface {
|
||||
try {
|
||||
observer.next(
|
||||
isRaw
|
||||
? this.registry.createType('Raw', result)
|
||||
: this._formatOutput(method, def, params, result)
|
||||
? registry.createType('Raw', result)
|
||||
: this._formatOutput(registry, method, def, params, result)
|
||||
);
|
||||
} catch (error) {
|
||||
observer.error(error);
|
||||
@@ -289,16 +318,8 @@ export default class Rpc implements RpcInterface {
|
||||
|
||||
// Teardown logic
|
||||
return (): void => {
|
||||
// Delete from cache
|
||||
// Reason:
|
||||
// ```
|
||||
// const s = api.query.system.account(addr1).subscribe(); // let's say it's 6
|
||||
// s.unsubscribe();
|
||||
// // wait a bit, for the nonce to increase to 7
|
||||
// api.query.system.account(addr1).subscribe(); // will output 6 instead of 7 if we don't clear cache
|
||||
// // that's because all our observables are replay(1)
|
||||
// ```
|
||||
memoized && memoized.delete(...values);
|
||||
// Delete from cache, so old results don't hang around
|
||||
memoized?.delete(...values);
|
||||
|
||||
// Unsubscribe from provider
|
||||
subscriptionPromise
|
||||
@@ -325,7 +346,7 @@ export default class Rpc implements RpcInterface {
|
||||
return memoized;
|
||||
}
|
||||
|
||||
private _formatInputs (def: DefinitionRpc, inputs: any[]): Codec[] {
|
||||
private _formatInputs (registry: Registry, def: DefinitionRpc, inputs: any[]): Codec[] {
|
||||
const reqArgCount = def.params.filter(({ isOptional }): boolean => !isOptional).length;
|
||||
const optText = reqArgCount === def.params.length
|
||||
? ''
|
||||
@@ -334,7 +355,7 @@ export default class Rpc implements RpcInterface {
|
||||
assert(inputs.length >= reqArgCount && inputs.length <= def.params.length, `Expected ${def.params.length} parameters${optText}, ${inputs.length} found instead`);
|
||||
|
||||
return inputs.map((input, index): Codec =>
|
||||
createTypeUnsafe(this.registry, def.params[index].type, [input])
|
||||
createTypeUnsafe(registry, def.params[index].type, [input])
|
||||
);
|
||||
}
|
||||
|
||||
@@ -344,12 +365,12 @@ export default class Rpc implements RpcInterface {
|
||||
return ['0x3a636f6465'].includes(key.toHex());
|
||||
}
|
||||
|
||||
private _formatOutput (method: string, rpc: DefinitionRpc, params: Codec[], result?: any): Codec | Codec[] {
|
||||
private _formatOutput (registry: Registry, method: string, rpc: DefinitionRpc, params: Codec[], result?: any): Codec | Codec[] {
|
||||
if (rpc.type === 'StorageData') {
|
||||
const key = params[0] as StorageKey;
|
||||
|
||||
try {
|
||||
return this._formatStorageData(key, result);
|
||||
return this._formatStorageData(registry, key, result);
|
||||
} catch (error) {
|
||||
console.error(`Unable to decode storage ${key.section || 'unknown'}.${key.method || 'unknown'}:`, (error as Error).message);
|
||||
|
||||
@@ -359,12 +380,12 @@ export default class Rpc implements RpcInterface {
|
||||
const keys = params[0] as Vec<StorageKey>;
|
||||
|
||||
return keys
|
||||
? this._formatStorageSet(keys, (result as StorageChangeSetJSON).changes)
|
||||
: this.registry.createType('StorageChangeSet', result);
|
||||
? this._formatStorageSet(registry, keys, (result as StorageChangeSetJSON).changes)
|
||||
: registry.createType('StorageChangeSet', result);
|
||||
} else if (rpc.type === 'Vec<StorageChangeSet>') {
|
||||
const mapped = (result as StorageChangeSetJSON[]).map(({ block, changes }): [Hash, Codec[]] => [
|
||||
this.registry.createType('Hash', block),
|
||||
this._formatStorageSet(params[0] as Vec<StorageKey>, changes)
|
||||
registry.createType('Hash', block),
|
||||
this._formatStorageSet(registry, params[0] as Vec<StorageKey>, changes)
|
||||
]);
|
||||
|
||||
// we only query at a specific block, not a range - flatten
|
||||
@@ -373,10 +394,10 @@ export default class Rpc implements RpcInterface {
|
||||
: mapped as unknown as Codec[];
|
||||
}
|
||||
|
||||
return createTypeUnsafe(this.registry, rpc.type, [result]);
|
||||
return createTypeUnsafe(registry, rpc.type, [result]);
|
||||
}
|
||||
|
||||
private _formatStorageData (key: StorageKey, value: string | null): Codec {
|
||||
private _formatStorageData (registry: Registry, key: StorageKey, value: string | null): Codec {
|
||||
// single return value (via state.getStorage), decode the value based on the
|
||||
// outputType that we have specified. Fallback to Raw on nothing
|
||||
const type = key.outputType || 'Raw';
|
||||
@@ -393,15 +414,15 @@ export default class Rpc implements RpcInterface {
|
||||
|
||||
if (meta.modifier.isOptional) {
|
||||
return new Option(
|
||||
this.registry,
|
||||
createClass(this.registry, type),
|
||||
registry,
|
||||
createClass(registry, type),
|
||||
isEmpty
|
||||
? null
|
||||
: createTypeUnsafe(this.registry, type, [input], true)
|
||||
: createTypeUnsafe(registry, type, [input], true)
|
||||
);
|
||||
}
|
||||
|
||||
return createTypeUnsafe(this.registry, type, [
|
||||
return createTypeUnsafe(registry, type, [
|
||||
isEmpty
|
||||
? meta.fallback
|
||||
? hexToU8a(meta.fallback.toHex())
|
||||
@@ -410,7 +431,7 @@ export default class Rpc implements RpcInterface {
|
||||
], true);
|
||||
}
|
||||
|
||||
private _formatStorageSet (keys: Vec<StorageKey>, changes: [string, string | null][]): Codec[] {
|
||||
private _formatStorageSet (registry: Registry, keys: Vec<StorageKey>, changes: [string, string | null][]): Codec[] {
|
||||
// For StorageChangeSet, the changes has the [key, value] mappings
|
||||
const withCache = keys.length !== 1;
|
||||
|
||||
@@ -420,7 +441,7 @@ export default class Rpc implements RpcInterface {
|
||||
// - null - The storage key is empty
|
||||
return keys.reduce((results: Codec[], key: StorageKey): Codec[] => {
|
||||
try {
|
||||
results.push(this._formatStorageSetEntry(key, changes, withCache));
|
||||
results.push(this._formatStorageSetEntry(registry, key, changes, withCache));
|
||||
} catch (error) {
|
||||
console.error(`Unable to decode storage ${key.section || 'unknown'}.${key.method || 'unknown'}:`, (error as Error).message);
|
||||
|
||||
@@ -431,7 +452,7 @@ export default class Rpc implements RpcInterface {
|
||||
}, []);
|
||||
}
|
||||
|
||||
private _formatStorageSetEntry (key: StorageKey, changes: [string, string | null][], witCache: boolean): Codec {
|
||||
private _formatStorageSetEntry (registry: Registry, key: StorageKey, changes: [string, string | null][], witCache: boolean): Codec {
|
||||
// Fallback to Raw (i.e. just the encoding) if we don't have a specific type
|
||||
const type = key.outputType || 'Raw';
|
||||
const hexKey = key.toHex();
|
||||
@@ -457,15 +478,15 @@ export default class Rpc implements RpcInterface {
|
||||
|
||||
if (meta.modifier.isOptional) {
|
||||
return new Option(
|
||||
this.registry,
|
||||
createClass(this.registry, type),
|
||||
registry,
|
||||
createClass(registry, type),
|
||||
isEmpty
|
||||
? null
|
||||
: createTypeUnsafe(this.registry, type, [input], true)
|
||||
: createTypeUnsafe(registry, type, [input], true)
|
||||
);
|
||||
}
|
||||
|
||||
return createTypeUnsafe(this.registry, type, [
|
||||
return createTypeUnsafe(registry, type, [
|
||||
isEmpty
|
||||
? meta.fallback
|
||||
? hexToU8a(meta.fallback.toHex())
|
||||
|
||||
@@ -12,6 +12,7 @@ import { refCountDelay } from './refCountDelay';
|
||||
export type DrrResult = <T> (source$: Observable<T>) => Observable<T>;
|
||||
|
||||
interface Options {
|
||||
delay?: number;
|
||||
skipChange?: boolean;
|
||||
skipTimeout?: boolean;
|
||||
}
|
||||
@@ -35,7 +36,7 @@ const NOOP = (): void => undefined;
|
||||
* @ignore
|
||||
* @internal
|
||||
*/
|
||||
export const drr = ({ skipChange = false, skipTimeout = false }: Options = {}): DrrResult => <T> (source$: Observable<T>): Observable<T> =>
|
||||
export const drr = ({ delay, skipChange = false, skipTimeout = false }: Options = {}): DrrResult => <T> (source$: Observable<T>): Observable<T> =>
|
||||
source$.pipe(
|
||||
catchError(ERR),
|
||||
skipChange
|
||||
@@ -44,5 +45,5 @@ export const drr = ({ skipChange = false, skipTimeout = false }: Options = {}):
|
||||
publishReplay(1),
|
||||
skipTimeout
|
||||
? refCount()
|
||||
: refCountDelay()
|
||||
: refCountDelay(delay)
|
||||
);
|
||||
|
||||
@@ -4,45 +4,40 @@
|
||||
|
||||
import { asapScheduler, ConnectableObservable, MonoTypeOperatorFunction, Observable, Subscription, TeardownLogic } from 'rxjs';
|
||||
|
||||
const DELAY = 1750;
|
||||
|
||||
/** @internal */
|
||||
function refCountDelayInner <T> (source: Observable<T>): Observable<T> {
|
||||
// state: 0 = disconnected, 1 = disconnecting, 2 = connecting, 3 = connected
|
||||
let [state, refCount, connection, scheduler] = [0, 0, Subscription.EMPTY, Subscription.EMPTY];
|
||||
export function refCountDelay <T> (delay = 1750): MonoTypeOperatorFunction<T> {
|
||||
return (source: Observable<T>): Observable<T> => {
|
||||
// state: 0 = disconnected, 1 = disconnecting, 2 = connecting, 3 = connected
|
||||
let [state, refCount, connection, scheduler] = [0, 0, Subscription.EMPTY, Subscription.EMPTY];
|
||||
|
||||
return new Observable((ob): TeardownLogic => {
|
||||
source.subscribe(ob);
|
||||
return new Observable((ob): TeardownLogic => {
|
||||
source.subscribe(ob);
|
||||
|
||||
if (refCount++ === 0) {
|
||||
if (state === 1) {
|
||||
scheduler.unsubscribe();
|
||||
} else {
|
||||
connection = (source as ConnectableObservable<T>).connect();
|
||||
}
|
||||
|
||||
state = 3;
|
||||
}
|
||||
|
||||
return (): void => {
|
||||
if (--refCount === 0) {
|
||||
if (state === 2) {
|
||||
state = 0;
|
||||
if (refCount++ === 0) {
|
||||
if (state === 1) {
|
||||
scheduler.unsubscribe();
|
||||
} else {
|
||||
// state === 3
|
||||
state = 1;
|
||||
scheduler = asapScheduler.schedule((): void => {
|
||||
state = 0;
|
||||
connection.unsubscribe();
|
||||
}, DELAY);
|
||||
connection = (source as ConnectableObservable<T>).connect();
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function refCountDelay <T> (): MonoTypeOperatorFunction<T> {
|
||||
return refCountDelayInner;
|
||||
state = 3;
|
||||
}
|
||||
|
||||
return (): void => {
|
||||
if (--refCount === 0) {
|
||||
if (state === 2) {
|
||||
state = 0;
|
||||
scheduler.unsubscribe();
|
||||
} else {
|
||||
// state === 3
|
||||
state = 1;
|
||||
scheduler = asapScheduler.schedule((): void => {
|
||||
state = 0;
|
||||
connection.unsubscribe();
|
||||
}, delay);
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/rpc-provider",
|
||||
"version": "1.27.1",
|
||||
"version": "1.31.1",
|
||||
"description": "Transport providers for the API",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
@@ -26,19 +26,19 @@
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/rpc-provider#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.11.0",
|
||||
"@polkadot/metadata": "1.27.1",
|
||||
"@polkadot/types": "1.27.1",
|
||||
"@polkadot/util": "^3.0.1",
|
||||
"@polkadot/util-crypto": "^3.0.1",
|
||||
"bn.js": "^5.1.2",
|
||||
"eventemitter3": "^4.0.4",
|
||||
"@babel/runtime": "^7.11.2",
|
||||
"@polkadot/metadata": "1.31.1",
|
||||
"@polkadot/types": "1.31.1",
|
||||
"@polkadot/util": "^3.4.1",
|
||||
"@polkadot/util-crypto": "^3.4.1",
|
||||
"bn.js": "^5.1.3",
|
||||
"eventemitter3": "^4.0.6",
|
||||
"isomorphic-fetch": "^2.2.1",
|
||||
"websocket": "^1.0.31"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^3.0.1",
|
||||
"@polkadot/keyring": "^3.4.1",
|
||||
"mock-socket": "^9.0.3",
|
||||
"nock": "^13.0.3"
|
||||
"nock": "^13.0.4"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/typegen",
|
||||
"version": "1.27.1",
|
||||
"version": "1.31.1",
|
||||
"description": "Type generation scripts",
|
||||
"main": "index.js",
|
||||
"bin": {
|
||||
@@ -33,14 +33,14 @@
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/typegen#readme",
|
||||
"dependencies": {
|
||||
"@babel/core": "^7.11.0",
|
||||
"@babel/core": "^7.11.4",
|
||||
"@babel/register": "^7.10.5",
|
||||
"@babel/runtime": "^7.11.0",
|
||||
"@polkadot/api": "1.27.1",
|
||||
"@polkadot/metadata": "1.27.1",
|
||||
"@polkadot/rpc-provider": "1.27.1",
|
||||
"@polkadot/types": "1.27.1",
|
||||
"@polkadot/util": "^3.0.1",
|
||||
"@babel/runtime": "^7.11.2",
|
||||
"@polkadot/api": "1.31.1",
|
||||
"@polkadot/metadata": "1.31.1",
|
||||
"@polkadot/rpc-provider": "1.31.1",
|
||||
"@polkadot/types": "1.31.1",
|
||||
"@polkadot/util": "^3.4.1",
|
||||
"handlebars": "^4.7.6",
|
||||
"websocket": "^1.0.31",
|
||||
"yargs": "^15.4.1"
|
||||
|
||||
@@ -16,7 +16,7 @@ import Vec from '@polkadot/types/codec/Vec';
|
||||
import Tuple from '@polkadot/types/codec/Tuple';
|
||||
import { AllConvictions } from '@polkadot/types/interfaces/democracy/definitions';
|
||||
import GenericAccountId from '@polkadot/types/generic/AccountId';
|
||||
import GenericAddress from '@polkadot/types/generic/Address';
|
||||
import GenericLookupSource from '@polkadot/types/generic/LookupSource';
|
||||
import Vote from '@polkadot/types/generic/Vote';
|
||||
import Null from '@polkadot/types/primitive/Null';
|
||||
import * as primitiveClasses from '@polkadot/types/primitive';
|
||||
@@ -122,8 +122,8 @@ export function getSimilarTypes (definitions: Record<string, ModuleTypes>, regis
|
||||
possibleTypes.push('Uint8Array');
|
||||
} else if (isChildClass(AbstractInt as unknown as Constructor<UInt>, Clazz) || isChildClass(Compact, Clazz)) {
|
||||
possibleTypes.push('AnyNumber', 'Uint8Array');
|
||||
} else if (isChildClass(GenericAddress, Clazz)) {
|
||||
possibleTypes.push('Address', 'AccountId', 'AccountIndex', 'string', 'Uint8Array');
|
||||
} else if (isChildClass(GenericLookupSource, Clazz)) {
|
||||
possibleTypes.push('Address', 'AccountId', 'AccountIndex', 'LookupSource', 'string', 'Uint8Array');
|
||||
} else if (isChildClass(GenericAccountId, Clazz)) {
|
||||
possibleTypes.push('string', 'Uint8Array');
|
||||
} else if (isChildClass(registry.createClass('bool'), Clazz)) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/types-known",
|
||||
"version": "1.27.1",
|
||||
"version": "1.31.1",
|
||||
"description": "A JavaScript wrapper for the Polkadot JsonRPC interface",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
@@ -26,10 +26,10 @@
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/types-known#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.11.0",
|
||||
"@polkadot/types": "1.27.1",
|
||||
"@polkadot/util": "^3.0.1",
|
||||
"bn.js": "^5.1.2"
|
||||
"@babel/runtime": "^7.11.2",
|
||||
"@polkadot/types": "1.31.1",
|
||||
"@polkadot/util": "^3.4.1",
|
||||
"bn.js": "^5.1.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/bn.js": "^4.11.6"
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import type BN from 'bn.js';
|
||||
import { DefinitionRpc, DefinitionRpcSub, Registry, RegistryTypes, OverrideModuleType, OverrideVersionedType } from '@polkadot/types/types';
|
||||
import { Hash } from '@polkadot/types/interfaces';
|
||||
import { ChainUpgradeVersion, DefinitionRpc, DefinitionRpcSub, Registry, RegistryTypes, OverrideModuleType, OverrideVersionedType } from '@polkadot/types/types';
|
||||
|
||||
import { Text } from '@polkadot/types';
|
||||
import { bnToBn, isUndefined } from '@polkadot/util';
|
||||
@@ -12,6 +13,7 @@ import typesChain from './chain';
|
||||
import typesMeta from './metadata';
|
||||
import typesModules from './modules';
|
||||
import typesSpec from './spec';
|
||||
import upgrades from './upgrades';
|
||||
import warnings from './warnings';
|
||||
|
||||
// flatten a VersionedType[] into a Record<string, string>
|
||||
@@ -91,3 +93,21 @@ export function getSpecAlias ({ knownTypes }: Registry, chainName: Text | string
|
||||
...(knownTypes.typesBundle?.chain?.[_chainName]?.alias || {})
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns a version record for known chains where upgrades are being tracked
|
||||
*/
|
||||
export function getUpgradeVersion (genesisHash: Hash, blockNumber: BN): [ChainUpgradeVersion | undefined, ChainUpgradeVersion | undefined] {
|
||||
const known = upgrades.find((u) => genesisHash.eq(u.genesisHash));
|
||||
|
||||
return known
|
||||
? [
|
||||
known.versions.reduce((last: ChainUpgradeVersion | undefined, version): ChainUpgradeVersion | undefined => {
|
||||
return blockNumber.gt(version.blockNumber)
|
||||
? version
|
||||
: last;
|
||||
}, undefined),
|
||||
known.versions.find((version) => blockNumber.lte(version.blockNumber))
|
||||
]
|
||||
: [undefined, undefined];
|
||||
}
|
||||
|
||||
@@ -29,6 +29,12 @@ const typesModules: Record<string, OverrideModuleType> = {
|
||||
parachains: {
|
||||
Id: 'ParaId'
|
||||
},
|
||||
proposeParachain: {
|
||||
Proposal: 'ParachainProposal'
|
||||
},
|
||||
proxy: {
|
||||
Announcement: 'ProxyAnnouncement'
|
||||
},
|
||||
society: {
|
||||
Judgement: 'SocietyJudgement',
|
||||
Vote: 'SocietyVote'
|
||||
|
||||
@@ -5,28 +5,46 @@
|
||||
import { OverrideVersionedType } from '@polkadot/types/types';
|
||||
|
||||
const sharedTypes = {
|
||||
Address: 'GenericAddress',
|
||||
LookupSource: 'GenericAddress',
|
||||
Address: 'LookupSource',
|
||||
AnchorData: {
|
||||
anchoredBlock: 'u64',
|
||||
docRoot: 'H256',
|
||||
id: 'H256'
|
||||
},
|
||||
Fee: {
|
||||
key: 'Hash',
|
||||
price: 'Balance'
|
||||
},
|
||||
MultiAccountData: {
|
||||
deposit: 'Balance',
|
||||
depositor: 'AccountId',
|
||||
signatories: 'Vec<AccountId>',
|
||||
threshold: 'u16'
|
||||
},
|
||||
Multiplier: 'Fixed64',
|
||||
PreCommitData: {
|
||||
expirationBlock: 'u64',
|
||||
identity: 'H256',
|
||||
signingRoot: 'H256'
|
||||
},
|
||||
Proof: {
|
||||
leafHash: 'H256',
|
||||
sortedHashes: 'H256'
|
||||
},
|
||||
ReferendumInfo: 'ReferendumInfoTo239',
|
||||
StakingLedger: 'StakingLedgerTo240',
|
||||
Weight: 'u32'
|
||||
};
|
||||
|
||||
const versioned: OverrideVersionedType[] = [
|
||||
{
|
||||
// most chains started at 1000 (Fulvous at 224)
|
||||
minmax: [1, 228],
|
||||
types: {
|
||||
...sharedTypes,
|
||||
Address: 'AccountId',
|
||||
LookupSource: 'AccountId'
|
||||
}
|
||||
},
|
||||
{
|
||||
minmax: [229, undefined],
|
||||
types: {
|
||||
...sharedTypes
|
||||
...sharedTypes,
|
||||
ChainId: 'u8',
|
||||
DepositNonce: 'u64',
|
||||
ResourceId: '[u8; 32]',
|
||||
'chainbridge::ChainId': 'u8'
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
@@ -18,15 +18,16 @@ const versioned: OverrideVersionedType[] = [
|
||||
// 1020 is first CC3
|
||||
minmax: [1019, 1031],
|
||||
types: {
|
||||
Address: 'GenericAddress',
|
||||
Address: 'LookupSource',
|
||||
BalanceLock: 'BalanceLockTo212',
|
||||
CompactAssignments: 'CompactAssignmentsTo257',
|
||||
DispatchError: 'DispatchErrorTo198',
|
||||
DispatchInfo: 'DispatchInfoTo244',
|
||||
Keys: 'SessionKeys5',
|
||||
LookupSource: 'Address',
|
||||
Multiplier: 'Fixed64',
|
||||
OpenTip: 'OpenTipTo225',
|
||||
ReferendumInfo: 'ReferendumInfoTo239',
|
||||
RewardDestination: 'RewardDestinationTo257',
|
||||
SlashingSpans: 'SlashingSpansTo204',
|
||||
StakingLedger: 'StakingLedgerTo223',
|
||||
Votes: 'VotesTo230',
|
||||
@@ -36,14 +37,15 @@ const versioned: OverrideVersionedType[] = [
|
||||
{
|
||||
minmax: [1032, 1042],
|
||||
types: {
|
||||
Address: 'GenericAddress',
|
||||
Address: 'LookupSource',
|
||||
BalanceLock: 'BalanceLockTo212',
|
||||
CompactAssignments: 'CompactAssignmentsTo257',
|
||||
DispatchInfo: 'DispatchInfoTo244',
|
||||
Keys: 'SessionKeys5',
|
||||
LookupSource: 'Address',
|
||||
Multiplier: 'Fixed64',
|
||||
OpenTip: 'OpenTipTo225',
|
||||
ReferendumInfo: 'ReferendumInfoTo239',
|
||||
RewardDestination: 'RewardDestinationTo257',
|
||||
SlashingSpans: 'SlashingSpansTo204',
|
||||
StakingLedger: 'StakingLedgerTo223',
|
||||
Votes: 'VotesTo230',
|
||||
@@ -54,14 +56,15 @@ const versioned: OverrideVersionedType[] = [
|
||||
// actual at 1045 (1043-1044 is dev)
|
||||
minmax: [1043, 1045],
|
||||
types: {
|
||||
Address: 'GenericAddress',
|
||||
Address: 'LookupSource',
|
||||
BalanceLock: 'BalanceLockTo212',
|
||||
CompactAssignments: 'CompactAssignmentsTo257',
|
||||
DispatchInfo: 'DispatchInfoTo244',
|
||||
Keys: 'SessionKeys5',
|
||||
LookupSource: 'Address',
|
||||
Multiplier: 'Fixed64',
|
||||
OpenTip: 'OpenTipTo225',
|
||||
ReferendumInfo: 'ReferendumInfoTo239',
|
||||
RewardDestination: 'RewardDestinationTo257',
|
||||
StakingLedger: 'StakingLedgerTo223',
|
||||
Votes: 'VotesTo230',
|
||||
Weight: 'u32'
|
||||
@@ -72,10 +75,12 @@ const versioned: OverrideVersionedType[] = [
|
||||
types: {
|
||||
// Indices optional, not in transaction
|
||||
...sharedTypes,
|
||||
CompactAssignments: 'CompactAssignmentsTo257',
|
||||
DispatchInfo: 'DispatchInfoTo244',
|
||||
Multiplier: 'Fixed64',
|
||||
OpenTip: 'OpenTipTo225',
|
||||
ReferendumInfo: 'ReferendumInfoTo239',
|
||||
RewardDestination: 'RewardDestinationTo257',
|
||||
StakingLedger: 'StakingLedgerTo240',
|
||||
Weight: 'u32'
|
||||
}
|
||||
@@ -84,9 +89,11 @@ const versioned: OverrideVersionedType[] = [
|
||||
minmax: [1055, 1056],
|
||||
types: {
|
||||
...sharedTypes,
|
||||
CompactAssignments: 'CompactAssignmentsTo257',
|
||||
DispatchInfo: 'DispatchInfoTo244',
|
||||
Multiplier: 'Fixed64',
|
||||
OpenTip: 'OpenTipTo225',
|
||||
RewardDestination: 'RewardDestinationTo257',
|
||||
StakingLedger: 'StakingLedgerTo240',
|
||||
Weight: 'u32'
|
||||
}
|
||||
@@ -95,19 +102,31 @@ const versioned: OverrideVersionedType[] = [
|
||||
minmax: [1057, 1061],
|
||||
types: {
|
||||
...sharedTypes,
|
||||
CompactAssignments: 'CompactAssignmentsTo257',
|
||||
DispatchInfo: 'DispatchInfoTo244',
|
||||
OpenTip: 'OpenTipTo225'
|
||||
OpenTip: 'OpenTipTo225',
|
||||
RewardDestination: 'RewardDestinationTo257'
|
||||
}
|
||||
},
|
||||
{
|
||||
minmax: [1062, 2012],
|
||||
types: {
|
||||
...sharedTypes,
|
||||
OpenTip: 'OpenTipTo225'
|
||||
CompactAssignments: 'CompactAssignmentsTo257',
|
||||
OpenTip: 'OpenTipTo225',
|
||||
RewardDestination: 'RewardDestinationTo257'
|
||||
}
|
||||
},
|
||||
{
|
||||
minmax: [2013, undefined],
|
||||
minmax: [2013, 2022],
|
||||
types: {
|
||||
...sharedTypes,
|
||||
CompactAssignments: 'CompactAssignmentsTo257',
|
||||
RewardDestination: 'RewardDestinationTo257'
|
||||
}
|
||||
},
|
||||
{
|
||||
minmax: [2023, undefined],
|
||||
types: {
|
||||
...sharedTypes
|
||||
}
|
||||
|
||||
@@ -9,7 +9,8 @@ const sharedTypes = {
|
||||
Keys: 'SessionKeys5',
|
||||
LookupSource: 'AccountId',
|
||||
ProxyType: {
|
||||
_enum: ['Any', 'NonTransfer', 'Governance', 'Staking', 'SudoBalances', 'IdentityJudgement']
|
||||
// was: SudoBalances
|
||||
_enum: ['Any', 'NonTransfer', 'Governance', 'Staking', 'Unused', 'IdentityJudgement']
|
||||
}
|
||||
};
|
||||
|
||||
@@ -19,11 +20,21 @@ const versioned: OverrideVersionedType[] = [
|
||||
minmax: [0, 12],
|
||||
types: {
|
||||
...sharedTypes,
|
||||
OpenTip: 'OpenTipTo225'
|
||||
CompactAssignments: 'CompactAssignmentsTo257',
|
||||
OpenTip: 'OpenTipTo225',
|
||||
RewardDestination: 'RewardDestinationTo257'
|
||||
}
|
||||
},
|
||||
{
|
||||
minmax: [13, undefined],
|
||||
minmax: [13, 22],
|
||||
types: {
|
||||
...sharedTypes,
|
||||
CompactAssignments: 'CompactAssignmentsTo257',
|
||||
RewardDestination: 'RewardDestinationTo257'
|
||||
}
|
||||
},
|
||||
{
|
||||
minmax: [23, undefined],
|
||||
types: {
|
||||
...sharedTypes
|
||||
}
|
||||
|
||||
@@ -7,14 +7,16 @@ import { OverrideVersionedType } from '@polkadot/types/types';
|
||||
const sharedTypes = {
|
||||
Address: 'AccountId',
|
||||
Keys: 'SessionKeys5',
|
||||
LookupSource: 'AccountId'
|
||||
LookupSource: 'AccountId',
|
||||
RewardDestination: 'RewardDestinationTo257'
|
||||
};
|
||||
|
||||
const versioned: OverrideVersionedType[] = [
|
||||
{
|
||||
minmax: [0, undefined],
|
||||
types: {
|
||||
...sharedTypes
|
||||
...sharedTypes,
|
||||
CompactAssignments: 'CompactAssignmentsTo257'
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
@@ -9,7 +9,8 @@ const sharedTypes = {
|
||||
Keys: 'SessionKeys5',
|
||||
LookupSource: 'AccountId',
|
||||
ProxyType: {
|
||||
_enum: ['Any', 'NonTransfer', 'Staking', 'SudoBalances', 'IdentityJudgement']
|
||||
// was: SudoBalances
|
||||
_enum: ['Any', 'NonTransfer', 'Staking', 'Unused', 'IdentityJudgement']
|
||||
}
|
||||
};
|
||||
|
||||
@@ -18,8 +19,10 @@ const versioned: OverrideVersionedType[] = [
|
||||
minmax: [1, 2],
|
||||
types: {
|
||||
...sharedTypes,
|
||||
CompactAssignments: 'CompactAssignmentsTo257',
|
||||
Multiplier: 'Fixed64',
|
||||
OpenTip: 'OpenTipTo225',
|
||||
RewardDestination: 'RewardDestinationTo257',
|
||||
Weight: 'u32'
|
||||
}
|
||||
},
|
||||
@@ -27,11 +30,21 @@ const versioned: OverrideVersionedType[] = [
|
||||
minmax: [3, 22],
|
||||
types: {
|
||||
...sharedTypes,
|
||||
OpenTip: 'OpenTipTo225'
|
||||
CompactAssignments: 'CompactAssignmentsTo257',
|
||||
OpenTip: 'OpenTipTo225',
|
||||
RewardDestination: 'RewardDestinationTo257'
|
||||
}
|
||||
},
|
||||
{
|
||||
minmax: [23, undefined],
|
||||
minmax: [23, 42],
|
||||
types: {
|
||||
...sharedTypes,
|
||||
CompactAssignments: 'CompactAssignmentsTo257',
|
||||
RewardDestination: 'RewardDestinationTo257'
|
||||
}
|
||||
},
|
||||
{
|
||||
minmax: [43, undefined],
|
||||
types: {
|
||||
...sharedTypes
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
// Copyright 2017-2020 @polkadot/types-known authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { ChainUpgrades } from '@polkadot/types/types';
|
||||
|
||||
import kusama from './kusama';
|
||||
import polkadot from './polkadot';
|
||||
import westend from './westend';
|
||||
|
||||
// Type overrides for specific spec types & versions as given in runtimeVersion
|
||||
const upgrades: ChainUpgrades[] = [
|
||||
kusama,
|
||||
polkadot,
|
||||
westend
|
||||
];
|
||||
|
||||
export default upgrades;
|
||||
@@ -0,0 +1,26 @@
|
||||
// Copyright 2017-2020 @polkadot/types-known authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { ChainUpgrades } from '@polkadot/types/types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { hexToU8a } from '@polkadot/util';
|
||||
|
||||
const upgrades: ChainUpgrades = {
|
||||
genesisHash: hexToU8a('0xb0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe'),
|
||||
versions: [
|
||||
[0, 1020], [26669, 1021], [38245, 1022], [54248, 1023], [59659, 1024],
|
||||
[67651, 1025], [82191, 1027], [83238, 1028], [101503, 1029], [203466, 1030],
|
||||
[295787, 1031], [461692, 1032], [504329, 1033], [569327, 1038], [587687, 1039],
|
||||
[653183, 1040], [693488, 1042], [901442, 1045], [1375086, 1050], [1445458, 1051],
|
||||
[1472960, 1052], [1475648, 1053], [1491596, 1054], [1574408, 1055], [2064961, 1058],
|
||||
[2201991, 1062], [2671528, 2005], [2704202, 2007], [2728002, 2008], [2832534, 2011],
|
||||
[2962294, 2012], [3240000, 2013], [3274408, 2015], [3323565, 2019], [3534175, 2022]
|
||||
].map(([blockNumber, specVersion]) => ({
|
||||
blockNumber: new BN(blockNumber),
|
||||
specVersion: new BN(specVersion)
|
||||
}))
|
||||
};
|
||||
|
||||
export default upgrades;
|
||||
@@ -0,0 +1,23 @@
|
||||
// Copyright 2017-2020 @polkadot/types-known authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { ChainUpgrades } from '@polkadot/types/types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { hexToU8a } from '@polkadot/util';
|
||||
|
||||
const upgrades: ChainUpgrades = {
|
||||
genesisHash: hexToU8a('0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3'),
|
||||
versions: [
|
||||
[0, 0], [29231, 1], [188836, 5], [199405, 6], [214264, 7],
|
||||
[244358, 8], [303079, 9], [314201, 10], [342400, 11], [443963, 12],
|
||||
[528470, 13], [687751, 14], [746085, 15], [787923, 16], [799302, 17],
|
||||
[1205128, 18]
|
||||
].map(([blockNumber, specVersion]) => ({
|
||||
blockNumber: new BN(blockNumber),
|
||||
specVersion: new BN(specVersion)
|
||||
}))
|
||||
};
|
||||
|
||||
export default upgrades;
|
||||
@@ -0,0 +1,23 @@
|
||||
// Copyright 2017-2020 @polkadot/types-known authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { ChainUpgrades } from '@polkadot/types/types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { hexToU8a } from '@polkadot/util';
|
||||
|
||||
const upgrades: ChainUpgrades = {
|
||||
genesisHash: hexToU8a('0xe143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e'),
|
||||
versions: [
|
||||
[214356, 4], [392764, 7], [409740, 8], [809976, 20], [877581, 24],
|
||||
[879238, 25], [889472, 26], [902937, 27], [932751, 28], [991142, 29],
|
||||
[1030162, 31], [1119657, 32], [1199282, 33], [1342534, 34], [1392263, 35],
|
||||
[1431703, 36], [1433369, 37], [1490972, 41]
|
||||
].map(([blockNumber, specVersion]) => ({
|
||||
blockNumber: new BN(blockNumber),
|
||||
specVersion: new BN(specVersion)
|
||||
}))
|
||||
};
|
||||
|
||||
export default upgrades;
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/types",
|
||||
"version": "1.27.1",
|
||||
"version": "1.31.1",
|
||||
"description": "Implementation of the Parity codec",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
@@ -26,17 +26,17 @@
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/types#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.11.0",
|
||||
"@polkadot/metadata": "1.27.1",
|
||||
"@polkadot/util": "^3.0.1",
|
||||
"@polkadot/util-crypto": "^3.0.1",
|
||||
"@babel/runtime": "^7.11.2",
|
||||
"@polkadot/metadata": "1.31.1",
|
||||
"@polkadot/util": "^3.4.1",
|
||||
"@polkadot/util-crypto": "^3.4.1",
|
||||
"@types/bn.js": "^4.11.6",
|
||||
"bn.js": "^5.1.2",
|
||||
"bn.js": "^5.1.3",
|
||||
"memoizee": "^0.4.14",
|
||||
"rxjs": "^6.6.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^3.0.1",
|
||||
"@polkadot/keyring": "^3.4.1",
|
||||
"@types/memoizee": "^0.4.4"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import { AliveContractInfo, CodeHash, ContractCallRequest, ContractExecResult, C
|
||||
import { AccountVote, AccountVoteSplit, AccountVoteStandard, Conviction, Delegations, PreimageStatus, PreimageStatusAvailable, PriorLock, PropIndex, Proposal, ProxyState, ReferendumIndex, ReferendumInfo, ReferendumInfoFinished, ReferendumInfoTo239, ReferendumStatus, Tally, Voting, VotingDelegating, VotingDirect, VotingDirectVote } from '@polkadot/types/interfaces/democracy';
|
||||
import { ApprovalFlag, DefunctVoter, Renouncing, SetIndex, Vote, VoteIndex, VoteThreshold, VoterInfo } from '@polkadot/types/interfaces/elections';
|
||||
import { CreatedBlock, ImportedAux } from '@polkadot/types/interfaces/engine';
|
||||
import { EthereumAccountId, EthereumLookupSource } from '@polkadot/types/interfaces/ethereum';
|
||||
import { Account, Log, Vicinity } from '@polkadot/types/interfaces/evm';
|
||||
import { EcdsaSignature, Ed25519Signature, Extrinsic, ExtrinsicEra, ExtrinsicPayload, ExtrinsicPayloadUnknown, ExtrinsicPayloadV1, ExtrinsicPayloadV2, ExtrinsicPayloadV3, ExtrinsicPayloadV4, ExtrinsicSignatureV1, ExtrinsicSignatureV2, ExtrinsicSignatureV3, ExtrinsicSignatureV4, ExtrinsicUnknown, ExtrinsicV1, ExtrinsicV2, ExtrinsicV3, ExtrinsicV4, ImmortalEra, MortalEra, MultiSignature, Signature, SignerPayload, Sr25519Signature } from '@polkadot/types/interfaces/extrinsics';
|
||||
import { AssetOptions, Owner, PermissionLatest, PermissionVersions, PermissionsV1 } from '@polkadot/types/interfaces/genericAsset';
|
||||
@@ -27,23 +28,24 @@ import { AuthIndex, AuthoritySignature, Heartbeat, HeartbeatTo244, OpaqueMultiad
|
||||
import { CallMetadataV0, DoubleMapTypeLatest, DoubleMapTypeV10, DoubleMapTypeV11, DoubleMapTypeV3, DoubleMapTypeV4, DoubleMapTypeV5, DoubleMapTypeV6, DoubleMapTypeV7, DoubleMapTypeV8, DoubleMapTypeV9, ErrorMetadataV10, ErrorMetadataV11, ErrorMetadataV8, ErrorMetadataV9, EventMetadataLatest, EventMetadataV0, EventMetadataV1, EventMetadataV10, EventMetadataV11, EventMetadataV2, EventMetadataV3, EventMetadataV4, EventMetadataV5, EventMetadataV6, EventMetadataV7, EventMetadataV8, EventMetadataV9, ExtrinsicMetadataLatest, ExtrinsicMetadataV11, FunctionArgumentMetadataLatest, FunctionArgumentMetadataV0, FunctionArgumentMetadataV1, FunctionArgumentMetadataV10, FunctionArgumentMetadataV11, FunctionArgumentMetadataV2, FunctionArgumentMetadataV3, FunctionArgumentMetadataV4, FunctionArgumentMetadataV5, FunctionArgumentMetadataV6, FunctionArgumentMetadataV7, FunctionArgumentMetadataV8, FunctionArgumentMetadataV9, FunctionMetadataLatest, FunctionMetadataV0, FunctionMetadataV1, FunctionMetadataV10, FunctionMetadataV11, FunctionMetadataV2, FunctionMetadataV3, FunctionMetadataV4, FunctionMetadataV5, FunctionMetadataV6, FunctionMetadataV7, FunctionMetadataV8, FunctionMetadataV9, MapTypeLatest, MapTypeV0, MapTypeV10, MapTypeV11, MapTypeV2, MapTypeV3, MapTypeV4, MapTypeV5, MapTypeV6, MapTypeV7, MapTypeV8, MapTypeV9, MetadataAll, MetadataLatest, MetadataV0, MetadataV1, MetadataV10, MetadataV11, MetadataV2, MetadataV3, MetadataV4, MetadataV5, MetadataV6, MetadataV7, MetadataV8, MetadataV9, ModuleConstantMetadataLatest, ModuleConstantMetadataV10, ModuleConstantMetadataV11, ModuleConstantMetadataV6, ModuleConstantMetadataV7, ModuleConstantMetadataV8, ModuleConstantMetadataV9, ModuleMetadataLatest, ModuleMetadataV0, ModuleMetadataV1, ModuleMetadataV10, ModuleMetadataV11, ModuleMetadataV2, ModuleMetadataV3, ModuleMetadataV4, ModuleMetadataV5, ModuleMetadataV6, ModuleMetadataV7, ModuleMetadataV8, ModuleMetadataV9, OuterDispatchCallV0, OuterDispatchMetadataV0, OuterEventEventMetadataEventsV0, OuterEventEventMetadataV0, OuterEventMetadataV0, PlainTypeLatest, PlainTypeV0, PlainTypeV10, PlainTypeV11, PlainTypeV2, PlainTypeV3, PlainTypeV4, PlainTypeV5, PlainTypeV6, PlainTypeV7, PlainTypeV8, PlainTypeV9, RuntimeModuleMetadataV0, StorageEntryMetadataLatest, StorageEntryMetadataV10, StorageEntryMetadataV11, StorageEntryMetadataV6, StorageEntryMetadataV7, StorageEntryMetadataV8, StorageEntryMetadataV9, StorageEntryModifierLatest, StorageEntryModifierV10, StorageEntryModifierV11, StorageEntryModifierV6, StorageEntryModifierV7, StorageEntryModifierV8, StorageEntryModifierV9, StorageEntryTypeLatest, StorageEntryTypeV10, StorageEntryTypeV11, StorageEntryTypeV6, StorageEntryTypeV7, StorageEntryTypeV8, StorageEntryTypeV9, StorageFunctionMetadataV0, StorageFunctionMetadataV1, StorageFunctionMetadataV2, StorageFunctionMetadataV3, StorageFunctionMetadataV4, StorageFunctionMetadataV5, StorageFunctionModifierV0, StorageFunctionModifierV1, StorageFunctionModifierV2, StorageFunctionModifierV3, StorageFunctionModifierV4, StorageFunctionModifierV5, StorageFunctionTypeV0, StorageFunctionTypeV1, StorageFunctionTypeV2, StorageFunctionTypeV3, StorageFunctionTypeV4, StorageFunctionTypeV5, StorageHasher, StorageHasherV10, StorageHasherV11, StorageHasherV4, StorageHasherV5, StorageHasherV6, StorageHasherV7, StorageHasherV8, StorageHasherV9, StorageMetadataLatest, StorageMetadataV0, StorageMetadataV10, StorageMetadataV11, StorageMetadataV7, StorageMetadataV8, StorageMetadataV9 } from '@polkadot/types/interfaces/metadata';
|
||||
import { StorageKind } from '@polkadot/types/interfaces/offchain';
|
||||
import { DeferredOffenceOf, Kind, OffenceDetails, Offender, OpaqueTimeSlot, ReportIdOf, Reporter } from '@polkadot/types/interfaces/offences';
|
||||
import { AbridgedCandidateReceipt, AttestedCandidate, AuctionIndex, Bidder, CandidateCommitments, CandidateReceipt, CollatorId, CollatorSignature, DoubleVoteReport, DownwardMessage, GlobalValidationSchedule, HeadData, IncomingParachain, IncomingParachainDeploy, IncomingParachainFixed, LeasePeriod, LeasePeriodOf, LocalValidationData, NewBidder, ParaId, ParaInfo, ParaPastCodeMeta, ParaScheduling, ParachainDispatchOrigin, Remark, Retriable, Scheduling, SigningContext, SlotRange, Statement, SubId, UpwardMessage, ValidationCode, ValidatorSignature, ValidityAttestation, WinningData, WinningDataEntry } from '@polkadot/types/interfaces/parachains';
|
||||
import { AbridgedCandidateReceipt, AttestedCandidate, AuctionIndex, Bidder, CandidateCommitments, CandidateReceipt, CollatorId, CollatorSignature, DoubleVoteReport, DownwardMessage, GlobalValidationSchedule, HeadData, IncomingParachain, IncomingParachainDeploy, IncomingParachainFixed, LeasePeriod, LeasePeriodOf, LocalValidationData, NewBidder, ParaId, ParaInfo, ParaPastCodeMeta, ParaScheduling, ParachainDispatchOrigin, ParachainProposal, RegisteredParachainInfo, RelayChainBlockNumber, Remark, Retriable, Scheduling, SigningContext, SlotRange, Statement, SubId, UpwardMessage, ValidationCode, ValidationFunctionParams, ValidatorSignature, ValidityAttestation, WinningData, WinningDataEntry } from '@polkadot/types/interfaces/parachains';
|
||||
import { RuntimeDispatchInfo } from '@polkadot/types/interfaces/payment';
|
||||
import { Approvals } from '@polkadot/types/interfaces/poll';
|
||||
import { ProxyAnnouncement, ProxyDefinition, ProxyType } from '@polkadot/types/interfaces/proxy';
|
||||
import { AccountStatus, AccountValidity } from '@polkadot/types/interfaces/purchase';
|
||||
import { ActiveRecovery, RecoveryConfig } from '@polkadot/types/interfaces/recovery';
|
||||
import { RpcMethods } from '@polkadot/types/interfaces/rpc';
|
||||
import { AccountId, AccountIdOf, AccountIndex, Address, AssetId, Balance, BalanceOf, Block, BlockNumber, Call, ChangesTrieConfiguration, Consensus, ConsensusEngineId, Digest, DigestItem, ExtrinsicsWeight, Fixed128, Fixed64, H160, H256, H512, Hash, Header, Index, Justification, KeyTypeId, KeyValue, LockIdentifier, LookupSource, LookupTarget, ModuleId, Moment, OpaqueCall, Origin, Pays, Perbill, Percent, Permill, Perquintill, Phantom, PhantomData, PreRuntime, ProxyType, Releases, RuntimeDbWeight, Seal, SealV0, SignedBlock, StorageData, ValidatorId, Weight, WeightMultiplier } from '@polkadot/types/interfaces/runtime';
|
||||
import { AccountId, AccountIdOf, AccountIndex, Address, AssetId, Balance, BalanceOf, Block, BlockNumber, Call, CallHash, CallHashOf, ChangesTrieConfiguration, Consensus, ConsensusEngineId, Digest, DigestItem, ExtrinsicsWeight, Fixed128, Fixed64, FixedI128, FixedI64, FixedU128, FixedU64, GenericAddress, H160, H256, H512, Hash, Header, I32F32, Index, Justification, KeyTypeId, KeyValue, LockIdentifier, LookupSource, LookupTarget, ModuleId, Moment, OpaqueCall, Origin, Pays, PerU16, Perbill, Percent, Permill, Perquintill, Phantom, PhantomData, PreRuntime, Releases, RuntimeDbWeight, Seal, SealV0, SignedBlock, StorageData, TransactionPriority, U32F32, ValidatorId, Weight, WeightMultiplier } from '@polkadot/types/interfaces/runtime';
|
||||
import { Period, Priority, SchedulePeriod, SchedulePriority, Scheduled, TaskAddress } from '@polkadot/types/interfaces/scheduler';
|
||||
import { FullIdentification, IdentificationTuple, Keys, MembershipProof, SessionIndex, SessionKeys1, SessionKeys2, SessionKeys3, SessionKeys4, SessionKeys5, SessionKeys6, ValidatorCount } from '@polkadot/types/interfaces/session';
|
||||
import { Bid, BidKind, SocietyJudgement, SocietyVote, StrikeCount, VouchingStatus } from '@polkadot/types/interfaces/society';
|
||||
import { ActiveEraInfo, CompactAssignments, CompactScore, ElectionCompute, ElectionResult, ElectionScore, ElectionSize, ElectionStatus, EraIndex, EraPoints, EraRewardPoints, EraRewards, Exposure, Forcing, IndividualExposure, KeyType, MomentOf, Nominations, NominatorIndex, OffchainAccuracy, PerU16, PhragmenScore, Points, RewardDestination, RewardPoint, SlashJournalEntry, SlashingSpans, SlashingSpansTo204, SpanIndex, SpanRecord, StakingLedger, StakingLedgerTo223, StakingLedgerTo240, UnappliedSlash, UnappliedSlashOther, UnlockChunk, ValidatorIndex, ValidatorPrefs, ValidatorPrefsTo145, ValidatorPrefsTo196 } from '@polkadot/types/interfaces/staking';
|
||||
import { ActiveEraInfo, CompactAssignments, CompactAssignmentsTo257, CompactScore, CompactScoreCompact, ElectionCompute, ElectionResult, ElectionScore, ElectionSize, ElectionStatus, EraIndex, EraPoints, EraRewardPoints, EraRewards, Exposure, Forcing, IndividualExposure, KeyType, MomentOf, Nominations, NominatorIndex, NominatorIndexCompact, OffchainAccuracy, OffchainAccuracyCompact, PhragmenScore, Points, RewardDestination, RewardDestinationTo257, RewardPoint, SlashJournalEntry, SlashingSpans, SlashingSpansTo204, SpanIndex, SpanRecord, StakingLedger, StakingLedgerTo223, StakingLedgerTo240, UnappliedSlash, UnappliedSlashOther, UnlockChunk, ValidatorIndex, ValidatorIndexCompact, ValidatorPrefs, ValidatorPrefsTo145, ValidatorPrefsTo196 } from '@polkadot/types/interfaces/staking';
|
||||
import { ApiId, KeyValueOption, ReadProof, RuntimeVersion, RuntimeVersionApi, StorageChangeSet } from '@polkadot/types/interfaces/state';
|
||||
import { WeightToFeeCoefficient } from '@polkadot/types/interfaces/support';
|
||||
import { AccountInfo, ApplyExtrinsicResult, ChainProperties, ChainType, DigestOf, DispatchClass, DispatchError, DispatchErrorModule, DispatchErrorTo198, DispatchInfo, DispatchInfoTo190, DispatchInfoTo244, DispatchOutcome, DispatchResult, DispatchResultOf, DispatchResultTo198, Event, EventId, EventIndex, EventRecord, EventRecordTo76, Health, InvalidTransaction, Key, LastRuntimeUpgradeInfo, NetworkState, NetworkStatePeerset, NetworkStatePeersetInfo, NodeRole, NotConnectedPeer, Peer, PeerEndpoint, PeerEndpointAddr, PeerInfo, PeerPing, Phase, RefCount, TransactionValidityError, UnknownTransaction } from '@polkadot/types/interfaces/system';
|
||||
import { OpenTip, OpenTipFinderTo225, OpenTipTip, OpenTipTo225, TreasuryProposal } from '@polkadot/types/interfaces/treasury';
|
||||
import { Multiplier } from '@polkadot/types/interfaces/txpayment';
|
||||
import { CallHash, Multisig, Timepoint } from '@polkadot/types/interfaces/utility';
|
||||
import { Multisig, Timepoint } from '@polkadot/types/interfaces/utility';
|
||||
import { VestingInfo } from '@polkadot/types/interfaces/vesting';
|
||||
|
||||
declare module '@polkadot/types/types/registry' {
|
||||
@@ -128,6 +130,50 @@ declare module '@polkadot/types/types/registry' {
|
||||
Raw: Raw;
|
||||
'Option<Raw>': Option<Raw>;
|
||||
'Vec<Raw>': Vec<Raw>;
|
||||
Fixed64: Fixed64;
|
||||
'Option<Fixed64>': Option<Fixed64>;
|
||||
'Vec<Fixed64>': Vec<Fixed64>;
|
||||
FixedI64: FixedI64;
|
||||
'Option<FixedI64>': Option<FixedI64>;
|
||||
'Vec<FixedI64>': Vec<FixedI64>;
|
||||
FixedU64: FixedU64;
|
||||
'Option<FixedU64>': Option<FixedU64>;
|
||||
'Vec<FixedU64>': Vec<FixedU64>;
|
||||
Fixed128: Fixed128;
|
||||
'Option<Fixed128>': Option<Fixed128>;
|
||||
'Vec<Fixed128>': Vec<Fixed128>;
|
||||
FixedI128: FixedI128;
|
||||
'Option<FixedI128>': Option<FixedI128>;
|
||||
'Vec<FixedI128>': Vec<FixedI128>;
|
||||
FixedU128: FixedU128;
|
||||
'Option<FixedU128>': Option<FixedU128>;
|
||||
'Vec<FixedU128>': Vec<FixedU128>;
|
||||
I32F32: I32F32;
|
||||
'Option<I32F32>': Option<I32F32>;
|
||||
'Vec<I32F32>': Vec<I32F32>;
|
||||
U32F32: U32F32;
|
||||
'Option<U32F32>': Option<U32F32>;
|
||||
'Vec<U32F32>': Vec<U32F32>;
|
||||
PerU16: PerU16;
|
||||
'Compact<PerU16>': Compact<PerU16>;
|
||||
'Option<PerU16>': Option<PerU16>;
|
||||
'Vec<PerU16>': Vec<PerU16>;
|
||||
Perbill: Perbill;
|
||||
'Compact<Perbill>': Compact<Perbill>;
|
||||
'Option<Perbill>': Option<Perbill>;
|
||||
'Vec<Perbill>': Vec<Perbill>;
|
||||
Percent: Percent;
|
||||
'Compact<Percent>': Compact<Percent>;
|
||||
'Option<Percent>': Option<Percent>;
|
||||
'Vec<Percent>': Vec<Percent>;
|
||||
Permill: Permill;
|
||||
'Compact<Permill>': Compact<Permill>;
|
||||
'Option<Permill>': Option<Permill>;
|
||||
'Vec<Permill>': Vec<Permill>;
|
||||
Perquintill: Perquintill;
|
||||
'Compact<Perquintill>': Compact<Perquintill>;
|
||||
'Option<Perquintill>': Option<Perquintill>;
|
||||
'Vec<Perquintill>': Vec<Perquintill>;
|
||||
AccountId: AccountId;
|
||||
'Option<AccountId>': Option<AccountId>;
|
||||
'Vec<AccountId>': Vec<AccountId>;
|
||||
@@ -161,6 +207,12 @@ declare module '@polkadot/types/types/registry' {
|
||||
Call: Call;
|
||||
'Option<Call>': Option<Call>;
|
||||
'Vec<Call>': Vec<Call>;
|
||||
CallHash: CallHash;
|
||||
'Option<CallHash>': Option<CallHash>;
|
||||
'Vec<CallHash>': Vec<CallHash>;
|
||||
CallHashOf: CallHashOf;
|
||||
'Option<CallHashOf>': Option<CallHashOf>;
|
||||
'Vec<CallHashOf>': Vec<CallHashOf>;
|
||||
ChangesTrieConfiguration: ChangesTrieConfiguration;
|
||||
'Option<ChangesTrieConfiguration>': Option<ChangesTrieConfiguration>;
|
||||
'Vec<ChangesTrieConfiguration>': Vec<ChangesTrieConfiguration>;
|
||||
@@ -176,12 +228,9 @@ declare module '@polkadot/types/types/registry' {
|
||||
ExtrinsicsWeight: ExtrinsicsWeight;
|
||||
'Option<ExtrinsicsWeight>': Option<ExtrinsicsWeight>;
|
||||
'Vec<ExtrinsicsWeight>': Vec<ExtrinsicsWeight>;
|
||||
Fixed64: Fixed64;
|
||||
'Option<Fixed64>': Option<Fixed64>;
|
||||
'Vec<Fixed64>': Vec<Fixed64>;
|
||||
Fixed128: Fixed128;
|
||||
'Option<Fixed128>': Option<Fixed128>;
|
||||
'Vec<Fixed128>': Vec<Fixed128>;
|
||||
GenericAddress: GenericAddress;
|
||||
'Option<GenericAddress>': Option<GenericAddress>;
|
||||
'Vec<GenericAddress>': Vec<GenericAddress>;
|
||||
H160: H160;
|
||||
'Option<H160>': Option<H160>;
|
||||
'Vec<H160>': Vec<H160>;
|
||||
@@ -236,31 +285,12 @@ declare module '@polkadot/types/types/registry' {
|
||||
Pays: Pays;
|
||||
'Option<Pays>': Option<Pays>;
|
||||
'Vec<Pays>': Vec<Pays>;
|
||||
Perbill: Perbill;
|
||||
'Compact<Perbill>': Compact<Perbill>;
|
||||
'Option<Perbill>': Option<Perbill>;
|
||||
'Vec<Perbill>': Vec<Perbill>;
|
||||
Percent: Percent;
|
||||
'Compact<Percent>': Compact<Percent>;
|
||||
'Option<Percent>': Option<Percent>;
|
||||
'Vec<Percent>': Vec<Percent>;
|
||||
Permill: Permill;
|
||||
'Compact<Permill>': Compact<Permill>;
|
||||
'Option<Permill>': Option<Permill>;
|
||||
'Vec<Permill>': Vec<Permill>;
|
||||
Perquintill: Perquintill;
|
||||
'Compact<Perquintill>': Compact<Perquintill>;
|
||||
'Option<Perquintill>': Option<Perquintill>;
|
||||
'Vec<Perquintill>': Vec<Perquintill>;
|
||||
Phantom: Phantom;
|
||||
'Option<Phantom>': Option<Phantom>;
|
||||
'Vec<Phantom>': Vec<Phantom>;
|
||||
PhantomData: PhantomData;
|
||||
'Option<PhantomData>': Option<PhantomData>;
|
||||
'Vec<PhantomData>': Vec<PhantomData>;
|
||||
ProxyType: ProxyType;
|
||||
'Option<ProxyType>': Option<ProxyType>;
|
||||
'Vec<ProxyType>': Vec<ProxyType>;
|
||||
Releases: Releases;
|
||||
'Option<Releases>': Option<Releases>;
|
||||
'Vec<Releases>': Vec<Releases>;
|
||||
@@ -273,6 +303,10 @@ declare module '@polkadot/types/types/registry' {
|
||||
StorageData: StorageData;
|
||||
'Option<StorageData>': Option<StorageData>;
|
||||
'Vec<StorageData>': Vec<StorageData>;
|
||||
TransactionPriority: TransactionPriority;
|
||||
'Compact<TransactionPriority>': Compact<TransactionPriority>;
|
||||
'Option<TransactionPriority>': Option<TransactionPriority>;
|
||||
'Vec<TransactionPriority>': Vec<TransactionPriority>;
|
||||
ValidatorId: ValidatorId;
|
||||
'Option<ValidatorId>': Option<ValidatorId>;
|
||||
'Vec<ValidatorId>': Vec<ValidatorId>;
|
||||
@@ -789,6 +823,15 @@ declare module '@polkadot/types/types/registry' {
|
||||
Reporter: Reporter;
|
||||
'Option<Reporter>': Option<Reporter>;
|
||||
'Vec<Reporter>': Vec<Reporter>;
|
||||
ProxyDefinition: ProxyDefinition;
|
||||
'Option<ProxyDefinition>': Option<ProxyDefinition>;
|
||||
'Vec<ProxyDefinition>': Vec<ProxyDefinition>;
|
||||
ProxyType: ProxyType;
|
||||
'Option<ProxyType>': Option<ProxyType>;
|
||||
'Vec<ProxyType>': Vec<ProxyType>;
|
||||
ProxyAnnouncement: ProxyAnnouncement;
|
||||
'Option<ProxyAnnouncement>': Option<ProxyAnnouncement>;
|
||||
'Vec<ProxyAnnouncement>': Vec<ProxyAnnouncement>;
|
||||
ActiveRecovery: ActiveRecovery;
|
||||
'Option<ActiveRecovery>': Option<ActiveRecovery>;
|
||||
'Vec<ActiveRecovery>': Vec<ActiveRecovery>;
|
||||
@@ -884,9 +927,15 @@ declare module '@polkadot/types/types/registry' {
|
||||
CompactAssignments: CompactAssignments;
|
||||
'Option<CompactAssignments>': Option<CompactAssignments>;
|
||||
'Vec<CompactAssignments>': Vec<CompactAssignments>;
|
||||
CompactAssignmentsTo257: CompactAssignmentsTo257;
|
||||
'Option<CompactAssignmentsTo257>': Option<CompactAssignmentsTo257>;
|
||||
'Vec<CompactAssignmentsTo257>': Vec<CompactAssignmentsTo257>;
|
||||
CompactScore: CompactScore;
|
||||
'Option<CompactScore>': Option<CompactScore>;
|
||||
'Vec<CompactScore>': Vec<CompactScore>;
|
||||
CompactScoreCompact: CompactScoreCompact;
|
||||
'Option<CompactScoreCompact>': Option<CompactScoreCompact>;
|
||||
'Vec<CompactScoreCompact>': Vec<CompactScoreCompact>;
|
||||
ElectionCompute: ElectionCompute;
|
||||
'Option<ElectionCompute>': Option<ElectionCompute>;
|
||||
'Vec<ElectionCompute>': Vec<ElectionCompute>;
|
||||
@@ -934,19 +983,24 @@ declare module '@polkadot/types/types/registry' {
|
||||
'Compact<NominatorIndex>': Compact<NominatorIndex>;
|
||||
'Option<NominatorIndex>': Option<NominatorIndex>;
|
||||
'Vec<NominatorIndex>': Vec<NominatorIndex>;
|
||||
NominatorIndexCompact: NominatorIndexCompact;
|
||||
'Option<NominatorIndexCompact>': Option<NominatorIndexCompact>;
|
||||
'Vec<NominatorIndexCompact>': Vec<NominatorIndexCompact>;
|
||||
OffchainAccuracy: OffchainAccuracy;
|
||||
'Option<OffchainAccuracy>': Option<OffchainAccuracy>;
|
||||
'Vec<OffchainAccuracy>': Vec<OffchainAccuracy>;
|
||||
PerU16: PerU16;
|
||||
'Compact<PerU16>': Compact<PerU16>;
|
||||
'Option<PerU16>': Option<PerU16>;
|
||||
'Vec<PerU16>': Vec<PerU16>;
|
||||
OffchainAccuracyCompact: OffchainAccuracyCompact;
|
||||
'Option<OffchainAccuracyCompact>': Option<OffchainAccuracyCompact>;
|
||||
'Vec<OffchainAccuracyCompact>': Vec<OffchainAccuracyCompact>;
|
||||
PhragmenScore: PhragmenScore;
|
||||
'Option<PhragmenScore>': Option<PhragmenScore>;
|
||||
'Vec<PhragmenScore>': Vec<PhragmenScore>;
|
||||
RewardDestination: RewardDestination;
|
||||
'Option<RewardDestination>': Option<RewardDestination>;
|
||||
'Vec<RewardDestination>': Vec<RewardDestination>;
|
||||
RewardDestinationTo257: RewardDestinationTo257;
|
||||
'Option<RewardDestinationTo257>': Option<RewardDestinationTo257>;
|
||||
'Vec<RewardDestinationTo257>': Vec<RewardDestinationTo257>;
|
||||
RewardPoint: RewardPoint;
|
||||
'Compact<RewardPoint>': Compact<RewardPoint>;
|
||||
'Option<RewardPoint>': Option<RewardPoint>;
|
||||
@@ -989,6 +1043,9 @@ declare module '@polkadot/types/types/registry' {
|
||||
'Compact<ValidatorIndex>': Compact<ValidatorIndex>;
|
||||
'Option<ValidatorIndex>': Option<ValidatorIndex>;
|
||||
'Vec<ValidatorIndex>': Vec<ValidatorIndex>;
|
||||
ValidatorIndexCompact: ValidatorIndexCompact;
|
||||
'Option<ValidatorIndexCompact>': Option<ValidatorIndexCompact>;
|
||||
'Vec<ValidatorIndexCompact>': Vec<ValidatorIndexCompact>;
|
||||
ValidatorPrefs: ValidatorPrefs;
|
||||
'Option<ValidatorPrefs>': Option<ValidatorPrefs>;
|
||||
'Vec<ValidatorPrefs>': Vec<ValidatorPrefs>;
|
||||
@@ -1138,9 +1195,6 @@ declare module '@polkadot/types/types/registry' {
|
||||
Multiplier: Multiplier;
|
||||
'Option<Multiplier>': Option<Multiplier>;
|
||||
'Vec<Multiplier>': Vec<Multiplier>;
|
||||
CallHash: CallHash;
|
||||
'Option<CallHash>': Option<CallHash>;
|
||||
'Vec<CallHash>': Vec<CallHash>;
|
||||
Multisig: Multisig;
|
||||
'Option<Multisig>': Option<Multisig>;
|
||||
'Vec<Multisig>': Vec<Multisig>;
|
||||
@@ -1165,6 +1219,12 @@ declare module '@polkadot/types/types/registry' {
|
||||
StatementKind: StatementKind;
|
||||
'Option<StatementKind>': Option<StatementKind>;
|
||||
'Vec<StatementKind>': Vec<StatementKind>;
|
||||
ParachainProposal: ParachainProposal;
|
||||
'Option<ParachainProposal>': Option<ParachainProposal>;
|
||||
'Vec<ParachainProposal>': Vec<ParachainProposal>;
|
||||
RegisteredParachainInfo: RegisteredParachainInfo;
|
||||
'Option<RegisteredParachainInfo>': Option<RegisteredParachainInfo>;
|
||||
'Vec<RegisteredParachainInfo>': Vec<RegisteredParachainInfo>;
|
||||
AbridgedCandidateReceipt: AbridgedCandidateReceipt;
|
||||
'Option<AbridgedCandidateReceipt>': Option<AbridgedCandidateReceipt>;
|
||||
'Vec<AbridgedCandidateReceipt>': Vec<AbridgedCandidateReceipt>;
|
||||
@@ -1239,6 +1299,9 @@ declare module '@polkadot/types/types/registry' {
|
||||
ParaScheduling: ParaScheduling;
|
||||
'Option<ParaScheduling>': Option<ParaScheduling>;
|
||||
'Vec<ParaScheduling>': Vec<ParaScheduling>;
|
||||
RelayChainBlockNumber: RelayChainBlockNumber;
|
||||
'Option<RelayChainBlockNumber>': Option<RelayChainBlockNumber>;
|
||||
'Vec<RelayChainBlockNumber>': Vec<RelayChainBlockNumber>;
|
||||
Remark: Remark;
|
||||
'Option<Remark>': Option<Remark>;
|
||||
'Vec<Remark>': Vec<Remark>;
|
||||
@@ -1264,6 +1327,9 @@ declare module '@polkadot/types/types/registry' {
|
||||
UpwardMessage: UpwardMessage;
|
||||
'Option<UpwardMessage>': Option<UpwardMessage>;
|
||||
'Vec<UpwardMessage>': Vec<UpwardMessage>;
|
||||
ValidationFunctionParams: ValidationFunctionParams;
|
||||
'Option<ValidationFunctionParams>': Option<ValidationFunctionParams>;
|
||||
'Vec<ValidationFunctionParams>': Vec<ValidationFunctionParams>;
|
||||
ValidationCode: ValidationCode;
|
||||
'Option<ValidationCode>': Option<ValidationCode>;
|
||||
'Vec<ValidationCode>': Vec<ValidationCode>;
|
||||
@@ -1288,6 +1354,12 @@ declare module '@polkadot/types/types/registry' {
|
||||
AccountValidity: AccountValidity;
|
||||
'Option<AccountValidity>': Option<AccountValidity>;
|
||||
'Vec<AccountValidity>': Vec<AccountValidity>;
|
||||
EthereumAccountId: EthereumAccountId;
|
||||
'Option<EthereumAccountId>': Option<EthereumAccountId>;
|
||||
'Vec<EthereumAccountId>': Vec<EthereumAccountId>;
|
||||
EthereumLookupSource: EthereumLookupSource;
|
||||
'Option<EthereumLookupSource>': Option<EthereumLookupSource>;
|
||||
'Vec<EthereumLookupSource>': Vec<EthereumLookupSource>;
|
||||
CallMetadataV0: CallMetadataV0;
|
||||
'Option<CallMetadataV0>': Option<CallMetadataV0>;
|
||||
'Vec<CallMetadataV0>': Vec<CallMetadataV0>;
|
||||
|
||||
@@ -6,7 +6,6 @@ import { H256 } from '../interfaces/runtime';
|
||||
import { AnyJson, Codec, Registry } from '../types';
|
||||
|
||||
import { u8aConcat, u8aToHex } from '@polkadot/util';
|
||||
import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
import Compact from './Compact';
|
||||
import Raw from './Raw';
|
||||
@@ -41,7 +40,7 @@ export default abstract class AbstractArray<T extends Codec> extends Array<T> im
|
||||
* @description returns a hash of the contents
|
||||
*/
|
||||
public get hash (): H256 {
|
||||
return new Raw(this.registry, blake2AsU8a(this.toU8a(), 256));
|
||||
return new Raw(this.registry, this.registry.hash(this.toU8a()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -136,10 +135,15 @@ export default abstract class AbstractArray<T extends Codec> extends Array<T> im
|
||||
// we want it to return an Array. We only override the methods that return a
|
||||
// new instance.
|
||||
|
||||
/**
|
||||
* @description Concatenates two arrays
|
||||
*/
|
||||
public concat (other: T[]): T[] {
|
||||
return this.toArray().concat(other instanceof AbstractArray ? other.toArray() : other);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Filters the array with the callback
|
||||
* @param callbackfn The filter function
|
||||
* @param thisArg The `this` object to apply the result to
|
||||
*/
|
||||
public filter (callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: unknown): T[] {
|
||||
return this.toArray().filter(callbackfn, thisArg);
|
||||
@@ -147,8 +151,6 @@ export default abstract class AbstractArray<T extends Codec> extends Array<T> im
|
||||
|
||||
/**
|
||||
* @description Maps the array with the callback
|
||||
* @param callbackfn The mapping function
|
||||
* @param thisArg The `this` onject to apply the result to
|
||||
*/
|
||||
public map<U> (callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: unknown): U[] {
|
||||
return this.toArray().map(callbackfn, thisArg);
|
||||
|
||||
@@ -7,7 +7,6 @@ import { AnyNumber, Codec, Registry } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { BN_ZERO, assert, bnToBn, bnToHex, bnToU8a, formatBalance, formatNumber, hexToBn, isHex, isString, isU8a, u8aToBn } from '@polkadot/util';
|
||||
import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
import Raw from './Raw';
|
||||
|
||||
@@ -92,7 +91,7 @@ export default abstract class AbstractInt extends BN implements Codec {
|
||||
* @description returns a hash of the contents
|
||||
*/
|
||||
public get hash (): H256 {
|
||||
return new Raw(this.registry, blake2AsU8a(this.toU8a(), 256));
|
||||
return new Raw(this.registry, this.registry.hash(this.toU8a()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -139,6 +138,13 @@ export default abstract class AbstractInt extends BN implements Codec {
|
||||
return u8a.length === (this.#bitLength / 8);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns a BigInt representation of the number
|
||||
*/
|
||||
public toBigInt (): BigInt {
|
||||
return BigInt(this.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the BN representation of the number. (Compatibility)
|
||||
*/
|
||||
|
||||
@@ -6,7 +6,6 @@ import { H256 } from '../interfaces/runtime';
|
||||
import { AnyJson, Constructor, Codec, InterfaceTypes, Registry } from '../types';
|
||||
|
||||
import { isHex, hexToU8a, isU8a, u8aConcat, u8aToHex, u8aToU8a } from '@polkadot/util';
|
||||
import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
import Compact from './Compact';
|
||||
import Raw from './Raw';
|
||||
@@ -117,7 +116,7 @@ export default class BTreeSet<V extends Codec = Codec> extends Set<V> implements
|
||||
* @description Returns a hash of the value
|
||||
*/
|
||||
public get hash (): H256 {
|
||||
return new Raw(this.registry, blake2AsU8a(this.toU8a(), 256));
|
||||
return new Raw(this.registry, this.registry.hash(this.toU8a()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
import { H256 } from '../interfaces/runtime';
|
||||
import { AnyJson, BareOpts, Codec, Registry } from '../types';
|
||||
|
||||
import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
import Raw from './Raw';
|
||||
|
||||
/**
|
||||
@@ -34,7 +32,7 @@ export default abstract class Base<T extends Codec> implements Codec {
|
||||
* @description returns a hash of the contents
|
||||
*/
|
||||
public get hash (): H256 {
|
||||
return new Raw(this.registry, blake2AsU8a(this.toU8a(), 256));
|
||||
return new Raw(this.registry, this.registry.hash(this.toU8a()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -162,6 +162,14 @@ describe('Compact', (): void => {
|
||||
it('unwraps to the wrapped value', (): void => {
|
||||
expect(new (Compact.with(U32))(registry, 12345).unwrap() instanceof U32).toBe(true);
|
||||
});
|
||||
|
||||
it('has a valid toBn interface', (): void => {
|
||||
expect(new (Compact.with('u128'))(registry, '12345678987654321').toBn().eq(new BN('12345678987654321'))).toBe(true);
|
||||
});
|
||||
|
||||
it('has a valid toBigInt interface', (): void => {
|
||||
expect(new (Compact.with('u128'))(registry, 12345678987654321n).toBigInt() === 12345678987654321n).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('helpers', (): void => {
|
||||
|
||||
@@ -8,7 +8,6 @@ import { AnyJson, AnyNumber, Codec, Constructor, ICompact, InterfaceTypes, Regis
|
||||
import BN from 'bn.js';
|
||||
import { compactAddLength, compactFromU8a, compactStripLength, compactToU8a, isBigInt, isBn, isNumber, isString } from '@polkadot/util';
|
||||
import { DEFAULT_BITLENGTH } from '@polkadot/util/compact/defaults';
|
||||
import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
import typeToConstructor from './utils/typeToConstructor';
|
||||
import { UIntBitLength } from './AbstractInt';
|
||||
@@ -90,7 +89,7 @@ export default class Compact<T extends CompactEncodable> implements ICompact<T>
|
||||
* @description returns a hash of the contents
|
||||
*/
|
||||
public get hash (): H256 {
|
||||
return new Raw(this.registry, blake2AsU8a(this.toU8a(), 256));
|
||||
return new Raw(this.registry, this.registry.hash(this.toU8a()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -118,6 +117,13 @@ export default class Compact<T extends CompactEncodable> implements ICompact<T>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns a BigInt representation of the number
|
||||
*/
|
||||
public toBigInt (): BigInt {
|
||||
return BigInt(this.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the BN representation of the number
|
||||
*/
|
||||
|
||||
@@ -26,11 +26,12 @@ describe('Date', (): void => {
|
||||
});
|
||||
|
||||
describe('encode', (): void => {
|
||||
const testEncode = (to: 'toBn' | 'toISOString' | 'toNumber' | CodecTo, expected: BN | number | string | Uint8Array): void =>
|
||||
const testEncode = (to: 'toBigInt' | 'toBn' | 'toISOString' | 'toNumber' | CodecTo, expected: BigInt | BN | number | string | Uint8Array): void =>
|
||||
it(`can encode ${to}`, (): void => {
|
||||
expect(new CodecDate(registry, 421)[to]()).toEqual(expected);
|
||||
});
|
||||
|
||||
testEncode('toBigInt', 421n);
|
||||
testEncode('toBn', new BN(421));
|
||||
testEncode('toJSON', 421);
|
||||
testEncode('toISOString', '1970-01-01T00:07:01.000Z');
|
||||
|
||||
@@ -7,7 +7,6 @@ import { AnyNumber, Codec, Registry } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { bnToBn, bnToHex, bnToU8a, isString, isU8a, u8aToBn } from '@polkadot/util';
|
||||
import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
import { UIntBitLength } from './AbstractInt';
|
||||
|
||||
@@ -58,7 +57,7 @@ export default class CodecDate extends Date implements Codec {
|
||||
* @description returns a hash of the contents
|
||||
*/
|
||||
public get hash (): H256 {
|
||||
return this.registry.createType('H256', blake2AsU8a(this.toU8a(), 256));
|
||||
return this.registry.createType('H256', this.registry.hash(this.toU8a()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,6 +81,13 @@ export default class CodecDate extends Date implements Codec {
|
||||
return BITLENGTH;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns a BigInt representation of the number
|
||||
*/
|
||||
public toBigInt (): BigInt {
|
||||
return BigInt(this.toNumber());
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the BN representation of the timestamp
|
||||
*/
|
||||
|
||||
@@ -149,6 +149,8 @@ describe('Enum', (): void => {
|
||||
|
||||
expect(new Test(registry).toJSON()).toEqual({ A: null });
|
||||
expect(new Test(registry, 1234, 1).toJSON()).toEqual({ B: 1234 });
|
||||
expect(new Test(registry, 0x1234, 1).toU8a()).toEqual(new Uint8Array([1, 0x34, 0x12, 0x00, 0x00]));
|
||||
expect(new Test(registry, 0x1234, 1).toU8a(true)).toEqual(new Uint8Array([0x34, 0x12, 0x00, 0x00]));
|
||||
});
|
||||
|
||||
it('allows accessing the type and value', (): void => {
|
||||
|
||||
@@ -6,7 +6,6 @@ import { H256 } from '@polkadot/types/interfaces';
|
||||
import { AnyJson, Codec, Constructor, InterfaceTypes, Registry } from '../types';
|
||||
|
||||
import { assert, hexToU8a, isHex, isNumber, isObject, isString, isU8a, isUndefined, stringCamelCase, stringUpperFirst, u8aConcat, u8aToHex } from '@polkadot/util';
|
||||
import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
import Null from '../primitive/Null';
|
||||
import { mapToTypeMap } from './utils';
|
||||
@@ -188,7 +187,7 @@ export default class Enum implements Codec {
|
||||
* @description returns a hash of the contents
|
||||
*/
|
||||
public get hash (): H256 {
|
||||
return new Raw(this.registry, blake2AsU8a(this.toU8a(), 256));
|
||||
return new Raw(this.registry, this.registry.hash(this.toU8a()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -339,10 +338,8 @@ export default class Enum implements Codec {
|
||||
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
||||
*/
|
||||
public toU8a (isBare?: boolean): Uint8Array {
|
||||
const index = this.#indexes[this.#index];
|
||||
|
||||
return u8aConcat(
|
||||
new Uint8Array([index]),
|
||||
new Uint8Array(isBare ? [] : [this.#indexes[this.#index]]),
|
||||
this.#raw.toU8a(isBare)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,12 @@ import Int from './Int';
|
||||
describe('Int', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
it('provides a toBigInt interface', (): void => {
|
||||
expect(
|
||||
new Int(registry, -1234).toBigInt()
|
||||
).toEqual(-1234n);
|
||||
});
|
||||
|
||||
it('provides a toBn interface', (): void => {
|
||||
expect(
|
||||
new Int(registry, -1234).toBn().toNumber()
|
||||
|
||||
@@ -6,7 +6,6 @@ import { H256 } from '../interfaces/runtime';
|
||||
import { AnyJson, Constructor, Codec, InterfaceTypes, Registry } from '../types';
|
||||
|
||||
import { isHex, hexToU8a, isObject, isU8a, u8aConcat, u8aToHex, u8aToU8a } from '@polkadot/util';
|
||||
import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
import Compact from './Compact';
|
||||
import Raw from './Raw';
|
||||
@@ -126,7 +125,7 @@ export default class CodecMap<K extends Codec = Codec, V extends Codec = Codec>
|
||||
* @description Returns a hash of the value
|
||||
*/
|
||||
public get hash (): H256 {
|
||||
return new Raw(this.registry, blake2AsU8a(this.toU8a(), 256));
|
||||
return new Raw(this.registry, this.registry.hash(this.toU8a()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,7 +6,6 @@ import { H256 } from '@polkadot/types/interfaces';
|
||||
import { AnyJson, Codec, Constructor, InterfaceTypes, Registry } from '../types';
|
||||
|
||||
import { isNull, isU8a, isUndefined, u8aToHex } from '@polkadot/util';
|
||||
import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
import Null from '../primitive/Null';
|
||||
import { typeToConstructor } from './utils';
|
||||
@@ -83,7 +82,7 @@ export default class Option<T extends Codec> implements Codec {
|
||||
* @description returns a hash of the contents
|
||||
*/
|
||||
public get hash (): H256 {
|
||||
return new Raw(this.registry, blake2AsU8a(this.toU8a(), 256));
|
||||
return new Raw(this.registry, this.registry.hash(this.toU8a()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,7 +6,6 @@ import { H256 } from '../interfaces/runtime';
|
||||
import { AnyJson, AnyU8a, IU8a, Registry } from '../types';
|
||||
|
||||
import { assert, isAscii, isU8a, isUndefined, isUtf8, u8aToHex, u8aToString, u8aToU8a } from '@polkadot/util';
|
||||
import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
/** @internal */
|
||||
function decodeU8a (value?: any): Uint8Array {
|
||||
@@ -46,7 +45,7 @@ export default class Raw extends Uint8Array implements IU8a {
|
||||
* @description returns a hash of the contents
|
||||
*/
|
||||
public get hash (): H256 {
|
||||
return new Raw(this.registry, blake2AsU8a(this.toU8a(), 256));
|
||||
return new Raw(this.registry, this.registry.hash(this.toU8a()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,7 +7,6 @@ import { Codec, Constructor, Registry } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { assert, bnToBn, bnToU8a, isBn, isU8a, isNumber, isString, isUndefined, stringCamelCase, stringUpperFirst, u8aToHex, u8aToBn, u8aToU8a } from '@polkadot/util';
|
||||
import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
import Raw from './Raw';
|
||||
import { compareArray } from './utils';
|
||||
@@ -127,7 +126,7 @@ export default class CodecSet extends Set<string> implements Codec {
|
||||
* @description returns a hash of the contents
|
||||
*/
|
||||
public get hash (): H256 {
|
||||
return new Raw(this.registry, blake2AsU8a(this.toU8a(), 256));
|
||||
return new Raw(this.registry, this.registry.hash(this.toU8a()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,7 +6,6 @@ import { H256 } from '../interfaces/runtime';
|
||||
import { AnyJson, BareOpts, Codec, Constructor, ConstructorDef, InterfaceTypes, Registry } from '../types';
|
||||
|
||||
import { hexToU8a, isBoolean, isFunction, isHex, isObject, isU8a, isUndefined, u8aConcat, u8aToHex } from '@polkadot/util';
|
||||
import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
import Raw from './Raw';
|
||||
import { compareMap, decodeU8a, mapToTypeMap } from './utils';
|
||||
@@ -198,7 +197,7 @@ export default class Struct<
|
||||
* @description returns a hash of the contents
|
||||
*/
|
||||
public get hash (): H256 {
|
||||
return new Raw(this.registry, blake2AsU8a(this.toU8a(), 256));
|
||||
return new Raw(this.registry, this.registry.hash(this.toU8a()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,7 +6,6 @@ import { H256 } from '../interfaces/runtime';
|
||||
import { AnyJson, Codec, Registry } from '../types';
|
||||
|
||||
import { isUndefined } from '@polkadot/util';
|
||||
import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
import Raw from './Raw';
|
||||
|
||||
@@ -61,7 +60,7 @@ export default class StructAny extends Map<string, any> implements Codec {
|
||||
* @description returns a hash of the contents
|
||||
*/
|
||||
public get hash (): H256 {
|
||||
return new Raw(this.registry, blake2AsU8a(this.toU8a(), 256));
|
||||
return new Raw(this.registry, this.registry.hash(this.toU8a()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -28,6 +28,12 @@ describe('UInt', (): void => {
|
||||
).toEqual('123,456,789,123,456,789,123,456,789');
|
||||
});
|
||||
|
||||
it('provides a toBigInt interface', (): void => {
|
||||
expect(
|
||||
new UInt(registry, 9876543210123456789n).toBigInt()
|
||||
).toEqual(9876543210123456789n);
|
||||
});
|
||||
|
||||
it('provides a toBn interface', (): void => {
|
||||
expect(
|
||||
new UInt(registry, 987).toBn().toNumber()
|
||||
|
||||
@@ -110,6 +110,12 @@ describe('Vec', (): void => {
|
||||
});
|
||||
});
|
||||
|
||||
it('exposes a working concat', (): void => {
|
||||
expect(
|
||||
vector.concat(new Vec(registry, Text, ['987', '654'])).toString()
|
||||
).toEqual('1,23,345,4567,56789,987,654');
|
||||
});
|
||||
|
||||
it('exposes a working filter', (): void => {
|
||||
expect(
|
||||
vector.filter((e, i): boolean => i >= 3).toString()
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
|
||||
import { Codec, Constructor } from '../types';
|
||||
|
||||
import { isChildClass } from '@polkadot/util';
|
||||
import { isChildClass, u8aToU8a } from '@polkadot/util';
|
||||
import { keccakAsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
import Struct from '../codec/Struct';
|
||||
import DoNotConstruct from '../primitive/DoNotConstruct';
|
||||
@@ -159,4 +160,30 @@ describe('TypeRegistry', (): void => {
|
||||
expect(struct.bar.toString()).toEqual('testing');
|
||||
});
|
||||
});
|
||||
|
||||
it('hashes via blake2 by default', (): void => {
|
||||
expect(
|
||||
registry.hash(u8aToU8a('abc'))
|
||||
).toEqual(
|
||||
new Uint8Array([189, 221, 129, 60, 99, 66, 57, 114, 49, 113, 239, 63, 238, 152, 87, 155, 148, 150, 78, 59, 177, 203, 62, 66, 114, 98, 200, 192, 104, 213, 35, 25])
|
||||
);
|
||||
});
|
||||
|
||||
it('hashes via override hasher', (): void => {
|
||||
registry.setHasher(keccakAsU8a);
|
||||
|
||||
expect(
|
||||
registry.hash(u8aToU8a('test value'))
|
||||
).toEqual(
|
||||
u8aToU8a('0x2d07364b5c231c56ce63d49430e085ea3033c750688ba532b24029124c26ca5e')
|
||||
);
|
||||
|
||||
registry.setHasher();
|
||||
|
||||
expect(
|
||||
registry.hash(u8aToU8a('abc'))
|
||||
).toEqual(
|
||||
new Uint8Array([189, 221, 129, 60, 99, 66, 57, 114, 49, 113, 239, 63, 238, 152, 87, 155, 148, 150, 78, 59, 177, 203, 62, 66, 114, 98, 200, 192, 104, 213, 35, 25])
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -8,7 +8,8 @@ import { ChainProperties, DispatchErrorModule } from '../interfaces/types';
|
||||
import { CallFunction, Codec, Constructor, InterfaceTypes, RegistryError, RegistryTypes, Registry, RegistryMetadata, RegisteredTypes, TypeDef } from '../types';
|
||||
|
||||
import extrinsicsFromMeta from '@polkadot/metadata/Decorated/extrinsics/fromMetadata';
|
||||
import { assert, formatBalance, isFunction, isString, isU8a, isUndefined, stringCamelCase, u8aToHex } from '@polkadot/util';
|
||||
import { BN_ZERO, assert, formatBalance, isFunction, isString, isU8a, isUndefined, stringCamelCase, u8aToHex } from '@polkadot/util';
|
||||
import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
import Raw from '../codec/Raw';
|
||||
import { defaultExtensions, expandExtensionTypes, findUnknownExtensions } from '../extrinsic/signedExtensions';
|
||||
@@ -94,6 +95,8 @@ export class TypeRegistry implements Registry {
|
||||
|
||||
#chainProperties?: ChainProperties;
|
||||
|
||||
#hasher: (data: Uint8Array) => Uint8Array = blake2AsU8a;
|
||||
|
||||
#knownTypes: RegisteredTypes = {};
|
||||
|
||||
#signedExtensions: string[] = defaultExtensions;
|
||||
@@ -271,6 +274,10 @@ export class TypeRegistry implements Registry {
|
||||
return !this.#unknownTypes.get(name) && (this.hasClass(name) || this.hasDef(name));
|
||||
}
|
||||
|
||||
public hash (data: Uint8Array): Uint8Array {
|
||||
return this.#hasher(data);
|
||||
}
|
||||
|
||||
public register (type: Constructor | RegistryTypes): void;
|
||||
|
||||
// eslint-disable-next-line no-dupe-class-members
|
||||
@@ -317,6 +324,10 @@ export class TypeRegistry implements Registry {
|
||||
}
|
||||
}
|
||||
|
||||
setHasher (hasher: (data: Uint8Array) => Uint8Array = blake2AsU8a): void {
|
||||
this.#hasher = hasher;
|
||||
}
|
||||
|
||||
setKnownTypes (knownTypes: RegisteredTypes): void {
|
||||
this.#knownTypes = knownTypes;
|
||||
}
|
||||
@@ -330,7 +341,7 @@ export class TypeRegistry implements Registry {
|
||||
// setup the available extensions
|
||||
this.setSignedExtensions(
|
||||
signedExtensions || (
|
||||
metadata.asLatest.extrinsic.version.gtn(0)
|
||||
metadata.asLatest.extrinsic.version.gt(BN_ZERO)
|
||||
? metadata.asLatest.extrinsic.signedExtensions.map((key) => key.toString())
|
||||
: defaultExtensions
|
||||
)
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
// Copyright 2017-2020 @polkadot/types authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||
|
||||
import { TypeRegistry } from '../create';
|
||||
import Raw from '../codec/Raw';
|
||||
import AccountId from './AccountId';
|
||||
|
||||
describe('EthereumAccountId', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
describe('defaults', (): void => {
|
||||
const id = registry.createType('EthereumAccountId');
|
||||
|
||||
it('has a 20-byte length', (): void => {
|
||||
expect(id).toHaveLength(20);
|
||||
});
|
||||
|
||||
it('is empty by default', (): void => {
|
||||
expect(id.isEmpty).toBe(true);
|
||||
});
|
||||
|
||||
it('equals the empty address', (): void => {
|
||||
expect(id.eq('0x0000000000000000000000000000000000000000')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('decoding', (): void => {
|
||||
const testDecode = (type: string, input: Uint8Array | string | AccountId, expected: string): void =>
|
||||
it(`can decode from ${type}`, (): void => {
|
||||
const a = registry.createType('EthereumAccountId', input);
|
||||
|
||||
expect(a.toString()).toBe(expected);
|
||||
});
|
||||
|
||||
testDecode(
|
||||
'AccountId',
|
||||
registry.createType('EthereumAccountId', '0x4119b2e6c3Cb618F4f0B93ac77f9BeeC7FF02887'),
|
||||
'0x4119b2e6c3Cb618F4f0B93ac77f9BeeC7FF02887'
|
||||
);
|
||||
testDecode('hex', '0x4119b2e6c3cb618f4f0B93ac77f9Beec7ff02887', '0x4119b2e6c3Cb618F4f0B93ac77f9BeeC7FF02887');
|
||||
testDecode(
|
||||
'Raw',
|
||||
new Raw(registry, [
|
||||
1, 2, 3, 4, 5, 6, 7, 8, 1, 2,
|
||||
1, 2, 3, 4, 5, 6, 7, 8, 1, 2
|
||||
]),
|
||||
'0x0102030405060708010201020304050607080102'
|
||||
);
|
||||
testDecode(
|
||||
'Uint8Array',
|
||||
Uint8Array.from([
|
||||
1, 2, 3, 4, 5, 6, 7, 8, 1, 2,
|
||||
1, 2, 3, 4, 5, 6, 7, 8, 1, 2
|
||||
]),
|
||||
'0x0102030405060708010201020304050607080102'
|
||||
);
|
||||
});
|
||||
|
||||
describe('encoding', (): void => {
|
||||
const testEncode = (to: 'toHex' | 'toJSON' | 'toString' | 'toU8a', expected: Uint8Array | string, input = '0x4119b2e6c3Cb618F4f0B93ac77f9BeeC7FF02887'): void =>
|
||||
it(`can encode ${to}`, (): void => {
|
||||
const a = registry.createType('EthereumAccountId', input);
|
||||
|
||||
expect(a[to]()).toEqual(expected);
|
||||
});
|
||||
|
||||
testEncode('toHex', '0x4119b2e6c3cb618f4f0b93ac77f9beec7ff02887');
|
||||
testEncode('toJSON', '0x4119b2e6c3Cb618F4f0B93ac77f9BeeC7FF02887');
|
||||
testEncode('toString', '0x4119b2e6c3Cb618F4f0B93ac77f9BeeC7FF02887');
|
||||
testEncode('toString', '0x0000000000000000000000000000000000000000', '0x00');
|
||||
testEncode('toU8a', Uint8Array.from([
|
||||
0x41, 0x19, 0xb2, 0xe6, 0xc3, 0xcb, 0x61, 0x8f, 0x4f, 0x0b,
|
||||
0x93, 0xac, 0x77, 0xf9, 0xbe, 0xec, 0x7f, 0xf0, 0x28, 0x87
|
||||
]));
|
||||
|
||||
it('decodes to a non-empty value', (): void => {
|
||||
expect(registry.createType('EthereumAccountId', '0x4119b2e6c3Cb618F4f0B93ac77f9BeeC7FF02887').isEmpty).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,75 @@
|
||||
// Copyright 2017-2020 @polkadot/types authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { AnyString, AnyU8a, Registry } from '../types';
|
||||
|
||||
import { hexToU8a, isHex, isString, isU8a, u8aToU8a } from '@polkadot/util';
|
||||
import { ethereumEncode, isEthereumAddress } from '@polkadot/util-crypto';
|
||||
|
||||
import U8aFixed from '../codec/U8aFixed';
|
||||
|
||||
/** @internal */
|
||||
function decodeAccountId (value: AnyU8a | AnyString): AnyU8a {
|
||||
if (isU8a(value) || Array.isArray(value)) {
|
||||
return u8aToU8a(value);
|
||||
} else if (isHex(value) || isEthereumAddress(value)) {
|
||||
return hexToU8a(value.toString());
|
||||
} else if (isString(value)) {
|
||||
return u8aToU8a((value as string).toString());
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @name EthereumAccountId
|
||||
* @description
|
||||
* A wrapper around an Ethereum-compatible AccountId. Since we are dealing with
|
||||
* underlying addresses (20 bytes in length), we extend from U8aFixed which is
|
||||
* just a Uint8Array wrapper with a fixed length.
|
||||
*/
|
||||
export default class AccountId extends U8aFixed {
|
||||
constructor (registry: Registry, value: AnyU8a = new Uint8Array()) {
|
||||
super(registry, decodeAccountId(value), 160);
|
||||
}
|
||||
|
||||
public static encode (value: Uint8Array): string {
|
||||
return ethereumEncode(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Compares the value of the input to see if there is a match
|
||||
*/
|
||||
public eq (other?: unknown): boolean {
|
||||
return super.eq(decodeAccountId(other as AnyU8a));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
||||
*/
|
||||
public toHuman (): string {
|
||||
return this.toJSON();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Converts the Object to JSON, typically used for RPC transfers
|
||||
*/
|
||||
public toJSON (): string {
|
||||
return this.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the string representation of the value
|
||||
*/
|
||||
public toString (): string {
|
||||
return AccountId.encode(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the base runtime type name for this instance
|
||||
*/
|
||||
public toRawType (): string {
|
||||
return 'AccountId';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
// Copyright 2017-2020 @polkadot/types authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { TypeRegistry } from '../create';
|
||||
import AccountIndex from '../generic/AccountIndex';
|
||||
import AccountId from './AccountId';
|
||||
import Address from './LookupSource';
|
||||
|
||||
describe('EthereumLookupSource', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
const testDecode = (type: string, input: Address | AccountId | AccountIndex | number[] | Uint8Array, expected: string): void =>
|
||||
it(`can decode from ${type}`, (): void => {
|
||||
const a = registry.createType('EthereumLookupSource', input);
|
||||
|
||||
expect(a.toString()).toBe(expected);
|
||||
});
|
||||
|
||||
describe('decoding', (): void => {
|
||||
testDecode(
|
||||
'Address',
|
||||
registry.createType('EthereumLookupSource', '0x00a329c0648769a73afac7f9381e08fb43dbea72'),
|
||||
'0x00a329c0648769A73afAc7F9381E08FB43dBEA72'
|
||||
);
|
||||
testDecode(
|
||||
'AccountId',
|
||||
registry.createType('EthereumAccountId', '0x4119b2e6c3Cb618F4f0B93ac77f9BeeC7FF02887'),
|
||||
'0x4119b2e6c3Cb618F4f0B93ac77f9BeeC7FF02887'
|
||||
);
|
||||
testDecode(
|
||||
'AccountIndex (mixed prefixes)',
|
||||
registry.createType('EthereumLookupSource', '2jpAFn'),
|
||||
// NOTE Expected address here is encoded with prefix 42, input above with 68
|
||||
'25GUyv'
|
||||
);
|
||||
testDecode(
|
||||
'AccountIndex (hex)',
|
||||
registry.createType('AccountIndex', '0x0100'),
|
||||
'25GUyv'
|
||||
);
|
||||
testDecode(
|
||||
'Uint8Array (with prefix 255)',
|
||||
Uint8Array.from([
|
||||
255,
|
||||
0x41, 0x19, 0xb2, 0xe6, 0xc3, 0xcb, 0x61, 0x8f, 0x4f, 0x0b,
|
||||
0x93, 0xac, 0x77, 0xf9, 0xbe, 0xec, 0x7f, 0xf0, 0x28, 0x87
|
||||
]),
|
||||
'0x4119b2e6c3Cb618F4f0B93ac77f9BeeC7FF02887'
|
||||
);
|
||||
testDecode(
|
||||
'Uint8Array (with prefix 1 byte)',
|
||||
Uint8Array.from([1]),
|
||||
'F7NZ'
|
||||
);
|
||||
testDecode(
|
||||
'Uint8Array (with prefix 2 bytes)',
|
||||
Uint8Array.from([0xfc, 0, 1]),
|
||||
'25GUyv'
|
||||
);
|
||||
testDecode(
|
||||
'Uint8Array (with prefix 4 bytes)',
|
||||
Uint8Array.from([0xfd, 17, 18, 19, 20]),
|
||||
'Mwz15xP2'
|
||||
);
|
||||
});
|
||||
|
||||
describe('encoding', (): void => {
|
||||
const testEncode = (to: 'toHex' | 'toString' | 'toU8a', expected: string | Uint8Array): void =>
|
||||
it(`can encode ${to}`, (): void => {
|
||||
const a = registry.createType('EthereumLookupSource', '0x4119b2e6c3Cb618F4f0B93ac77f9BeeC7FF02887');
|
||||
|
||||
expect(a[to]()).toEqual(expected);
|
||||
});
|
||||
|
||||
testEncode(
|
||||
'toHex',
|
||||
'0xff4119b2e6c3cb618f4f0b93ac77f9beec7ff02887'
|
||||
);
|
||||
testEncode(
|
||||
'toString',
|
||||
'0x4119b2e6c3Cb618F4f0B93ac77f9BeeC7FF02887'
|
||||
);
|
||||
testEncode(
|
||||
'toU8a',
|
||||
Uint8Array.from([
|
||||
255,
|
||||
0x41, 0x19, 0xb2, 0xe6, 0xc3, 0xcb, 0x61, 0x8f, 0x4f, 0x0b,
|
||||
0x93, 0xac, 0x77, 0xf9, 0xbe, 0xec, 0x7f, 0xf0, 0x28, 0x87
|
||||
])
|
||||
);
|
||||
});
|
||||
|
||||
describe('utility', (): void => {
|
||||
it('equals on AccountId', (): void => {
|
||||
const addr = '0x4119b2e6c3Cb618F4f0B93ac77f9BeeC7FF02887';
|
||||
|
||||
expect(registry.createType('EthereumLookupSource', addr).eq(addr)).toBe(true);
|
||||
});
|
||||
|
||||
it('equals on AccountIndex', (): void => {
|
||||
// see the test below - these are equivalent (with different prefix encoding)
|
||||
expect(registry.createType('EthereumLookupSource', '2jpAFn').eq('25GUyv')).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,124 @@
|
||||
// Copyright 2017-2020 @polkadot/types authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Registry } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { isBn, isHex, isNumber, isU8a, u8aConcat, u8aToHex, u8aToU8a, u8aToBn } from '@polkadot/util';
|
||||
import { decodeAddress } from '@polkadot/util-crypto';
|
||||
|
||||
import Base from '../codec/Base';
|
||||
import AccountIndex from '../generic/AccountIndex';
|
||||
import EthereumAccountId from './AccountId';
|
||||
|
||||
type AnyAddress = BN | LookupSource | EthereumAccountId | AccountIndex | number[] | Uint8Array | number | string;
|
||||
|
||||
export const ACCOUNT_ID_PREFIX = new Uint8Array([0xff]);
|
||||
|
||||
/** @internal */
|
||||
function decodeString (registry: Registry, value: string): EthereumAccountId | AccountIndex {
|
||||
const decoded = decodeAddress(value);
|
||||
|
||||
return decoded.length === 20
|
||||
? registry.createType('EthereumAccountId', decoded)
|
||||
: registry.createType('AccountIndex', u8aToBn(decoded, true));
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function decodeU8a (registry: Registry, value: Uint8Array): EthereumAccountId | AccountIndex {
|
||||
// This allows us to instantiate an address with a raw publicKey. Do this first before
|
||||
// we checking the first byte, otherwise we may split an already-existent valid address
|
||||
if (value.length === 20) {
|
||||
return registry.createType('EthereumAccountId', value);
|
||||
} else if (value[0] === 0xff) {
|
||||
return registry.createType('EthereumAccountId', value.subarray(1));
|
||||
}
|
||||
|
||||
const [offset, length] = AccountIndex.readLength(value);
|
||||
|
||||
return registry.createType('AccountIndex', u8aToBn(value.subarray(offset, offset + length), true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @name LookupSource
|
||||
* @description
|
||||
* A wrapper around an EthereumAccountId and/or AccountIndex that is encoded with a prefix.
|
||||
* Since we are dealing with underlying publicKeys (or shorter encoded addresses),
|
||||
* we extend from Base with an AccountId/AccountIndex wrapper. Basically the Address
|
||||
* is encoded as `[ <prefix-byte>, ...publicKey/...bytes ]` as per spec
|
||||
*/
|
||||
export default class LookupSource extends Base<EthereumAccountId | AccountIndex> {
|
||||
constructor (registry: Registry, value: AnyAddress = new Uint8Array()) {
|
||||
super(registry, LookupSource._decodeAddress(registry, value));
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
private static _decodeAddress (registry: Registry, value: AnyAddress): EthereumAccountId | AccountIndex {
|
||||
if (value instanceof EthereumAccountId || value instanceof AccountIndex) {
|
||||
return value;
|
||||
} else if (value instanceof LookupSource) {
|
||||
return value._raw;
|
||||
} else if (isBn(value) || isNumber(value)) {
|
||||
return registry.createType('AccountIndex', value);
|
||||
} else if (Array.isArray(value) || isHex(value) || isU8a(value)) {
|
||||
return decodeU8a(registry, u8aToU8a(value));
|
||||
}
|
||||
|
||||
return decodeString(registry, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The length of the value when encoded as a Uint8Array
|
||||
*/
|
||||
public get encodedLength (): number {
|
||||
const rawLength = this._rawLength;
|
||||
|
||||
return rawLength + (
|
||||
// for 1 byte AccountIndexes, we are not adding a specific prefix
|
||||
rawLength > 1
|
||||
? 1
|
||||
: 0
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The length of the raw value, either AccountIndex or AccountId
|
||||
*/
|
||||
protected get _rawLength (): number {
|
||||
return this._raw instanceof AccountIndex
|
||||
? AccountIndex.calcLength(this._raw)
|
||||
: this._raw.encodedLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns a hex string representation of the value
|
||||
*/
|
||||
public toHex (): string {
|
||||
return u8aToHex(this.toU8a());
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the base runtime type name for this instance
|
||||
*/
|
||||
public toRawType (): string {
|
||||
return 'Address';
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
||||
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
||||
*/
|
||||
public toU8a (isBare?: boolean): Uint8Array {
|
||||
const encoded = this._raw.toU8a().subarray(0, this._rawLength);
|
||||
|
||||
return isBare
|
||||
? encoded
|
||||
: u8aConcat(
|
||||
this._raw instanceof AccountIndex
|
||||
? AccountIndex.writeLength(encoded)
|
||||
: ACCOUNT_ID_PREFIX,
|
||||
encoded
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// Copyright 2017-2020 @polkadot/types authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
export { default as GenericEthereumAccountId } from './AccountId';
|
||||
export { default as GenericEthereumLookupSource } from './LookupSource';
|
||||
@@ -3,14 +3,12 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { SignOptions } from '@polkadot/keyring/types';
|
||||
import { IKeyringPair } from '../types';
|
||||
|
||||
import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
import { IKeyringPair, Registry } from '../types';
|
||||
|
||||
// a helper function for both types of payloads, Raw and metadata-known
|
||||
export function sign (signerPair: IKeyringPair, u8a: Uint8Array, options?: SignOptions): Uint8Array {
|
||||
export function sign (registry: Registry, signerPair: IKeyringPair, u8a: Uint8Array, options?: SignOptions): Uint8Array {
|
||||
const encoded = u8a.length > 256
|
||||
? blake2AsU8a(u8a)
|
||||
? registry.hash(u8a)
|
||||
: u8a;
|
||||
|
||||
return signerPair.sign(encoded, options);
|
||||
|
||||
@@ -67,6 +67,6 @@ export default class ExtrinsicPayloadV1 extends Struct {
|
||||
* @description Sign the payload with the keypair
|
||||
*/
|
||||
public sign (signerPair: IKeyringPair): Uint8Array {
|
||||
return sign(signerPair, this.toU8a({ method: true }));
|
||||
return sign(this.registry, signerPair, this.toU8a({ method: true }));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,6 @@ import { Address, Balance, Call, Index } from '../../interfaces/runtime';
|
||||
import { ExtrinsicPayloadValue, IExtrinsicSignature, IKeyringPair, Registry, SignatureOptions } from '../../types';
|
||||
import { ExtrinsicSignatureOptions } from '../types';
|
||||
|
||||
import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
import Compact from '../../codec/Compact';
|
||||
import Struct from '../../codec/Struct';
|
||||
import { EMPTY_U8A, IMMORTAL_ERA } from '../constants';
|
||||
@@ -142,10 +140,7 @@ export default class ExtrinsicSignatureV1 extends Struct implements IExtrinsicSi
|
||||
* @description Generate a payload and applies the signature from a keypair
|
||||
*/
|
||||
public sign (method: Call, account: IKeyringPair, options: SignatureOptions): IExtrinsicSignature {
|
||||
const address = account.publicKey.length > 32
|
||||
? blake2AsU8a(account.publicKey, 256)
|
||||
: account.publicKey;
|
||||
const signer = this.registry.createType('Address', address);
|
||||
const signer = this.registry.createType('Address', account.addressRaw);
|
||||
const payload = this.createPayload(method, options);
|
||||
const signature = this.registry.createType('Signature', payload.sign(account));
|
||||
|
||||
|
||||
@@ -69,6 +69,6 @@ export default class ExtrinsicPayloadV2 extends Struct {
|
||||
* @description Sign the payload with the keypair
|
||||
*/
|
||||
public sign (signerPair: IKeyringPair): Uint8Array {
|
||||
return sign(signerPair, this.toU8a({ method: true }));
|
||||
return sign(this.registry, signerPair, this.toU8a({ method: true }));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,6 @@ import { Address, Balance, Call, Index } from '../../interfaces/runtime';
|
||||
import { ExtrinsicPayloadValue, IExtrinsicSignature, IKeyringPair, Registry, SignatureOptions } from '../../types';
|
||||
import { ExtrinsicSignatureOptions } from '../types';
|
||||
|
||||
import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
import Compact from '../../codec/Compact';
|
||||
import Struct from '../../codec/Struct';
|
||||
import { EMPTY_U8A, IMMORTAL_ERA } from '../constants';
|
||||
@@ -138,10 +136,7 @@ export default class ExtrinsicSignatureV2 extends Struct implements IExtrinsicSi
|
||||
* @description Generate a payload and applies the signature from a keypair
|
||||
*/
|
||||
public sign (method: Call, account: IKeyringPair, options: SignatureOptions): IExtrinsicSignature {
|
||||
const address = account.publicKey.length > 32
|
||||
? blake2AsU8a(account.publicKey, 256)
|
||||
: account.publicKey;
|
||||
const signer = this.registry.createType('Address', address);
|
||||
const signer = this.registry.createType('Address', account.addressRaw);
|
||||
const payload = this.createPayload(method, options);
|
||||
const signature = this.registry.createType('Signature', payload.sign(account));
|
||||
|
||||
|
||||
@@ -88,6 +88,6 @@ export default class ExtrinsicPayloadV3 extends Struct {
|
||||
* @description Sign the payload with the keypair
|
||||
*/
|
||||
public sign (signerPair: IKeyringPair): Uint8Array {
|
||||
return sign(signerPair, this.toU8a({ method: true }));
|
||||
return sign(this.registry, signerPair, this.toU8a({ method: true }));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
import { Address, Call } from '../../interfaces/runtime';
|
||||
import { ExtrinsicPayloadValue, IExtrinsicSignature, IKeyringPair, SignatureOptions } from '../../types';
|
||||
|
||||
import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
import { IMMORTAL_ERA } from '../constants';
|
||||
import ExtrinsicSignatureV2 from '../v2/ExtrinsicSignature';
|
||||
import ExtrinsicPayloadV3 from './ExtrinsicPayload';
|
||||
@@ -48,10 +46,7 @@ export default class ExtrinsicSignatureV3 extends ExtrinsicSignatureV2 {
|
||||
* @description Generate a payload and applies the signature from a keypair
|
||||
*/
|
||||
public sign (method: Call, account: IKeyringPair, options: SignatureOptions): IExtrinsicSignature {
|
||||
const address = account.publicKey.length > 32
|
||||
? blake2AsU8a(account.publicKey, 256)
|
||||
: account.publicKey;
|
||||
const signer = this.registry.createType('Address', address);
|
||||
const signer = this.registry.createType('Address', account.addressRaw);
|
||||
const payload = this.createPayload(method, options);
|
||||
const signature = this.registry.createType('Signature', payload.sign(account));
|
||||
|
||||
|
||||
@@ -91,6 +91,6 @@ export default class ExtrinsicPayloadV4 extends Struct {
|
||||
// to have the length prefix included. This means that the data-as-signed is un-decodable,
|
||||
// but is also doesn't need the extra information, only the pure data (and is not decoded)
|
||||
// ... The same applies to V1..V3, if we have a V5, carry move this comment to latest
|
||||
return sign(signerPair, this.toU8a({ method: true }), { withType: true });
|
||||
return sign(this.registry, signerPair, this.toU8a({ method: true }), { withType: true });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import { ExtrinsicPayloadValue, IExtrinsicSignature, IKeyringPair, Registry, Sig
|
||||
import { ExtrinsicSignatureOptions } from '../types';
|
||||
|
||||
import { u8aConcat } from '@polkadot/util';
|
||||
import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
import Compact from '../../codec/Compact';
|
||||
import Struct from '../../codec/Struct';
|
||||
@@ -142,10 +141,7 @@ export default class ExtrinsicSignatureV4 extends Struct implements IExtrinsicSi
|
||||
* @description Generate a payload and applies the signature from a keypair
|
||||
*/
|
||||
public sign (method: Call, account: IKeyringPair, options: SignatureOptions): IExtrinsicSignature {
|
||||
const address = account.publicKey.length > 32
|
||||
? blake2AsU8a(account.publicKey, 256)
|
||||
: account.publicKey;
|
||||
const signer = this.registry.createType('Address', address);
|
||||
const signer = this.registry.createType('Address', account.addressRaw);
|
||||
const payload = this.createPayload(method, options);
|
||||
const signature = this.registry.createType('MultiSignature', payload.sign(account));
|
||||
|
||||
|
||||
@@ -26,6 +26,12 @@ describe('AccountId', (): void => {
|
||||
it('equals the empty address', (): void => {
|
||||
expect(id.eq('5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM')).toBe(true);
|
||||
});
|
||||
|
||||
it('allows decoding from null', (): void => {
|
||||
expect(
|
||||
registry.createType('AccountId', null).eq('5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM')
|
||||
).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('decoding', (): void => {
|
||||
@@ -36,6 +42,12 @@ describe('AccountId', (): void => {
|
||||
expect(a.toString()).toBe(expected);
|
||||
});
|
||||
|
||||
it('fails with non-32-byte lengths', (): void => {
|
||||
expect(
|
||||
() => registry.createType('AccountId', '0x1234')
|
||||
).toThrow(/Invalid AccountId provided, expected 32 bytes/);
|
||||
});
|
||||
|
||||
testDecode(
|
||||
'AccountId',
|
||||
registry.createType('AccountId', '0x0102030405060708010203040506070801020304050607080102030405060708'),
|
||||
@@ -72,7 +84,7 @@ describe('AccountId', (): void => {
|
||||
testEncode('toHex', '0x0102030405060708010203040506070801020304050607080102030405060708');
|
||||
testEncode('toJSON', '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF');
|
||||
testEncode('toString', '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF');
|
||||
testEncode('toString', '5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM', '0x00');
|
||||
testEncode('toString', '5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM', '0x0000000000000000000000000000000000000000000000000000000000000000');
|
||||
testEncode('toU8a', Uint8Array.from([
|
||||
1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8,
|
||||
1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8
|
||||
@@ -92,7 +104,7 @@ describe('AccountId', (): void => {
|
||||
);
|
||||
|
||||
const data = registry.createType('StorageData', jsonVec.params.result.changes[0][1]);
|
||||
const list = registry.createType('Vec<AccountId>', data).map((accountId): string => accountId.toString());
|
||||
const list = registry.createType('Vec<AccountId>', data).map((accountId) => accountId.toString());
|
||||
|
||||
expect(list).toEqual([
|
||||
'7qVJujLF3EDbZt5WfQXWvueFedMS4Vfk2Hb4GyR8jwksTLup',
|
||||
|
||||
@@ -4,14 +4,16 @@
|
||||
|
||||
import { AnyString, AnyU8a, Registry } from '../types';
|
||||
|
||||
import { hexToU8a, isHex, isString, isU8a, u8aToU8a } from '@polkadot/util';
|
||||
import { hexToU8a, isHex, isString, isU8a, u8aToU8a, assert } from '@polkadot/util';
|
||||
import { decodeAddress, encodeAddress } from '@polkadot/util-crypto';
|
||||
|
||||
import U8aFixed from '../codec/U8aFixed';
|
||||
|
||||
/** @internal */
|
||||
function decodeAccountId (value: AnyU8a | AnyString): AnyU8a {
|
||||
if (isU8a(value) || Array.isArray(value)) {
|
||||
function decodeAccountId (value?: AnyU8a | AnyString): Uint8Array {
|
||||
if (!value) {
|
||||
return new Uint8Array();
|
||||
} else if (isU8a(value) || Array.isArray(value)) {
|
||||
return u8aToU8a(value);
|
||||
} else if (isHex(value)) {
|
||||
return hexToU8a(value.toString());
|
||||
@@ -19,7 +21,7 @@ function decodeAccountId (value: AnyU8a | AnyString): AnyU8a {
|
||||
return decodeAddress((value as string).toString());
|
||||
}
|
||||
|
||||
return value;
|
||||
throw new Error('Unknown type passed to AccountId constructor');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -30,8 +32,13 @@ function decodeAccountId (value: AnyU8a | AnyString): AnyU8a {
|
||||
* just a Uint8Array wrapper with a fixed length.
|
||||
*/
|
||||
export default class AccountId extends U8aFixed {
|
||||
constructor (registry: Registry, value: AnyU8a = new Uint8Array()) {
|
||||
super(registry, decodeAccountId(value), 256);
|
||||
constructor (registry: Registry, value?: AnyU8a) {
|
||||
const decoded = decodeAccountId(value);
|
||||
|
||||
// Part of stream containing >= 32 bytes or a all empty (defaults)
|
||||
assert(decoded.length >= 32 || !decoded.some((b) => b), `Invalid AccountId provided, expected 32 bytes, found ${decoded.length}`);
|
||||
|
||||
super(registry, decoded, 256);
|
||||
}
|
||||
|
||||
public static encode (value: Uint8Array, ss58Format?: number): string {
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
import { Digest, DigestItem, H256, Header } from '../interfaces/runtime';
|
||||
import { AnyNumber, AnyU8a, Registry } from '../types';
|
||||
|
||||
import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
import Extrinsic from '../extrinsic/Extrinsic';
|
||||
import Struct from '../codec/Struct';
|
||||
import Vec from '../codec/Vec';
|
||||
@@ -42,7 +40,7 @@ export default class Block extends Struct {
|
||||
* @description Encodes a content [[Hash]] for the block
|
||||
*/
|
||||
public get contentHash (): H256 {
|
||||
return this.registry.createType('H256', blake2AsU8a(this.toU8a(), 256));
|
||||
return this.registry.createType('H256', this.registry.hash(this.toU8a()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+7
-7
@@ -5,12 +5,12 @@
|
||||
import { TypeRegistry } from '../create';
|
||||
import AccountId from './AccountId';
|
||||
import AccountIndex from './AccountIndex';
|
||||
import Address from './Address';
|
||||
import LookupSource from './LookupSource';
|
||||
|
||||
describe('Address', (): void => {
|
||||
describe('LookupSource', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
const testDecode = (type: string, input: Address | AccountId | AccountIndex | number[] | Uint8Array, expected: string): void =>
|
||||
const testDecode = (type: string, input: LookupSource | AccountId | AccountIndex | number[] | Uint8Array, expected: string): void =>
|
||||
it(`can decode from ${type}`, (): void => {
|
||||
const a = registry.createType('Address', input);
|
||||
|
||||
@@ -21,19 +21,19 @@ describe('Address', (): void => {
|
||||
it('equals on AccountId', (): void => {
|
||||
const addr = '5DkQbYAExs3M2sZgT1Ec3mKfZnAQCL4Dt9beTCknkCUn5jzo';
|
||||
|
||||
expect(registry.createType('Address', addr).eq(addr)).toBe(true);
|
||||
expect(registry.createType('LookupSource', addr).eq(addr)).toBe(true);
|
||||
});
|
||||
|
||||
it('equals on AccountIndex', (): void => {
|
||||
// see the test below - these are equivalent (with different prefix encoding)
|
||||
expect(registry.createType('Address', '2jpAFn').eq('25GUyv')).toBe(true);
|
||||
expect(registry.createType('LookupSource', '2jpAFn').eq('25GUyv')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('decoding', (): void => {
|
||||
testDecode(
|
||||
'Address',
|
||||
registry.createType('Address', '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF'),
|
||||
registry.createType('LookupSource', '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF'),
|
||||
'5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF'
|
||||
);
|
||||
testDecode(
|
||||
@@ -43,7 +43,7 @@ describe('Address', (): void => {
|
||||
);
|
||||
testDecode(
|
||||
'AccountIndex (mixed prefixes)',
|
||||
registry.createType('Address', '2jpAFn'),
|
||||
registry.createType('LookupSource', '2jpAFn'),
|
||||
// NOTE Expected adress here is encoded with prefix 42, input above with 68
|
||||
'25GUyv'
|
||||
);
|
||||
@@ -12,7 +12,7 @@ import Base from '../codec/Base';
|
||||
import AccountId from './AccountId';
|
||||
import AccountIndex from './AccountIndex';
|
||||
|
||||
type AnyAddress = BN | Address | AccountId | AccountIndex | number[] | Uint8Array | number | string;
|
||||
type AnyAddress = BN | LookupSource | AccountId | AccountIndex | number[] | Uint8Array | number | string;
|
||||
|
||||
export const ACCOUNT_ID_PREFIX = new Uint8Array([0xff]);
|
||||
|
||||
@@ -41,23 +41,23 @@ function decodeU8a (registry: Registry, value: Uint8Array): AccountId | AccountI
|
||||
}
|
||||
|
||||
/**
|
||||
* @name Address
|
||||
* @name LookupSource
|
||||
* @description
|
||||
* A wrapper around an AccountId and/or AccountIndex that is encoded with a prefix.
|
||||
* Since we are dealing with underlying publicKeys (or shorter encoded addresses),
|
||||
* we extend from Base with an AccountId/AccountIndex wrapper. Basically the Address
|
||||
* is encoded as `[ <prefix-byte>, ...publicKey/...bytes ]` as per spec
|
||||
*/
|
||||
export default class Address extends Base<AccountId | AccountIndex> {
|
||||
export default class LookupSource extends Base<AccountId | AccountIndex> {
|
||||
constructor (registry: Registry, value: AnyAddress = new Uint8Array()) {
|
||||
super(registry, Address._decodeAddress(registry, value));
|
||||
super(registry, LookupSource._decodeAddress(registry, value));
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
private static _decodeAddress (registry: Registry, value: AnyAddress): AccountId | AccountIndex {
|
||||
if (value instanceof AccountId || value instanceof AccountIndex) {
|
||||
return value;
|
||||
} else if (value instanceof Address) {
|
||||
} else if (value instanceof LookupSource) {
|
||||
return value._raw;
|
||||
} else if (isBn(value) || isNumber(value)) {
|
||||
return registry.createType('AccountIndex', value);
|
||||
@@ -2,11 +2,13 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
export * from '../ethereum';
|
||||
|
||||
export { default as GenericAccountId } from './AccountId';
|
||||
export { default as GenericAccountIndex } from './AccountIndex';
|
||||
export { default as GenericAddress } from './Address';
|
||||
export { default as GenericBlock } from './Block';
|
||||
export { default as GenericCall } from './Call';
|
||||
export { default as GenericConsensusEngineId } from './ConsensusEngineId';
|
||||
export { default as GenericEvent } from './Event';
|
||||
export { default as GenericLookupSource } from './LookupSource';
|
||||
export { default as GenericVote } from './Vote';
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user