@pezkuwi/api 16.5.6 → 16.5.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/LICENSE +201 -0
- package/build/README.md +100 -0
- package/build/augment.d.ts +1 -0
- package/build/augment.js +1 -0
- package/build/base/Decorate.d.ts +143 -0
- package/build/base/Decorate.js +752 -0
- package/build/base/Events.d.ts +67 -0
- package/build/base/Events.js +78 -0
- package/build/base/Getters.d.ts +163 -0
- package/build/base/Getters.js +207 -0
- package/build/base/Init.d.ts +44 -0
- package/build/base/Init.js +400 -0
- package/build/base/find.d.ts +3 -0
- package/build/base/find.js +7 -0
- package/build/base/index.d.ts +47 -0
- package/build/base/index.js +57 -0
- package/build/base/types.d.ts +15 -0
- package/build/base/types.js +1 -0
- package/build/bundle-pezkuwi-api.js +26247 -0
- package/build/bundle.d.ts +7 -0
- package/build/bundle.js +7 -0
- package/build/cjs/augment.d.ts +1 -0
- package/build/cjs/augment.js +3 -0
- package/build/cjs/base/Decorate.d.ts +143 -0
- package/build/cjs/base/Decorate.js +756 -0
- package/build/cjs/base/Events.d.ts +67 -0
- package/build/cjs/base/Events.js +82 -0
- package/build/cjs/base/Getters.d.ts +163 -0
- package/build/cjs/base/Getters.js +211 -0
- package/build/cjs/base/Init.d.ts +44 -0
- package/build/cjs/base/Init.js +404 -0
- package/build/cjs/base/find.d.ts +3 -0
- package/build/cjs/base/find.js +11 -0
- package/build/cjs/base/index.d.ts +47 -0
- package/build/cjs/base/index.js +61 -0
- package/build/cjs/base/types.d.ts +15 -0
- package/build/cjs/base/types.js +2 -0
- package/build/cjs/bundle.d.ts +7 -0
- package/build/cjs/bundle.js +17 -0
- package/build/cjs/index.d.ts +2 -0
- package/build/cjs/index.js +5 -0
- package/build/cjs/package.json +3 -0
- package/build/cjs/packageDetect.d.ts +1 -0
- package/build/cjs/packageDetect.js +10 -0
- package/build/cjs/packageInfo.d.ts +6 -0
- package/build/cjs/packageInfo.js +4 -0
- package/build/cjs/promise/Api.d.ts +158 -0
- package/build/cjs/promise/Api.js +195 -0
- package/build/cjs/promise/Combinator.d.ts +12 -0
- package/build/cjs/promise/Combinator.js +72 -0
- package/build/cjs/promise/decorateMethod.d.ts +14 -0
- package/build/cjs/promise/decorateMethod.js +75 -0
- package/build/cjs/promise/index.d.ts +2 -0
- package/build/cjs/promise/index.js +7 -0
- package/build/cjs/promise/types.d.ts +5 -0
- package/build/cjs/promise/types.js +2 -0
- package/build/cjs/rx/Api.d.ts +155 -0
- package/build/cjs/rx/Api.js +173 -0
- package/build/cjs/rx/decorateMethod.d.ts +3 -0
- package/build/cjs/rx/decorateMethod.js +6 -0
- package/build/cjs/rx/index.d.ts +2 -0
- package/build/cjs/rx/index.js +7 -0
- package/build/cjs/submittable/Result.d.ts +31 -0
- package/build/cjs/submittable/Result.js +84 -0
- package/build/cjs/submittable/createClass.d.ts +12 -0
- package/build/cjs/submittable/createClass.js +277 -0
- package/build/cjs/submittable/createSubmittable.d.ts +8 -0
- package/build/cjs/submittable/createSubmittable.js +8 -0
- package/build/cjs/submittable/index.d.ts +2 -0
- package/build/cjs/submittable/index.js +7 -0
- package/build/cjs/submittable/types.d.ts +1 -0
- package/build/cjs/submittable/types.js +2 -0
- package/build/cjs/types/calls.d.ts +1 -0
- package/build/cjs/types/calls.js +4 -0
- package/build/cjs/types/consts.d.ts +1 -0
- package/build/cjs/types/consts.js +4 -0
- package/build/cjs/types/errors.d.ts +1 -0
- package/build/cjs/types/errors.js +4 -0
- package/build/cjs/types/events.d.ts +1 -0
- package/build/cjs/types/events.js +4 -0
- package/build/cjs/types/index.d.ts +114 -0
- package/build/cjs/types/index.js +13 -0
- package/build/cjs/types/storage.d.ts +1 -0
- package/build/cjs/types/storage.js +4 -0
- package/build/cjs/types/submittable.d.ts +1 -0
- package/build/cjs/types/submittable.js +4 -0
- package/build/cjs/util/augmentObject.d.ts +9 -0
- package/build/cjs/util/augmentObject.js +84 -0
- package/build/cjs/util/decorate.d.ts +16 -0
- package/build/cjs/util/decorate.js +17 -0
- package/build/cjs/util/filterEvents.d.ts +6 -0
- package/build/cjs/util/filterEvents.js +25 -0
- package/build/cjs/util/index.d.ts +4 -0
- package/build/cjs/util/index.js +11 -0
- package/build/cjs/util/isKeyringPair.d.ts +3 -0
- package/build/cjs/util/isKeyringPair.js +7 -0
- package/build/cjs/util/logging.d.ts +1 -0
- package/build/cjs/util/logging.js +5 -0
- package/build/cjs/util/validate.d.ts +3 -0
- package/build/cjs/util/validate.js +26 -0
- package/build/index.d.ts +2 -0
- package/build/index.js +2 -0
- package/build/package.json +612 -0
- package/build/packageDetect.d.ts +1 -0
- package/build/packageDetect.js +8 -0
- package/build/packageInfo.d.ts +6 -0
- package/build/packageInfo.js +1 -0
- package/build/promise/Api.d.ts +158 -0
- package/build/promise/Api.js +191 -0
- package/build/promise/Combinator.d.ts +12 -0
- package/build/promise/Combinator.js +68 -0
- package/build/promise/decorateMethod.d.ts +14 -0
- package/build/promise/decorateMethod.js +71 -0
- package/build/promise/index.d.ts +2 -0
- package/build/promise/index.js +2 -0
- package/build/promise/types.d.ts +5 -0
- package/build/promise/types.js +1 -0
- package/build/rx/Api.d.ts +155 -0
- package/build/rx/Api.js +169 -0
- package/build/rx/decorateMethod.d.ts +3 -0
- package/build/rx/decorateMethod.js +3 -0
- package/build/rx/index.d.ts +2 -0
- package/build/rx/index.js +2 -0
- package/build/submittable/Result.d.ts +31 -0
- package/build/submittable/Result.js +80 -0
- package/build/submittable/createClass.d.ts +12 -0
- package/build/submittable/createClass.js +274 -0
- package/build/submittable/createSubmittable.d.ts +8 -0
- package/build/submittable/createSubmittable.js +5 -0
- package/build/submittable/index.d.ts +2 -0
- package/build/submittable/index.js +2 -0
- package/build/submittable/types.d.ts +1 -0
- package/build/submittable/types.js +1 -0
- package/build/types/calls.d.ts +1 -0
- package/build/types/calls.js +1 -0
- package/build/types/consts.d.ts +1 -0
- package/build/types/consts.js +1 -0
- package/build/types/errors.d.ts +1 -0
- package/build/types/errors.js +1 -0
- package/build/types/events.d.ts +1 -0
- package/build/types/events.js +1 -0
- package/build/types/index.d.ts +114 -0
- package/build/types/index.js +8 -0
- package/build/types/storage.d.ts +1 -0
- package/build/types/storage.js +1 -0
- package/build/types/submittable.d.ts +1 -0
- package/build/types/submittable.js +1 -0
- package/build/util/augmentObject.d.ts +9 -0
- package/build/util/augmentObject.js +81 -0
- package/build/util/decorate.d.ts +16 -0
- package/build/util/decorate.js +14 -0
- package/build/util/filterEvents.d.ts +6 -0
- package/build/util/filterEvents.js +22 -0
- package/build/util/index.d.ts +4 -0
- package/build/util/index.js +4 -0
- package/build/util/isKeyringPair.d.ts +3 -0
- package/build/util/isKeyringPair.js +4 -0
- package/build/util/logging.d.ts +1 -0
- package/build/util/logging.js +2 -0
- package/build/util/validate.d.ts +3 -0
- package/build/util/validate.js +23 -0
- package/build-deno/README.md +95 -0
- package/build-deno/augment.ts +2 -0
- package/build-deno/base/Decorate.ts +1100 -0
- package/build-deno/base/Events.ts +89 -0
- package/build-deno/base/Getters.ts +243 -0
- package/build-deno/base/Init.ts +523 -0
- package/build-deno/base/find.ts +12 -0
- package/build-deno/base/index.ts +83 -0
- package/build-deno/base/types.ts +17 -0
- package/build-deno/bundle.ts +11 -0
- package/build-deno/checkTypes.manual.ts +320 -0
- package/build-deno/index.ts +4 -0
- package/build-deno/mod.ts +2 -0
- package/build-deno/packageDetect.ts +12 -0
- package/build-deno/packageInfo.ts +3 -0
- package/build-deno/promise/Api.ts +212 -0
- package/build-deno/promise/Combinator.ts +89 -0
- package/build-deno/promise/decorateMethod.ts +111 -0
- package/build-deno/promise/index.ts +3 -0
- package/build-deno/promise/types.ts +7 -0
- package/build-deno/rx/Api.ts +184 -0
- package/build-deno/rx/decorateMethod.ts +7 -0
- package/build-deno/rx/index.ts +3 -0
- package/build-deno/submittable/Result.ts +109 -0
- package/build-deno/submittable/createClass.ts +436 -0
- package/build-deno/submittable/createSubmittable.ts +17 -0
- package/build-deno/submittable/index.ts +3 -0
- package/build-deno/submittable/types.ts +2 -0
- package/build-deno/test/SingleAccountSigner.ts +51 -0
- package/build-deno/test/index.ts +3 -0
- package/build-deno/test/logEvents.ts +21 -0
- package/build-deno/types/calls.ts +2 -0
- package/build-deno/types/consts.ts +2 -0
- package/build-deno/types/errors.ts +2 -0
- package/build-deno/types/events.ts +2 -0
- package/build-deno/types/index.ts +124 -0
- package/build-deno/types/storage.ts +2 -0
- package/build-deno/types/submittable.ts +2 -0
- package/build-deno/util/augmentObject.ts +109 -0
- package/build-deno/util/decorate.ts +38 -0
- package/build-deno/util/filterEvents.ts +32 -0
- package/build-deno/util/index.ts +6 -0
- package/build-deno/util/isKeyringPair.ts +9 -0
- package/build-deno/util/logging.ts +4 -0
- package/build-deno/util/validate.ts +32 -0
- package/build-tsc/augment.d.ts +1 -0
- package/build-tsc/base/Decorate.d.ts +143 -0
- package/build-tsc/base/Events.d.ts +67 -0
- package/build-tsc/base/Getters.d.ts +163 -0
- package/build-tsc/base/Init.d.ts +44 -0
- package/build-tsc/base/find.d.ts +3 -0
- package/build-tsc/base/index.d.ts +47 -0
- package/build-tsc/base/types.d.ts +15 -0
- package/build-tsc/bundle.d.ts +7 -0
- package/build-tsc/index.d.ts +2 -0
- package/build-tsc/packageDetect.d.ts +1 -0
- package/build-tsc/packageInfo.d.ts +6 -0
- package/build-tsc/promise/Api.d.ts +158 -0
- package/build-tsc/promise/Combinator.d.ts +12 -0
- package/build-tsc/promise/decorateMethod.d.ts +14 -0
- package/build-tsc/promise/index.d.ts +2 -0
- package/build-tsc/promise/types.d.ts +5 -0
- package/build-tsc/rx/Api.d.ts +155 -0
- package/build-tsc/rx/decorateMethod.d.ts +3 -0
- package/build-tsc/rx/index.d.ts +2 -0
- package/build-tsc/submittable/Result.d.ts +31 -0
- package/build-tsc/submittable/createClass.d.ts +12 -0
- package/build-tsc/submittable/createSubmittable.d.ts +8 -0
- package/build-tsc/submittable/index.d.ts +2 -0
- package/build-tsc/submittable/types.d.ts +1 -0
- package/build-tsc/types/calls.d.ts +1 -0
- package/build-tsc/types/consts.d.ts +1 -0
- package/build-tsc/types/errors.d.ts +1 -0
- package/build-tsc/types/events.d.ts +1 -0
- package/build-tsc/types/index.d.ts +114 -0
- package/build-tsc/types/storage.d.ts +1 -0
- package/build-tsc/types/submittable.d.ts +1 -0
- package/build-tsc/util/augmentObject.d.ts +9 -0
- package/build-tsc/util/decorate.d.ts +16 -0
- package/build-tsc/util/filterEvents.d.ts +6 -0
- package/build-tsc/util/index.d.ts +4 -0
- package/build-tsc/util/isKeyringPair.d.ts +3 -0
- package/build-tsc/util/logging.d.ts +1 -0
- package/build-tsc/util/validate.d.ts +3 -0
- package/build-tsc-cjs/augment.js +3 -0
- package/build-tsc-cjs/base/Decorate.js +756 -0
- package/build-tsc-cjs/base/Events.js +82 -0
- package/build-tsc-cjs/base/Getters.js +211 -0
- package/build-tsc-cjs/base/Init.js +404 -0
- package/build-tsc-cjs/base/find.js +11 -0
- package/build-tsc-cjs/base/index.js +61 -0
- package/build-tsc-cjs/base/types.js +2 -0
- package/build-tsc-cjs/bundle.js +17 -0
- package/build-tsc-cjs/index.js +5 -0
- package/build-tsc-cjs/packageDetect.js +10 -0
- package/build-tsc-cjs/packageInfo.js +4 -0
- package/build-tsc-cjs/promise/Api.js +195 -0
- package/build-tsc-cjs/promise/Combinator.js +72 -0
- package/build-tsc-cjs/promise/decorateMethod.js +75 -0
- package/build-tsc-cjs/promise/index.js +7 -0
- package/build-tsc-cjs/promise/types.js +2 -0
- package/build-tsc-cjs/rx/Api.js +173 -0
- package/build-tsc-cjs/rx/decorateMethod.js +6 -0
- package/build-tsc-cjs/rx/index.js +7 -0
- package/build-tsc-cjs/submittable/Result.js +84 -0
- package/build-tsc-cjs/submittable/createClass.js +277 -0
- package/build-tsc-cjs/submittable/createSubmittable.js +8 -0
- package/build-tsc-cjs/submittable/index.js +7 -0
- package/build-tsc-cjs/submittable/types.js +2 -0
- package/build-tsc-cjs/types/calls.js +4 -0
- package/build-tsc-cjs/types/consts.js +4 -0
- package/build-tsc-cjs/types/errors.js +4 -0
- package/build-tsc-cjs/types/events.js +4 -0
- package/build-tsc-cjs/types/index.js +13 -0
- package/build-tsc-cjs/types/storage.js +4 -0
- package/build-tsc-cjs/types/submittable.js +4 -0
- package/build-tsc-cjs/util/augmentObject.js +84 -0
- package/build-tsc-cjs/util/decorate.js +17 -0
- package/build-tsc-cjs/util/filterEvents.js +25 -0
- package/build-tsc-cjs/util/index.js +11 -0
- package/build-tsc-cjs/util/isKeyringPair.js +7 -0
- package/build-tsc-cjs/util/logging.js +5 -0
- package/build-tsc-cjs/util/validate.js +26 -0
- package/build-tsc-esm/augment.js +1 -0
- package/build-tsc-esm/base/Decorate.js +752 -0
- package/build-tsc-esm/base/Events.js +78 -0
- package/build-tsc-esm/base/Getters.js +207 -0
- package/build-tsc-esm/base/Init.js +400 -0
- package/build-tsc-esm/base/find.js +7 -0
- package/build-tsc-esm/base/index.js +57 -0
- package/build-tsc-esm/base/types.js +1 -0
- package/build-tsc-esm/bundle.js +7 -0
- package/build-tsc-esm/index.js +2 -0
- package/build-tsc-esm/packageDetect.js +8 -0
- package/build-tsc-esm/packageInfo.js +1 -0
- package/build-tsc-esm/promise/Api.js +191 -0
- package/build-tsc-esm/promise/Combinator.js +68 -0
- package/build-tsc-esm/promise/decorateMethod.js +71 -0
- package/build-tsc-esm/promise/index.js +2 -0
- package/build-tsc-esm/promise/types.js +1 -0
- package/build-tsc-esm/rx/Api.js +169 -0
- package/build-tsc-esm/rx/decorateMethod.js +3 -0
- package/build-tsc-esm/rx/index.js +2 -0
- package/build-tsc-esm/submittable/Result.js +80 -0
- package/build-tsc-esm/submittable/createClass.js +274 -0
- package/build-tsc-esm/submittable/createSubmittable.js +5 -0
- package/build-tsc-esm/submittable/index.js +2 -0
- package/build-tsc-esm/submittable/types.js +1 -0
- package/build-tsc-esm/types/calls.js +1 -0
- package/build-tsc-esm/types/consts.js +1 -0
- package/build-tsc-esm/types/errors.js +1 -0
- package/build-tsc-esm/types/events.js +1 -0
- package/build-tsc-esm/types/index.js +8 -0
- package/build-tsc-esm/types/storage.js +1 -0
- package/build-tsc-esm/types/submittable.js +1 -0
- package/build-tsc-esm/util/augmentObject.js +81 -0
- package/build-tsc-esm/util/decorate.js +14 -0
- package/build-tsc-esm/util/filterEvents.js +22 -0
- package/build-tsc-esm/util/index.js +4 -0
- package/build-tsc-esm/util/isKeyringPair.js +4 -0
- package/build-tsc-esm/util/logging.js +2 -0
- package/build-tsc-esm/util/validate.js +23 -0
- package/bundle-pezkuwi-api.js +26240 -26231
- package/cjs/packageInfo.js +1 -1
- package/package.json +12 -12
- package/packageInfo.js +1 -1
- package/src/augment.ts +4 -0
- package/src/base/Decorate.ts +1103 -0
- package/src/base/Events.ts +91 -0
- package/src/base/Getters.ts +245 -0
- package/src/base/Init.ts +525 -0
- package/src/base/find.ts +14 -0
- package/src/base/index.ts +85 -0
- package/src/base/types.ts +19 -0
- package/src/bundle.ts +16 -0
- package/src/checkTypes.manual.ts +323 -0
- package/src/index.ts +6 -0
- package/src/mod.ts +4 -0
- package/src/packageDetect.ts +16 -0
- package/src/packageInfo.ts +6 -0
- package/src/promise/Api.ts +214 -0
- package/src/promise/Combinator.ts +91 -0
- package/src/promise/Combinators.spec.ts +109 -0
- package/src/promise/decorateMethod.ts +118 -0
- package/src/promise/index.spec.ts +167 -0
- package/src/promise/index.ts +5 -0
- package/src/promise/types.ts +9 -0
- package/src/rx/Api.ts +186 -0
- package/src/rx/decorateMethod.ts +9 -0
- package/src/rx/index.ts +5 -0
- package/src/submittable/Result.ts +111 -0
- package/src/submittable/createClass.ts +438 -0
- package/src/submittable/createSubmittable.ts +19 -0
- package/src/submittable/index.ts +5 -0
- package/src/submittable/types.ts +4 -0
- package/src/test/SingleAccountSigner.ts +53 -0
- package/src/test/index.ts +5 -0
- package/src/test/logEvents.ts +24 -0
- package/src/types/calls.ts +4 -0
- package/src/types/consts.ts +4 -0
- package/src/types/errors.ts +4 -0
- package/src/types/events.ts +4 -0
- package/src/types/index.ts +137 -0
- package/src/types/storage.ts +4 -0
- package/src/types/submittable.ts +4 -0
- package/src/util/augmentObject.spec.ts +54 -0
- package/src/util/augmentObject.ts +112 -0
- package/src/util/decorate.ts +43 -0
- package/src/util/filterEvents.ts +34 -0
- package/src/util/index.ts +10 -0
- package/src/util/isKeyringPair.ts +11 -0
- package/src/util/logging.ts +6 -0
- package/src/util/validate.spec.ts +72 -0
- package/src/util/validate.ts +36 -0
- package/tsconfig.build.json +25 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.spec.json +26 -0
- package/tsconfig.spec.tsbuildinfo +1 -0
package/build/rx/Api.js
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { from } from 'rxjs';
|
|
2
|
+
import { objectSpread } from '@pezkuwi/util';
|
|
3
|
+
import { ApiBase } from '../base/index.js';
|
|
4
|
+
import { toRxMethod } from './decorateMethod.js';
|
|
5
|
+
/**
|
|
6
|
+
* # @pezkuwi/api/rx
|
|
7
|
+
*
|
|
8
|
+
* ## Overview
|
|
9
|
+
*
|
|
10
|
+
* @name ApiRx
|
|
11
|
+
*
|
|
12
|
+
* @description
|
|
13
|
+
* ApiRx is a powerful RxJS Observable wrapper around the RPC and interfaces on the Pezkuwi network. As a full Observable API, all interface calls return RxJS Observables, including the static `.create(...)`. In the same fashion and subscription-based methods return long-running Observables that update with the latest values.
|
|
14
|
+
*
|
|
15
|
+
* The API is well suited to real-time applications where the latest state is needed, unlocking the subscription-based features of Pezkuwi (and Bizinikiwi) clients. Some familiarity with RxJS is a requirement to use the API, however just understanding `.subscribe` and `.pipe` on Observables will unlock full-scale use thereof.
|
|
16
|
+
*
|
|
17
|
+
* @see [[ApiPromise]]
|
|
18
|
+
*
|
|
19
|
+
* ## Usage
|
|
20
|
+
*
|
|
21
|
+
* Making rpc calls -
|
|
22
|
+
* <BR>
|
|
23
|
+
*
|
|
24
|
+
* ```javascript
|
|
25
|
+
* import ApiRx from '@pezkuwi/api/rx';
|
|
26
|
+
*
|
|
27
|
+
* // initialize via Promise & static create
|
|
28
|
+
* const api = await ApiRx.create().toPromise();
|
|
29
|
+
*
|
|
30
|
+
* // make a call to retrieve the current network head
|
|
31
|
+
* api.rpc.chain.subscribeNewHeads().subscribe((header) => {
|
|
32
|
+
* console.log(`Chain is at #${header.number}`);
|
|
33
|
+
* });
|
|
34
|
+
* ```
|
|
35
|
+
* <BR>
|
|
36
|
+
*
|
|
37
|
+
* Subscribing to chain state -
|
|
38
|
+
* <BR>
|
|
39
|
+
*
|
|
40
|
+
* ```javascript
|
|
41
|
+
* import { combineLatest, pairwise, switchMap } from 'rxjs';
|
|
42
|
+
* import { ApiRx, WsProvider } from '@pezkuwi/api';
|
|
43
|
+
*
|
|
44
|
+
*
|
|
45
|
+
* // initialize a provider with a specific endpoint
|
|
46
|
+
* const provider = new WsProvider('wss://example.com:9944')
|
|
47
|
+
*
|
|
48
|
+
* // initialize via isReady & new with specific provider
|
|
49
|
+
* new ApiRx({ provider })
|
|
50
|
+
* .isReady
|
|
51
|
+
* .pipe(
|
|
52
|
+
* switchMap((api) =>
|
|
53
|
+
* combineLatest([
|
|
54
|
+
* api.query.timestamp.blockPeriod(),
|
|
55
|
+
* api.query.timestamp.now().pipe(pairwise())
|
|
56
|
+
* ])
|
|
57
|
+
* )
|
|
58
|
+
* )
|
|
59
|
+
* .subscribe(([blockPeriod, timestamp]) => {
|
|
60
|
+
* const elapsed = timestamp[1].toNumber() - timestamp[0].toNumber();
|
|
61
|
+
* console.log(`timestamp ${timestamp[1]} \nelapsed ${elapsed} \n(${blockPeriod}s target)`);
|
|
62
|
+
* });
|
|
63
|
+
* ```
|
|
64
|
+
* <BR>
|
|
65
|
+
*
|
|
66
|
+
* Submitting a transaction -
|
|
67
|
+
* <BR>
|
|
68
|
+
*
|
|
69
|
+
* ```javascript
|
|
70
|
+
* import { first, switchMap } from 'rxjs';
|
|
71
|
+
* import ApiRx from '@pezkuwi/api/rx';
|
|
72
|
+
*
|
|
73
|
+
* // import the test keyring (already has dev keys for Alice, Bob, Charlie, Eve & Ferdie)
|
|
74
|
+
* import testingPairs from '@pezkuwi/keyring/testingPairs';
|
|
75
|
+
* const keyring = testingPairs();
|
|
76
|
+
*
|
|
77
|
+
* // get api via Promise
|
|
78
|
+
* const api = await ApiRx.create().toPromise();
|
|
79
|
+
*
|
|
80
|
+
* // retrieve nonce for the account
|
|
81
|
+
* api.query.system
|
|
82
|
+
* .account(keyring.alice.address)
|
|
83
|
+
* .pipe(
|
|
84
|
+
* first(),
|
|
85
|
+
* // pipe nonce into transfer
|
|
86
|
+
* switchMap(([nonce]) =>
|
|
87
|
+
* api.tx.balances
|
|
88
|
+
* // create transfer
|
|
89
|
+
* .transferAllowDeath(keyring.bob.address, 12345)
|
|
90
|
+
* // sign the transaction
|
|
91
|
+
* .sign(keyring.alice, { nonce })
|
|
92
|
+
* // send the transaction
|
|
93
|
+
* .send()
|
|
94
|
+
* )
|
|
95
|
+
* )
|
|
96
|
+
* // subscribe to overall result
|
|
97
|
+
* .subscribe(({ status }) => {
|
|
98
|
+
* if (status.isInBlock) {
|
|
99
|
+
* console.log('Completed at block hash', status.asFinalized.toHex());
|
|
100
|
+
* }
|
|
101
|
+
* });
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
export class ApiRx extends ApiBase {
|
|
105
|
+
#isReadyRx;
|
|
106
|
+
/**
|
|
107
|
+
* @description Create an instance of the ApiRx class
|
|
108
|
+
* @param options Options to create an instance. Can be either [[ApiOptions]] or [[WsProvider]]
|
|
109
|
+
* @example
|
|
110
|
+
* <BR>
|
|
111
|
+
*
|
|
112
|
+
* ```javascript
|
|
113
|
+
* import { switchMap } from 'rxjs';
|
|
114
|
+
* import Api from '@pezkuwi/api/rx';
|
|
115
|
+
*
|
|
116
|
+
* new Api().isReady
|
|
117
|
+
* .pipe(
|
|
118
|
+
* switchMap((api) =>
|
|
119
|
+
* api.rpc.chain.subscribeNewHeads()
|
|
120
|
+
* ))
|
|
121
|
+
* .subscribe((header) => {
|
|
122
|
+
* console.log(`new block #${header.number.toNumber()}`);
|
|
123
|
+
* });
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
constructor(options) {
|
|
127
|
+
super(options, 'rxjs', toRxMethod);
|
|
128
|
+
this.#isReadyRx = from(
|
|
129
|
+
// You can create an observable from an event, however my mind groks this form better
|
|
130
|
+
new Promise((resolve) => {
|
|
131
|
+
super.on('ready', () => resolve(this));
|
|
132
|
+
}));
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* @description Creates an ApiRx instance using the supplied provider. Returns an Observable containing the actual Api instance.
|
|
136
|
+
* @param options options that is passed to the class constructor. Can be either [[ApiOptions]] or [[WsProvider]]
|
|
137
|
+
* @example
|
|
138
|
+
* <BR>
|
|
139
|
+
*
|
|
140
|
+
* ```javascript
|
|
141
|
+
* import { switchMap } from 'rxjs';
|
|
142
|
+
* import Api from '@pezkuwi/api/rx';
|
|
143
|
+
*
|
|
144
|
+
* Api.create()
|
|
145
|
+
* .pipe(
|
|
146
|
+
* switchMap((api) =>
|
|
147
|
+
* api.rpc.chain.subscribeNewHeads()
|
|
148
|
+
* ))
|
|
149
|
+
* .subscribe((header) => {
|
|
150
|
+
* console.log(`new block #${header.number.toNumber()}`);
|
|
151
|
+
* });
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
static create(options) {
|
|
155
|
+
return new ApiRx(options).isReady;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* @description Observable that returns the first time we are connected and loaded
|
|
159
|
+
*/
|
|
160
|
+
get isReady() {
|
|
161
|
+
return this.#isReadyRx;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* @description Returns a clone of this ApiRx instance (new underlying provider connection)
|
|
165
|
+
*/
|
|
166
|
+
clone() {
|
|
167
|
+
return new ApiRx(objectSpread({}, this._options, { source: this }));
|
|
168
|
+
}
|
|
169
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { BlockNumber, DispatchError, DispatchInfo, EventRecord, ExtrinsicStatus, Hash } from '@pezkuwi/types/interfaces';
|
|
2
|
+
import type { AnyJson, ISubmittableResult } from '@pezkuwi/types/types';
|
|
3
|
+
import type { SubmittableResultValue } from './types.js';
|
|
4
|
+
export declare class SubmittableResult implements ISubmittableResult {
|
|
5
|
+
readonly dispatchError?: DispatchError | undefined;
|
|
6
|
+
readonly dispatchInfo?: DispatchInfo | undefined;
|
|
7
|
+
readonly internalError?: Error | undefined;
|
|
8
|
+
readonly events: EventRecord[];
|
|
9
|
+
readonly status: ExtrinsicStatus;
|
|
10
|
+
readonly txHash: Hash;
|
|
11
|
+
readonly txIndex?: number | undefined;
|
|
12
|
+
readonly blockNumber?: BlockNumber | undefined;
|
|
13
|
+
constructor({ blockNumber, dispatchError, dispatchInfo, events, internalError, status, txHash, txIndex }: SubmittableResultValue);
|
|
14
|
+
get isCompleted(): boolean;
|
|
15
|
+
get isError(): boolean;
|
|
16
|
+
get isFinalized(): boolean;
|
|
17
|
+
get isInBlock(): boolean;
|
|
18
|
+
get isWarning(): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* @description Filters EventRecords for the specified method & section (there could be multiple)
|
|
21
|
+
*/
|
|
22
|
+
filterRecords(section: string, method: string | string[]): EventRecord[];
|
|
23
|
+
/**
|
|
24
|
+
* @description Finds an EventRecord for the specified method & section
|
|
25
|
+
*/
|
|
26
|
+
findRecord(section: string, method: string | string[]): EventRecord | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* @description Creates a human representation of the output
|
|
29
|
+
*/
|
|
30
|
+
toHuman(isExtended?: boolean): AnyJson;
|
|
31
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
const recordIdentity = (record) => record;
|
|
2
|
+
function filterAndApply(events, section, methods, onFound) {
|
|
3
|
+
return events
|
|
4
|
+
.filter(({ event }) => section === event.section &&
|
|
5
|
+
methods.includes(event.method))
|
|
6
|
+
.map((record) => onFound(record));
|
|
7
|
+
}
|
|
8
|
+
function getDispatchError({ event: { data: [dispatchError] } }) {
|
|
9
|
+
return dispatchError;
|
|
10
|
+
}
|
|
11
|
+
function getDispatchInfo({ event: { data, method } }) {
|
|
12
|
+
return method === 'ExtrinsicSuccess'
|
|
13
|
+
? data[0]
|
|
14
|
+
: data[1];
|
|
15
|
+
}
|
|
16
|
+
function extractError(events = []) {
|
|
17
|
+
return filterAndApply(events, 'system', ['ExtrinsicFailed'], getDispatchError)[0];
|
|
18
|
+
}
|
|
19
|
+
function extractInfo(events = []) {
|
|
20
|
+
return filterAndApply(events, 'system', ['ExtrinsicFailed', 'ExtrinsicSuccess'], getDispatchInfo)[0];
|
|
21
|
+
}
|
|
22
|
+
export class SubmittableResult {
|
|
23
|
+
dispatchError;
|
|
24
|
+
dispatchInfo;
|
|
25
|
+
internalError;
|
|
26
|
+
events;
|
|
27
|
+
status;
|
|
28
|
+
txHash;
|
|
29
|
+
txIndex;
|
|
30
|
+
blockNumber;
|
|
31
|
+
constructor({ blockNumber, dispatchError, dispatchInfo, events, internalError, status, txHash, txIndex }) {
|
|
32
|
+
this.dispatchError = dispatchError || extractError(events);
|
|
33
|
+
this.dispatchInfo = dispatchInfo || extractInfo(events);
|
|
34
|
+
this.events = events || [];
|
|
35
|
+
this.internalError = internalError;
|
|
36
|
+
this.status = status;
|
|
37
|
+
this.txHash = txHash;
|
|
38
|
+
this.txIndex = txIndex;
|
|
39
|
+
this.blockNumber = blockNumber;
|
|
40
|
+
}
|
|
41
|
+
get isCompleted() {
|
|
42
|
+
return this.isError || this.status.isInBlock || this.status.isFinalized;
|
|
43
|
+
}
|
|
44
|
+
get isError() {
|
|
45
|
+
return this.status.isDropped || this.status.isFinalityTimeout || this.status.isInvalid || this.status.isUsurped;
|
|
46
|
+
}
|
|
47
|
+
get isFinalized() {
|
|
48
|
+
return this.status.isFinalized;
|
|
49
|
+
}
|
|
50
|
+
get isInBlock() {
|
|
51
|
+
return this.status.isInBlock;
|
|
52
|
+
}
|
|
53
|
+
get isWarning() {
|
|
54
|
+
return this.status.isRetracted;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* @description Filters EventRecords for the specified method & section (there could be multiple)
|
|
58
|
+
*/
|
|
59
|
+
filterRecords(section, method) {
|
|
60
|
+
return filterAndApply(this.events, section, Array.isArray(method) ? method : [method], recordIdentity);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* @description Finds an EventRecord for the specified method & section
|
|
64
|
+
*/
|
|
65
|
+
findRecord(section, method) {
|
|
66
|
+
return this.filterRecords(section, method)[0];
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* @description Creates a human representation of the output
|
|
70
|
+
*/
|
|
71
|
+
toHuman(isExtended) {
|
|
72
|
+
return {
|
|
73
|
+
dispatchError: this.dispatchError?.toHuman(),
|
|
74
|
+
dispatchInfo: this.dispatchInfo?.toHuman(),
|
|
75
|
+
events: this.events.map((e) => e.toHuman(isExtended)),
|
|
76
|
+
internalError: this.internalError?.message.toString(),
|
|
77
|
+
status: this.status.toHuman(isExtended)
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { CodecClass } from '@pezkuwi/types/types';
|
|
2
|
+
import type { ApiBase } from '../base/index.js';
|
|
3
|
+
import type { ApiInterfaceRx, ApiTypes } from '../types/index.js';
|
|
4
|
+
import type { SubmittableExtrinsic } from './types.js';
|
|
5
|
+
interface SubmittableOptions<ApiType extends ApiTypes> {
|
|
6
|
+
api: ApiInterfaceRx;
|
|
7
|
+
apiType: ApiTypes;
|
|
8
|
+
blockHash?: Uint8Array | undefined;
|
|
9
|
+
decorateMethod: ApiBase<ApiType>['_decorateMethod'];
|
|
10
|
+
}
|
|
11
|
+
export declare function createClass<ApiType extends ApiTypes>({ api, apiType, blockHash, decorateMethod }: SubmittableOptions<ApiType>): CodecClass<SubmittableExtrinsic<ApiType>>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { catchError, first, map, mergeMap, of, switchMap, tap } from 'rxjs';
|
|
2
|
+
import { identity, isBn, isFunction, isNumber, isString, isU8a, objectSpread } from '@pezkuwi/util';
|
|
3
|
+
import { filterEvents, isKeyringPair } from '../util/index.js';
|
|
4
|
+
import { SubmittableResult } from './Result.js';
|
|
5
|
+
function makeEraOptions(api, registry, partialOptions, { header, mortalLength, nonce }) {
|
|
6
|
+
if (!header) {
|
|
7
|
+
if (partialOptions.era && !partialOptions.blockHash) {
|
|
8
|
+
throw new Error('Expected blockHash to be passed alongside non-immortal era options');
|
|
9
|
+
}
|
|
10
|
+
if (isNumber(partialOptions.era)) {
|
|
11
|
+
// since we have no header, it is immortal, remove any option overrides
|
|
12
|
+
// so we only supply the genesisHash and no era to the construction
|
|
13
|
+
delete partialOptions.era;
|
|
14
|
+
delete partialOptions.blockHash;
|
|
15
|
+
}
|
|
16
|
+
return makeSignOptions(api, partialOptions, { nonce });
|
|
17
|
+
}
|
|
18
|
+
return makeSignOptions(api, partialOptions, {
|
|
19
|
+
blockHash: header.hash,
|
|
20
|
+
era: registry.createTypeUnsafe('ExtrinsicEra', [{
|
|
21
|
+
current: header.number,
|
|
22
|
+
period: partialOptions.era || mortalLength
|
|
23
|
+
}]),
|
|
24
|
+
nonce
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
function makeSignAndSendOptions(partialOptions, statusCb) {
|
|
28
|
+
let options = {};
|
|
29
|
+
if (isFunction(partialOptions)) {
|
|
30
|
+
statusCb = partialOptions;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
options = objectSpread({}, partialOptions);
|
|
34
|
+
}
|
|
35
|
+
return [options, statusCb];
|
|
36
|
+
}
|
|
37
|
+
function makeSignOptions(api, partialOptions, extras) {
|
|
38
|
+
return objectSpread({ blockHash: api.genesisHash, genesisHash: api.genesisHash }, partialOptions, extras, { runtimeVersion: api.runtimeVersion, signedExtensions: api.registry.signedExtensions, version: api.extrinsicType });
|
|
39
|
+
}
|
|
40
|
+
function optionsOrNonce(partialOptions = {}) {
|
|
41
|
+
return isBn(partialOptions) || isNumber(partialOptions)
|
|
42
|
+
? { nonce: partialOptions }
|
|
43
|
+
: partialOptions;
|
|
44
|
+
}
|
|
45
|
+
export function createClass({ api, apiType, blockHash, decorateMethod }) {
|
|
46
|
+
// an instance of the base extrinsic for us to extend
|
|
47
|
+
const ExtrinsicBase = api.registry.createClass('Extrinsic');
|
|
48
|
+
const extrinsicInfoMap = new WeakMap();
|
|
49
|
+
class Submittable extends ExtrinsicBase {
|
|
50
|
+
#ignoreStatusCb;
|
|
51
|
+
#transformResult = (identity);
|
|
52
|
+
constructor(registry, extrinsic) {
|
|
53
|
+
super(registry, extrinsic, { version: api.extrinsicType });
|
|
54
|
+
this.#ignoreStatusCb = apiType === 'rxjs';
|
|
55
|
+
}
|
|
56
|
+
get hasDryRun() {
|
|
57
|
+
return isFunction(api.rpc.system?.dryRun);
|
|
58
|
+
}
|
|
59
|
+
get hasPaymentInfo() {
|
|
60
|
+
return isFunction(api.call.transactionPaymentApi?.queryInfo);
|
|
61
|
+
}
|
|
62
|
+
// dry run an extrinsic
|
|
63
|
+
dryRun(account, optionsOrHash) {
|
|
64
|
+
if (!this.hasDryRun) {
|
|
65
|
+
throw new Error('The system.dryRun RPC call is not available in your environment');
|
|
66
|
+
}
|
|
67
|
+
if (blockHash || isString(optionsOrHash) || isU8a(optionsOrHash)) {
|
|
68
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
69
|
+
return decorateMethod(() => api.rpc.system.dryRun(this.toHex(), blockHash || optionsOrHash));
|
|
70
|
+
}
|
|
71
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return,@typescript-eslint/no-unsafe-call
|
|
72
|
+
return decorateMethod(() => this.#observeSign(account, optionsOrHash).pipe(switchMap(() => api.rpc.system.dryRun(this.toHex()))))();
|
|
73
|
+
}
|
|
74
|
+
// calculate the payment info for this transaction (if signed and submitted)
|
|
75
|
+
paymentInfo(account, optionsOrHash) {
|
|
76
|
+
if (!this.hasPaymentInfo) {
|
|
77
|
+
throw new Error('The transactionPaymentApi.queryInfo runtime call is not available in your environment');
|
|
78
|
+
}
|
|
79
|
+
if (blockHash || isString(optionsOrHash) || isU8a(optionsOrHash)) {
|
|
80
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
81
|
+
return decorateMethod(() => api.callAt(blockHash || optionsOrHash).pipe(switchMap((callAt) => {
|
|
82
|
+
const u8a = this.toU8a();
|
|
83
|
+
return callAt.transactionPaymentApi.queryInfo(u8a, u8a.length);
|
|
84
|
+
})));
|
|
85
|
+
}
|
|
86
|
+
const [allOptions] = makeSignAndSendOptions(optionsOrHash);
|
|
87
|
+
const address = isKeyringPair(account) ? account.address : account.toString();
|
|
88
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return,@typescript-eslint/no-unsafe-call
|
|
89
|
+
return decorateMethod(() => api.derive.tx.signingInfo(address, allOptions.nonce, allOptions.era).pipe(first(), switchMap((signingInfo) => {
|
|
90
|
+
// setup our options (same way as in signAndSend)
|
|
91
|
+
const eraOptions = makeEraOptions(api, this.registry, allOptions, signingInfo);
|
|
92
|
+
const signOptions = makeSignOptions(api, eraOptions, {});
|
|
93
|
+
// 1. Don't use the internal objects inside the new tx (hence toU8a)
|
|
94
|
+
// 2. Don't override the data from existing signed extrinsics
|
|
95
|
+
// 3. Ensure that this object stays intact, with no new sign after operation
|
|
96
|
+
const u8a = api.tx(this.toU8a()).signFake(address, signOptions).toU8a();
|
|
97
|
+
return api.call.transactionPaymentApi.queryInfo(u8a, u8a.length);
|
|
98
|
+
})))();
|
|
99
|
+
}
|
|
100
|
+
// send implementation for both immediate Hash and statusCb variants
|
|
101
|
+
send(statusCb) {
|
|
102
|
+
const isSubscription = api.hasSubscriptions && (this.#ignoreStatusCb || !!statusCb);
|
|
103
|
+
const updatedInfo = extrinsicInfoMap.get(this);
|
|
104
|
+
extrinsicInfoMap.delete(this);
|
|
105
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return,@typescript-eslint/no-unsafe-call
|
|
106
|
+
return decorateMethod(isSubscription
|
|
107
|
+
? () => this.#observeSubscribe(updatedInfo)
|
|
108
|
+
: () => this.#observeSend(updatedInfo))(statusCb);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* @description Signs a transaction, returning `this` to allow chaining. E.g.: `signAsync(...).send()`. Like `.signAndSend` this will retrieve the nonce and blockHash to send the tx with.
|
|
112
|
+
*/
|
|
113
|
+
signAsync(account, partialOptions) {
|
|
114
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return,@typescript-eslint/no-unsafe-call
|
|
115
|
+
return decorateMethod(() => this.#observeSign(account, partialOptions).pipe(map((info) => {
|
|
116
|
+
// If we got a full signed transaction from the signer, attach it
|
|
117
|
+
if (info.signedTransaction) {
|
|
118
|
+
const extrinsic = new Submittable(api.registry, info.signedTransaction);
|
|
119
|
+
extrinsicInfoMap.set(this, info);
|
|
120
|
+
return extrinsic;
|
|
121
|
+
}
|
|
122
|
+
// Fallback if signer didn’t return signedTransaction
|
|
123
|
+
return this;
|
|
124
|
+
})))();
|
|
125
|
+
}
|
|
126
|
+
// signAndSend implementation for all 3 cases above
|
|
127
|
+
signAndSend(account, partialOptions, optionalStatusCb) {
|
|
128
|
+
const [options, statusCb] = makeSignAndSendOptions(partialOptions, optionalStatusCb);
|
|
129
|
+
const isSubscription = api.hasSubscriptions && (this.#ignoreStatusCb || !!statusCb);
|
|
130
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return,@typescript-eslint/no-unsafe-call
|
|
131
|
+
return decorateMethod(() => this.#observeSign(account, options).pipe(switchMap((info) => isSubscription
|
|
132
|
+
? this.#observeSubscribe(info)
|
|
133
|
+
: this.#observeSend(info))) // FIXME This is wrong, SubmittableResult is _not_ a codec
|
|
134
|
+
)(statusCb);
|
|
135
|
+
}
|
|
136
|
+
// adds a transform to the result, applied before result is returned
|
|
137
|
+
withResultTransform(transform) {
|
|
138
|
+
this.#transformResult = transform;
|
|
139
|
+
return this;
|
|
140
|
+
}
|
|
141
|
+
#observeSign = (account, partialOptions) => {
|
|
142
|
+
const address = isKeyringPair(account) ? account.address : account.toString();
|
|
143
|
+
const options = optionsOrNonce(partialOptions);
|
|
144
|
+
return api.derive.tx.signingInfo(address, options.nonce, options.era).pipe(first(), mergeMap(async (signingInfo) => {
|
|
145
|
+
const eraOptions = makeEraOptions(api, this.registry, options, signingInfo);
|
|
146
|
+
let updateId = -1;
|
|
147
|
+
let signedTx = null;
|
|
148
|
+
if (isKeyringPair(account)) {
|
|
149
|
+
this.sign(account, eraOptions);
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
const result = await this.#signViaSigner(address, eraOptions, signingInfo.header);
|
|
153
|
+
updateId = result.id;
|
|
154
|
+
if (result.signedTransaction) {
|
|
155
|
+
signedTx = result.signedTransaction;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return { options: eraOptions, signedTransaction: signedTx, updateId };
|
|
159
|
+
}));
|
|
160
|
+
};
|
|
161
|
+
#observeStatus = (txHash, status) => {
|
|
162
|
+
if (!status.isFinalized && !status.isInBlock) {
|
|
163
|
+
return of(this.#transformResult(new SubmittableResult({
|
|
164
|
+
status,
|
|
165
|
+
txHash
|
|
166
|
+
})));
|
|
167
|
+
}
|
|
168
|
+
const blockHash = status.isInBlock
|
|
169
|
+
? status.asInBlock
|
|
170
|
+
: status.asFinalized;
|
|
171
|
+
return api.derive.tx.events(blockHash).pipe(map(({ block, events }) => this.#transformResult(new SubmittableResult({
|
|
172
|
+
...filterEvents(txHash, block, events, status),
|
|
173
|
+
status,
|
|
174
|
+
txHash
|
|
175
|
+
}))), catchError((internalError) => of(this.#transformResult(new SubmittableResult({
|
|
176
|
+
internalError,
|
|
177
|
+
status,
|
|
178
|
+
txHash
|
|
179
|
+
})))));
|
|
180
|
+
};
|
|
181
|
+
#observeSend = (info) => {
|
|
182
|
+
return api.rpc.author.submitExtrinsic(info?.signedTransaction || this).pipe(tap((hash) => {
|
|
183
|
+
this.#updateSigner(hash, info);
|
|
184
|
+
}));
|
|
185
|
+
};
|
|
186
|
+
#observeSubscribe = (info) => {
|
|
187
|
+
const txHash = this.hash;
|
|
188
|
+
return api.rpc.author.submitAndWatchExtrinsic(info?.signedTransaction || this).pipe(switchMap((status) => this.#observeStatus(txHash, status)), tap((status) => {
|
|
189
|
+
this.#updateSigner(status, info);
|
|
190
|
+
}));
|
|
191
|
+
};
|
|
192
|
+
#signViaSigner = async (address, options, header) => {
|
|
193
|
+
const signer = options.signer || api.signer;
|
|
194
|
+
const allowCallDataAlteration = options.allowCallDataAlteration ?? true;
|
|
195
|
+
if (!signer) {
|
|
196
|
+
throw new Error('No signer specified, either via api.setSigner or via sign options. You possibly need to pass through an explicit keypair for the origin so it can be used for signing.');
|
|
197
|
+
}
|
|
198
|
+
const payload = this.registry.createTypeUnsafe('SignerPayload', [objectSpread({}, options, {
|
|
199
|
+
address,
|
|
200
|
+
blockNumber: header ? header.number : 0,
|
|
201
|
+
method: this.method
|
|
202
|
+
})]);
|
|
203
|
+
let result;
|
|
204
|
+
if (isFunction(signer.signPayload)) {
|
|
205
|
+
result = await signer.signPayload(payload.toPayload());
|
|
206
|
+
if (result.signedTransaction && !options.withSignedTransaction) {
|
|
207
|
+
throw new Error('The `signedTransaction` field may not be submitted when `withSignedTransaction` is disabled');
|
|
208
|
+
}
|
|
209
|
+
if (result.signedTransaction && options.withSignedTransaction) {
|
|
210
|
+
const ext = this.registry.createTypeUnsafe('Extrinsic', [result.signedTransaction]);
|
|
211
|
+
const newSignerPayload = this.registry.createTypeUnsafe('SignerPayload', [objectSpread({}, {
|
|
212
|
+
address,
|
|
213
|
+
assetId: ext.assetId && ext.assetId.isSome ? ext.assetId.toHex() : null,
|
|
214
|
+
blockHash: payload.blockHash,
|
|
215
|
+
blockNumber: header ? header.number : 0,
|
|
216
|
+
era: ext.era.toHex(),
|
|
217
|
+
genesisHash: payload.genesisHash,
|
|
218
|
+
metadataHash: ext.metadataHash ? ext.metadataHash.toHex() : null,
|
|
219
|
+
method: ext.method.toHex(),
|
|
220
|
+
mode: ext.mode ? ext.mode.toHex() : null,
|
|
221
|
+
nonce: ext.nonce.toHex(),
|
|
222
|
+
runtimeVersion: payload.runtimeVersion,
|
|
223
|
+
signedExtensions: payload.signedExtensions,
|
|
224
|
+
tip: ext.tip ? ext.tip.toHex() : null,
|
|
225
|
+
version: payload.version
|
|
226
|
+
})]);
|
|
227
|
+
if (!ext.isSigned) {
|
|
228
|
+
throw new Error(`When using the signedTransaction field, the transaction must be signed. Recieved isSigned: ${ext.isSigned}`);
|
|
229
|
+
}
|
|
230
|
+
if (!allowCallDataAlteration) {
|
|
231
|
+
this.#validateSignedTransaction(payload, ext);
|
|
232
|
+
}
|
|
233
|
+
// This is only used for signAsync - signAndSend does not need to adjust the super payload or
|
|
234
|
+
// add the signature.
|
|
235
|
+
super.addSignature(address, result.signature, newSignerPayload.toPayload());
|
|
236
|
+
return { id: result.id, signedTransaction: result.signedTransaction };
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
else if (isFunction(signer.signRaw)) {
|
|
240
|
+
result = await signer.signRaw(payload.toRaw());
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
throw new Error('Invalid signer interface, it should implement either signPayload or signRaw (or both)');
|
|
244
|
+
}
|
|
245
|
+
// Here we explicitly call `toPayload()` again instead of working with an object
|
|
246
|
+
// (reference) as passed to the signer. This means that we are sure that the
|
|
247
|
+
// payload data is not modified from our inputs, but the signer
|
|
248
|
+
super.addSignature(address, result.signature, payload.toPayload());
|
|
249
|
+
return { id: result.id };
|
|
250
|
+
};
|
|
251
|
+
#updateSigner = (status, info) => {
|
|
252
|
+
if (info && (info.updateId !== -1)) {
|
|
253
|
+
const { options, updateId } = info;
|
|
254
|
+
const signer = options.signer || api.signer;
|
|
255
|
+
if (signer && isFunction(signer.update)) {
|
|
256
|
+
signer.update(updateId, status);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
/**
|
|
261
|
+
* When a signer includes `signedTransaction` within the SignerResult this will validate
|
|
262
|
+
* specific fields within the signed extrinsic against the original payload that was passed
|
|
263
|
+
* to the signer.
|
|
264
|
+
*/
|
|
265
|
+
#validateSignedTransaction = (signerPayload, signedExt) => {
|
|
266
|
+
const payload = signerPayload.toPayload();
|
|
267
|
+
const errMsg = (field) => `signAndSend: ${field} does not match the original payload`;
|
|
268
|
+
if (payload.method !== signedExt.method.toHex()) {
|
|
269
|
+
throw new Error(errMsg('call data'));
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
return Submittable;
|
|
274
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Call } from '@pezkuwi/types/interfaces';
|
|
2
|
+
import type { Registry } from '@pezkuwi/types-codec/types';
|
|
3
|
+
import type { ApiBase } from '../base/index.js';
|
|
4
|
+
import type { ApiInterfaceRx, ApiTypes } from '../types/index.js';
|
|
5
|
+
import type { SubmittableExtrinsic } from './types.js';
|
|
6
|
+
type Creator<ApiType extends ApiTypes> = (extrinsic: Call | Uint8Array | string) => SubmittableExtrinsic<ApiType>;
|
|
7
|
+
export declare function createSubmittable<ApiType extends ApiTypes>(apiType: ApiTypes, api: ApiInterfaceRx, decorateMethod: ApiBase<ApiType>['_decorateMethod'], registry?: Registry, blockHash?: Uint8Array): Creator<ApiType>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { createClass } from './createClass.js';
|
|
2
|
+
export function createSubmittable(apiType, api, decorateMethod, registry, blockHash) {
|
|
3
|
+
const Submittable = createClass({ api, apiType, blockHash, decorateMethod });
|
|
4
|
+
return (extrinsic) => new Submittable(registry || api.registry, extrinsic);
|
|
5
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { AddressOrPair, SignerOptions, SubmittableDryRunResult, SubmittableExtrinsic, SubmittablePaymentResult, SubmittableResultResult, SubmittableResultSubscription, SubmittableResultValue } from '@pezkuwi/api-base/types';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@pezkuwi/api-base/types/calls';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@pezkuwi/api-base/types/calls';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@pezkuwi/api-base/types/consts';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@pezkuwi/api-base/types/consts';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@pezkuwi/api-base/types/errors';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@pezkuwi/api-base/types/errors';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@pezkuwi/api-base/types/events';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@pezkuwi/api-base/types/events';
|