Compare commits

..
253 Commits
Author SHA1 Message Date
github-actions[bot] cbb5a021a0 [CI Skip] release/stable 6.12.1
skip-checks: true
2021-12-13 08:29:38 +00:00
Jaco da7f32d96f 6.12.1 (#4326) 2021-12-13 10:20:32 +02:00
github-actions[bot] 591784cd65 [CI Skip] release/beta 6.11.2-24
skip-checks: true
2021-12-13 06:21:35 +00:00
Jaco ddd2f2dfe5 Add tsconfig.base (#4325) 2021-12-13 08:13:54 +02:00
github-actions[bot] 56f297d3b9 [CI Skip] release/beta 6.11.2-23
skip-checks: true
2021-12-12 09:51:00 +00:00
Jaco fa7669f0af Bump tsc (#4323)
* Bump tsc

* Checktypes update
2021-12-12 11:44:20 +02:00
github-actions[bot] 2aa8525fe7 [CI Skip] release/beta 6.11.2-22
skip-checks: true
2021-12-12 07:40:06 +00:00
Jaco 9254c5781f Dedupe progress extraction (#4322)
* Dedupe progress extraction

* Adjust
2021-12-12 09:32:20 +02:00
github-actions[bot] e13f3bea65 [CI Skip] release/beta 6.11.2-21
skip-checks: true
2021-12-12 06:55:31 +00:00
Jaco 59c2327768 Add firstMemo (dedupes) (#4321)
* Add firstMemo (dedupes)

* Adjust

* flatten

* Readability

* Readability
2021-12-12 08:47:58 +02:00
github-actions[bot] 4b0c6aa515 [CI Skip] release/beta 6.11.2-20
skip-checks: true
2021-12-11 09:00:51 +00:00
Jaco 6276e45155 More cleanups to collective derives (#4320) 2021-12-11 10:50:33 +02:00
github-actions[bot] c7cb1d84ab [CI Skip] release/beta 6.11.2-19
skip-checks: true
2021-12-11 08:19:31 +00:00
Jaco 1a6025e012 Collective dedupe (#4319) 2021-12-11 10:08:41 +02:00
github-actions[bot] 83655c92c4 [CI Skip] release/beta 6.11.2-18
skip-checks: true
2021-12-11 07:45:04 +00:00
Jaco 63a55d2f8a Cleanups for bestNumber derives (#4318)
* Cleanups for bestNumber derives

* Unused imports

* Re-exports of types for *.d.ts outputs
2021-12-11 09:35:52 +02:00
github-actions[bot] c32953b2ea [CI Skip] release/beta 6.11.2-17
skip-checks: true
2021-12-10 15:39:53 +00:00
Jaco e51cd1a2f7 CheckNonZeroSender (#4316) 2021-12-10 17:31:53 +02:00
github-actions[bot] e58694566e [CI Skip] release/beta 6.11.2-16
skip-checks: true
2021-12-09 19:27:10 +00:00
Jaco 248561ca14 Cleanups with DRY-er code (#4312)
* Cleanups with DRY-er code

* dedupe

* lint fixes
2021-12-09 21:17:29 +02:00
github-actions[bot] d4a9b43e88 [CI Skip] release/beta 6.11.2-15
skip-checks: true
2021-12-09 16:34:11 +00:00
Jaco f717663f50 Update metadata generation docs (#4311)
* Update metadata generation docs

* Add cross-link
2021-12-09 18:26:20 +02:00
github-actions[bot] 49ebae9a55 [CI Skip] release/beta 6.11.2-14
skip-checks: true
2021-12-09 12:40:32 +00:00
Jaco 7a1419e73a Split relative & package imports in TS templates (#4310)
* Split relative & package imports in TS templates

* Cleanup unneeded spread

* Regen with importsAll
2021-12-09 14:32:01 +02:00
github-actions[bot] d15d05918c [CI Skip] release/beta 6.11.2-13
skip-checks: true
2021-12-09 11:04:56 +00:00
Jaco 969151c4a7 Additional derive cleanups (#4308)
* Additional derive cleanups

* unwrapNumber

* Adjust
2021-12-09 12:54:51 +02:00
github-actions[bot] 23717bb180 [CI Skip] release/beta 6.11.2-12
skip-checks: true
2021-12-09 10:19:29 +00:00
Jaco e32ac213b9 Additional derive cleanups (#4307)
* Additional derive cleanups

* Adjust

* Multi cache set

* Adjust mapping
2021-12-09 12:12:05 +02:00
github-actions[bot] 584cbb994b [CI Skip] release/beta 6.11.2-11
skip-checks: true
2021-12-08 18:26:13 +00:00
Jaco dcb7760a0e Remove capabilities (#4303) 2021-12-08 20:18:38 +02:00
github-actions[bot] fd6ba08f58 [CI Skip] release/beta 6.11.2-10
skip-checks: true
2021-12-08 17:25:20 +00:00
Jaco a30329b47d Support for contracts metadata V2 (#4289)
* Support for contracts metadata V2

* Add & use latest

* Build interfaces

* conversion of V1 -> Latest

* spreads

* Use V2 in creation, aka s/name/label/

* Extract -> latest conversion

* Flatten

* Add V2 test contracts (tests are failing)

* V2, V1 & V1 catered for in Abi.spec.ts

* Explicit v0/v1 -> Latest conversions

* Adjust V2/V1/V0 check order

* Cleanup type assertions

* Save

* Remove eslint unsafe

* Flatten test exports

* Entries... last non-critical, OCD-driven change...

* tsc check fixes

* Conversion tests

* v1ToLatest renames

* Text[]

* Split conversion (ease of future change)

* V2 in V2 conversion

* Dedupe?

* Additional cleanups

* Adjust

* Flatten types

* Adjust

* filter versions adjustments

* additional, get it done.
2021-12-08 19:14:51 +02:00
github-actions[bot] 610f03d006 [CI Skip] release/beta 6.11.2-9
skip-checks: true
2021-12-08 16:59:07 +00:00
Jaco 1cc9756d0e Dedupe collectives (#4302)
* Dedupe collectives

* Members

* Type imports (unused)

* Work-around for TS type imports

* tsconfig

* Adjust with only local imports
2021-12-08 18:50:18 +02:00
github-actions[bot] bf753cb858 [CI Skip] release/beta 6.11.2-8
skip-checks: true
2021-12-08 15:25:27 +00:00
Jaco 9a2cd1c446 Dedupe staking derive caches (#4301)
* Dedupe staking derive caches

* Dedupe

* Adjust

* Adjust

* typing

* lintin

* Adjust
2021-12-08 17:17:38 +02:00
github-actions[bot] 4a7bfe96e1 [CI Skip] release/beta 6.11.2-7
skip-checks: true
2021-12-08 12:23:29 +00:00
Jaco 7c51354186 Additional derive cleanups (#4299)
* Additional derive cleanups

* map var

* Apply suggestions from code review

* Additional

* Metadata cleanups

* Adjust

* Apply HexString to all Metadata init

* typegen HexString

* generator HexString

* basepath
2021-12-08 14:15:26 +02:00
github-actions[bot] 8a7707eb41 [CI Skip] release/beta 6.11.2-6
skip-checks: true
2021-12-08 11:22:53 +00:00
Jaco 88eac8e654 CC check adjustments (#4300) 2021-12-08 13:15:10 +02:00
github-actions[bot] c637d699bc [CI Skip] release/beta 6.11.2-5
skip-checks: true
2021-12-08 10:20:44 +00:00
Jaco d2450a9382 Cleanup storage createFunction (#4298)
* Cleanup storage createFunction

* Fix build
2021-12-08 12:12:01 +02:00
github-actions[bot] 4dd6b82471 [CI Skip] release/beta 6.11.2-4
skip-checks: true
2021-12-08 09:37:16 +00:00
Jaco 93ce2210da Adjust private members to JS privates (#4297) 2021-12-08 11:28:19 +02:00
github-actions[bot] 2463b52381 [CI Skip] release/beta 6.11.2-3
skip-checks: true
2021-12-08 09:26:53 +00:00
Jaco bc1cdc17e0 Cleanup author extraction (#4296) 2021-12-08 11:16:50 +02:00
github-actions[bot] 47ddfd75f7 [CI Skip] release/beta 6.11.2-2
skip-checks: true
2021-12-08 08:46:02 +00:00
Jaco 9643a2e026 Expose type on generated interfaces (#4295) 2021-12-08 10:36:12 +02:00
github-actions[bot] 5ceaa53c59 [CI Skip] release/beta 6.11.2-1
skip-checks: true
2021-12-08 08:21:38 +00:00
Jaco edc09b56b4 Small utility dedups (#4294) 2021-12-08 10:13:04 +02:00
github-actions[bot] 9b940738d4 [CI Skip] release/beta 6.11.2-0
skip-checks: true
2021-12-07 14:21:11 +00:00
Jaco b86610381a Kusama 9130 upgrade block (#4291) 2021-12-07 16:11:38 +02:00
github-actions[bot] dfe4bb32f0 [CI Skip] release/stable 6.11.1
skip-checks: true
2021-12-05 18:52:48 +00:00
Jaco b81c73b6ec 6.11.1 (#4288) 2021-12-05 20:45:20 +02:00
github-actions[bot] 9bb2549d0b [CI Skip] release/beta 6.10.4-4
skip-checks: true
2021-12-05 12:09:16 +00:00
Jaco ab90f8bd41 Bump metadata (#4286)
* Bump metadata

* Kusama & Polkadot

* Build interfaces

* Build json
2021-12-05 13:59:55 +02:00
github-actions[bot] 221712753f [CI Skip] release/beta 6.10.4-3
skip-checks: true
2021-12-05 11:49:23 +00:00
Jaco ed28a990af Bump common (#4285)
* Bump common

* 8.1.2
2021-12-05 13:40:10 +02:00
github-actions[bot] 055f32d1d9 [CI Skip] release/beta 6.10.4-2
skip-checks: true
2021-12-01 08:57:36 +00:00
Jaco a175ce87d7 Adjust cron (#4278) 2021-12-01 10:49:08 +02:00
github-actions[bot] f0f1714b12 [CI Skip] release/beta 6.10.4-1
skip-checks: true
2021-12-01 08:06:03 +00:00
Jaco 3778bd893b Add extra param to state_traceBlock (#4276)
* Add extra param to state_traceBlock

* CHANGELOG
2021-12-01 09:57:56 +02:00
github-actions[bot] d4436e19fa [CI Skip] release/beta 6.10.4-0
skip-checks: true
2021-12-01 07:48:35 +00:00
Jaco 4cf93fd4c0 Bump common (#4277) 2021-12-01 09:41:33 +02:00
github-actions[bot] 6d94896764 [CI Skip] release/stable 6.10.3
skip-checks: true
2021-11-30 14:14:46 +00:00
Jaco bacb757d7d Fix ss58Prefix extraction (#4274)
* Fix ss58Prefix extraction

* allow fallback

* adjust
2021-11-30 16:07:50 +02:00
github-actions[bot] 7be3cc949f [CI Skip] release/stable 6.10.2
skip-checks: true
2021-11-30 05:32:43 +00:00
Jaco 41cc8b34aa Bump util (#4272)
* Bump util

* util 8.0.4

* 8.0.4
2021-11-30 07:25:50 +02:00
github-actions[bot] 4bbba5bb35 [CI Skip] release/beta 6.10.2-0
skip-checks: true
2021-11-29 15:48:19 +00:00
Jaco feae323f5c Adjust augmentation interface consistency (#4269)
* Adjust augmetation interface consistency

* spelling

* Remove useless eslint slience

* slience escapes

* rebuild

* Fix indent

* comment fix (again)

* Adjust

* Additional adjustments
2021-11-29 17:41:23 +02:00
github-actions[bot] b363833a9f [CI Skip] release/stable 6.10.1
skip-checks: true
2021-11-29 06:45:19 +00:00
Jaco f083ea3861 6.10.1 (#4267) 2021-11-29 08:38:21 +02:00
github-actions[bot] f62e7f8bf9 [CI Skip] release/beta 6.9.3-6
skip-checks: true
2021-11-29 05:55:26 +00:00
Jaco fedb0a3f09 Re-order augmentation imports (#4266) 2021-11-29 07:46:34 +02:00
github-actions[bot] 38928448bf [CI Skip] release/beta 6.9.3-5
skip-checks: true
2021-11-26 12:54:56 +00:00
Jaco cfbde5f6bd Fix RPC non-available section init (#4263) 2021-11-26 14:47:54 +02:00
github-actions[bot] 4b0e0bc6d3 [CI Skip] release/beta 6.9.3-4
skip-checks: true
2021-11-26 10:51:45 +00:00
Jaco 9acb79f500 Bump common (#4262)
* Bump common

* Adjust
2021-11-26 12:45:02 +02:00
Github Actions 5dc0b38881 [CI Skip] release/beta 6.9.3-3
skip-checks: true
2021-11-24 14:59:43 +00:00
Jaco fab6f7e883 Adjust stale schedule (#4257) 2021-11-24 16:52:40 +02:00
Github Actions 66e635e909 [CI Skip] release/beta 6.9.3-2
skip-checks: true
2021-11-23 08:08:38 +00:00
Jaco 6e496d5a3c Add missing types -> types-known dep (#4252)
* Add missing types -> types-known dep

* Run install :)
2021-11-23 09:59:53 +02:00
Github Actions ca172c9a53 [CI Skip] release/beta 6.9.3-1
skip-checks: true
2021-11-22 09:49:34 +00:00
Jaco e9b83a9ff6 Bump static metadata (#4248)
* Bump static metadata

* metadata static json

* Adjust tests (new signed extensions)
2021-11-22 11:42:27 +02:00
Github Actions cf18d97b3a [CI Skip] release/beta 6.9.3-0
skip-checks: true
2021-11-22 06:41:45 +00:00
Jaco 0b1c715408 Bump dev (#4247) 2021-11-22 08:32:50 +02:00
Github Actions 5d493e1a03 [CI Skip] release/stable 6.9.2
skip-checks: true
2021-11-22 05:34:55 +00:00
Jaco e5437ef9e9 6.9.2 (#4246)
* 6.9.2

* Pull in new util
2021-11-22 07:26:47 +02:00
Github Actions b56bed39e1 [CI Skip] release/stable 6.9.1
skip-checks: true
2021-11-21 09:36:41 +00:00
Jaco e789f91850 6.9.1 (#4244) 2021-11-21 11:28:52 +02:00
Github Actions a236eb9453 [CI Skip] release/beta 6.8.2-18
skip-checks: true
2021-11-21 09:14:31 +00:00
Jaco 7ef01b8534 Bump common (#4243) 2021-11-21 11:06:08 +02:00
Github Actions 0e58545a9d [CI Skip] release/beta 6.8.2-17
skip-checks: true
2021-11-19 10:21:44 +00:00
Jaco c474123777 Bump common (#4239)
* Bump common

* CHANGELOG
2021-11-19 12:14:05 +02:00
Github Actions 93edfcf560 [CI Skip] release/beta 6.8.2-16
skip-checks: true
2021-11-19 07:59:40 +00:00
Daniel SavuandGithub Actions e5a67d82fa fix: Generate custom type definitions (#4224)
* fix: Generate custom type definitions

* Generate separate lookup types

* fix: Custom imports

* fix linting errors

Co-authored-by: Github Actions <action@github.com>
2021-11-19 09:51:51 +02:00
Github Actions 194f6aece1 [CI Skip] release/beta 6.8.2-15
skip-checks: true
2021-11-19 05:35:22 +00:00
Jaco 3b4fef8f6e Bump deps (#4238) 2021-11-19 07:26:28 +02:00
Github Actions 6c7323ee3a [CI Skip] release/beta 6.8.2-14
skip-checks: true
2021-11-18 20:00:39 +00:00
Jaco a97b50decb Additional isU8a decoding shortcuts (#4236) 2021-11-18 21:52:24 +02:00
Github Actions 52accf6444 [CI Skip] release/beta 6.8.2-13
skip-checks: true
2021-11-18 13:27:34 +00:00
Jaco 5b8eb231cc CHANGELOG (#4234) 2021-11-18 15:20:21 +02:00
Github Actions 5ea62367d3 [CI Skip] release/beta 6.8.2-12
skip-checks: true
2021-11-18 10:49:36 +00:00
Jaco 49a034a1a0 Place u8a decoding top-of-tree (#4230)
* Place u8a decoding top-of-tree

* Adjust
2021-11-18 12:41:27 +02:00
Github Actions 62a476cb4c [CI Skip] release/beta 6.8.2-11
skip-checks: true
2021-11-18 09:59:41 +00:00
Jaco b283673812 Squeek less recursion out of DetectCodec (#4232)
* Squeek less recursion out of DetectCodec

* Flatten more

* TS 4.5.2 for checking
2021-11-18 11:52:31 +02:00
Github Actions b6a075fefb [CI Skip] release/beta 6.8.2-10
skip-checks: true
2021-11-18 09:11:06 +00:00
Jaco afa844ae01 Bump deps (#4231) 2021-11-18 11:03:45 +02:00
Github Actions 353ef59a1c [CI Skip] release/beta 6.8.2-9
skip-checks: true
2021-11-18 06:32:55 +00:00
Jaco 6228999e6f Decoding cleanups (#4228)
* Decoding cleanups

* CHANGELOG

* Additional adjustments

* Adjust

* Ordering
2021-11-18 08:24:52 +02:00
Github Actions 56db42fedf [CI Skip] release/beta 6.8.2-8
skip-checks: true
2021-11-18 04:48:36 +00:00
Jaco df44693e5d Use stringPascalCase from @polkadot/util (#4211) 2021-11-18 06:40:28 +02:00
Github Actions cfa25f8dda [CI Skip] release/beta 6.8.2-7
skip-checks: true
2021-11-18 04:01:38 +00:00
Jaco bc8934f3c3 Ensure generation of Call/Event enums (#4226) 2021-11-18 05:53:54 +02:00
Github Actions bc67c72e9b [CI Skip] release/beta 6.8.2-6
skip-checks: true
2021-11-17 12:26:35 +00:00
Jaco 22d85e745a Bump deps (#4221)
* Bump deps

* Adjust

* Adjust
2021-11-17 14:19:21 +02:00
Github Actions 60ba2952f7 [CI Skip] release/beta 6.8.2-5
skip-checks: true
2021-11-17 08:28:22 +00:00
Jaco bb10d2813f Expand runtime Call/Event matching (#4220)
* Expand runtime Call/Event matching

* Adjust * matching

* CHANGELOG
2021-11-17 10:18:55 +02:00
Github Actions 80b581f0df [CI Skip] release/beta 6.8.2-4
skip-checks: true
2021-11-13 06:00:08 +00:00
Jaco ef37c421ac Option toJSON output same as from Substrate input (#4212)
* Option toJSON output same as from Substrate input

* CHANGELOG
2021-11-13 07:53:15 +02:00
Github Actions 6e1e8e622b [CI Skip] release/beta 6.8.2-3
skip-checks: true
2021-11-13 05:41:31 +00:00
Jaco ec38a1510f CHANGELOG (#4210) 2021-11-13 07:33:18 +02:00
Github Actions e550ca5a71 [CI Skip] release/beta 6.8.2-2
skip-checks: true
2021-11-12 10:56:32 +00:00
Jaco 80241f732f Split base/essential definition handling (#4206)
* Split base/essential definition handling

* Adjust
2021-11-12 12:47:34 +02:00
Github Actions 84fc0be12e [CI Skip] release/beta 6.8.2-1
skip-checks: true
2021-11-12 08:53:05 +00:00
flex e1f14e8a83 Change BeefySignedCommitment signatures type to EcdsaSignature (#4204) 2021-11-12 10:45:09 +02:00
Github Actions 1155724604 [CI Skip] release/beta 6.8.2-0
skip-checks: true
2021-11-11 12:55:42 +00:00
Jaco 3bb9541943 Bump deps (#4203) 2021-11-11 14:47:26 +02:00
Github Actions 25288f664a [CI Skip] release/stable 6.8.1
skip-checks: true
2021-11-11 11:15:45 +00:00
Jaco 879c5d7b44 6.8.1 (#4201)
* 6.8.1

* rx.queryAt param CHANGELOG
2021-11-11 13:08:24 +02:00
Jaco cdaec1953c Add knownVersion on rx.queryAt (#4194) 2021-11-11 11:30:16 +02:00
Github Actions f4bf7a9c52 [CI Skip] release/beta 6.7.3-7
skip-checks: true
2021-11-11 05:28:44 +00:00
Jaco 7b46c6aa15 Adjust signFake to apply large default signature (#4199)
* Adjust signFake to apply empty default signature

* 0x01... default

* Rename constant

* Add previously failing test
2021-11-11 07:19:21 +02:00
Github Actions d28f4ccfa0 [CI Skip] release/beta 6.7.3-6
skip-checks: true
2021-11-10 17:43:43 +00:00
Jaco e5b05dc700 Slight adjustment to rpc-provider LRU (#4198) 2021-11-10 19:35:20 +02:00
Github Actions bf9831753e [CI Skip] release/beta 6.7.3-5
skip-checks: true
2021-11-10 12:53:27 +00:00
Jaco 5e1670dbae Provider-level caching for historic requests (#4195)
* Provider-level caching for historic requests

* LRUCache

* Adjust

* Adjust

* Adjust

* Opts

* private variables

* Implementation link

* lru .entries adjustment (using .keys)

* Adjust expectations
2021-11-10 14:46:13 +02:00
Github Actions 0d0a230c86 [CI Skip] release/beta 6.7.3-4
skip-checks: true
2021-11-10 08:55:22 +00:00
Jaco 9989b69b46 Rename decorate method (#4193)
* Rename decorateMethod*

* Split exports
2021-11-10 10:48:20 +02:00
Github Actions 66693253ef [CI Skip] release/beta 6.7.3-3
skip-checks: true
2021-11-10 07:05:56 +00:00
Jaco cbffc37dcf Optimize PortableRegistry (#4192)
* Optimize PortableRegistry

* Additional

* Adjust shortcut

* Adjust params

* Move decorateMethod

* Ordering

* Adjust

* Exports

* Renames
2021-11-10 08:58:50 +02:00
Github Actions 74ee42ed66 [CI Skip] release/beta 6.7.3-2
skip-checks: true
2021-11-10 05:15:04 +00:00
Jaco f642e2399f Polkadot 9122 block (#4191) 2021-11-10 07:07:31 +02:00
Github Actions 8cefb055db [CI Skip] release/beta 6.7.3-1
skip-checks: true
2021-11-09 14:17:36 +00:00
Jaco 1f31756019 Ensure known types for v14 is empty (#4190) 2021-11-09 16:10:44 +02:00
Github Actions 4d6a1da6d5 [CI Skip] release/beta 6.7.3-0
skip-checks: true
2021-11-09 11:30:34 +00:00
Jaco d62e720627 Remove ::generic:: from names & namespaces (#4189) 2021-11-09 13:23:10 +02:00
Github Actions 4af4470998 [CI Skip] release/stable 6.7.2
skip-checks: true
2021-11-09 09:24:30 +00:00
Jaco 8bb6218132 Detect AccountId & Address via SpRuntime* defs (#4188)
* Detect AccountId & Address via SpRuntime* defs

* Always do check via UncheckedExtrinsic

* Adjust

* 6.7.2

* Add Signature detection

* Extract ExtrinsicSignature type
2021-11-09 11:14:31 +02:00
Github Actions f4197f8752 [CI Skip] release/beta 6.7.2-0
skip-checks: true
2021-11-08 14:31:55 +00:00
Jaco 7cfad3b1c4 Derive combineLatest order adjustments (#4186) 2021-11-08 16:24:27 +02:00
Github Actions ff67a659b6 [CI Skip] release/stable 6.7.1
skip-checks: true
2021-11-07 09:17:39 +00:00
Jaco a5c69a42fc 6.7.1 (#4184)
* 6.7.1

* packgeInfo

* voteLockingPeriod
2021-11-07 11:09:03 +02:00
Github Actions 3facbf00eb [CI Skip] release/beta 6.6.2-27
skip-checks: true
2021-11-07 07:54:42 +00:00
Jaco 5a6eece6d6 Swap to objectProperty from @polkadot/util (#4183)
* Swap to objectProperty from @polkadot/util

* Re-apply
2021-11-07 09:45:37 +02:00
Github Actions 9219fa3197 [CI Skip] release/beta 6.6.2-26
skip-checks: true
2021-11-07 01:10:02 +00:00
Jaco 32b9a39b1e Multiple Codec property assignments helper (#4182)
* Multiple Codec property assignments helper

* Pass index

* consistency in naming

* typesToMap external

* Loop on index

* any -> unknown

* CHANGELOG

* Adjust

* Fix Enum with Array keys
2021-11-07 03:00:37 +02:00
Github Actions 61a7fe6307 [CI Skip] release/beta 6.6.2-25
skip-checks: true
2021-11-06 20:50:48 +00:00
Jaco ca755d3e0d Make v4 payload driven by extension fields (#4017)
* Make v4 payload driven by extension fields

* Add getters for additional fields

* Move keys

* Re-adjust

* abstract

* SignerPayload fields

* CHANGELOG
2021-11-06 22:42:14 +02:00
Github Actions 442dba42ba [CI Skip] release/beta 6.6.2-24
skip-checks: true
2021-11-06 14:43:03 +00:00
Jaco ba80dd8873 Bump metadata (#4180)
* Bump metadata

* Re-generate types.json

* Kusama hex

* Kusama (... after some struggles)
2021-11-06 16:34:33 +02:00
Github Actions 1d35302dca [CI Skip] release/beta 6.6.2-23
skip-checks: true
2021-11-06 12:36:03 +00:00
Jaco 39c3121437 CHANGELOG (#4179) 2021-11-06 14:28:22 +02:00
Github Actions d7de1d84fb [CI Skip] release/beta 6.6.2-22
skip-checks: true
2021-11-06 10:24:30 +00:00
Jaco 0ee1dfb353 Caching for previously-created complex classes (#4177)
* Caching for previousl-created complex classes

* Drop non-output testing test
2021-11-06 12:17:07 +02:00
Github Actions 0a6f1d87d4 [CI Skip] release/beta 6.6.2-21
skip-checks: true
2021-11-06 10:12:27 +00:00
Jaco b7c563391c Remove memoized caches (Enum, Set) (#4178) 2021-11-06 12:01:40 +02:00
Github Actions b648c4ba6c [CI Skip] release/beta 6.6.2-20
skip-checks: true
2021-11-06 08:09:13 +00:00
Jaco 0eb995c9a1 Apply hashCache on Extrinsic only (no duplication) (#4176) 2021-11-06 10:01:05 +02:00
Github Actions 936d14ffea [CI Skip] release/beta 6.6.2-19
skip-checks: true
2021-11-06 07:34:38 +00:00
Nazar Mokrynskyi 72c7a0a34b Performance tweaks (#4143)
* Avoid unnecessary work in `filterEvents`

* Memoize computed extrinsic hash

* Optimize sanitize by reusing precompiled regular expressions

* Memoize generation of property names in `Enum` and `Set`

* Memoize sanitizing
2021-11-06 09:25:54 +02:00
Jaco 8402013e97 Add account::AccountId20 mapping (#4175)
Replaces https://github.com/polkadot-js/api/pull/4117

Sadly I messed up that one since I moved the PortableRegistry, so despite best-efforts cannot quite revolve the now-conflicts on GitHub itself

Will give acknowledgement since it is deserved, just cannot quite get the PR merged as of right now.
2021-11-06 09:12:12 +02:00
Github Actions fde6b72974 [CI Skip] release/beta 6.6.2-18
skip-checks: true
2021-11-05 16:06:06 +00:00
Jaco d98d4d6908 Move PortableRegistry alongside metadata (#4172) 2021-11-05 17:47:02 +02:00
Github Actions ed384666ee [CI Skip] release/beta 6.6.2-17
skip-checks: true
2021-11-05 14:38:57 +00:00
Jaco 4e64e3d654 Change initialU8aLength to non-getter (#4170)
* Change initialU8aLength to non-getter

* Remove time comments

* Adjust Compact shortcut

* Adjust

* Move isU8a check first in decoding

* #initialLength for Compact

* Compact re-adjust

* Split decodeU8aVec

* decodeVec opt

* Fix compare

* Adjust

* Additional objectSpread

* Additional objectSpread

* isU8a always first

* Comment time logs

* Convert String right at point of using

* Optimize Text from Text

* Fix Text test

* Additional ordering updates

* Enum adjustments

* Reorder Option

* Adjust

* Remove comments

* Adjust
2021-11-05 16:19:38 +02:00
Github Actions 72b4b51915 [CI Skip] release/beta 6.6.2-16
skip-checks: true
2021-11-05 07:25:57 +00:00
Jaco 81f5bf96f5 Adjust Struct loops (#4169) 2021-11-05 09:09:52 +02:00
Github Actions e935281b77 [CI Skip] release/beta 6.6.2-15
skip-checks: true
2021-11-05 06:23:39 +00:00
Jaco e132330c0b Update rpc mappings (#4168)
* Update rpc mappings

* spread
2021-11-05 08:07:57 +02:00
Github Actions 21594aa660 [CI Skip] release/beta 6.6.2-14
skip-checks: true
2021-11-04 14:14:02 +00:00
Jaco 6fb7989b41 Lazy decoration (part 9, rpc) (#4165)
* Lazy decoration (part 9, rpc)

* Flatten

* Cleanups (& bump dev, fix copy-to)

* Only RPC methods are lazy

* Decorate rpc-core lazily

* Adjust import

* Remove (now) invalid test
2021-11-04 15:59:05 +02:00
Github Actions 1f38a38bd5 [CI Skip] release/beta 6.6.2-13
skip-checks: true
2021-11-04 13:06:08 +00:00
Jaco e918aa8b14 Lazy decoration (part 10, Import lazy* from @polkadot/util) (#4166)
* Impot lazy* from @polkadot/util

* Bumps
2021-11-04 14:51:06 +02:00
Github Actions 4a33b18ac4 [CI Skip] release/beta 6.6.2-12
skip-checks: true
2021-11-04 09:36:06 +00:00
Jaco cb97fd1a48 Use new object utilities (as applicable) (#4161)
* Use new object utilities (as applicable)

* Extract utility functions

* Renames

* Comment cleanup

* Fix types
2021-11-04 11:20:03 +02:00
Github Actions 51600bc560 [CI Skip] release/beta 6.6.2-11
skip-checks: true
2021-11-04 09:01:50 +00:00
Jaco 12344ed980 Bump deps (dev & common) (#4162) 2021-11-04 10:43:42 +02:00
Github Actions 0b6773a744 [CI Skip] release/beta 6.6.2-10
skip-checks: true
2021-11-03 14:19:54 +00:00
Jaco 17a38e9c09 Rebump dev, rollup build fixes (#4158) 2021-11-03 16:01:27 +02:00
Github Actions 70499fe6ac [CI Skip] release/beta 6.6.2-9
skip-checks: true
2021-11-03 13:09:32 +00:00
Jaco 64493e0091 Bump dev (#4156) 2021-11-03 15:05:39 +02:00
Github Actions ae3efb31f8 [CI Skip] release/beta 6.6.2-8
skip-checks: true
2021-11-03 10:34:20 +00:00
Jaco 6da58d0698 Dedupe decorate for storage & storageAt (#4155)
* Dedupe decorate for storage & storageAt

* blockHash as last param

* Adjust

* Reorder

* Reorder
2021-11-03 12:16:27 +02:00
Github Actions 07f40c1429 [CI Skip] release/beta 6.6.2-7
skip-checks: true
2021-11-03 09:00:41 +00:00
Jaco f5f67e795e Lazy decoration (part 8, consistent call order) (#4153)
* Lazy decoration (part 8, consistent call order)

* Dedupe

* Flatten, no extra calls

* Dedupe more

* Adjust lazyVariants

* Additional flatten

* Adjust lazyVariants

* Reorder name/index

* Deupe strings

* Flatten createkeys

* Adjust
2021-11-03 10:47:04 +02:00
Github Actions 5b0652c272 [CI Skip] release/beta 6.6.2-6
skip-checks: true
2021-11-03 05:42:40 +00:00
Jaco 53ef5f7c56 Lazy decoration (part 7, augment optimize) (#4152)
* Lazy decoration (part 7, augment optimize)

* augment with generics

* Adjust
2021-11-03 07:26:02 +02:00
Github Actions 71f99875e4 [CI Skip] release/beta 6.6.2-5
skip-checks: true
2021-11-02 14:43:15 +00:00
Jaco a097075bfe Lazy decorate (part 6, API internals) (#4150)
* Lazy decorate (part 6, API internals)

* Rework tx decoration

* Adjust metadata decoration triggers

* Reformat registry lazy decoration

* storage
2021-11-02 16:29:08 +02:00
Jaco 527f840950 More internal reduce adjustments (#4149) 2021-11-02 16:13:20 +02:00
Github Actions 7fadc7eedb [CI Skip] release/beta 6.6.2-4
skip-checks: true
2021-11-02 11:37:04 +00:00
Jaco 35663319d9 Lazy decoration (part 5, augmentObject) (#4145)
* Lazy decoration (part 5, augmentObject)

* hasOwnProperty update

* Fix comments

* loop indexes

* Extract lazySection

* Use hasOwnProperty on is/as getters

* defineProperty helper

* Update defineProperty & use for loops

* skip/adjust for some keys
2021-11-02 13:21:16 +02:00
Github Actions b9d9670d18 [CI Skip] release/beta 6.6.2-3
skip-checks: true
2021-11-02 10:32:15 +00:00
Jaco fd027f452c Lazy decoration (part 3, derives) (#4142)
* Lazy decoration (part 3, prep for derives)

* Derives are lazy

* ... it should have derives

* dedupe api-derive lazy

* function -> inline

* Cleanup defineProperty

* Adjust

* Final readability tweaks

* ... I lied, alignment tweaks

* Exportable lazyDeriveSection

* lazy from @polkadot/types

* Adjust
2021-11-02 12:10:30 +02:00
Github Actions 10a6e03f85 [CI Skip] release/beta 6.6.2-2
skip-checks: true
2021-11-02 09:42:13 +00:00
Jaco 522eb8359f Lazy decoration (part 2, registry) (#4141)
* Lazy decoration (part 2)

* createCallFunction

* Remove previous gen

* WIP, registry dedup

* ... anbd with extrinsics

* Additional cleanups

* Creator

* This should be sharable with derive...

* getName

* Adjust

* lazy.ts in types/create

* Go crazy on comments...
2021-11-02 11:28:29 +02:00
Github Actions d1fd7f75af [CI Skip] release/beta 6.6.2-1
skip-checks: true
2021-11-02 08:05:34 +00:00
Jaco bb61b1e6ac Lazy decoration (part 1, metadata) (#4139)
* Make decoration lazy

* Extract common

* w/ Extrinsics

* Storage lazy

* V14 -> Latest

* Util

* Adjust to use create/lazy

* Adjust

* Add tests for errors & events (long-time outstanding)
2021-11-02 09:49:16 +02:00
Github Actions 7c17baa5be [CI Skip] release/beta 6.6.2-0
skip-checks: true
2021-11-02 05:56:45 +00:00
Jaco 9e7c0a1959 Lazy decoration (part 4, lazyMethod/lazyMethods) (#4144) 2021-11-02 07:35:32 +02:00
Github Actions db2e97bf66 [CI Skip] release/stable 6.6.1
skip-checks: true
2021-11-01 16:17:29 +00:00
Jaco 057f6b6041 6.6.1 (#4140)
* 6.6.1

* 6.6.1
2021-11-01 17:59:50 +02:00
Github Actions ca82336087 [CI Skip] release/beta 6.5.3-13
skip-checks: true
2021-11-01 09:50:27 +00:00
Jaco 761ceaeaa3 Internal adjustments (part 6) (#4138)
* Internal adjustments (part 6)

* Additional
2021-11-01 11:35:17 +02:00
Github Actions 0cbca0adb8 [CI Skip] release/beta 6.5.3-12
skip-checks: true
2021-11-01 09:21:33 +00:00
Jaco d24db4fd6a Internal adjustments (part 4) (#4136)
* Internal adjustments (part 3)

* Internal adjustments (part 4)

* Additional

* Additional

* Fix set encoding
2021-11-01 11:01:31 +02:00
Jaco 4a893b9feb Internal adjustments (part 5) (#4137) 2021-11-01 10:56:16 +02:00
Github Actions 71a0a84f26 [CI Skip] release/beta 6.5.3-11
skip-checks: true
2021-11-01 08:25:14 +00:00
Jaco 44d241f489 Internal adjustments (part 3) (#4135) 2021-11-01 10:03:13 +02:00
Github Actions a4cb5f558d [CI Skip] release/beta 6.5.3-10
skip-checks: true
2021-11-01 07:46:07 +00:00
Jaco aef4d07c48 Internal adjustments (part 2) (#4134) 2021-11-01 09:27:04 +02:00
Github Actions 6a5f1bbbf4 [CI Skip] release/beta 6.5.3-9
skip-checks: true
2021-10-31 05:15:37 +00:00
Jaco e60ef2d677 Optimize internal u8a decoding (#4131)
* Optimize internal u8a decoding

* linting

* tsc fixes & HexString usage

* yet more... it passes now (well... tsc & lint)
2021-10-31 06:58:14 +02:00
Github Actions f4622d05db [CI Skip] release/beta 6.5.3-8
skip-checks: true
2021-10-30 15:33:20 +00:00
Jaco 47d7900809 Adjust struct iterable creation (#4130) 2021-10-30 18:12:12 +03:00
Jaco 2c86e9347b Optimize Struct from Struct construction (#4128)
* Optimize Struct from Map constrcution

* Update packages/types/src/metadata/MetadataVersioned.ts

* CHANGELOG

* Only shortcut Struct

* tests
2021-10-30 17:50:37 +03:00
Github Actions 5827d298ad [CI Skip] release/beta 6.5.3-7
skip-checks: true
2021-10-29 15:25:42 +00:00
Jaco 60e0f69920 Adjust AbstractArray & Struct decoders (#4127)
* Adjust AbstractArray & Struct decoders

* Fixes, add Text & Bytes/Raw to shortcuts

* Additional

* Additional

* Remove debug log

* Revert extra arg, make CC happy

* BTreeSet
2021-10-29 18:06:57 +03:00
Github Actions 97f1ee17b0 [CI Skip] release/beta 6.5.3-6
skip-checks: true
2021-10-28 12:13:17 +00:00
Jaco 85215a308d Bump metadata (#4123) 2021-10-28 14:48:42 +03:00
Github Actions 89fa4edcf7 [CI Skip] release/beta 6.5.3-5
skip-checks: true
2021-10-28 11:05:51 +00:00
Jaco ec42fb9bff Update known Westend upgrade blocks (#4122) 2021-10-28 13:48:10 +03:00
Github Actions 96d696dbf3 [CI Skip] release/beta 6.5.3-4
skip-checks: true
2021-10-28 08:43:46 +00:00
Jaco b7992ecc0b Use lookupName in createClass (as available) (#4121)
* User lookupName in createClass (as available)

* CHANGELOG

* cleanups

* Adjust for Vecs

* Small check cleanups
2021-10-28 11:19:30 +03:00
Github Actions 0acae6e158 [CI Skip] release/beta 6.5.3-3
skip-checks: true
2021-10-26 12:58:10 +00:00
Jaco 6afea5043e Add and dedupe EthereumAddress (#4118)
* Add and dedupe EthereumAddress

* Override for Polkadot claims
2021-10-26 15:40:58 +03:00
Github Actions c9ee8d9942 [CI Skip] release/beta 6.5.3-2
skip-checks: true
2021-10-26 11:58:39 +00:00
Jaco 55f4e150c0 Split namespaces (#4116) 2021-10-26 14:42:18 +03:00
Github Actions 3e3e9c5f5a [CI Skip] release/beta 6.5.3-1
skip-checks: true
2021-10-26 10:40:54 +00:00
Jaco 66215890dd Correct construction of palletVersion keys (#4115) 2021-10-26 13:20:54 +03:00
Github Actions bf6c7ee0c3 [CI Skip] release/beta 6.5.3-0
skip-checks: true
2021-10-26 07:58:18 +00:00
Jaco f726edf725 Bump dev (#4113) 2021-10-26 10:42:23 +03:00
Github Actions d917861a77 [CI Skip] release/stable 6.5.2
skip-checks: true
2021-10-26 06:02:42 +00:00
Jaco 12a54efde5 Fix Struct decoding for null (#4112)
* Fix Struct decoding for null

* CHANGELOG

* 6.5.2
2021-10-26 08:46:03 +03:00
Github Actions 9ae87bed78 [CI Skip] release/beta 6.5.2-3
skip-checks: true
2021-10-25 14:27:40 +00:00
Jaco 7f5a52258c Adjust toHuman on Call (#4109) 2021-10-25 17:10:26 +03:00
Github Actions 2c212e6b4d [CI Skip] release/beta 6.5.2-2
skip-checks: true
2021-10-25 14:07:57 +00:00
Jaco 3d75744a20 Bump dev deps (#4108) 2021-10-25 16:51:05 +03:00
Github Actions d2ff259989 [CI Skip] release/beta 6.5.2-1
skip-checks: true
2021-10-25 12:08:53 +00:00
Jaco cac2ef30a1 Bump dev (#4106) 2021-10-25 14:44:47 +03:00
Github Actions ea38dedcc1 [CI Skip] release/beta 6.5.2-0
skip-checks: true
2021-10-25 06:15:30 +00:00
Jaco 0bd632e612 Allow for optional known RuntimeVersion on api.at (#4103)
* Allow for optional known RuntimeVersion on api.at

* CHANGELOG typo
2021-10-25 08:57:26 +03:00
389 changed files with 37701 additions and 20874 deletions
+6 -1
View File
@@ -40,4 +40,9 @@
6.0.5 6.0.5
6.1.2 6.1.2
6.4.2 6.4.2
6.5.2
6.7.2
6.9.2
6.10.2
6.10.3
+14
View File
@@ -1,3 +1,17 @@
checks:
argument-count:
config:
threshold: 5
method-complexity:
config:
threshold: 7
method-count:
config:
threshold: 25
method-lines:
config:
threshold: 30
exclude_patterns: exclude_patterns:
- "**/*.spec.js" - "**/*.spec.js"
- "**/*.spec.ts" - "**/*.spec.ts"
+1 -1
View File
@@ -2,7 +2,7 @@ name: 'Lock Threads'
on: on:
schedule: schedule:
- cron: '30 1/2 * * *' - cron: '10 1/3 * * *'
jobs: jobs:
lock: lock:
+1 -1
View File
@@ -1,7 +1,7 @@
name: 'Close stale issues and PRs' name: 'Close stale issues and PRs'
on: on:
schedule: schedule:
- cron: '30 2/2 * * *' - cron: '55 1/3 * * *'
jobs: jobs:
stale: stale:
+2 -1
View File
@@ -21,6 +21,7 @@ tmp/
cc-test-reporter cc-test-reporter
lerna-debug.log* lerna-debug.log*
npm-debug.log* npm-debug.log*
package-lock.json
tsconfig.*buildinfo
yarn-debug.log* yarn-debug.log*
yarn-error.log* yarn-error.log*
package-lock.json
+165 -3
View File
@@ -1,10 +1,172 @@
# CHANGELOG # CHANGELOG
## 6.5.1 Oct 24, 2021 ## 6.12.1 Dec 13, 2021
Upgrade priority: Low. Recommended for users of contracts on the current Substrate master version and TS users who generate metadata v14 interfaces.
Changes:
- Add support for contracts V2 ABI metadata
- `CheckNonZeroSender` signed extension support
- Remove old-style capabilities detection (unneeded with metadata v14+)
- Generated TS Enum interfaces now expose the `type` (with allowed values)
- Split local & package imports in generated TS interfaces
- Add Kusama 9130 upgrade block
- Internal maintainability cleanups
## 6.11.1 Dec 5, 2021
Upgrade priority: Low. Maintenance upgrade, tracking the latest `@polkadot` libraries.
Changes:
- Align `state_traceBlock` RPC with Substrate
- Bump static metadata for latest Substrate, Polkadot & Kusama
## 6.10.3 Nov 30, 2021
Upgrade priority: Medium. Recommended for 6.10.x users
Changes:
- Fix ss58Prefix extraction
## 6.10.2 Nov 30, 2021
Upgrade priority: Low. Aligns TS augmentation and decoration with older behavior for ALL_CAPS identifiers.
Changes:
- Adjust augmentation interface consistency with top-level declarations
- Update `@polkadot/util` to 8.0.4 with adjusted `stringCamelCase`
## 6.10.1 Nov 29, 2021
Upgrade priority: Low. Recommended for users of `HttpProvider` and for chains generating types using TS augmentation.
Changes:
- Fix for HttpProvider init (RPC sections with only subscriptions)
- Re-order imports in lookup type augmentation interfaces
- Bump static metadata for latest Substrate, Polkadot & Kusama
## 6.9.2 Nov 22, 2021
Upgrade priority: Medium. Pulls in `@polkadot/util-crypto` fix for TS projects.
Changes:
- Update `@polkadot/util-crypto` with TS compilation work-around
## 6.9.1 Nov 21, 2021
Upgrade priority: Medium. Recommended for metadata v14 parachains. For TS users, the package now support TypeScript 4.5.2 and allows extraction of user types from metadata v14.
Contributed: Contributed:
- Add `Auction` to Polkadot pre-0.9.11 `ProxyType` (Thnaks to https://github.com/wirednkod) - Lookup TS generation for all metadata v14 chains (Thanks to https://github.com/savudani8)
- Update `BeefySignedCommitment` type (Thanks to https://github.com/czl1378)
Changes:
- Adjust runtime `*::{Call, Event}` matching for metadata v14
- Adjust derive decoration with (optional) known methods
- Expose `*{Call, Event, Error}` TS types for metadata v14
- Align Option `.toJSON` output with Substrate input
- Optimize Enum, Struct, Option & Number decoding paths
- Ajust PascalCase conversions with function from util
- Prepare pre-v13 types for optional injection
- Adjustments for TS 4.5.2 support (flatten type infers)
## 6.8.1 Nov 11, 2021
Upgrade priority: Low. Recommended for chains with non-MultiSignature variants where `paymentInfo` is required.
Changes:
- Adjust `paymentInfo` signatures to cater for non-MultiSignature variants
- Remove `::generic::` from names & namespaces under metadata v14
- Add Polkadot 9122 upgrade block
- Cleanup Polkadot/Kusama/Westend/Rococo known types (>= v14 metadata)
- Internal `decorateMethod{Promise, Rx}` renamed to `to{Promise, Rx}Method`
- Add RPC provider-level LRU for historic requests
- Add optional known runtime version param to internal `rx.queryAt`
## 6.7.2 Nov 9, 2021
Upgrade priority: Low. Recommended for chains on metadata v14 with non-default `Address` implementations.
Changes:
- Detect `AccountId` & `Address` types via `SpRuntime*` definitions
- Adjust api-derive call ordering when using `.queryAt`
## 6.7.1 Nov 7, 2021
Upgrade priority: Low. Internal maintenance updates, focussed on internal optimizations.
Changelog:
- Optimize Extrinsic & block handling (Thanks to https://github.com/nazar-pc)
- Add `account::AccountId20` mapping (Thanks to https://github.com/joelamouche)
Changes:
- Use new-gen `voteLockingPeriod` in democracy derives (as available)
- Dynamically inject getters for `Extrinsic` payloads
- Optimize caching for complex constructed type classes per registry
- Convert metadata, rpc and api to use lazy decoration
- Split u8a decoding paths for `Vec` (different from general path)
- Keep track of initial u8a decoded length inside base Codecs
- Extract multi property assignments for `Struct`, `Set`, `Json` & `Enum`
- Move `PortableRegistry` location inside `@polkadot/types/metadata`
- Bump static metadata for latest Substrate, Polkadot & Kusama
## 6.6.1 Nov 1, 2021
Upgrade priority: Low. Internal maintenance updates.
Changes:
- Fix construction for `palletVersion` keys with correct prefix
- Add Polkadot `EthereumAddress` as a known `PortableRegistry` override
- De-dupe `PortableRegistry` namespace splitting operations
- Optimize internal `AbstractArray` & `Struct` u8a decoding
- Shortcut `Struct` construction from `Struct` instance
- Use internal `lookupName` in `createClass` (allows deeply recursive lookups)
- Codec `toHex()` will now correctly return the TS `HexString` type
- Update known upgrade blocks for Westend & Kusama
- Bump static metadata for latest Substrate, Polkadot & Kusama
## 6.5.2 Oct 26, 2021
Upgrade priority: Low. Recommended for users with `.at` queries on unknown blocks.
Changes:
- Adjust `toHuman` on `Call` to return names & (not only) values
- Allow for optional known `RuntimeVersion` to short-circuit `api.at`
- Ensure `Struct` decodes fully on `null` input (equivalent to `undefined` & `{}`)
## 6.5.1 Oct 24, 2021
Upgrade priority: Low. Internal maintenance upgrades.
Contributed:
- Add `Auction` to Polkadot pre-0.9.11 `ProxyType` (Thanks to https://github.com/wirednkod)
Changes: Changes:
@@ -13,7 +175,7 @@ Changes:
- `TypeDef` structures now contain the `typeName` from metadata v14 on fields - `TypeDef` structures now contain the `typeName` from metadata v14 on fields
- Fix browser bundle imports for xcm-mapping (move to `types-known`) - Fix browser bundle imports for xcm-mapping (move to `types-known`)
- Expose all extracted type names in `PortableRegistry` - Expose all extracted type names in `PortableRegistry`
- Adjust `toJSON` (Asicc) output detection on `Raw` - Adjust `toJSON` (Ascii) output detection on `Raw`
- Adjust `api.rpc.*.*.raw(..args)` return to the actual over-the-wire JSON result - Adjust `api.rpc.*.*.raw(..args)` return to the actual over-the-wire JSON result
- Remove `api.rpc.*.*.json(..args)` since it now overlaps with new `.raw` - Remove `api.rpc.*.*.json(..args)` since it now overlaps with new `.raw`
- Bump static metadata for latest Substrate, Polkadot & Kusama - Bump static metadata for latest Substrate, Polkadot & Kusama
+20 -14
View File
@@ -1,40 +1,46 @@
{ {
"repository": "https://github.com/polkadot-js/api",
"author": "Jaco Greeff <jacogr@gmail.com>", "author": "Jaco Greeff <jacogr@gmail.com>",
"bugs": "https://github.com/polkadot-js/api/issues",
"homepage": "https://github.com/polkadot-js/api#readme",
"license": "Apache-2", "license": "Apache-2",
"packageManager": "yarn@3.0.1",
"private": true, "private": true,
"repository": {
"type": "git",
"url": "https://github.com/polkadot-js/api.git"
},
"sideEffects": false,
"type": "commonjs", "type": "commonjs",
"version": "6.12.1",
"workspaces": [ "workspaces": [
"packages/*" "packages/*"
], ],
"resolutions": {
"typescript": "^4.4.4"
},
"scripts": { "scripts": {
"build": "yarn build:interfaces && polkadot-dev-build-ts", "build": "yarn build:interfaces && polkadot-dev-build-ts",
"build:extra": "(cd packages/typegen && copyfiles scripts/* build)", "build:extra": "(cd packages/typegen && copyfiles scripts/* build)",
"build:interfaces": "polkadot-types-internal-interfaces", "build:interfaces": "polkadot-types-internal-interfaces",
"build:release": "polkadot-ci-ghact-build", "build:release": "polkadot-ci-ghact-build",
"build:rollup": "polkadot-exec-rollup --config", "build:rollup": "polkadot-exec-rollup --config",
"docs:metadata": "polkadot-types-internal-metadata",
"chain:info": "polkadot-types-chain-info", "chain:info": "polkadot-types-chain-info",
"lint": "polkadot-dev-run-lint",
"clean": "polkadot-dev-clean-build", "clean": "polkadot-dev-clean-build",
"docs:metadata": "polkadot-types-internal-metadata",
"lint": "polkadot-dev-run-lint",
"postinstall": "polkadot-dev-yarn-only", "postinstall": "polkadot-dev-yarn-only",
"test": "polkadot-dev-run-test --coverage --forceExit --runInBand --testPathIgnorePatterns e2e", "test": "polkadot-dev-run-test --coverage --forceExit --runInBand --testPathIgnorePatterns e2e",
"test:one": "polkadot-dev-run-test --detectOpenHandles --forceExit", "test:one": "polkadot-dev-run-test --detectOpenHandles --forceExit",
"test:watch": "polkadot-dev-run-test --watch" "test:watch": "polkadot-dev-run-test --watch"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.15.8", "@babel/core": "^7.16.0",
"@babel/register": "^7.15.3", "@babel/register": "^7.16.0",
"@babel/runtime": "^7.15.4", "@babel/runtime": "^7.16.3",
"@polkadot/dev": "^0.63.6", "@polkadot/dev": "^0.63.39",
"@polkadot/ts": "^0.4.10", "@polkadot/ts": "^0.4.18",
"@polkadot/typegen": "workspace:packages/typegen", "@polkadot/typegen": "workspace:packages/typegen",
"@types/jest": "^27.0.2", "@types/jest": "^27.0.3",
"copyfiles": "^2.4.1" "copyfiles": "^2.4.1"
}, },
"version": "6.5.1", "resolutions": {
"packageManager": "yarn@3.0.1" "typescript": "^4.5.3"
}
} }
+22 -18
View File
@@ -1,28 +1,32 @@
{ {
"name": "@polkadot/api-contract", "author": "Jaco Greeff <jacogr@gmail.com>",
"version": "6.5.1", "bugs": "https://github.com/polkadot-js/api/issues",
"type": "module", "contributors": [],
"description": "Interfaces for interacting with contracts and contract ABIs", "description": "Interfaces for interacting with contracts and contract ABIs",
"main": "index.js", "engines": {
"node": ">=14.0.0"
},
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-contract#readme",
"license": "Apache-2.0",
"maintainers": [],
"name": "@polkadot/api-contract",
"repository": {
"directory": "packages/api-contract",
"type": "git",
"url": "https://github.com/polkadot-js/api.git"
},
"sideEffects": [ "sideEffects": [
"./detectPackage.js", "./detectPackage.js",
"./detectPackage.cjs" "./detectPackage.cjs"
], ],
"engines": { "type": "module",
"node": ">=14.0.0" "version": "6.12.1",
}, "main": "index.js",
"author": "Jaco Greeff <jacogr@gmail.com>",
"maintainers": [],
"contributors": [],
"license": "Apache-2.0",
"repository": "github:polkadot-js/api",
"bugs": "https://github.com/polkadot-js/api/issues",
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-contract#readme",
"dependencies": { "dependencies": {
"@babel/runtime": "^7.15.4", "@babel/runtime": "^7.16.3",
"@polkadot/api": "6.5.1", "@polkadot/api": "6.12.1",
"@polkadot/types": "6.5.1", "@polkadot/types": "6.12.1",
"@polkadot/util": "^7.6.1", "@polkadot/util": "^8.1.2",
"rxjs": "^7.4.0" "rxjs": "^7.4.0"
} }
} }
+19 -7
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2021 @polkadot/api-contract authors & contributors // Copyright 2017-2021 @polkadot/api-contract authors & contributors
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
import type { AnyJson, Registry } from '@polkadot/types/types'; import type { Registry } from '@polkadot/types/types';
import fs from 'fs'; import fs from 'fs';
import path from 'path'; import path from 'path';
@@ -14,6 +14,7 @@ import { Abi } from '.';
interface SpecDef { interface SpecDef {
messages: { messages: {
label: string;
name: string[] | string name: string[] | string
}[] }[]
} }
@@ -28,6 +29,9 @@ interface JSONAbi {
spec: SpecDef; spec: SpecDef;
V1: { V1: {
spec: SpecDef; spec: SpecDef;
},
V2: {
spec: SpecDef;
} }
} }
@@ -47,11 +51,19 @@ function stringifyJson (registry: Registry): string {
describe('Abi', (): void => { describe('Abi', (): void => {
describe('ABI', (): void => { describe('ABI', (): void => {
Object.entries(abis).forEach(([abiName, abi]: [string, JSONAbi]) => { Object.entries(abis).forEach(([abiName, _abi]) => {
const abi = _abi as unknown as JSONAbi;
it(`initializes from a contract ABI (${abiName})`, (): void => { it(`initializes from a contract ABI (${abiName})`, (): void => {
try { try {
const messageIds = (abi.V1 ? abi.V1 : abi).spec.messages.map(({ name }) => Array.isArray(name) ? name[0] : name); const messageIds = (abi.V2 || abi.V1 || abi).spec.messages.map(({ label, name }) =>
const inkAbi = new Abi(abis[abiName] as AnyJson); label || (
Array.isArray(name)
? name[0]
: name
)
);
const inkAbi = new Abi(abis[abiName]);
expect(inkAbi.messages.map(({ identifier }) => identifier)).toEqual(messageIds); expect(inkAbi.messages.map(({ identifier }) => identifier)).toEqual(messageIds);
} catch (error) { } catch (error) {
@@ -66,7 +78,7 @@ describe('Abi', (): void => {
describe('TypeDef', (): void => { describe('TypeDef', (): void => {
Object.keys(abis).forEach((abiName) => { Object.keys(abis).forEach((abiName) => {
it(`initializes from a contract ABI (${abiName})`, (): void => { it(`initializes from a contract ABI (${abiName})`, (): void => {
const abi = new Abi(abis[abiName] as AnyJson); const abi = new Abi(abis[abiName]);
const json = stringifyJson(abi.registry); const json = stringifyJson(abi.registry);
const cmpPath = path.join(__dirname, `../../test/compare/${abiName}.test.json`); const cmpPath = path.join(__dirname, `../../test/compare/${abiName}.test.json`);
@@ -87,8 +99,8 @@ describe('Abi', (): void => {
}); });
it('has the correct hash for the source', (): void => { it('has the correct hash for the source', (): void => {
const bundle = abis.ink_v0_flipperBundle as JSONAbi; const abi = new Abi(abis.ink_v0_flipperBundle);
const abi = new Abi(bundle as unknown as AnyJson); const bundle = abis.ink_v0_flipperBundle as unknown as JSONAbi;
// manual // manual
expect(bundle.source.hash).toEqual(blake2AsHex(bundle.source.wasm)); expect(bundle.source.hash).toEqual(blake2AsHex(bundle.source.wasm));
+41 -38
View File
@@ -1,25 +1,15 @@
// Copyright 2017-2021 @polkadot/api-contract authors & contributors // Copyright 2017-2021 @polkadot/api-contract authors & contributors
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
import type { Bytes } from '@polkadot/types'; import type { Bytes, PortableRegistry } from '@polkadot/types';
import type { ChainProperties, ContractConstructorSpec, ContractEventSpec, ContractMessageParamSpec, ContractMessageSpec, ContractMetadataLatest, ContractProjectInfo } from '@polkadot/types/interfaces'; import type { ChainProperties, ContractConstructorSpecLatest, ContractEventSpecLatest, ContractMessageParamSpecLatest, ContractMessageSpecLatest, ContractMetadataLatest, ContractProjectInfo } from '@polkadot/types/interfaces';
import type { AnyJson, Codec, Registry } from '@polkadot/types/types'; import type { Codec, Registry } from '@polkadot/types/types';
import type { AbiConstructor, AbiEvent, AbiMessage, AbiParam, DecodedEvent, DecodedMessage } from '../types'; import type { AbiConstructor, AbiEvent, AbiMessage, AbiParam, DecodedEvent, DecodedMessage } from '../types';
import { TypeDefInfo, TypeRegistry } from '@polkadot/types'; import { TypeDefInfo, TypeRegistry } from '@polkadot/types';
import { assert, assertReturn, compactAddLength, compactStripLength, isNumber, isObject, isString, logger, stringCamelCase, stringify, u8aConcat, u8aToHex } from '@polkadot/util'; import { assert, assertReturn, compactAddLength, compactStripLength, isNumber, isObject, isString, logger, stringCamelCase, stringify, u8aConcat, u8aToHex } from '@polkadot/util';
import { toLatest } from './toLatest'; import { v0ToLatest, v1ToLatest } from './toLatest';
interface V0AbiJson {
metadataVersion: string;
spec: {
constructors: unknown[];
events: unknown[];
messages: unknown[];
};
types: unknown[];
}
const l = logger('Abi'); const l = logger('Abi');
@@ -35,17 +25,30 @@ function findMessage <T extends AbiMessage> (list: T[], messageOrId: T | string
return assertReturn(message, () => `Attempted to call an invalid contract interface, ${stringify(messageOrId)}`); return assertReturn(message, () => `Attempted to call an invalid contract interface, ${stringify(messageOrId)}`);
} }
function parseJson (json: AnyJson, chainProperties?: ChainProperties): [AnyJson, Registry, ContractMetadataLatest, ContractProjectInfo] { // FIXME: This is still workable with V0, V1 & V2, but certainly is not a scalable
// approach (right at this point don't quite have better ideas that is not as complex
// as the conversion tactics in the runtime Metadata)
function getLatestMeta (registry: Registry, json: Record<string, unknown>): ContractMetadataLatest {
const metadata = registry.createType('ContractMetadata',
isObject(json.V2)
? { V2: json.V2 }
: isObject(json.V1)
? { V1: json.V1 }
: { V0: json }
);
return metadata.isV2
? metadata.asV2
: metadata.isV1
? v1ToLatest(registry, metadata.asV1)
: v0ToLatest(registry, metadata.asV0);
}
function parseJson (json: Record<string, unknown>, chainProperties?: ChainProperties): [Record<string, unknown>, Registry, ContractMetadataLatest, ContractProjectInfo] {
const registry = new TypeRegistry(); const registry = new TypeRegistry();
const info = registry.createType('ContractProjectInfo', json); const info = registry.createType('ContractProjectInfo', json);
const metadata = registry.createType('ContractMetadata', isString((json as unknown as V0AbiJson).metadataVersion) const latest = getLatestMeta(registry, json);
? { V0: json } const lookup = registry.createType<PortableRegistry>('PortableRegistry', { types: latest.types });
: { V1: (json as Record<string, AnyJson>).V1 }
);
const latest = metadata.isV0
? toLatest(registry, metadata.asV0)
: metadata.asV1;
const lookup = registry.createType('PortableRegistry', { types: latest.types });
// attach the lookup to the registry - now the types are known // attach the lookup to the registry - now the types are known
registry.setLookup(lookup); registry.setLookup(lookup);
@@ -69,7 +72,7 @@ export class Abi {
public readonly info: ContractProjectInfo; public readonly info: ContractProjectInfo;
public readonly json: AnyJson; public readonly json: Record<string, unknown>;
public readonly messages: AbiMessage[]; public readonly messages: AbiMessage[];
@@ -77,22 +80,22 @@ export class Abi {
public readonly registry: Registry; public readonly registry: Registry;
constructor (abiJson: AnyJson, chainProperties?: ChainProperties) { constructor (abiJson: Record<string, unknown> | string, chainProperties?: ChainProperties) {
[this.json, this.registry, this.metadata, this.info] = parseJson( [this.json, this.registry, this.metadata, this.info] = parseJson(
isString(abiJson) isString(abiJson)
? JSON.parse(abiJson) as AnyJson ? JSON.parse(abiJson) as Record<string, unknown>
: abiJson, : abiJson,
chainProperties chainProperties
); );
this.constructors = this.metadata.spec.constructors.map((spec: ContractConstructorSpec, index) => this.constructors = this.metadata.spec.constructors.map((spec: ContractConstructorSpecLatest, index) =>
this.#createMessage(spec, index, { this.#createMessage(spec, index, {
isConstructor: true isConstructor: true
}) })
); );
this.events = this.metadata.spec.events.map((spec: ContractEventSpec, index) => this.events = this.metadata.spec.events.map((spec: ContractEventSpecLatest, index) =>
this.#createEvent(spec, index) this.#createEvent(spec, index)
); );
this.messages = this.metadata.spec.messages.map((spec: ContractMessageSpec, index): AbiMessage => { this.messages = this.metadata.spec.messages.map((spec: ContractMessageSpecLatest, index): AbiMessage => {
const typeSpec = spec.returnType.unwrapOr(null); const typeSpec = spec.returnType.unwrapOr(null);
return this.#createMessage(spec, index, { return this.#createMessage(spec, index, {
@@ -139,15 +142,15 @@ export class Abi {
return findMessage(this.messages, messageOrId); return findMessage(this.messages, messageOrId);
} }
#createArgs = (args: ContractMessageParamSpec[], spec: unknown): AbiParam[] => { #createArgs = (args: ContractMessageParamSpecLatest[], spec: unknown): AbiParam[] => {
return args.map(({ name, type }, index): AbiParam => { return args.map(({ label, type }, index): AbiParam => {
try { try {
assert(isObject(type), 'Invalid type definition found'); assert(isObject(type), 'Invalid type definition found');
const displayName = type.displayName.length const displayName = type.displayName.length
? type.displayName[type.displayName.length - 1].toString() ? type.displayName[type.displayName.length - 1].toString()
: undefined; : undefined;
const camelName = stringCamelCase(name); const camelName = stringCamelCase(label);
if (displayName && PRIMITIVE_ALWAYS.includes(displayName)) { if (displayName && PRIMITIVE_ALWAYS.includes(displayName)) {
return { return {
@@ -175,7 +178,7 @@ export class Abi {
}); });
}; };
#createEvent = (spec: ContractEventSpec, index: number): AbiEvent => { #createEvent = (spec: ContractEventSpecLatest, index: number): AbiEvent => {
const args = this.#createArgs(spec.args, spec); const args = this.#createArgs(spec.args, spec);
const event = { const event = {
args, args,
@@ -184,16 +187,16 @@ export class Abi {
args: this.#decodeArgs(args, data), args: this.#decodeArgs(args, data),
event event
}), }),
identifier: spec.name.toString(), identifier: spec.label.toString(),
index index
}; };
return event; return event;
}; };
#createMessage = (spec: ContractMessageSpec | ContractConstructorSpec, index: number, add: Partial<AbiMessage> = {}): AbiMessage => { #createMessage = (spec: ContractMessageSpecLatest | ContractConstructorSpecLatest, index: number, add: Partial<AbiMessage> = {}): AbiMessage => {
const args = this.#createArgs(spec.args, spec); const args = this.#createArgs(spec.args, spec);
const identifier = spec.name.toString(); const identifier = spec.label.toString();
const message = { const message = {
...add, ...add,
args, args,
@@ -237,8 +240,8 @@ export class Abi {
return message.fromU8a(trimmed.subarray(4)); return message.fromU8a(trimmed.subarray(4));
}; };
#encodeArgs = ({ name, selector }: ContractMessageSpec | ContractConstructorSpec, args: AbiParam[], data: unknown[]): Uint8Array => { #encodeArgs = ({ label, selector }: ContractMessageSpecLatest | ContractConstructorSpecLatest, args: AbiParam[], data: unknown[]): Uint8Array => {
assert(data.length === args.length, () => `Expected ${args.length} arguments to contract message '${name.toString()}', found ${data.length}`); assert(data.length === args.length, () => `Expected ${args.length} arguments to contract message '${label.toString()}', found ${data.length}`);
return compactAddLength( return compactAddLength(
u8aConcat( u8aConcat(
@@ -0,0 +1,73 @@
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { TypeRegistry } from '@polkadot/types';
import abis from '../../test/contracts';
import { v0ToLatest, v1ToLatest } from './toLatest';
describe('v0ToLatest', (): void => {
const registry = new TypeRegistry();
const contract = registry.createType('ContractMetadata', { V0: abis.ink_v0_erc20 });
const latest = v0ToLatest(registry, contract.asV0);
it('has the correct constructors', (): void => {
expect(
latest.spec.constructors.map(({ label }) => label.toString())
).toEqual(['new']);
});
it('has the correct messages', (): void => {
expect(
latest.spec.messages.map(({ label }) => label.toString())
).toEqual(['total_supply', 'balance_of', 'allowance', 'transfer', 'approve', 'transfer_from']);
});
it('has the correct events', (): void => {
expect(
latest.spec.events.map(({ label }) => label.toString())
).toEqual(['Transfer', 'Approval']);
});
it('has the correct constructor arguments', (): void => {
expect(
latest.spec.constructors[0].args.map(({ label }) => label.toString())
).toEqual(['initial_supply']);
});
it('has the correct message arguments', (): void => {
expect(
latest.spec.messages[1].args.map(({ label }) => label.toString())
).toEqual(['owner']);
});
it('has the correct event arguments', (): void => {
expect(
latest.spec.events[0].args.map(({ label }) => label.toString())
).toEqual(['from', 'to', 'value']);
});
});
describe('v1ToLatest', (): void => {
const registry = new TypeRegistry();
const contract = registry.createType('ContractMetadata', { V1: abis.ink_v1_flipper.V1 });
const latest = v1ToLatest(registry, contract.asV1);
it('has the correct constructors', (): void => {
expect(
latest.spec.constructors.map(({ label }) => label.toString())
).toEqual(['new', 'default']);
});
it('has the correct messages', (): void => {
expect(
latest.spec.messages.map(({ label }) => label.toString())
).toEqual(['flip', 'get']);
});
it('has the correct constructor arguments', (): void => {
expect(
latest.spec.constructors[0].args.map(({ label }) => label.toString())
).toEqual(['init_value']);
});
});
+9 -7
View File
@@ -1,14 +1,16 @@
// Copyright 2017-2021 @polkadot/api-contract authors & contributors // Copyright 2017-2021 @polkadot/api-contract authors & contributors
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
import type { ContractMetadataLatest, ContractMetadataV0 } from '@polkadot/types/interfaces'; import type { ContractMetadataLatest, ContractMetadataV0, ContractMetadataV1 } from '@polkadot/types/interfaces';
import type { Registry } from '@polkadot/types/types'; import type { Registry } from '@polkadot/types/types';
import { convertSiV0toV1 } from '@polkadot/types'; import { v0ToV1 } from './toV1';
import { v1ToV2 } from './toV2';
export function toLatest (registry: Registry, v0: ContractMetadataV0): ContractMetadataLatest { export function v1ToLatest (registry: Registry, v1: ContractMetadataV1): ContractMetadataLatest {
return registry.createType('ContractMetadataLatest', { return v1ToV2(registry, v1);
...v0, }
types: convertSiV0toV1(registry, v0.types)
}); export function v0ToLatest (registry: Registry, v0: ContractMetadataV0): ContractMetadataLatest {
return v1ToLatest(registry, v0ToV1(registry, v0));
} }
+14
View File
@@ -0,0 +1,14 @@
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { ContractMetadataV0, ContractMetadataV1 } from '@polkadot/types/interfaces';
import type { Registry } from '@polkadot/types/types';
import { convertSiV0toV1 } from '@polkadot/types';
import { objectSpread } from '@polkadot/util';
export function v0ToV1 (registry: Registry, v0: ContractMetadataV0): ContractMetadataV1 {
return registry.createType('ContractMetadataV1', objectSpread({}, v0, {
types: convertSiV0toV1(registry, v0.types)
}));
}
+52
View File
@@ -0,0 +1,52 @@
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Text } from '@polkadot/types';
import type { ContractMetadataV1, ContractMetadataV2 } from '@polkadot/types/interfaces';
import type { InterfaceTypes, Registry } from '@polkadot/types/types';
import { objectSpread } from '@polkadot/util';
type WithArgs = keyof typeof ARG_TYPES;
interface NamedEntry {
name: Text | Text[];
}
interface ArgsEntry <T extends WithArgs> extends NamedEntry {
args: InterfaceTypes[`${T}V0`]['args'][0][];
}
const ARG_TYPES = {
ContractConstructorSpec: 'ContractMessageParamSpecV2',
ContractEventSpec: 'ContractEventParamSpecV2',
ContractMessageSpec: 'ContractMessageParamSpecV2'
};
function v1ToV2Label (entry: NamedEntry): { label: Text } {
return objectSpread({}, entry, {
label: Array.isArray(entry.name)
? entry.name[0]
: entry.name
});
}
function v1ToV2Labels <T extends WithArgs> (registry: Registry, outType: T, all: ArgsEntry<T>[]): unknown[] {
return all.map((e) =>
registry.createType(`${outType}V2`, objectSpread(v1ToV2Label(e), {
args: e.args.map((a) =>
registry.createType(ARG_TYPES[outType], v1ToV2Label(a))
)
}))
);
}
export function v1ToV2 (registry: Registry, v1: ContractMetadataV1): ContractMetadataV2 {
return registry.createType('ContractMetadataV2', objectSpread({}, v1, {
spec: objectSpread({}, v1.spec, {
constructors: v1ToV2Labels(registry, 'ContractConstructorSpec', v1.spec.constructors),
events: v1ToV2Labels(registry, 'ContractEventSpec', v1.spec.events),
messages: v1ToV2Labels(registry, 'ContractMessageSpec', v1.spec.messages)
})
}));
}
+4 -3
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
import type { ApiTypes, DecorateMethod } from '@polkadot/api/types'; import type { ApiTypes, DecorateMethod } from '@polkadot/api/types';
import type { AnyJson, Registry } from '@polkadot/types/types'; import type { Registry } from '@polkadot/types/types';
import { ApiBase } from '@polkadot/api/base'; import { ApiBase } from '@polkadot/api/base';
import { assert, isFunction } from '@polkadot/util'; import { assert, isFunction } from '@polkadot/util';
@@ -16,14 +16,15 @@ export abstract class Base<ApiType extends ApiTypes> {
protected readonly _decorateMethod: DecorateMethod<ApiType>; protected readonly _decorateMethod: DecorateMethod<ApiType>;
constructor (api: ApiBase<ApiType>, abi: AnyJson | Abi, decorateMethod: DecorateMethod<ApiType>) { constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, decorateMethod: DecorateMethod<ApiType>) {
this.abi = abi instanceof Abi this.abi = abi instanceof Abi
? abi ? abi
: new Abi(abi, api.registry.getChainProperties()); : new Abi(abi, api.registry.getChainProperties());
this.api = api; this.api = api;
this._decorateMethod = decorateMethod; this._decorateMethod = decorateMethod;
assert(!!(api && api.isConnected && api.tx && api.tx.contracts && Object.keys(api.tx.contracts).length), 'Your API has not been initialized correctly and it not decorated with the runtime interfaces for contracts as retrieved from the on-chain runtime'); assert(!!(api && api.isConnected && api.tx), 'Your API has not been initialized correctly and is not connected to a chain');
assert(!!(api.tx.contracts && Object.keys(api.tx.contracts).length), 'You need to connect to a chain with a runtime that supports contracts');
assert(isFunction(api.tx.contracts.instantiateWithCode), 'You need to connect to a chain with a runtime with a V3 contracts module. The runtime does not expose api.tx.contracts.instantiateWithCode'); assert(isFunction(api.tx.contracts.instantiateWithCode), 'You need to connect to a chain with a runtime with a V3 contracts module. The runtime does not expose api.tx.contracts.instantiateWithCode');
} }
+16 -2
View File
@@ -4,7 +4,7 @@
import type { SubmittableExtrinsic } from '@polkadot/api/submittable/types'; import type { SubmittableExtrinsic } from '@polkadot/api/submittable/types';
import type { ApiTypes, DecorateMethod } from '@polkadot/api/types'; import type { ApiTypes, DecorateMethod } from '@polkadot/api/types';
import type { AccountId, EventRecord, Hash } from '@polkadot/types/interfaces'; import type { AccountId, EventRecord, Hash } from '@polkadot/types/interfaces';
import type { AnyJson, ISubmittableResult } from '@polkadot/types/types'; import type { ISubmittableResult } from '@polkadot/types/types';
import type { AbiConstructor, BlueprintOptions } from '../types'; import type { AbiConstructor, BlueprintOptions } from '../types';
import type { MapConstructorExec } from './types'; import type { MapConstructorExec } from './types';
@@ -18,6 +18,10 @@ import { Base } from './Base';
import { Contract } from './Contract'; import { Contract } from './Contract';
import { createBluePrintTx, encodeSalt } from './util'; import { createBluePrintTx, encodeSalt } from './util';
export interface BlueprintConstructor<ApiType extends ApiTypes> {
new(api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, codeHash: string | Hash | Uint8Array): Blueprint<ApiType>;
}
export class BlueprintSubmittableResult<ApiType extends ApiTypes> extends SubmittableResult { export class BlueprintSubmittableResult<ApiType extends ApiTypes> extends SubmittableResult {
public readonly contract?: Contract<ApiType>; public readonly contract?: Contract<ApiType>;
@@ -36,7 +40,7 @@ export class Blueprint<ApiType extends ApiTypes> extends Base<ApiType> {
readonly #tx: MapConstructorExec<ApiType> = {}; readonly #tx: MapConstructorExec<ApiType> = {};
constructor (api: ApiBase<ApiType>, abi: AnyJson | Abi, codeHash: string | Hash | Uint8Array, decorateMethod: DecorateMethod<ApiType>) { constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, codeHash: string | Hash | Uint8Array, decorateMethod: DecorateMethod<ApiType>) {
super(api, abi, decorateMethod); super(api, abi, decorateMethod);
this.codeHash = this.registry.createType('Hash', codeHash); this.codeHash = this.registry.createType('Hash', codeHash);
@@ -68,3 +72,13 @@ export class Blueprint<ApiType extends ApiTypes> extends Base<ApiType> {
); );
}; };
} }
export function extendBlueprint <ApiType extends ApiTypes> (type: ApiType, decorateMethod: DecorateMethod<ApiType>): BlueprintConstructor<ApiType> {
return class extends Blueprint<ApiType> {
static __BlueprintType = type;
constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, codeHash: string | Hash | Uint8Array) {
super(api, abi, codeHash, decorateMethod);
}
};
}
+4 -6
View File
@@ -1,12 +1,10 @@
// Copyright 2017-2021 @polkadot/api-contract authors & contributors // Copyright 2017-2021 @polkadot/api-contract authors & contributors
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
import type { AnyJson } from '@polkadot/types/types';
import fs from 'fs'; import fs from 'fs';
import path from 'path'; import path from 'path';
import { decorateMethodPromise } from '@polkadot/api'; import { toPromiseMethod } from '@polkadot/api';
import v0contractFlipper from '../../test/contracts/ink/v0/flipper.contract.json'; import v0contractFlipper from '../../test/contracts/ink/v0/flipper.contract.json';
import v0abiFlipper from '../../test/contracts/ink/v0/flipper.json'; import v0abiFlipper from '../../test/contracts/ink/v0/flipper.json';
@@ -19,19 +17,19 @@ const v0wasmFlipper = fs.readFileSync(path.join(__dirname, '../../test/contracts
describe('Code', (): void => { describe('Code', (): void => {
it('can construct with an individual ABI/WASM combo', (): void => { it('can construct with an individual ABI/WASM combo', (): void => {
expect( expect(
() => new Code(mockApi, v0abiFlipper as AnyJson, v0wasmFlipper, decorateMethodPromise) () => new Code(mockApi, v0abiFlipper as Record<string, unknown>, v0wasmFlipper, toPromiseMethod)
).not.toThrow(); ).not.toThrow();
}); });
it('can construct with an .contract ABI (v0)', (): void => { it('can construct with an .contract ABI (v0)', (): void => {
expect( expect(
() => new Code(mockApi, v0contractFlipper as AnyJson, null, decorateMethodPromise) () => new Code(mockApi, v0contractFlipper as Record<string, unknown>, null, toPromiseMethod)
).not.toThrow(); ).not.toThrow();
}); });
it.only('can construct with an .contract ABI (v1)', (): void => { it.only('can construct with an .contract ABI (v1)', (): void => {
expect( expect(
() => new Code(mockApi, v1contractFlipper as AnyJson, null, decorateMethodPromise) () => new Code(mockApi, v1contractFlipper as Record<string, unknown>, null, toPromiseMethod)
).not.toThrow(); ).not.toThrow();
}); });
}); });
+16 -2
View File
@@ -4,7 +4,7 @@
import type { SubmittableExtrinsic } from '@polkadot/api/submittable/types'; import type { SubmittableExtrinsic } from '@polkadot/api/submittable/types';
import type { ApiTypes, DecorateMethod } from '@polkadot/api/types'; import type { ApiTypes, DecorateMethod } from '@polkadot/api/types';
import type { EventRecord } from '@polkadot/types/interfaces'; import type { EventRecord } from '@polkadot/types/interfaces';
import type { AnyJson, ISubmittableResult } from '@polkadot/types/types'; import type { ISubmittableResult } from '@polkadot/types/types';
import type { AbiConstructor, BlueprintOptions } from '../types'; import type { AbiConstructor, BlueprintOptions } from '../types';
import type { MapConstructorExec } from './types'; import type { MapConstructorExec } from './types';
@@ -19,6 +19,10 @@ import { Blueprint } from './Blueprint';
import { Contract } from './Contract'; import { Contract } from './Contract';
import { createBluePrintTx, encodeSalt } from './util'; import { createBluePrintTx, encodeSalt } from './util';
export interface CodeConstructor<ApiType extends ApiTypes> {
new(api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, wasm: Uint8Array | string | Buffer | null | undefined): Code<ApiType>;
}
export class CodeSubmittableResult<ApiType extends ApiTypes> extends SubmittableResult { export class CodeSubmittableResult<ApiType extends ApiTypes> extends SubmittableResult {
public readonly blueprint?: Blueprint<ApiType>; public readonly blueprint?: Blueprint<ApiType>;
public readonly contract?: Contract<ApiType>; public readonly contract?: Contract<ApiType>;
@@ -36,7 +40,7 @@ export class Code<ApiType extends ApiTypes> extends Base<ApiType> {
readonly #tx: MapConstructorExec<ApiType> = {}; readonly #tx: MapConstructorExec<ApiType> = {};
constructor (api: ApiBase<ApiType>, abi: AnyJson | Abi, wasm: Uint8Array | string | Buffer | null | undefined, decorateMethod: DecorateMethod<ApiType>) { constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, wasm: Uint8Array | string | Buffer | null | undefined, decorateMethod: DecorateMethod<ApiType>) {
super(api, abi, decorateMethod); super(api, abi, decorateMethod);
this.code = isWasm(this.abi.info.source.wasm) this.code = isWasm(this.abi.info.source.wasm)
@@ -78,3 +82,13 @@ export class Code<ApiType extends ApiTypes> extends Base<ApiType> {
); );
}; };
} }
export function extendCode <ApiType extends ApiTypes> (type: ApiType, decorateMethod: DecorateMethod<ApiType>): CodeConstructor<ApiType> {
return class extends Code<ApiType> {
static __CodeType = type;
constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, wasm: Uint8Array | string | Buffer | null | undefined) {
super(api, abi, wasm, decorateMethod);
}
};
}
+16 -2
View File
@@ -5,7 +5,7 @@ import type { SubmittableExtrinsic } from '@polkadot/api/submittable/types';
import type { ApiTypes, DecorateMethod } from '@polkadot/api/types'; import type { ApiTypes, DecorateMethod } from '@polkadot/api/types';
import type { Bytes } from '@polkadot/types'; import type { Bytes } from '@polkadot/types';
import type { AccountId, EventRecord, Weight } from '@polkadot/types/interfaces'; import type { AccountId, EventRecord, Weight } from '@polkadot/types/interfaces';
import type { AnyJson, ISubmittableResult } from '@polkadot/types/types'; import type { ISubmittableResult } from '@polkadot/types/types';
import type { AbiMessage, ContractCallOutcome, ContractOptions, DecodedEvent } from '../types'; import type { AbiMessage, ContractCallOutcome, ContractOptions, DecodedEvent } from '../types';
import type { ContractCallResult, ContractCallSend, ContractQuery, ContractTx, MapMessageQuery, MapMessageTx } from './types'; import type { ContractCallResult, ContractCallSend, ContractQuery, ContractTx, MapMessageQuery, MapMessageTx } from './types';
@@ -19,6 +19,10 @@ import { Abi } from '../Abi';
import { applyOnEvent, extractOptions, isOptions } from '../util'; import { applyOnEvent, extractOptions, isOptions } from '../util';
import { Base } from './Base'; import { Base } from './Base';
export interface ContractConstructor<ApiType extends ApiTypes> {
new(api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, address: string | AccountId): Contract<ApiType>;
}
// As per Rust, 5 * GAS_PER_SEC // As per Rust, 5 * GAS_PER_SEC
const MAX_CALL_GAS = new BN(5_000_000_000_000).isub(BN_ONE); const MAX_CALL_GAS = new BN(5_000_000_000_000).isub(BN_ONE);
const ERROR_NO_CALL = 'Your node does not expose the contracts.call RPC. This is most probably due to a runtime configuration.'; const ERROR_NO_CALL = 'Your node does not expose the contracts.call RPC. This is most probably due to a runtime configuration.';
@@ -59,7 +63,7 @@ export class Contract<ApiType extends ApiTypes> extends Base<ApiType> {
readonly #tx: MapMessageTx<ApiType> = {}; readonly #tx: MapMessageTx<ApiType> = {};
constructor (api: ApiBase<ApiType>, abi: AnyJson | Abi, address: string | AccountId, decorateMethod: DecorateMethod<ApiType>) { constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, address: string | AccountId, decorateMethod: DecorateMethod<ApiType>) {
super(api, abi, decorateMethod); super(api, abi, decorateMethod);
this.address = this.registry.createType('AccountId', address); this.address = this.registry.createType('AccountId', address);
@@ -161,3 +165,13 @@ export class Contract<ApiType extends ApiTypes> extends Base<ApiType> {
}; };
}; };
} }
export function extendContract <ApiType extends ApiTypes> (type: ApiType, decorateMethod: DecorateMethod<ApiType>): ContractConstructor<ApiType> {
return class extends Contract<ApiType> {
static __ContractType = type;
constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, address: string | AccountId) {
super(api, abi, address, decorateMethod);
}
};
}
+3 -3
View File
@@ -1,6 +1,6 @@
// Copyright 2017-2021 @polkadot/api authors & contributors // Copyright 2017-2021 @polkadot/api authors & contributors
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
export { Blueprint, BlueprintSubmittableResult } from './Blueprint'; export { Blueprint, BlueprintSubmittableResult, extendBlueprint } from './Blueprint';
export { Code, CodeSubmittableResult } from './Code'; export { Code, CodeSubmittableResult, extendCode } from './Code';
export { Contract } from './Contract'; export { Contract, extendContract } from './Contract';
@@ -3,8 +3,6 @@
// Simple non-runnable checks to test type definitions in the editor itself // Simple non-runnable checks to test type definitions in the editor itself
import type { AnyJson } from '@polkadot/types/types';
import { ApiPromise } from '@polkadot/api'; import { ApiPromise } from '@polkadot/api';
import { createTestPairs, TestKeyringMap } from '@polkadot/keyring/testingPairs'; import { createTestPairs, TestKeyringMap } from '@polkadot/keyring/testingPairs';
@@ -12,7 +10,7 @@ import abiIncrementer from '../test/contracts/ink/incrementer.json';
import { BlueprintPromise, ContractPromise } from '.'; import { BlueprintPromise, ContractPromise } from '.';
async function checkBlueprint (api: ApiPromise, pairs: TestKeyringMap): Promise<void> { async function checkBlueprint (api: ApiPromise, pairs: TestKeyringMap): Promise<void> {
const blueprint = new BlueprintPromise(api, abiIncrementer as AnyJson, '0x1234'); const blueprint = new BlueprintPromise(api, abiIncrementer as Record<string, unknown>, '0x1234');
// new style // new style
await blueprint.tx.new({ gasLimit: 456, salt: '0x1234', value: 123 }, 42).signAndSend(pairs.bob); await blueprint.tx.new({ gasLimit: 456, salt: '0x1234', value: 123 }, 42).signAndSend(pairs.bob);
@@ -23,7 +21,7 @@ async function checkBlueprint (api: ApiPromise, pairs: TestKeyringMap): Promise<
} }
async function checkContract (api: ApiPromise, pairs: TestKeyringMap): Promise<void> { async function checkContract (api: ApiPromise, pairs: TestKeyringMap): Promise<void> {
const contract = new ContractPromise(api, abiIncrementer as AnyJson, '0x1234'); const contract = new ContractPromise(api, abiIncrementer as Record<string, unknown>, '0x1234');
// queries // queries
await contract.query.get(pairs.alice.address, {}); await contract.query.get(pairs.alice.address, {});
+1 -1
View File
@@ -3,4 +3,4 @@
// Auto-generated by @polkadot/dev, do not edit // Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/api-contract', version: '6.5.1' }; export const packageInfo = { name: '@polkadot/api-contract', version: '6.12.1' };
@@ -1,16 +0,0 @@
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Hash } from '@polkadot/types/interfaces';
import type { AnyJson } from '@polkadot/types/types';
import { ApiPromise, decorateMethodPromise } from '@polkadot/api';
import { Abi } from '../Abi';
import { Blueprint as BaseBlueprint } from '../base';
export class Blueprint extends BaseBlueprint<'promise'> {
constructor (api: ApiPromise, abi: AnyJson | Abi, codeHash: string | Hash) {
super(api, abi, codeHash, decorateMethodPromise);
}
}
-16
View File
@@ -1,16 +0,0 @@
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { ApiPromise } from '@polkadot/api';
import type { AnyJson } from '@polkadot/types/types';
import { decorateMethodPromise } from '@polkadot/api';
import { Abi } from '../Abi';
import { Code as BaseCode } from '../base';
export class Code extends BaseCode<'promise'> {
constructor (api: ApiPromise, abi: AnyJson | Abi, wasm: Uint8Array | string | Buffer | null | undefined) {
super(api, abi, wasm, decorateMethodPromise);
}
}
@@ -1,16 +0,0 @@
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { AccountId } from '@polkadot/types/interfaces';
import type { AnyJson } from '@polkadot/types/types';
import { ApiPromise, decorateMethodPromise } from '@polkadot/api';
import { Abi } from '../Abi';
import { Contract as BaseContract } from '../base';
export class Contract extends BaseContract<'promise'> {
constructor (api: ApiPromise, abi: AnyJson | Abi, address: string | AccountId) {
super(api, abi, address, decorateMethodPromise);
}
}
+7 -3
View File
@@ -1,6 +1,10 @@
// Copyright 2017-2021 @polkadot/api-contract authors & contributors // Copyright 2017-2021 @polkadot/api-contract authors & contributors
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
export { Blueprint } from './Blueprint'; import { toPromiseMethod } from '@polkadot/api';
export { Code } from './Code';
export { Contract } from './Contract'; import { extendBlueprint, extendCode, extendContract } from '../base';
export const Blueprint = extendBlueprint<'promise'>('promise', toPromiseMethod);
export const Code = extendCode<'promise'>('promise', toPromiseMethod);
export const Contract = extendContract<'promise'>('promise', toPromiseMethod);
-16
View File
@@ -1,16 +0,0 @@
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Hash } from '@polkadot/types/interfaces';
import type { AnyJson } from '@polkadot/types/types';
import { ApiRx, decorateMethodRx } from '@polkadot/api';
import { Abi } from '../Abi';
import { Blueprint as BaseBlueprint } from '../base';
export class Blueprint extends BaseBlueprint<'rxjs'> {
constructor (api: ApiRx, abi: AnyJson | Abi, codeHash: string | Hash) {
super(api, abi, codeHash, decorateMethodRx);
}
}
-16
View File
@@ -1,16 +0,0 @@
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { ApiRx } from '@polkadot/api';
import type { AnyJson } from '@polkadot/types/types';
import { decorateMethodRx } from '@polkadot/api';
import { Abi } from '../Abi';
import { Code as BaseCode } from '../base';
export class Code extends BaseCode<'rxjs'> {
constructor (api: ApiRx, abi: AnyJson | Abi, wasm: Uint8Array | string | Buffer | null | undefined) {
super(api, abi, wasm, decorateMethodRx);
}
}
-16
View File
@@ -1,16 +0,0 @@
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { AccountId } from '@polkadot/types/interfaces';
import type { AnyJson } from '@polkadot/types/types';
import { ApiRx, decorateMethodRx } from '@polkadot/api';
import { Abi } from '../Abi';
import { Contract as BaseContract } from '../base';
export class Contract extends BaseContract<'rxjs'> {
constructor (api: ApiRx, abi: AnyJson | Abi, address: string | AccountId) {
super(api, abi, address, decorateMethodRx);
}
}
+7 -3
View File
@@ -1,6 +1,10 @@
// Copyright 2017-2021 @polkadot/api-contract authors & contributors // Copyright 2017-2021 @polkadot/api-contract authors & contributors
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
export { Blueprint } from './Blueprint'; import { toRxMethod } from '@polkadot/api';
export { Code } from './Code';
export { Contract } from './Contract'; import { extendBlueprint, extendCode, extendContract } from '../base';
export const Blueprint = extendBlueprint<'rxjs'>('rxjs', toRxMethod);
export const Code = extendCode<'rxjs'>('rxjs', toRxMethod);
export const Contract = extendContract<'rxjs'>('rxjs', toRxMethod);
@@ -0,0 +1,204 @@
[
{
"info": "Plain",
"lookupIndex": 0,
"type": "u128",
"docs": [],
"namespace": ""
},
{
"info": "Struct",
"lookupIndex": 1,
"type": "{\"offsetKey\":\"InkPrimitivesKey\"}",
"docs": [],
"namespace": "ink_storage::lazy::mapping::Mapping",
"sub": [
{
"info": "VecFixed",
"lookupIndex": 5,
"lookupName": "InkPrimitivesKey",
"type": "[u8;32]",
"docs": [],
"namespace": "",
"length": 32,
"sub": {
"info": "Plain",
"lookupIndex": 4,
"type": "u8",
"docs": [],
"namespace": ""
},
"typeName": "Key",
"name": "offsetKey"
}
]
},
{
"info": "Plain",
"lookupIndex": 2,
"type": "AccountId",
"docs": [],
"namespace": "ink_env::types::AccountId",
"lookupNameRoot": "InkEnvAccountId"
},
{
"info": "VecFixed",
"lookupIndex": 3,
"type": "[u8;32]",
"docs": [],
"namespace": "",
"length": 32,
"sub": {
"info": "Plain",
"lookupIndex": 4,
"type": "u8",
"docs": [],
"namespace": ""
}
},
{
"info": "Plain",
"lookupIndex": 4,
"type": "u8",
"docs": [],
"namespace": ""
},
{
"info": "VecFixed",
"lookupIndex": 5,
"lookupName": "InkPrimitivesKey",
"type": "[u8;32]",
"docs": [],
"namespace": "",
"length": 32,
"sub": {
"info": "Plain",
"lookupIndex": 4,
"type": "u8",
"docs": [],
"namespace": ""
},
"typeName": "[u8;32]"
},
{
"info": "Struct",
"lookupIndex": 6,
"type": "{\"offsetKey\":\"InkPrimitivesKey\"}",
"docs": [],
"namespace": "ink_storage::lazy::mapping::Mapping",
"sub": [
{
"info": "VecFixed",
"lookupIndex": 5,
"lookupName": "InkPrimitivesKey",
"type": "[u8;32]",
"docs": [],
"namespace": "",
"length": 32,
"sub": {
"info": "Plain",
"lookupIndex": 4,
"type": "u8",
"docs": [],
"namespace": ""
},
"typeName": "Key",
"name": "offsetKey"
}
]
},
{
"info": "Tuple",
"lookupIndex": 7,
"type": "(AccountId,AccountId)",
"docs": [],
"namespace": "",
"sub": [
{
"info": "Plain",
"lookupIndex": 2,
"type": "AccountId",
"docs": [],
"namespace": "ink_env::types::AccountId",
"lookupNameRoot": "InkEnvAccountId"
},
{
"info": "Plain",
"lookupIndex": 2,
"type": "AccountId",
"docs": [],
"namespace": "ink_env::types::AccountId",
"lookupNameRoot": "InkEnvAccountId"
}
]
},
{
"info": "Result",
"lookupIndex": 8,
"type": "Result<Null, Erc20Error>",
"docs": [],
"namespace": "Result",
"sub": [
{
"name": "Ok",
"info": "Null",
"lookupIndex": 9,
"type": "Null",
"docs": [],
"namespace": ""
},
{
"name": "Error",
"docs": [],
"info": "Si",
"lookupIndex": 10,
"lookupName": "Erc20Error",
"type": "Lookup10"
}
]
},
{
"info": "Null",
"lookupIndex": 9,
"type": "Null",
"docs": [],
"namespace": ""
},
{
"info": "Enum",
"lookupIndex": 10,
"lookupName": "Erc20Error",
"type": "{\"_enum\":[\"InsufficientBalance\",\"InsufficientAllowance\"]}",
"docs": [],
"namespace": "erc20::erc20::Error",
"sub": [
{
"info": "Null",
"type": "Null",
"index": 0,
"name": "InsufficientBalance"
},
{
"info": "Null",
"type": "Null",
"index": 1,
"name": "InsufficientAllowance"
}
]
},
{
"info": "Option",
"lookupIndex": 11,
"type": "Option<AccountId>",
"docs": [],
"namespace": "Option",
"sub": {
"info": "Plain",
"lookupIndex": 2,
"type": "AccountId",
"docs": [],
"namespace": "ink_env::types::AccountId",
"lookupNameRoot": "InkEnvAccountId"
}
}
]
@@ -0,0 +1,9 @@
[
{
"info": "Plain",
"lookupIndex": 0,
"type": "bool",
"docs": [],
"namespace": ""
}
]
+6 -11
View File
@@ -5,17 +5,12 @@ import ink from './ink';
import solang from './solang'; import solang from './solang';
import user from './user'; import user from './user';
const all: Record<string, any> = {}; const all: Record<string, Record<string, unknown>> = {};
function addExport (type: string, abis: Record<string, any>): void { Object.entries({ ink, solang, user }).forEach(([type, abis]) =>
Object.keys(abis).forEach((key): void => { Object.entries(abis).forEach(([name, abi]): void => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment all[`${type}_${name}`] = abi;
all[`${type}_${key}`] = abis[key]; })
}); );
}
addExport('ink', ink);
addExport('solang', solang);
addExport('user', user);
export default all; export default all;
@@ -4,7 +4,6 @@
import { createVersionedExport } from '../util'; import { createVersionedExport } from '../util';
import * as v0 from './v0'; import * as v0 from './v0';
import * as v1 from './v1'; import * as v1 from './v1';
import * as v2 from './v2';
const exp = createVersionedExport('v0', v0, {}); export default createVersionedExport({ v0, v1, v2 });
export default createVersionedExport('v1', v1, exp);
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,5 @@
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
// SPDX-License-Identifier: Apache-2.0
export { default as erc20 } from './erc20.contract.json';
export { default as flipper } from './flipper.contract.json';
@@ -4,4 +4,4 @@
import { createVersionedExport } from '../util'; import { createVersionedExport } from '../util';
import * as v0 from './v0'; import * as v0 from './v0';
export default createVersionedExport('v0', v0, {}); export default createVersionedExport({ v0 });
@@ -4,4 +4,4 @@
import { createVersionedExport } from '../util'; import { createVersionedExport } from '../util';
import * as v0 from './v0'; import * as v0 from './v0';
export default createVersionedExport('v0', v0, {}); export default createVersionedExport({ v0 });
+9 -5
View File
@@ -1,10 +1,14 @@
// Copyright 2017-2021 @polkadot/api-contract authors & contributors // Copyright 2017-2021 @polkadot/api-contract authors & contributors
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
export function createVersionedExport (version: string, orig: Record<string, unknown>, exp: Record<string, unknown>): Record<string, unknown> { export function createVersionedExport (versioned: Record<string, Record<string, unknown>>): Record<string, Record<string, unknown>> {
Object.entries(orig).forEach(([name, json]): void => { const result: Record<string, Record<string, unknown>> = {};
exp[`${version}_${name}`] = json;
});
return exp; Object.entries(versioned).forEach(([version, contracts]) =>
Object.entries(contracts).forEach(([name, contract]): void => {
result[`${version}_${name}`] = contract as Record<string, unknown>;
})
);
return result;
} }
+26 -22
View File
@@ -1,34 +1,38 @@
{ {
"name": "@polkadot/api-derive", "author": "Jaco Greeff <jacogr@gmail.com>",
"version": "6.5.1", "bugs": "https://github.com/polkadot-js/api/issues",
"type": "module", "contributors": [],
"description": "Common functions used across Polkadot, derived from RPC calls and storage queries.", "description": "Common functions used across Polkadot, derived from RPC calls and storage queries.",
"main": "index.js", "engines": {
"node": ">=14.0.0"
},
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-derive#readme",
"license": "Apache-2.0",
"maintainers": [],
"name": "@polkadot/api-derive",
"repository": {
"directory": "packages/api-derive",
"type": "git",
"url": "https://github.com/polkadot-js/api.git"
},
"sideEffects": [ "sideEffects": [
"./detectPackage.js", "./detectPackage.js",
"./detectPackage.cjs" "./detectPackage.cjs"
], ],
"engines": { "type": "module",
"node": ">=14.0.0" "version": "6.12.1",
}, "main": "index.js",
"author": "Jaco Greeff <jacogr@gmail.com>",
"maintainers": [],
"contributors": [],
"license": "Apache-2.0",
"repository": "github:polkadot-js/api",
"bugs": "https://github.com/polkadot-js/api/issues",
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-derive#readme",
"dependencies": { "dependencies": {
"@babel/runtime": "^7.15.4", "@babel/runtime": "^7.16.3",
"@polkadot/api": "6.5.1", "@polkadot/api": "6.12.1",
"@polkadot/rpc-core": "6.5.1", "@polkadot/rpc-core": "6.12.1",
"@polkadot/types": "6.5.1", "@polkadot/types": "6.12.1",
"@polkadot/util": "^7.6.1", "@polkadot/util": "^8.1.2",
"@polkadot/util-crypto": "^7.6.1", "@polkadot/util-crypto": "^8.1.2",
"rxjs": "^7.4.0" "rxjs": "^7.4.0"
}, },
"devDependencies": { "devDependencies": {
"@polkadot/keyring": "^7.6.1", "@polkadot/keyring": "^8.1.2",
"@polkadot/rpc-provider": "6.5.1" "@polkadot/rpc-provider": "6.12.1"
} }
} }
+15 -18
View File
@@ -12,28 +12,25 @@ import { decodeAddress } from '@polkadot/util-crypto';
import { memo } from '../util'; import { memo } from '../util';
function retrieve (api: ApiInterfaceRx, address: Address | AccountId | AccountIndex | string | null | undefined): Observable<AccountId> {
const decoded = isU8a(address)
? address
: decodeAddress((address || '').toString());
if (decoded.length > 8) {
return of(api.registry.createType('AccountId', decoded));
}
const accountIndex = api.registry.createType('AccountIndex', decoded);
return api.derive.accounts.indexToId(accountIndex.toString()).pipe(
map((accountId) => assertReturn(accountId, 'Unable to retrieve accountId'))
);
}
/** /**
* @name accountId * @name accountId
* @param {(Address | AccountId | AccountIndex | string | null)} address - An accounts address in various formats. * @param {(Address | AccountId | AccountIndex | string | null)} address - An accounts address in various formats.
* @description An [[AccountId]] * @description An [[AccountId]]
*/ */
export function accountId (instanceId: string, api: ApiInterfaceRx): (address?: Address | AccountId | AccountIndex | string | null) => Observable<AccountId> { export function accountId (instanceId: string, api: ApiInterfaceRx): (address?: Address | AccountId | AccountIndex | string | null) => Observable<AccountId> {
return memo(instanceId, (address?: Address | AccountId | AccountIndex | string | null): Observable<AccountId> => return memo(instanceId, (address?: Address | AccountId | AccountIndex | string | null): Observable<AccountId> => {
retrieve(api, address)); const decoded = isU8a(address)
? address
: decodeAddress((address || '').toString());
if (decoded.length > 8) {
return of(api.registry.createType('AccountId', decoded));
}
const accountIndex = api.registry.createType('AccountIndex', decoded);
return api.derive.accounts.indexToId(accountIndex.toString()).pipe(
map((a) => assertReturn(a, 'Unable to retrieve accountId'))
);
});
} }
+4 -8
View File
@@ -40,15 +40,11 @@ function parseFlags (address: AccountId | Address | string | null | undefined, [
*/ */
export function flags (instanceId: string, api: ApiInterfaceRx): (address?: AccountId | Address | string | null) => Observable<DeriveAccountFlags> { export function flags (instanceId: string, api: ApiInterfaceRx): (address?: AccountId | Address | string | null) => Observable<DeriveAccountFlags> {
return memo(instanceId, (address?: AccountId | Address | string | null): Observable<DeriveAccountFlags> => { return memo(instanceId, (address?: AccountId | Address | string | null): Observable<DeriveAccountFlags> => {
const councilSection = api.query.phragmenElection const elections = api.query.phragmenElection || api.query.electionsPhragmen || api.query.elections;
? 'phragmenElection'
: api.query.electionsPhragmen
? 'electionsPhragmen'
: 'elections';
return combineLatest([ return combineLatest([
address && api.query[councilSection]?.members address && elections?.members
? api.query[councilSection].members<Vec<ITuple<[AccountId, Balance]>>>() ? elections.members<Vec<ITuple<[AccountId, Balance]>>>()
: of(undefined), : of(undefined),
address && api.query.council?.members address && api.query.council?.members
? api.query.council.members() ? api.query.council.members()
@@ -63,7 +59,7 @@ export function flags (instanceId: string, api: ApiInterfaceRx): (address?: Acco
? api.query.sudo.key() ? api.query.sudo.key()
: of(undefined) : of(undefined)
]).pipe( ]).pipe(
map((result) => parseFlags(address, result)) map((r) => parseFlags(address, r))
); );
}); });
} }
+24 -27
View File
@@ -13,31 +13,6 @@ import { decodeAddress } from '@polkadot/util-crypto';
import { memo } from '../util'; import { memo } from '../util';
function retrieve (api: ApiInterfaceRx, address: Address | AccountId | AccountIndex | Uint8Array | string | null | undefined): Observable<AccountIdAndIndex> {
try {
// yes, this can fail, don't care too much, catch will catch it
const decoded = isU8a(address)
? address
: decodeAddress((address || '').toString());
if (decoded.length > 8) {
const accountId = api.registry.createType('AccountId', decoded);
return api.derive.accounts.idToIndex(accountId).pipe(
map((accountIndex): AccountIdAndIndex => [accountId, accountIndex])
);
}
const accountIndex = api.registry.createType('AccountIndex', decoded);
return api.derive.accounts.indexToId(accountIndex.toString()).pipe(
map((accountId): AccountIdAndIndex => [accountId, accountIndex])
);
} catch (error) {
return of([undefined, undefined]);
}
}
/** /**
* @name idAndIndex * @name idAndIndex
* @param {(Address | AccountId | AccountIndex | Uint8Array | string | null)} address - An accounts address in various formats. * @param {(Address | AccountId | AccountIndex | Uint8Array | string | null)} address - An accounts address in various formats.
@@ -52,6 +27,28 @@ function retrieve (api: ApiInterfaceRx, address: Address | AccountId | AccountIn
* ``` * ```
*/ */
export function idAndIndex (instanceId: string, api: ApiInterfaceRx): (address?: Address | AccountId | AccountIndex | Uint8Array | string | null) => Observable<AccountIdAndIndex> { export function idAndIndex (instanceId: string, api: ApiInterfaceRx): (address?: Address | AccountId | AccountIndex | Uint8Array | string | null) => Observable<AccountIdAndIndex> {
return memo(instanceId, (address?: Address | AccountId | AccountIndex | Uint8Array | string | null): Observable<AccountIdAndIndex> => return memo(instanceId, (address?: Address | AccountId | AccountIndex | Uint8Array | string | null): Observable<AccountIdAndIndex> => {
retrieve(api, address)); try {
// yes, this can fail, don't care too much, catch will catch it
const decoded = isU8a(address)
? address
: decodeAddress((address || '').toString());
if (decoded.length > 8) {
const accountId = api.registry.createType('AccountId', decoded);
return api.derive.accounts.idToIndex(accountId).pipe(
map((accountIndex): AccountIdAndIndex => [accountId, accountIndex])
);
}
const accountIndex = api.registry.createType('AccountIndex', decoded);
return api.derive.accounts.indexToId(accountIndex.toString()).pipe(
map((accountId): AccountIdAndIndex => [accountId, accountIndex])
);
} catch (error) {
return of([undefined, undefined]);
}
});
} }
+5 -8
View File
@@ -13,7 +13,7 @@ import { combineLatest, map, of, switchMap } from 'rxjs';
import { isHex, u8aToString } from '@polkadot/util'; import { isHex, u8aToString } from '@polkadot/util';
import { memo } from '../util'; import { firstMemo, memo } from '../util';
type IdentityInfoAdditional = PalletIdentityIdentityInfo['additional'][0]; type IdentityInfoAdditional = PalletIdentityIdentityInfo['additional'][0];
@@ -104,13 +104,10 @@ export function identity (instanceId: string, api: ApiInterfaceRx): (accountId?:
); );
} }
export function hasIdentity (instanceId: string, api: ApiInterfaceRx): (accountId: AccountId | Uint8Array | string) => Observable<DeriveHasIdentity> { export const hasIdentity = firstMemo(
return memo(instanceId, (accountId: AccountId | Uint8Array | string): Observable<DeriveHasIdentity> => (api: ApiInterfaceRx, accountId: AccountId | Uint8Array | string) =>
api.derive.accounts.hasIdentityMulti([accountId]).pipe( api.derive.accounts.hasIdentityMulti([accountId])
map(([first]) => first) );
)
);
}
export function hasIdentityMulti (instanceId: string, api: ApiInterfaceRx): (accountIds: (AccountId | Uint8Array | string)[]) => Observable<DeriveHasIdentity[]> { export function hasIdentityMulti (instanceId: string, api: ApiInterfaceRx): (accountIds: (AccountId | Uint8Array | string)[]) => Observable<DeriveHasIdentity[]> {
return memo(instanceId, (accountIds: (AccountId | Uint8Array | string)[]): Observable<DeriveHasIdentity[]> => return memo(instanceId, (accountIds: (AccountId | Uint8Array | string)[]): Observable<DeriveHasIdentity[]> =>
+1 -3
View File
@@ -165,9 +165,7 @@ function queryCurrent (api: ApiInterfaceRx, accountId: AccountId, balanceInstanc
return [ return [
vesting vesting
? Array.isArray(vesting) ? Array.isArray(vesting) ? vesting : [vesting]
? vesting
: [vesting]
: null, : null,
lockEmpty.map((e) => e ? api.registry.createType<Vec<PalletBalancesBalanceLock>>('Vec<BalanceLock>') : locks[++offset]) lockEmpty.map((e) => e ? api.registry.createType<Vec<PalletBalancesBalanceLock>>('Vec<BalanceLock>') : locks[++offset])
]; ];
+6 -8
View File
@@ -42,14 +42,12 @@ export function bounties (instanceId: string, api: ApiInterfaceRx): () => Observ
? api.query.council.proposalCount<ProposalIndex>() ? api.query.council.proposalCount<ProposalIndex>()
: of(0) : of(0)
]).pipe( ]).pipe(
switchMap(() => switchMap(() => combineLatest([
combineLatest([ bountyBase.bounties.keys<[BountyIndex]>(),
bountyBase.bounties.keys<[BountyIndex]>(), api.derive.council
api.derive.council ? api.derive.council.proposals()
? api.derive.council.proposals() : of([])
: of([]) ])),
])
),
switchMap(([keys, proposals]): Observable<Result> => { switchMap(([keys, proposals]): Observable<Result> => {
const ids = keys.map(({ args: [id] }) => id); const ids = keys.map(({ args: [id] }) => id);
+92 -42
View File
@@ -5,6 +5,7 @@ import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types'; import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { AnyFunction } from '@polkadot/types/types'; import type { AnyFunction } from '@polkadot/types/types';
import { lazyDeriveSection } from './util/lazy';
import * as accounts from './accounts'; import * as accounts from './accounts';
import * as balances from './balances'; import * as balances from './balances';
import * as bounties from './bounties'; import * as bounties from './bounties';
@@ -29,18 +30,21 @@ export * from './type';
interface Avail { interface Avail {
instances: string[]; instances: string[];
methods: string[];
withDetect?: boolean; withDetect?: boolean;
} }
export { lazyDeriveSection };
export const derive = { accounts, balances, bounties, chain, contracts, council, crowdloan, democracy, elections, imOnline, membership, parachains, session, society, staking, technicalCommittee, treasury, tx }; export const derive = { accounts, balances, bounties, chain, contracts, council, crowdloan, democracy, elections, imOnline, membership, parachains, session, society, staking, technicalCommittee, treasury, tx };
type DeriveSection<Section> = { type DeriveSection<Section> = {
[Method in keyof Section]: Section[Method] extends AnyFunction [M in keyof Section]: Section[M] extends AnyFunction
? ReturnType<Section[Method]> // ReturnType<Section[Method]> will be the inner function, i.e. without (api) argument ? ReturnType<Section[M]> // ReturnType<Section[Method]> will be the inner function, i.e. without (api) argument
: never; : never;
}; };
type DeriveAllSections<AllSections> = { type DeriveAllSections<AllSections> = {
[Section in keyof AllSections]: DeriveSection<AllSections[Section]> [S in keyof AllSections]: DeriveSection<AllSections[S]>
}; };
type DeriveCreator = (instanceId: string, api: ApiInterfaceRx) => (...args: unknown[]) => Observable<any>; type DeriveCreator = (instanceId: string, api: ApiInterfaceRx) => (...args: unknown[]) => Observable<any>;
@@ -51,64 +55,110 @@ export type ExactDerive = DeriveAllSections<typeof derive>;
// Enable derive only if some of these modules are available // Enable derive only if some of these modules are available
const checks: Record<string, Avail> = { const checks: Record<string, Avail> = {
contracts: { instances: ['contracts'] }, contracts: {
council: { instances: ['council'], withDetect: true }, instances: ['contracts'],
crowdloan: { instances: ['crowdloan'] }, methods: []
democracy: { instances: ['democracy'] }, },
elections: { instances: ['phragmenElection', 'electionsPhragmen', 'elections', 'council'], withDetect: true }, council: {
imOnline: { instances: ['imOnline'] }, instances: ['council'],
membership: { instances: ['membership'] }, methods: [],
parachains: { instances: ['parachains', 'registrar'] }, withDetect: true
session: { instances: ['session'] }, },
society: { instances: ['society'] }, crowdloan: {
staking: { instances: ['staking'] }, instances: ['crowdloan'],
technicalCommittee: { instances: ['technicalCommittee'], withDetect: true }, methods: []
treasury: { instances: ['treasury'] } },
democracy: {
instances: ['democracy'],
methods: []
},
elections: {
instances: ['phragmenElection', 'electionsPhragmen', 'elections', 'council'],
methods: [],
withDetect: true
},
imOnline: {
instances: ['imOnline'],
methods: []
},
membership: {
instances: ['membership'],
methods: []
},
parachains: {
instances: ['parachains', 'registrar'],
methods: []
},
session: {
instances: ['session'],
methods: []
},
society: {
instances: ['society'],
methods: []
},
staking: {
instances: ['staking'],
methods: ['erasRewardPoints']
},
technicalCommittee: {
instances: ['technicalCommittee'],
methods: [],
withDetect: true
},
treasury: {
instances: ['treasury'],
methods: []
}
}; };
function getModuleInstances (api: ApiInterfaceRx, specName: string, moduleName: string): string[] {
return api.registry.getModuleInstances(specName, moduleName) || [];
}
/** /**
* Returns an object that will inject `api` into all the functions inside * Returns an object that will inject `api` into all the functions inside
* `allSections`, and keep the object architecture of `allSections`. * `allSections`, and keep the object architecture of `allSections`.
*/ */
/** @internal */ /** @internal */
function injectFunctions<AllSections> (instanceId: string, api: ApiInterfaceRx, allSections: AllSections): DeriveAllSections<AllSections> { function injectFunctions (instanceId: string, api: ApiInterfaceRx, derives: DeriveCustom): ExactDerive {
const queryKeys = Object.keys(api.query); const result: Record<string, Record<string, AnyFunction>> = {};
const names = Object.keys(derives);
const keys = Object.keys(api.query);
const specName = api.runtimeVersion.specName.toString(); const specName = api.runtimeVersion.specName.toString();
return Object const filterKeys = (q: string) => keys.includes(q);
.keys(allSections) const filterInstances = (q: string) => getModuleInstances(api, specName, q).some(filterKeys);
.filter((sectionName) => const filterMethods = (all: string[]) => (m: string) => all.some((q) => keys.includes(q) && api.query[q][m]);
!checks[sectionName] || const getKeys = (s: string) => Object.keys(derives[s]);
checks[sectionName].instances.some((q) => queryKeys.includes(q)) || const creator = (s: string, m: string) => derives[s][m](instanceId, api);
( const isIncluded = (c: string) => (!checks[c] || (
checks[sectionName].withDetect && (checks[c].instances.some(filterKeys) && (
checks[sectionName].instances.some((q) => !checks[c].methods.length ||
(api.registry.getModuleInstances(specName, q) || []).some((q) => queryKeys.includes(q)) checks[c].methods.every(filterMethods(checks[c].instances))
) )) ||
) (
checks[c].withDetect &&
checks[c].instances.some(filterInstances)
) )
.reduce((derives, sectionName): DeriveAllSections<AllSections> => { ));
const section = allSections[sectionName as keyof AllSections];
derives[sectionName as keyof AllSections] = Object for (let i = 0; i < names.length; i++) {
.entries(section) const name = names[i];
.reduce((methods, [methodName, creator]): DeriveSection<typeof section> => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-call
methods[methodName as keyof typeof section] = creator(instanceId, api);
return methods; isIncluded(name) &&
}, {} as DeriveSection<typeof section>); lazyDeriveSection(result, name, getKeys, creator);
}
return derives; return result as ExactDerive;
}, {} as DeriveAllSections<AllSections>);
} }
// FIXME The return type of this function should be {...ExactDerive, ...DeriveCustom} // FIXME The return type of this function should be {...ExactDerive, ...DeriveCustom}
// For now we just drop the custom derive typings // For now we just drop the custom derive typings
/** @internal */ /** @internal */
export function decorateDerive (instanceId: string, api: ApiInterfaceRx, custom: DeriveCustom = {}): ExactDerive { export function getAvailableDerives (instanceId: string, api: ApiInterfaceRx, custom: DeriveCustom = {}): ExactDerive {
return { return {
...injectFunctions(instanceId, api, derive), ...injectFunctions(instanceId, api, derive as DeriveCustom),
...injectFunctions(instanceId, api, custom) ...injectFunctions(instanceId, api, custom)
}; };
} }
+5 -11
View File
@@ -1,13 +1,9 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors // Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types'; import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { BlockNumber } from '@polkadot/types/interfaces';
import { map } from 'rxjs'; import { unwrapBlockNumber } from './util';
import { memo } from '../util';
/** /**
* @name bestNumber * @name bestNumber
@@ -21,9 +17,7 @@ import { memo } from '../util';
* }); * });
* ``` * ```
*/ */
export function bestNumber (instanceId: string, api: ApiInterfaceRx): () => Observable<BlockNumber> { export const bestNumber = unwrapBlockNumber(
return memo(instanceId, (): Observable<BlockNumber> => (api: ApiInterfaceRx) =>
api.derive.chain.subscribeNewHeads().pipe( api.derive.chain.subscribeNewHeads()
map((header) => header.number.unwrap()) );
));
}
@@ -1,13 +1,9 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors // Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types'; import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { BlockNumber } from '@polkadot/types/interfaces';
import { map } from 'rxjs'; import { unwrapBlockNumber } from './util';
import { memo } from '../util';
/** /**
* @name bestNumberFinalized * @name bestNumberFinalized
@@ -22,9 +18,7 @@ import { memo } from '../util';
* }); * });
* ``` * ```
*/ */
export function bestNumberFinalized (instanceId: string, api: ApiInterfaceRx): () => Observable<BlockNumber> { export const bestNumberFinalized = unwrapBlockNumber(
return memo(instanceId, (): Observable<BlockNumber> => (api: ApiInterfaceRx) =>
api.rpc.chain.subscribeFinalizedHeads().pipe( api.rpc.chain.subscribeFinalizedHeads()
map((header) => header.number.unwrap()) );
));
}
+14 -11
View File
@@ -25,17 +25,20 @@ import { memo } from '../util';
*/ */
export function getBlock (instanceId: string, api: ApiInterfaceRx): (hash: Uint8Array | string) => Observable<SignedBlockExtended | undefined> { export function getBlock (instanceId: string, api: ApiInterfaceRx): (hash: Uint8Array | string) => Observable<SignedBlockExtended | undefined> {
return memo(instanceId, (blockHash: Uint8Array | string): Observable<SignedBlockExtended | undefined> => return memo(instanceId, (blockHash: Uint8Array | string): Observable<SignedBlockExtended | undefined> =>
api.queryAt(blockHash).pipe( combineLatest([
switchMap((queryAt) => api.rpc.chain.getBlock(blockHash),
combineLatest([ api.queryAt(blockHash).pipe(
api.rpc.chain.getBlock(blockHash), switchMap((queryAt) =>
queryAt.system.events(), combineLatest([
queryAt.session queryAt.system.events(),
? queryAt.session.validators() queryAt.session
: of([]) ? queryAt.session.validators()
]) : of([])
), ])
map(([signedBlock, events, validators]) => )
)
]).pipe(
map(([signedBlock, [events, validators]]) =>
createSignedBlockExtended(api.registry, signedBlock, events, validators) createSignedBlockExtended(api.registry, signedBlock, events, validators)
), ),
catchError((): Observable<undefined> => catchError((): Observable<undefined> =>
+9 -8
View File
@@ -25,17 +25,18 @@ import { memo } from '../util';
* console.log(`block #${number} was authored by ${author}`); * console.log(`block #${number} was authored by ${author}`);
* ``` * ```
*/ */
export function getHeader (instanceId: string, api: ApiInterfaceRx): (hash: Uint8Array | string) => Observable<HeaderExtended | undefined> { export function getHeader (instanceId: string, api: ApiInterfaceRx): (blockHash: Uint8Array | string) => Observable<HeaderExtended | undefined> {
return memo(instanceId, (hash: Uint8Array | string): Observable<HeaderExtended | undefined> => return memo(instanceId, (blockHash: Uint8Array | string): Observable<HeaderExtended | undefined> =>
api.queryAt(hash).pipe( combineLatest([
switchMap((queryAt) => api.rpc.chain.getHeader(blockHash),
combineLatest([ api.queryAt(blockHash).pipe(
api.rpc.chain.getHeader(hash), switchMap((queryAt) =>
queryAt.session queryAt.session
? queryAt.session.validators() ? queryAt.session.validators()
: of([] as AccountId[]) : of([] as AccountId[])
]) )
), )
]).pipe(
map(([header, validators]) => map(([header, validators]) =>
createHeaderExtended(header.registry, header, validators) createHeaderExtended(header.registry, header, validators)
), ),
@@ -21,15 +21,15 @@ export function subscribeNewBlocks (instanceId: string, api: ApiInterfaceRx): ()
const blockHash = header.createdAtHash || header.hash; const blockHash = header.createdAtHash || header.hash;
// we get the block first, setting up the registry // we get the block first, setting up the registry
return api.queryAt(blockHash).pipe( return combineLatest([
switchMap((queryAt) => of(header),
combineLatest([ api.rpc.chain.getBlock(blockHash),
of(header), api.queryAt(blockHash).pipe(
api.rpc.chain.getBlock(blockHash), switchMap((queryAt) =>
queryAt.system.events() queryAt.system.events()
]) )
) )
); ]);
}), }),
map(([header, block, events]) => map(([header, block, events]) =>
createSignedBlockExtended(block.registry, block, events, header.validators) createSignedBlockExtended(block.registry, block, events, header.validators)
+23
View File
@@ -0,0 +1,23 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { Compact } from '@polkadot/types';
import type { BlockNumber } from '@polkadot/types/interfaces';
import { map } from 'rxjs';
import { memo } from '../util';
// re-export these - since these needs to be resolvable from api-derive, i.e. without this
// we would emit code with ../<somewhere>/src embedded in the *.d.ts files
export type { ApiInterfaceRx } from '@polkadot/api/types';
export type { BlockNumber } from '@polkadot/types/interfaces';
export function unwrapBlockNumber <T extends { number: Compact<BlockNumber> }> (fn: (api: ApiInterfaceRx) => Observable<T>): (instanceId: string, api: ApiInterfaceRx) => () => Observable<BlockNumber> {
return (instanceId: string, api: ApiInterfaceRx) =>
memo(instanceId, () => fn(api).pipe(
map((r) => r.number.unwrap())
));
}
@@ -1,12 +0,0 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { ApiInterfaceRx } from '@polkadot/api/types';
export function getInstance (api: ApiInterfaceRx, section: string): string {
const instances = api.registry.getModuleInstances(api.runtimeVersion.specName.toString(), section);
return instances && instances.length
? instances[0]
: section;
}
@@ -0,0 +1,38 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { Collective } from './types';
import { of } from 'rxjs';
import { isFunction } from '@polkadot/util';
import { memo } from '../util';
// We are re-exporting these from here to ensure that *.d.ts generation is correct
export type { ApiInterfaceRx } from '@polkadot/api/types';
export function getInstance (api: ApiInterfaceRx, section: string): string {
const instances = api.registry.getModuleInstances(api.runtimeVersion.specName.toString(), section);
return instances && instances.length
? instances[0]
: section;
}
export function withSection <T, F extends (...args: any[]) => Observable<T>> (_section: Collective, fn: (section: string, api: ApiInterfaceRx, instanceId: string) => F): (instanceId: string, api: ApiInterfaceRx) => F {
return (instanceId: string, api: ApiInterfaceRx) =>
memo(instanceId, fn(getInstance(api, _section), api, instanceId)) as unknown as F;
}
export function callMethod <T> (method: 'members' | 'proposals' | 'proposalCount', empty: T): (_section: Collective) => (instanceId: string, api: ApiInterfaceRx) => () => Observable<T> {
return (_section: Collective) =>
withSection(_section, (section, api) =>
(): Observable<T> =>
isFunction(api.query[section]?.[method])
? api.query[section as 'council'][method]() as unknown as Observable<T>
: of(empty)
);
}
+4 -17
View File
@@ -1,24 +1,11 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors // Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { AccountId } from '@polkadot/types/interfaces'; import type { AccountId } from '@polkadot/types/interfaces';
import type { Collective } from './types';
import { of } from 'rxjs'; import { callMethod } from './helpers';
import { isFunction } from '@polkadot/util'; // We are re-exporting these from here to ensure that *.d.ts generation is correct
export type { AccountId } from '@polkadot/types/interfaces';
import { memo } from '../util'; export const members = callMethod<AccountId[]>('members', []);
import { getInstance } from './getInstance';
export function members (instanceId: string, api: ApiInterfaceRx, _section: Collective): () => Observable<AccountId[]> {
const section = getInstance(api, _section);
return memo(instanceId, (): Observable<AccountId[]> =>
isFunction(api.query[section]?.members)
? api.query[section as 'council'].members()
: of([])
);
}
+14 -11
View File
@@ -5,24 +5,27 @@ import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types'; import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { Option } from '@polkadot/types'; import type { Option } from '@polkadot/types';
import type { AccountId } from '@polkadot/types/interfaces'; import type { AccountId } from '@polkadot/types/interfaces';
import type { Collective } from './types';
import { map, of } from 'rxjs'; import { map, of } from 'rxjs';
import { isFunction } from '@polkadot/util'; import { isFunction } from '@polkadot/util';
import { memo } from '../util'; import { withSection } from './helpers';
import { getInstance } from './getInstance';
export function prime (instanceId: string, api: ApiInterfaceRx, _section: string): () => Observable<AccountId | null> { // We are re-exporting these from here to ensure that *.d.ts generation is correct
const section = getInstance(api, _section); export type { ApiInterfaceRx } from '@polkadot/api/types';
export type { AccountId } from '@polkadot/types/interfaces';
return memo(instanceId, (): Observable<AccountId | null> => export function prime (_section: Collective): (instanceId: string, api: ApiInterfaceRx) => () => Observable<AccountId | null> {
isFunction(api.query[section as 'council']?.prime) return withSection(_section, (section, api) =>
? api.query[section as 'council'].prime<Option<AccountId>>().pipe( (): Observable<AccountId | null> =>
map((optPrime): AccountId | null => isFunction(api.query[section as 'council']?.prime)
optPrime.unwrapOr(null) ? api.query[section as 'council'].prime<Option<AccountId>>().pipe(
map((optPrime): AccountId | null =>
optPrime.unwrapOr(null)
)
) )
) : of(null)
: of(null)
); );
} }
+48 -70
View File
@@ -12,18 +12,23 @@ import { catchError, combineLatest, map, of, switchMap } from 'rxjs';
import { isFunction } from '@polkadot/util'; import { isFunction } from '@polkadot/util';
import { memo } from '../util'; import { firstObservable } from '../util';
import { getInstance } from './getInstance'; import { callMethod, withSection } from './helpers';
// We are re-exporting these from here to ensure that *.d.ts generation is correct
export type { ApiInterfaceRx } from '@polkadot/api/types';
export type { Option, u32 } from '@polkadot/types';
export type { Hash, Proposal, Votes } from '@polkadot/types/interfaces';
type Result = [(Hash | Uint8Array | string)[], (Option<Proposal> | null)[], Option<Votes>[]]; type Result = [(Hash | Uint8Array | string)[], (Option<Proposal> | null)[], Option<Votes>[]];
function parse (api: ApiInterfaceRx, [hashes, proposals, votes]: Result): DeriveCollectiveProposal[] { function parse (api: ApiInterfaceRx, [hashes, proposals, votes]: Result): DeriveCollectiveProposal[] {
return proposals return proposals
.map((proposalOpt, index): DeriveCollectiveProposal | null => .map((o, index): DeriveCollectiveProposal | null =>
proposalOpt && proposalOpt.isSome o && o.isSome
? { ? {
hash: api.registry.createType('Hash', hashes[index]), hash: api.registry.createType('Hash', hashes[index]),
proposal: proposalOpt.unwrap(), proposal: o.unwrap(),
votes: votes[index].unwrapOr(null) votes: votes[index].unwrapOr(null)
} }
: null : null
@@ -31,77 +36,50 @@ function parse (api: ApiInterfaceRx, [hashes, proposals, votes]: Result): Derive
.filter((proposal): proposal is DeriveCollectiveProposal => !!proposal); .filter((proposal): proposal is DeriveCollectiveProposal => !!proposal);
} }
function _proposalsFrom (instanceId: string, api: ApiInterfaceRx, section: string): (hashes: (Hash | Uint8Array | string)[]) => Observable<DeriveCollectiveProposal[]> { function _proposalsFrom (section: string, api: ApiInterfaceRx, hashes: (Hash | Uint8Array | string)[]): Observable<DeriveCollectiveProposal[]> {
return memo(instanceId, (hashes: (Hash | Uint8Array | string)[]): Observable<DeriveCollectiveProposal[]> => return (isFunction(api.query[section]?.proposals) && hashes.length
(isFunction(api.query[section]?.proposals) && hashes.length ? combineLatest([
? combineLatest([ of(hashes),
of(hashes), // this should simply be api.query[section].proposalOf.multi<Option<Proposal>>(hashes),
// this should simply be api.query[section].proposalOf.multi<Option<Proposal>>(hashes), // however we have had cases on Edgeware where the indices have moved around after an
// however we have had cases on Edgeware where the indices have moved around after an // upgrade, which results in invalid on-chain data
// upgrade, which results in invalid on-chain data combineLatest(hashes.map((h) =>
combineLatest(hashes.map((hash) => api.query[section].proposalOf<Option<Proposal>>(h).pipe(
api.query[section].proposalOf<Option<Proposal>>(hash).pipe( catchError(() => of(null))
catchError(() => of(null)) )
) )),
)), api.query[section].voting.multi<Option<Votes>>(hashes)
api.query[section].voting.multi<Option<Votes>>(hashes) ])
]) : of<Result>([[], [], []])
: of<Result>([[], [], []]) ).pipe(
).pipe( map((r) => parse(api, r))
map((result) => parse(api, result))
)
); );
} }
export function hasProposals (instanceId: string, api: ApiInterfaceRx, _section: Collective): () => Observable<boolean> { export function hasProposals (_section: Collective): (instanceId: string, api: ApiInterfaceRx) => () => Observable<boolean> {
const section = getInstance(api, _section); return withSection(_section, (section, api) =>
(): Observable<boolean> =>
return memo(instanceId, (): Observable<boolean> => of(isFunction(api.query[section]?.proposals))
of(isFunction(api.query[section]?.proposals))
); );
} }
export function proposalCount (instanceId: string, api: ApiInterfaceRx, _section: Collective): () => Observable<u32 | null> { export function proposals (_section: Collective): (instanceId: string, api: ApiInterfaceRx) => () => Observable<DeriveCollectiveProposal[]> {
const section = getInstance(api, _section); return withSection(_section, (section, api) =>
(): Observable<DeriveCollectiveProposal[]> =>
return memo(instanceId, (): Observable<u32 | null> => api.derive[section as 'council'].proposalHashes().pipe(
isFunction(api.query[section].proposalCount) switchMap((all) => _proposalsFrom(section, api, all))
? api.query[section as 'council'].proposalCount()
: of(null)
);
}
export function proposalHashes (instanceId: string, api: ApiInterfaceRx, _section: Collective): () => Observable<Hash[]> {
const section = getInstance(api, _section);
return memo(instanceId, (): Observable<Hash[]> =>
isFunction(api.query[section]?.proposals)
? api.query[section as 'council'].proposals()
: of([])
);
}
export function proposals (instanceId: string, api: ApiInterfaceRx, _section: Collective): () => Observable<DeriveCollectiveProposal[]> {
const section = getInstance(api, _section);
const proposalsFrom = _proposalsFrom(instanceId, api, section);
const getHashes = proposalHashes(instanceId, api, _section);
return memo(instanceId, (): Observable<DeriveCollectiveProposal[]> =>
getHashes().pipe(
switchMap(proposalsFrom)
)
);
}
export function proposal (instanceId: string, api: ApiInterfaceRx, _section: Collective): (hash: Hash | Uint8Array | string) => Observable<DeriveCollectiveProposal | null> {
const section = getInstance(api, _section);
const proposalsFrom = _proposalsFrom(instanceId, api, section);
return memo(instanceId, (hash: Hash | Uint8Array | string): Observable<DeriveCollectiveProposal | null> =>
isFunction(api.query[section]?.proposals)
? proposalsFrom([hash]).pipe(
map(([proposal]) => proposal)
) )
: of(null)
); );
} }
export function proposal (_section: Collective): (instanceId: string, api: ApiInterfaceRx) => (hash: Hash | Uint8Array | string) => Observable<DeriveCollectiveProposal | null> {
return withSection(_section, (section, api) =>
(hash: Hash | Uint8Array | string): Observable<DeriveCollectiveProposal | null> =>
isFunction(api.query[section]?.proposals)
? firstObservable(_proposalsFrom(section, api, [hash]))
: of(null)
);
}
export const proposalCount = callMethod<u32 | null>('proposalCount', null);
export const proposalHashes = callMethod<Hash[]>('proposals', []);
+12 -3
View File
@@ -1,8 +1,17 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors // Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
export * from './members'; import { hasProposals as collectiveHasProposals, members as collectiveMembers, prime as collectivePrime, proposal as collectiveProposal, proposalCount as collectiveProposalCount, proposalHashes as collectiveProposalHashes, proposals as collectiveProposals } from '../collective';
export * from './prime';
export * from './proposals';
export * from './votes'; export * from './votes';
export * from './votesOf'; export * from './votesOf';
export const members = collectiveMembers('council');
export const hasProposals = collectiveHasProposals('council');
export const proposal = collectiveProposal('council');
export const proposalCount = collectiveProposalCount('council');
export const proposalHashes = collectiveProposalHashes('council');
export const proposals = collectiveProposals('council');
export const prime = collectivePrime('council');
@@ -1,13 +0,0 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { AccountId } from '@polkadot/types/interfaces';
import { members as collectiveMembers } from '../collective';
import { memo } from '../util';
export function members (instanceId: string, api: ApiInterfaceRx): () => Observable<AccountId[]> {
return memo(instanceId, collectiveMembers(instanceId, api, 'council'));
}
-13
View File
@@ -1,13 +0,0 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { AccountId } from '@polkadot/types/interfaces';
import { prime as collectivePrime } from '../collective';
import { memo } from '../util';
export function prime (instanceId: string, api: ApiInterfaceRx): () => Observable<AccountId | null> {
return memo(instanceId, collectivePrime(instanceId, api, 'council'));
}
@@ -1,31 +0,0 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { u32 } from '@polkadot/types';
import type { Hash } from '@polkadot/types/interfaces';
import type { DeriveCollectiveProposal } from '../types';
import { hasProposals as collectiveHasProposals, proposal as collectiveProposal, proposalCount as collectiveProposalCount, proposalHashes as collectiveProposalHashes, proposals as collectiveProposals } from '../collective';
import { memo } from '../util';
export function hasProposals (instanceId: string, api: ApiInterfaceRx): () => Observable<boolean> {
return memo(instanceId, collectiveHasProposals(instanceId, api, 'council'));
}
export function proposal (instanceId: string, api: ApiInterfaceRx): (hash: Hash | Uint8Array | string) => Observable<DeriveCollectiveProposal | null> {
return memo(instanceId, collectiveProposal(instanceId, api, 'council'));
}
export function proposalCount (instanceId: string, api: ApiInterfaceRx): () => Observable<u32 | null> {
return memo(instanceId, collectiveProposalCount(instanceId, api, 'council'));
}
export function proposalHashes (instanceId: string, api: ApiInterfaceRx): () => Observable<Hash[]> {
return memo(instanceId, collectiveProposalHashes(instanceId, api, 'council'));
}
export function proposals (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveCollectiveProposal[]> {
return memo(instanceId, collectiveProposals(instanceId, api, 'council'));
}
@@ -61,10 +61,8 @@ function schedulerEntries (api: ApiInterfaceRx): Observable<[BlockNumber[], (Opt
// however we have had cases on Darwinia where the indices have moved around after an // however we have had cases on Darwinia where the indices have moved around after an
// upgrade, which results in invalid on-chain data // upgrade, which results in invalid on-chain data
combineLatest(blockNumbers.map((blockNumber) => combineLatest(blockNumbers.map((blockNumber) =>
api.query.scheduler.agenda(blockNumber).pipe( // this does create an issue since it discards all at that block
// this does create an issue since it discards all at that block api.query.scheduler.agenda(blockNumber).pipe(catchError(() => of(null)))
catchError(() => of(null))
)
)) ))
]) ])
: of<[BlockNumber[], null[]]>([[], []]); : of<[BlockNumber[], null[]]>([[], []]);
@@ -78,30 +76,23 @@ function queryScheduler (api: ApiInterfaceRx): Observable<DeriveDispatch[]> {
const result: SchedulerInfo[] = []; const result: SchedulerInfo[] = [];
blockNumbers.forEach((at, index): void => { blockNumbers.forEach((at, index): void => {
(agendas[index] || []) (agendas[index] || []).filter((o) => o.isSome).forEach((o): void => {
.filter((opt) => opt.isSome) const scheduled = o.unwrap();
.forEach((optScheduled): void => {
const scheduled = optScheduled.unwrap();
if (scheduled.maybeId.isSome) { if (scheduled.maybeId.isSome) {
const id = scheduled.maybeId.unwrap().toHex(); const id = scheduled.maybeId.unwrap().toHex();
if (id.startsWith(DEMOCRACY_ID)) { id.startsWith(DEMOCRACY_ID) && result.push({ at, imageHash: scheduled.call.args[0] as Hash, index: api.registry.createType('(u64, ReferendumIndex)', id)[1] });
const [, index] = api.registry.createType('(u64, ReferendumIndex)', id); }
const imageHash = scheduled.call.args[0] as Hash; });
result.push({ at, imageHash, index });
}
}
});
}); });
return result.length return combineLatest([
? combineLatest([ of(result),
of(result), result.length
api.derive.democracy.preimages(result.map(({ imageHash }) => imageHash)) ? api.derive.democracy.preimages(result.map(({ imageHash }) => imageHash))
]) : of([])
: of([[], []]); ]);
}), }),
map(([infos, images]): DeriveDispatch[] => map(([infos, images]): DeriveDispatch[] =>
infos.map((info, index) => ({ ...info, image: images[index] })) infos.map((info, index) => ({ ...info, image: images[index] }))
+10 -2
View File
@@ -25,7 +25,11 @@ function parseEnd (api: ApiInterfaceRx, vote: Vote, { approved, end }: Referendu
return [ return [
end, end,
(approved.isTrue && vote.isAye) || (approved.isFalse && vote.isNay) (approved.isTrue && vote.isAye) || (approved.isFalse && vote.isNay)
? end.add(api.consts.democracy.enactmentPeriod.muln(LOCKUPS[vote.conviction.index])) ? end.add(
(
api.consts.democracy.voteLockingPeriod ||
api.consts.democracy.enactmentPeriod
).muln(LOCKUPS[vote.conviction.index]))
: BN_ZERO : BN_ZERO
]; ];
} }
@@ -50,7 +54,11 @@ function delegateLocks (api: ApiInterfaceRx, { balance, conviction, target }: Vo
referendumId, referendumId,
unlockAt: unlockAt.isZero() unlockAt: unlockAt.isZero()
? unlockAt ? unlockAt
: referendumEnd.add(api.consts.democracy.enactmentPeriod.muln(LOCKUPS[conviction.index])), : referendumEnd.add(
(
api.consts.democracy.voteLockingPeriod ||
api.consts.democracy.enactmentPeriod
).muln(LOCKUPS[conviction.index])),
vote: api.registry.createType('Vote', { aye: vote.isAye, conviction }) vote: api.registry.createType('Vote', { aye: vote.isAye, conviction })
})) }))
) )
@@ -20,7 +20,6 @@ type Depositors = DepositorsNew | DepositorsOld;
type Proposals = ITuple<[PropIndex, Hash, AccountId]>[]; type Proposals = ITuple<[PropIndex, Hash, AccountId]>[];
type Result = [Proposals, (DeriveProposalImage | undefined)[], Depositors[]]; type Result = [Proposals, (DeriveProposalImage | undefined)[], Depositors[]];
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function isNewDepositors (depositors: ITuple<[Vec<AccountId>, Balance]> | ITuple<[Balance, Vec<AccountId>]>): depositors is ITuple<[Vec<AccountId>, Balance]> { function isNewDepositors (depositors: ITuple<[Vec<AccountId>, Balance]> | ITuple<[Balance, Vec<AccountId>]>): depositors is ITuple<[Vec<AccountId>, Balance]> {
// Detect balance... // Detect balance...
// eslint-disable-next-line @typescript-eslint/unbound-method // eslint-disable-next-line @typescript-eslint/unbound-method
+6 -4
View File
@@ -6,6 +6,10 @@ import type { AccountId, Balance, BlockNumber, Hash, PropIndex, Proposal, Refere
import type { PalletDemocracyReferendumStatus, PalletDemocracyVoteThreshold } from '@polkadot/types/lookup'; import type { PalletDemocracyReferendumStatus, PalletDemocracyVoteThreshold } from '@polkadot/types/lookup';
import type { BN } from '@polkadot/util'; import type { BN } from '@polkadot/util';
export interface AtBlock {
at: BlockNumber;
}
export interface DeriveDemocracyLock { export interface DeriveDemocracyLock {
balance: Balance; balance: Balance;
isDelegated: boolean; isDelegated: boolean;
@@ -16,15 +20,13 @@ export interface DeriveDemocracyLock {
vote: Vote; vote: Vote;
} }
export interface DeriveProposalImage { export interface DeriveProposalImage extends AtBlock {
at: BlockNumber;
balance: Balance; balance: Balance;
proposal?: Proposal; proposal?: Proposal;
proposer: AccountId; proposer: AccountId;
} }
export interface DeriveDispatch { export interface DeriveDispatch extends AtBlock {
at: BlockNumber;
index: ReferendumIndex; index: ReferendumIndex;
imageHash: Hash; imageHash: Hash;
image?: DeriveProposalImage; image?: DeriveProposalImage;
+44 -38
View File
@@ -42,7 +42,20 @@ function sortAccounts ([, balanceA]: [AccountId, Balance], [, balanceB]: [Accoun
return balanceB.cmp(balanceA); return balanceB.cmp(balanceA);
} }
function queryElections (api: ApiInterfaceRx): Observable<DeriveElectionsInfo> { function getConstants (api: ApiInterfaceRx, elections: string | null): Partial<DeriveElectionsInfo> {
return elections
? {
candidacyBond: api.consts[elections].candidacyBond as Balance,
desiredRunnersUp: api.consts[elections].desiredRunnersUp as u32,
desiredSeats: api.consts[elections].desiredMembers as u32,
termDuration: api.consts[elections].termDuration as BlockNumber,
votingBond: api.consts[elections].votingBond as Balance
}
: {};
}
function getModules (api: ApiInterfaceRx): [string, string | null] {
const [council] = api.registry.getModuleInstances(api.runtimeVersion.specName.toString(), 'council') || ['council'];
const elections = api.query.phragmenElection const elections = api.query.phragmenElection
? 'phragmenElection' ? 'phragmenElection'
: api.query.electionsPhragmen : api.query.electionsPhragmen
@@ -50,43 +63,8 @@ function queryElections (api: ApiInterfaceRx): Observable<DeriveElectionsInfo> {
: api.query.elections : api.query.elections
? 'elections' ? 'elections'
: null; : null;
const [council] = api.registry.getModuleInstances(api.runtimeVersion.specName.toString(), 'council') || ['council'];
return ( return [council, elections];
elections
? api.queryMulti<[Vec<AccountId>, Vec<Candidate>, Vec<Member>, Vec<Member>]>([
api.query[council].members,
api.query[elections].candidates,
api.query[elections].members,
api.query[elections].runnersUp
])
: combineLatest([
api.query[council].members<Vec<AccountId>>(),
of<Candidate[]>([]),
of<Member[]>([]),
of<Member[]>([])
])
).pipe(
map(([councilMembers, candidates, members, runnersUp]): DeriveElectionsInfo => ({
...(
elections
? {
candidacyBond: api.consts[elections].candidacyBond as Balance,
desiredRunnersUp: api.consts[elections].desiredRunnersUp as u32,
desiredSeats: api.consts[elections].desiredMembers as u32,
termDuration: api.consts[elections].termDuration as BlockNumber,
votingBond: api.consts[elections].votingBond as Balance
}
: {}
),
candidateCount: api.registry.createType('u32', candidates.length),
candidates: candidates.map(getCandidate),
members: members.length
? members.map(getAccountTuple).sort(sortAccounts)
: councilMembers.map((accountId): [AccountId, Balance] => [accountId, api.registry.createType('Balance')]),
runnersUp: runnersUp.map(getAccountTuple).sort(sortAccounts)
}))
);
} }
/** /**
@@ -103,5 +81,33 @@ function queryElections (api: ApiInterfaceRx): Observable<DeriveElectionsInfo> {
* ``` * ```
*/ */
export function info (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveElectionsInfo> { export function info (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveElectionsInfo> {
return memo(instanceId, (): Observable<DeriveElectionsInfo> => queryElections(api)); return memo(instanceId, (): Observable<DeriveElectionsInfo> => {
const [council, elections] = getModules(api);
return (
elections
? api.queryMulti<[Vec<AccountId>, Vec<Candidate>, Vec<Member>, Vec<Member>]>([
api.query[council].members,
api.query[elections].candidates,
api.query[elections].members,
api.query[elections].runnersUp
])
: combineLatest([
api.query[council].members<Vec<AccountId>>(),
of<Candidate[]>([]),
of<Member[]>([]),
of<Member[]>([])
])
).pipe(
map(([councilMembers, candidates, members, runnersUp]): DeriveElectionsInfo => ({
...getConstants(api, elections),
candidateCount: api.registry.createType('u32', candidates.length),
candidates: candidates.map(getCandidate),
members: members.length
? members.map(getAccountTuple).sort(sortAccounts)
: councilMembers.map((a): [AccountId, Balance] => [a, api.registry.createType('Balance')]),
runnersUp: runnersUp.map(getAccountTuple).sort(sortAccounts)
}))
);
});
} }
+11 -3
View File
@@ -1,6 +1,14 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors // Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
export * from './members'; import { hasProposals as collectiveHasProposals, members as collectiveMembers, prime as collectivePrime, proposal as collectiveProposal, proposalCount as collectiveProposalCount, proposalHashes as collectiveProposalHashes, proposals as collectiveProposals } from '../collective';
export * from './prime';
export * from './proposals'; export const members = collectiveMembers('membership');
export const hasProposals = collectiveHasProposals('membership');
export const proposal = collectiveProposal('membership');
export const proposalCount = collectiveProposalCount('membership');
export const proposalHashes = collectiveProposalHashes('membership');
export const proposals = collectiveProposals('membership');
export const prime = collectivePrime('membership');
@@ -1,13 +0,0 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { AccountId } from '@polkadot/types/interfaces';
import { members as collectiveMembers } from '../collective';
import { memo } from '../util';
export function members (instanceId: string, api: ApiInterfaceRx): () => Observable<AccountId[]> {
return memo(instanceId, collectiveMembers(instanceId, api, 'membership'));
}
@@ -1,13 +0,0 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { AccountId } from '@polkadot/types/interfaces';
import { prime as collectivePrime } from '../collective';
import { memo } from '../util';
export function prime (instanceId: string, api: ApiInterfaceRx): () => Observable<AccountId | null> {
return memo(instanceId, collectivePrime(instanceId, api, 'membership'));
}
@@ -1,31 +0,0 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { u32 } from '@polkadot/types';
import type { Hash } from '@polkadot/types/interfaces';
import type { DeriveCollectiveProposal } from '../types';
import { hasProposals as collectiveHasProposals, proposal as collectiveProposal, proposalCount as collectiveProposalCount, proposalHashes as collectiveProposalHashes, proposals as collectiveProposals } from '../collective';
import { memo } from '../util';
export function hasProposals (instanceId: string, api: ApiInterfaceRx): () => Observable<boolean> {
return memo(instanceId, collectiveHasProposals(instanceId, api, 'membership'));
}
export function proposal (instanceId: string, api: ApiInterfaceRx): (hash: Hash | Uint8Array | string) => Observable<DeriveCollectiveProposal | null> {
return memo(instanceId, collectiveProposal(instanceId, api, 'membership'));
}
export function proposalCount (instanceId: string, api: ApiInterfaceRx): () => Observable<u32 | null> {
return memo(instanceId, collectiveProposalCount(instanceId, api, 'membership'));
}
export function proposalHashes (instanceId: string, api: ApiInterfaceRx): () => Observable<Hash[]> {
return memo(instanceId, collectiveProposalHashes(instanceId, api, 'membership'));
}
export function proposals (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveCollectiveProposal[]> {
return memo(instanceId, collectiveProposals(instanceId, api, 'membership'));
}
+1 -1
View File
@@ -3,4 +3,4 @@
// Auto-generated by @polkadot/dev, do not edit // Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/api-derive', version: '6.5.1' }; export const packageInfo = { name: '@polkadot/api-derive', version: '6.12.1' };
@@ -1,17 +0,0 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { BlockNumber } from '@polkadot/types/interfaces';
import { map } from 'rxjs';
import { memo } from '../util';
export function eraLength (instanceId: string, api: ApiInterfaceRx): () => Observable<BlockNumber> {
return memo(instanceId, (): Observable<BlockNumber> =>
api.derive.session.info().pipe(
map((info) => info.eraLength)
));
}
@@ -1,17 +0,0 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { BlockNumber } from '@polkadot/types/interfaces';
import { map } from 'rxjs';
import { memo } from '../util';
export function eraProgress (instanceId: string, api: ApiInterfaceRx): () => Observable<BlockNumber> {
return memo(instanceId, (): Observable<BlockNumber> =>
api.derive.session.progress().pipe(
map((info) => info.eraProgress)
));
}
-3
View File
@@ -1,9 +1,6 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors // Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
export * from './eraLength';
export * from './eraProgress';
export * from './indexes'; export * from './indexes';
export * from './info'; export * from './info';
export * from './progress'; export * from './progress';
export * from './sessionProgress';
+14 -1
View File
@@ -4,7 +4,7 @@
import type { Observable } from 'rxjs'; import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types'; import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { Option, u64 } from '@polkadot/types'; import type { Option, u64 } from '@polkadot/types';
import type { SessionIndex } from '@polkadot/types/interfaces'; import type { BlockNumber, SessionIndex } from '@polkadot/types/interfaces';
import type { DeriveSessionInfo, DeriveSessionProgress } from '../types'; import type { DeriveSessionInfo, DeriveSessionProgress } from '../types';
import { combineLatest, map, of, switchMap } from 'rxjs'; import { combineLatest, map, of, switchMap } from 'rxjs';
@@ -15,6 +15,15 @@ type ResultSlotsNoSession = [u64, u64, u64];
type ResultSlots = [u64, u64, u64, Option<SessionIndex>]; type ResultSlots = [u64, u64, u64, Option<SessionIndex>];
type ResultSlotsFlat = [u64, u64, u64, SessionIndex]; type ResultSlotsFlat = [u64, u64, u64, SessionIndex];
function withProgressField (field: 'eraLength' | 'eraProgress' | 'sessionProgress'): (instanceId: string, api: ApiInterfaceRx) => () => Observable<BlockNumber> {
return (instanceId: string, api: ApiInterfaceRx) =>
memo(instanceId, (): Observable<BlockNumber> =>
api.derive.session.progress().pipe(
map((info) => info[field])
)
);
}
function createDerive (api: ApiInterfaceRx, info: DeriveSessionInfo, [currentSlot, epochIndex, epochOrGenesisStartSlot, activeEraStartSessionIndex]: ResultSlotsFlat): DeriveSessionProgress { function createDerive (api: ApiInterfaceRx, info: DeriveSessionInfo, [currentSlot, epochIndex, epochOrGenesisStartSlot, activeEraStartSessionIndex]: ResultSlotsFlat): DeriveSessionProgress {
const epochStartSlot = epochIndex.mul(info.sessionLength).iadd(epochOrGenesisStartSlot); const epochStartSlot = epochIndex.mul(info.sessionLength).iadd(epochOrGenesisStartSlot);
const sessionProgress = currentSlot.sub(epochStartSlot); const sessionProgress = currentSlot.sub(epochStartSlot);
@@ -77,3 +86,7 @@ export function progress (instanceId: string, api: ApiInterfaceRx): () => Observ
: queryAura(api) : queryAura(api)
); );
} }
export const eraLength = withProgressField('eraLength');
export const eraProgress = withProgressField('eraProgress');
export const sessionProgress = withProgressField('sessionProgress');
@@ -1,17 +0,0 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { BlockNumber } from '@polkadot/types/interfaces';
import { map } from 'rxjs';
import { memo } from '../util';
export function sessionProgress (instanceId: string, api: ApiInterfaceRx): () => Observable<BlockNumber> {
return memo(instanceId, (): Observable<BlockNumber> =>
api.derive.session.progress().pipe(
map((info) => info.sessionProgress)
));
}
+8 -9
View File
@@ -11,7 +11,7 @@ import { combineLatest, map, switchMap } from 'rxjs';
import { BN, BN_ZERO } from '@polkadot/util'; import { BN, BN_ZERO } from '@polkadot/util';
import { memo } from '../util'; import { firstMemo, memo } from '../util';
const QUERY_OPTS = { const QUERY_OPTS = {
withDestination: true, withDestination: true,
@@ -73,7 +73,9 @@ export function accounts (instanceId: string, api: ApiInterfaceRx): (accountIds:
api.derive.staking.keysMulti(accountIds), api.derive.staking.keysMulti(accountIds),
api.derive.staking.queryMulti(accountIds, QUERY_OPTS) api.derive.staking.queryMulti(accountIds, QUERY_OPTS)
]).pipe( ]).pipe(
map(([keys, queries]) => queries.map((query, index) => parseResult(api, sessionInfo, keys[index], query))) map(([keys, queries]) =>
queries.map((q, index) => parseResult(api, sessionInfo, keys[index], q))
)
) )
) )
) )
@@ -83,10 +85,7 @@ export function accounts (instanceId: string, api: ApiInterfaceRx): (accountIds:
/** /**
* @description From a stash, retrieve the controllerId and fill in all the relevant staking details * @description From a stash, retrieve the controllerId and fill in all the relevant staking details
*/ */
export function account (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string) => Observable<DeriveStakingAccount> { export const account = firstMemo(
return memo(instanceId, (accountId: Uint8Array | string): Observable<DeriveStakingAccount> => (api: ApiInterfaceRx, accountId: Uint8Array | string) =>
api.derive.staking.accounts([accountId]).pipe( api.derive.staking.accounts([accountId])
map(([first]) => first) );
)
);
}
+46
View File
@@ -0,0 +1,46 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { EraIndex } from '@polkadot/types/interfaces';
import { deriveCache } from '../util';
export function getEraCache <T> (CACHE_KEY: string, era: EraIndex, withActive?: boolean): [string, T | undefined] {
const cacheKey = `${CACHE_KEY}-${era.toString()}`;
return [
cacheKey,
withActive
? undefined
: deriveCache.get<T>(cacheKey)
];
}
export function getEraMultiCache <T> (CACHE_KEY: string, eras: EraIndex[], withActive?: boolean): T[] {
const cached: T[] = withActive
? []
: eras
.map((e) => deriveCache.get<T>(`${CACHE_KEY}-${e.toString()}`))
.filter((v): v is T => !!v);
return cached;
}
export function setEraCache <T extends { era: EraIndex }> (cacheKey: string, withActive: boolean, value: T): T {
!withActive && deriveCache.set(cacheKey, value);
return value;
}
export function setEraMultiCache <T extends { era: EraIndex }> (CACHE_KEY: string, withActive: boolean, values: T[]): T[] {
!withActive && values.forEach((v) => deriveCache.set(`${CACHE_KEY}-${v.era.toString()}`, v));
return values;
}
export function filterCachedEras <T extends { era: EraIndex }> (eras: EraIndex[], cached: T[], query: T[]): T[] {
return eras.map((e) =>
cached.find(({ era }) => e.eq(era)) ||
query.find(({ era }) => e.eq(era)) as T
);
}
+11 -36
View File
@@ -8,9 +8,11 @@ import type { AccountId, EraIndex } from '@polkadot/types/interfaces';
import type { PalletStakingExposure } from '@polkadot/types/lookup'; import type { PalletStakingExposure } from '@polkadot/types/lookup';
import type { DeriveEraExposure, DeriveEraNominatorExposure, DeriveEraValidatorExposure } from '../types'; import type { DeriveEraExposure, DeriveEraNominatorExposure, DeriveEraValidatorExposure } from '../types';
import { combineLatest, map, of, switchMap } from 'rxjs'; import { map, of } from 'rxjs';
import { deriveCache, memo } from '../util'; import { memo } from '../util';
import { getEraCache, setEraCache } from './cache';
import { combineEras, erasHistoricApply, singleEra } from './util';
type KeysAndExposures = [StorageKey<[EraIndex, AccountId]>, PalletStakingExposure][]; type KeysAndExposures = [StorageKey<[EraIndex, AccountId]>, PalletStakingExposure][];
@@ -36,45 +38,18 @@ function mapStakers (era: EraIndex, stakers: KeysAndExposures): DeriveEraExposur
return { era, nominators, validators }; return { era, nominators, validators };
} }
export function _eraExposure (instanceId: string, api: ApiInterfaceRx): (era: EraIndex, withActive: boolean) => Observable<DeriveEraExposure> { export function _eraExposure (instanceId: string, api: ApiInterfaceRx): (era: EraIndex, withActive?: boolean) => Observable<DeriveEraExposure> {
return memo(instanceId, (era: EraIndex, withActive: boolean): Observable<DeriveEraExposure> => { return memo(instanceId, (era: EraIndex, withActive = false): Observable<DeriveEraExposure> => {
const cacheKey = `${CACHE_KEY}-${era.toString()}`; const [cacheKey, cached] = getEraCache<DeriveEraExposure>(CACHE_KEY, era, withActive);
const cached = withActive
? undefined
: deriveCache.get<DeriveEraExposure>(cacheKey);
return cached return cached
? of(cached) ? of(cached)
: api.query.staking.erasStakersClipped.entries(era).pipe( : api.query.staking.erasStakersClipped.entries(era).pipe(
map((stakers): DeriveEraExposure => { map((r) => setEraCache(cacheKey, withActive, mapStakers(era, r)))
const value = mapStakers(era, stakers);
!withActive && deriveCache.set(cacheKey, value);
return value;
})
); );
}); });
} }
export function eraExposure (instanceId: string, api: ApiInterfaceRx): (era: EraIndex) => Observable<DeriveEraExposure> { export const eraExposure = singleEra('_eraExposure');
return memo(instanceId, (era: EraIndex): Observable<DeriveEraExposure> => export const _erasExposure = combineEras('_eraExposure');
api.derive.staking._eraExposure(era, true) export const erasExposure = erasHistoricApply('_erasExposure');
);
}
export function _erasExposure (instanceId: string, api: ApiInterfaceRx): (eras: EraIndex[], withActive: boolean) => Observable<DeriveEraExposure[]> {
return memo(instanceId, (eras: EraIndex[], withActive: boolean): Observable<DeriveEraExposure[]> =>
eras.length
? combineLatest(eras.map((era) => api.derive.staking._eraExposure(era, withActive)))
: of([])
);
}
export function erasExposure (instanceId: string, api: ApiInterfaceRx): (withActive?: boolean) => Observable<DeriveEraExposure[]> {
return memo(instanceId, (withActive = false): Observable<DeriveEraExposure[]> =>
api.derive.staking.erasHistoric(withActive).pipe(
switchMap((eras) => api.derive.staking._erasExposure(eras, withActive))
)
);
}
@@ -13,8 +13,8 @@ import { BN_ONE, BN_ZERO } from '@polkadot/util';
import { memo } from '../util'; import { memo } from '../util';
export function erasHistoric (instanceId: string, api: ApiInterfaceRx): (withActive: boolean) => Observable<EraIndex[]> { export function erasHistoric (instanceId: string, api: ApiInterfaceRx): (withActive?: boolean) => Observable<EraIndex[]> {
return memo(instanceId, (withActive: boolean): Observable<EraIndex[]> => return memo(instanceId, (withActive?: boolean): Observable<EraIndex[]> =>
api.queryMulti<[Option<ActiveEraInfo>, u32]>([ api.queryMulti<[Option<ActiveEraInfo>, u32]>([
api.query.staking.activeEra, api.query.staking.activeEra,
api.query.staking.historyDepth api.query.staking.historyDepth
+7 -25
View File
@@ -7,12 +7,13 @@ import type { EraIndex } from '@polkadot/types/interfaces';
import type { PalletStakingEraRewardPoints } from '@polkadot/types/lookup'; import type { PalletStakingEraRewardPoints } from '@polkadot/types/lookup';
import type { DeriveEraPoints, DeriveEraValPoints } from '../types'; import type { DeriveEraPoints, DeriveEraValPoints } from '../types';
import { map, of, switchMap } from 'rxjs'; import { map, of } from 'rxjs';
import { BN_ZERO } from '@polkadot/util'; import { BN_ZERO } from '@polkadot/util';
import { deriveCache, memo } from '../util'; import { memo } from '../util';
import { filterEras } from './util'; import { filterCachedEras, getEraMultiCache, setEraMultiCache } from './cache';
import { erasHistoricApply, filterEras } from './util';
const CACHE_KEY = 'eraPoints'; const CACHE_KEY = 'eraPoints';
@@ -40,34 +41,15 @@ export function _erasPoints (instanceId: string, api: ApiInterfaceRx): (eras: Er
return of([]); return of([]);
} }
const cached: DeriveEraPoints[] = withActive const cached = getEraMultiCache<DeriveEraPoints>(CACHE_KEY, eras, withActive);
? []
: eras
.map((era) => deriveCache.get<DeriveEraPoints>(`${CACHE_KEY}-${era.toString()}`))
.filter((value): value is DeriveEraPoints => !!value);
const remaining = filterEras(eras, cached); const remaining = filterEras(eras, cached);
return !remaining.length return !remaining.length
? of(cached) ? of(cached)
: api.query.staking.erasRewardPoints.multi(remaining).pipe( : api.query.staking.erasRewardPoints.multi(remaining).pipe(
map((points): DeriveEraPoints[] => { map((p) => filterCachedEras(eras, cached, setEraMultiCache(CACHE_KEY, withActive, mapPoints(remaining, p))))
const query = mapPoints(remaining, points);
!withActive && query.forEach((q) => deriveCache.set(`${CACHE_KEY}-${q.era.toString()}`, q));
return eras.map((era): DeriveEraPoints =>
cached.find((cached) => era.eq(cached.era)) ||
query.find((query) => era.eq(query.era)) as DeriveEraPoints
);
})
); );
}); });
} }
export function erasPoints (instanceId: string, api: ApiInterfaceRx): (withActive?: boolean) => Observable<DeriveEraPoints[]> { export const erasPoints = erasHistoricApply('_erasPoints');
return memo(instanceId, (withActive = false): Observable<DeriveEraPoints[]> =>
api.derive.staking.erasHistoric(withActive).pipe(
switchMap((eras) => api.derive.staking._erasPoints(eras, withActive))
)
);
}
+9 -34
View File
@@ -8,9 +8,11 @@ import type { EraIndex } from '@polkadot/types/interfaces';
import type { PalletStakingValidatorPrefs } from '@polkadot/types/lookup'; import type { PalletStakingValidatorPrefs } from '@polkadot/types/lookup';
import type { DeriveEraPrefs, DeriveEraValPrefs } from '../types'; import type { DeriveEraPrefs, DeriveEraValPrefs } from '../types';
import { combineLatest, map, of, switchMap } from 'rxjs'; import { map, of } from 'rxjs';
import { deriveCache, memo } from '../util'; import { memo } from '../util';
import { getEraCache, setEraCache } from './cache';
import { combineEras, erasHistoricApply, singleEra } from './util';
const CACHE_KEY = 'eraPrefs'; const CACHE_KEY = 'eraPrefs';
@@ -26,43 +28,16 @@ function mapPrefs (era: EraIndex, all: [StorageKey, PalletStakingValidatorPrefs]
export function _eraPrefs (instanceId: string, api: ApiInterfaceRx): (era: EraIndex, withActive: boolean) => Observable<DeriveEraPrefs> { export function _eraPrefs (instanceId: string, api: ApiInterfaceRx): (era: EraIndex, withActive: boolean) => Observable<DeriveEraPrefs> {
return memo(instanceId, (era: EraIndex, withActive: boolean): Observable<DeriveEraPrefs> => { return memo(instanceId, (era: EraIndex, withActive: boolean): Observable<DeriveEraPrefs> => {
const cacheKey = `${CACHE_KEY}-${era.toString()}`; const [cacheKey, cached] = getEraCache<DeriveEraPrefs>(CACHE_KEY, era, withActive);
const cached = withActive
? undefined
: deriveCache.get<DeriveEraPrefs>(cacheKey);
return cached return cached
? of(cached) ? of(cached)
: api.query.staking.erasValidatorPrefs.entries(era).pipe( : api.query.staking.erasValidatorPrefs.entries(era).pipe(
map((prefs): DeriveEraPrefs => { map((r) => setEraCache(cacheKey, withActive, mapPrefs(era, r)))
const value = mapPrefs(era, prefs);
!withActive && deriveCache.set(cacheKey, value);
return value;
})
); );
}); });
} }
export function eraPrefs (instanceId: string, api: ApiInterfaceRx): (era: EraIndex) => Observable<DeriveEraPrefs> { export const eraPrefs = singleEra('_eraPrefs');
return memo(instanceId, (era: EraIndex): Observable<DeriveEraPrefs> => export const _erasPrefs = combineEras('_eraPrefs');
api.derive.staking._eraPrefs(era, true) export const erasPrefs = erasHistoricApply('_erasPrefs');
);
}
export function _erasPrefs (instanceId: string, api: ApiInterfaceRx): (eras: EraIndex[], withActive: boolean) => Observable<DeriveEraPrefs[]> {
return memo(instanceId, (eras: EraIndex[], withActive: boolean): Observable<DeriveEraPrefs[]> =>
eras.length
? combineLatest(eras.map((era) => api.derive.staking._eraPrefs(era, withActive)))
: of([])
);
}
export function erasPrefs (instanceId: string, api: ApiInterfaceRx): (withActive?: boolean) => Observable<DeriveEraPrefs[]> {
return memo(instanceId, (withActive = false): Observable<DeriveEraPrefs[]> =>
api.derive.staking.erasHistoric(withActive).pipe(
switchMap((eras) => api.derive.staking._erasPrefs(eras, withActive))
)
);
}
+7 -25
View File
@@ -7,10 +7,11 @@ import type { Option } from '@polkadot/types';
import type { Balance, EraIndex } from '@polkadot/types/interfaces'; import type { Balance, EraIndex } from '@polkadot/types/interfaces';
import type { DeriveEraRewards } from '../types'; import type { DeriveEraRewards } from '../types';
import { map, of, switchMap } from 'rxjs'; import { map, of } from 'rxjs';
import { deriveCache, memo } from '../util'; import { memo } from '../util';
import { filterEras } from './util'; import { filterCachedEras, getEraMultiCache, setEraMultiCache } from './cache';
import { erasHistoricApply, filterEras } from './util';
const CACHE_KEY = 'eraRewards'; const CACHE_KEY = 'eraRewards';
@@ -27,11 +28,7 @@ export function _erasRewards (instanceId: string, api: ApiInterfaceRx): (eras: E
return of([]); return of([]);
} }
const cached: DeriveEraRewards[] = withActive const cached = getEraMultiCache<DeriveEraRewards>(CACHE_KEY, eras, withActive);
? []
: eras
.map((era) => deriveCache.get<DeriveEraRewards>(`${CACHE_KEY}-${era.toString()}`))
.filter((value): value is DeriveEraRewards => !!value);
const remaining = filterEras(eras, cached); const remaining = filterEras(eras, cached);
if (!remaining.length) { if (!remaining.length) {
@@ -39,24 +36,9 @@ export function _erasRewards (instanceId: string, api: ApiInterfaceRx): (eras: E
} }
return api.query.staking.erasValidatorReward.multi(remaining).pipe( return api.query.staking.erasValidatorReward.multi(remaining).pipe(
map((optRewards) => { map((r) => filterCachedEras(eras, cached, setEraMultiCache(CACHE_KEY, withActive, mapRewards(remaining, r))))
const query = mapRewards(remaining, optRewards);
!withActive && query.forEach((q) => deriveCache.set(`${CACHE_KEY}-${q.era.toString()}`, q));
return eras.map((era): DeriveEraRewards =>
cached.find((cached) => era.eq(cached.era)) ||
query.find((query) => era.eq(query.era)) as DeriveEraRewards
);
})
); );
}); });
} }
export function erasRewards (instanceId: string, api: ApiInterfaceRx): (withActive?: boolean) => Observable<DeriveEraRewards[]> { export const erasRewards = erasHistoricApply('_erasRewards');
return memo(instanceId, (withActive = false): Observable<DeriveEraRewards[]> =>
api.derive.staking.erasHistoric(withActive).pipe(
switchMap((eras) => api.derive.staking._erasRewards(eras, withActive))
)
);
}
+9 -36
View File
@@ -8,9 +8,11 @@ import type { BalanceOf, EraIndex, Perbill } from '@polkadot/types/interfaces';
import type { ITuple } from '@polkadot/types/types'; import type { ITuple } from '@polkadot/types/types';
import type { DeriveEraSlashes, DeriveEraValSlash } from '../types'; import type { DeriveEraSlashes, DeriveEraValSlash } from '../types';
import { combineLatest, map, of, switchMap } from 'rxjs'; import { combineLatest, map, of } from 'rxjs';
import { deriveCache, memo } from '../util'; import { memo } from '../util';
import { getEraCache, setEraCache } from './cache';
import { combineEras, erasHistoricApply, singleEra } from './util';
const CACHE_KEY = 'eraSlashes'; const CACHE_KEY = 'eraSlashes';
@@ -31,10 +33,7 @@ function mapSlashes (era: EraIndex, noms: [StorageKey, Option<BalanceOf>][], val
export function _eraSlashes (instanceId: string, api: ApiInterfaceRx): (era: EraIndex, withActive: boolean) => Observable<DeriveEraSlashes> { export function _eraSlashes (instanceId: string, api: ApiInterfaceRx): (era: EraIndex, withActive: boolean) => Observable<DeriveEraSlashes> {
return memo(instanceId, (era: EraIndex, withActive: boolean): Observable<DeriveEraSlashes> => { return memo(instanceId, (era: EraIndex, withActive: boolean): Observable<DeriveEraSlashes> => {
const cacheKey = `${CACHE_KEY}-${era.toString()}`; const [cacheKey, cached] = getEraCache<DeriveEraSlashes>(CACHE_KEY, era, withActive);
const cached = withActive
? undefined
: deriveCache.get<DeriveEraSlashes>(cacheKey);
return cached return cached
? of(cached) ? of(cached)
@@ -42,37 +41,11 @@ export function _eraSlashes (instanceId: string, api: ApiInterfaceRx): (era: Era
api.query.staking.nominatorSlashInEra.entries(era), api.query.staking.nominatorSlashInEra.entries(era),
api.query.staking.validatorSlashInEra.entries(era) api.query.staking.validatorSlashInEra.entries(era)
]).pipe( ]).pipe(
map(([noms, vals]): DeriveEraSlashes => { map(([n, v]) => setEraCache(cacheKey, withActive, mapSlashes(era, n, v)))
const value = mapSlashes(era, noms, vals);
!withActive && deriveCache.set(cacheKey, value);
return value;
})
); );
}); });
} }
export function eraSlashes (instanceId: string, api: ApiInterfaceRx): (era: EraIndex) => Observable<DeriveEraSlashes> { export const eraSlashes = singleEra('_eraSlashes');
return memo(instanceId, (era: EraIndex): Observable<DeriveEraSlashes> => export const _erasSlashes = combineEras('_eraSlashes');
api.derive.staking._eraSlashes(era, true) export const erasSlashes = erasHistoricApply('_erasSlashes');
);
}
export function _erasSlashes (instanceId: string, api: ApiInterfaceRx): (eras: EraIndex[], withActive: boolean) => Observable<DeriveEraSlashes[]> {
return memo(instanceId, (eras: EraIndex[], withActive: boolean): Observable<DeriveEraSlashes[]> =>
eras.length
? combineLatest(
eras.map((era) => api.derive.staking._eraSlashes(era, withActive))
)
: of([])
);
}
export function erasSlashes (instanceId: string, api: ApiInterfaceRx): (withActive?: boolean) => Observable<DeriveEraSlashes[]> {
return memo(instanceId, (withActive = false): Observable<DeriveEraSlashes[]> =>
api.derive.staking.erasHistoric(withActive).pipe(
switchMap((eras) => api.derive.staking._erasSlashes(eras, withActive))
)
);
}
+5 -8
View File
@@ -11,7 +11,7 @@ import type { DeriveStakingKeys } from './types';
import { combineLatest, map, of, switchMap } from 'rxjs'; import { combineLatest, map, of, switchMap } from 'rxjs';
import { memo } from '../util'; import { firstMemo, memo } from '../util';
function extractsIds (stashId: Uint8Array | string, queuedKeys: [AccountId, NodeRuntimeSessionKeys | AccountId[]][], nextKeys: Option<NodeRuntimeSessionKeys>): DeriveStakingKeys { function extractsIds (stashId: Uint8Array | string, queuedKeys: [AccountId, NodeRuntimeSessionKeys | AccountId[]][], nextKeys: Option<NodeRuntimeSessionKeys>): DeriveStakingKeys {
const sessionIds = (queuedKeys.find(([currentId]) => currentId.eq(stashId)) || [undefined, [] as AccountId[]])[1]; const sessionIds = (queuedKeys.find(([currentId]) => currentId.eq(stashId)) || [undefined, [] as AccountId[]])[1];
@@ -27,13 +27,10 @@ function extractsIds (stashId: Uint8Array | string, queuedKeys: [AccountId, Node
}; };
} }
export function keys (instanceId: string, api: ApiInterfaceRx): (stashId: Uint8Array | string) => Observable<DeriveStakingKeys> { export const keys = firstMemo(
return memo(instanceId, (stashId: Uint8Array | string): Observable<DeriveStakingKeys> => (api: ApiInterfaceRx, stashId: Uint8Array | string) =>
api.derive.staking.keysMulti([stashId]).pipe( api.derive.staking.keysMulti([stashId])
map(([first]) => first) );
)
);
}
export function keysMulti (instanceId: string, api: ApiInterfaceRx): (stashIds: (Uint8Array | string)[]) => Observable<DeriveStakingKeys[]> { export function keysMulti (instanceId: string, api: ApiInterfaceRx): (stashIds: (Uint8Array | string)[]) => Observable<DeriveStakingKeys[]> {
return memo(instanceId, (stashIds: (Uint8Array | string)[]): Observable<DeriveStakingKeys[]> => return memo(instanceId, (stashIds: (Uint8Array | string)[]): Observable<DeriveStakingKeys[]> =>
+10 -20
View File
@@ -7,17 +7,18 @@ import type { EraIndex } from '@polkadot/types/interfaces';
import type { PalletStakingExposure } from '@polkadot/types/lookup'; import type { PalletStakingExposure } from '@polkadot/types/lookup';
import type { DeriveOwnExposure } from '../types'; import type { DeriveOwnExposure } from '../types';
import { map, of, switchMap } from 'rxjs'; import { map, of } from 'rxjs';
import { memo } from '../util'; import { firstMemo, memo } from '../util';
import { erasHistoricApplyAccount } from './util';
export function _ownExposures (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, eras: EraIndex[], withActive: boolean) => Observable<DeriveOwnExposure[]> { export function _ownExposures (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, eras: EraIndex[], withActive: boolean) => Observable<DeriveOwnExposure[]> {
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
return memo(instanceId, (accountId: Uint8Array | string, eras: EraIndex[], _withActive: boolean): Observable<DeriveOwnExposure[]> => return memo(instanceId, (accountId: Uint8Array | string, eras: EraIndex[], _withActive: boolean): Observable<DeriveOwnExposure[]> =>
eras.length eras.length
? api.queryMulti<PalletStakingExposure[]>([ ? api.queryMulti<PalletStakingExposure[]>([
...eras.map((era): QueryableStorageMultiArg<'rxjs'> => [api.query.staking.erasStakersClipped, [era, accountId]]), ...eras.map((e): QueryableStorageMultiArg<'rxjs'> => [api.query.staking.erasStakersClipped, [e, accountId]]),
...eras.map((era): QueryableStorageMultiArg<'rxjs'> => [api.query.staking.erasStakers, [era, accountId]]) ...eras.map((e): QueryableStorageMultiArg<'rxjs'> => [api.query.staking.erasStakers, [e, accountId]])
]).pipe( ]).pipe(
map((all): DeriveOwnExposure[] => map((all): DeriveOwnExposure[] =>
eras.map((era, index) => ({ clipped: all[index], era, exposure: all[eras.length + index] })) eras.map((era, index) => ({ clipped: all[index], era, exposure: all[eras.length + index] }))
@@ -27,20 +28,9 @@ export function _ownExposures (instanceId: string, api: ApiInterfaceRx): (accoun
); );
} }
export function ownExposure (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, era: EraIndex) => Observable<DeriveOwnExposure> { export const ownExposure = firstMemo(
return memo(instanceId, (accountId: Uint8Array | string, era: EraIndex): Observable<DeriveOwnExposure> => (api: ApiInterfaceRx, accountId: Uint8Array | string, era: EraIndex) =>
api.derive.staking._ownExposures(accountId, [era], true).pipe( api.derive.staking._ownExposures(accountId, [era], true)
map(([first]) => first) );
)
);
}
export function ownExposures (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, withActive?: boolean) => Observable<DeriveOwnExposure[]> { export const ownExposures = erasHistoricApplyAccount('_ownExposures');
return memo(instanceId, (accountId: Uint8Array | string, withActive = false): Observable<DeriveOwnExposure[]> => {
return api.derive.staking.erasHistoric(withActive).pipe(
switchMap((eras) =>
api.derive.staking._ownExposures(accountId, eras, withActive)
)
);
});
}
+10 -20
View File
@@ -8,17 +8,18 @@ import type { BalanceOf, EraIndex, Perbill } from '@polkadot/types/interfaces';
import type { ITuple } from '@polkadot/types/types'; import type { ITuple } from '@polkadot/types/types';
import type { DeriveStakerSlashes } from '../types'; import type { DeriveStakerSlashes } from '../types';
import { map, of, switchMap } from 'rxjs'; import { map, of } from 'rxjs';
import { memo } from '../util'; import { firstMemo, memo } from '../util';
import { erasHistoricApplyAccount } from './util';
export function _ownSlashes (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, eras: EraIndex[], withActive: boolean) => Observable<DeriveStakerSlashes[]> { export function _ownSlashes (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, eras: EraIndex[], withActive: boolean) => Observable<DeriveStakerSlashes[]> {
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
return memo(instanceId, (accountId: Uint8Array | string, eras: EraIndex[], _withActive: boolean): Observable<DeriveStakerSlashes[]> => return memo(instanceId, (accountId: Uint8Array | string, eras: EraIndex[], _withActive: boolean): Observable<DeriveStakerSlashes[]> =>
eras.length eras.length
? api.queryMulti<(Option<ITuple<[Perbill, BalanceOf]>> | Option<BalanceOf>)[]>([ ? api.queryMulti<(Option<ITuple<[Perbill, BalanceOf]>> | Option<BalanceOf>)[]>([
...eras.map((era): QueryableStorageMultiArg<'rxjs'> => [api.query.staking.validatorSlashInEra, [era, accountId]]), ...eras.map((e): QueryableStorageMultiArg<'rxjs'> => [api.query.staking.validatorSlashInEra, [e, accountId]]),
...eras.map((era): QueryableStorageMultiArg<'rxjs'> => [api.query.staking.nominatorSlashInEra, [era, accountId]]) ...eras.map((e): QueryableStorageMultiArg<'rxjs'> => [api.query.staking.nominatorSlashInEra, [e, accountId]])
]).pipe( ]).pipe(
map((values): DeriveStakerSlashes[] => map((values): DeriveStakerSlashes[] =>
eras.map((era, index) => ({ eras.map((era, index) => ({
@@ -33,20 +34,9 @@ export function _ownSlashes (instanceId: string, api: ApiInterfaceRx): (accountI
); );
} }
export function ownSlash (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, era: EraIndex) => Observable<DeriveStakerSlashes> { export const ownSlash = firstMemo(
return memo(instanceId, (accountId: Uint8Array | string, era: EraIndex): Observable<DeriveStakerSlashes> => (api: ApiInterfaceRx, accountId: Uint8Array | string, era: EraIndex) =>
api.derive.staking._ownSlashes(accountId, [era], true).pipe( api.derive.staking._ownSlashes(accountId, [era], true)
map(([first]) => first) );
)
);
}
export function ownSlashes (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, withActive?: boolean) => Observable<DeriveStakerSlashes[]> { export const ownSlashes = erasHistoricApplyAccount('_ownSlashes');
return memo(instanceId, (accountId: Uint8Array | string, withActive = false): Observable<DeriveStakerSlashes[]> => {
return api.derive.staking.erasHistoric(withActive).pipe(
switchMap((eras) =>
api.derive.staking._ownSlashes(accountId, eras, withActive)
)
);
});
}
+7 -10
View File
@@ -10,7 +10,7 @@ import type { DeriveStakingQuery, StakingQueryFlags } from '../types';
import { combineLatest, map, of, switchMap } from 'rxjs'; import { combineLatest, map, of, switchMap } from 'rxjs';
import { memo } from '../util'; import { firstMemo, memo } from '../util';
function parseDetails (stashId: AccountId, controllerIdOpt: Option<AccountId> | null, nominatorsOpt: Option<PalletStakingNominations>, rewardDestination: PalletStakingRewardDestination, validatorPrefs: PalletStakingValidatorPrefs, exposure: PalletStakingExposure, stakingLedgerOpt: Option<PalletStakingStakingLedger>): DeriveStakingQuery { function parseDetails (stashId: AccountId, controllerIdOpt: Option<AccountId> | null, nominatorsOpt: Option<PalletStakingNominations>, rewardDestination: PalletStakingRewardDestination, validatorPrefs: PalletStakingValidatorPrefs, exposure: PalletStakingExposure, stakingLedgerOpt: Option<PalletStakingStakingLedger>): DeriveStakingQuery {
return { return {
@@ -29,8 +29,8 @@ function parseDetails (stashId: AccountId, controllerIdOpt: Option<AccountId> |
function getLedgers (api: ApiInterfaceRx, optIds: (Option<AccountId> | null)[], { withLedger = false }: StakingQueryFlags): Observable<Option<PalletStakingStakingLedger>[]> { function getLedgers (api: ApiInterfaceRx, optIds: (Option<AccountId> | null)[], { withLedger = false }: StakingQueryFlags): Observable<Option<PalletStakingStakingLedger>[]> {
const ids = optIds const ids = optIds
.filter((opt): opt is Option<AccountId> => withLedger && !!opt && opt.isSome) .filter((o): o is Option<AccountId> => withLedger && !!o && o.isSome)
.map((opt) => opt.unwrap()); .map((o) => o.unwrap());
const emptyLed = api.registry.createType<Option<PalletStakingStakingLedger>>('Option<StakingLedger>'); const emptyLed = api.registry.createType<Option<PalletStakingStakingLedger>>('Option<StakingLedger>');
return ( return (
@@ -93,13 +93,10 @@ function getBatch (api: ApiInterfaceRx, activeEra: EraIndex, stashIds: AccountId
/** /**
* @description From a stash, retrieve the controllerId and all relevant details * @description From a stash, retrieve the controllerId and all relevant details
*/ */
export function query (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, flags: StakingQueryFlags) => Observable<DeriveStakingQuery> { export const query = firstMemo(
return memo(instanceId, (accountId: Uint8Array | string, flags: StakingQueryFlags): Observable<DeriveStakingQuery> => (api: ApiInterfaceRx, accountId: Uint8Array | string, flags: StakingQueryFlags) =>
api.derive.staking.queryMulti([accountId], flags).pipe( api.derive.staking.queryMulti([accountId], flags)
map(([first]) => first) );
)
);
}
export function queryMulti (instanceId: string, api: ApiInterfaceRx): (accountIds: (Uint8Array | string)[], flags: StakingQueryFlags) => Observable<DeriveStakingQuery[]> { export function queryMulti (instanceId: string, api: ApiInterfaceRx): (accountIds: (Uint8Array | string)[], flags: StakingQueryFlags) => Observable<DeriveStakingQuery[]> {
return memo(instanceId, (accountIds: (Uint8Array | string)[], flags: StakingQueryFlags): Observable<DeriveStakingQuery[]> => return memo(instanceId, (accountIds: (Uint8Array | string)[], flags: StakingQueryFlags): Observable<DeriveStakingQuery[]> =>
@@ -8,10 +8,10 @@ import type { DeriveEraValidatorExposure, DeriveStakerExposure } from '../types'
import { map, switchMap } from 'rxjs'; import { map, switchMap } from 'rxjs';
import { memo } from '../util'; import { firstMemo, memo } from '../util';
export function _stakerExposures (instanceId: string, api: ApiInterfaceRx): (accountIds: (Uint8Array | string)[], eras: EraIndex[], withActive: boolean) => Observable<DeriveStakerExposure[][]> { export function _stakerExposures (instanceId: string, api: ApiInterfaceRx): (accountIds: (Uint8Array | string)[], eras: EraIndex[], withActive?: boolean) => Observable<DeriveStakerExposure[][]> {
return memo(instanceId, (accountIds: (Uint8Array | string)[], eras: EraIndex[], withActive: boolean): Observable<DeriveStakerExposure[][]> => { return memo(instanceId, (accountIds: (Uint8Array | string)[], eras: EraIndex[], withActive = false): Observable<DeriveStakerExposure[][]> => {
const stakerIds = accountIds.map((a) => api.registry.createType('AccountId', a).toString()); const stakerIds = accountIds.map((a) => api.registry.createType('AccountId', a).toString());
return api.derive.staking._erasExposure(eras, withActive).pipe( return api.derive.staking._erasExposure(eras, withActive).pipe(
@@ -46,10 +46,7 @@ export function stakerExposures (instanceId: string, api: ApiInterfaceRx): (acco
); );
} }
export function stakerExposure (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, withActive?: boolean) => Observable<DeriveStakerExposure[]> { export const stakerExposure = firstMemo(
return memo(instanceId, (accountId: Uint8Array | string, withActive = false): Observable<DeriveStakerExposure[]> => (api: ApiInterfaceRx, accountId: Uint8Array | string, withActive?: boolean) =>
api.derive.staking.stakerExposures([accountId], withActive).pipe( api.derive.staking.stakerExposures([accountId], withActive)
map(([first]) => first) );
)
);
}
@@ -6,9 +6,10 @@ import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { EraIndex } from '@polkadot/types/interfaces'; import type { EraIndex } from '@polkadot/types/interfaces';
import type { DeriveStakerPoints } from '../types'; import type { DeriveStakerPoints } from '../types';
import { map, switchMap } from 'rxjs'; import { map } from 'rxjs';
import { memo } from '../util'; import { memo } from '../util';
import { erasHistoricApplyAccount } from './util';
export function _stakerPoints (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, eras: EraIndex[], withActive: boolean) => Observable<DeriveStakerPoints[]> { export function _stakerPoints (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, eras: EraIndex[], withActive: boolean) => Observable<DeriveStakerPoints[]> {
return memo(instanceId, (accountId: Uint8Array | string, eras: EraIndex[], withActive: boolean): Observable<DeriveStakerPoints[]> => { return memo(instanceId, (accountId: Uint8Array | string, eras: EraIndex[], withActive: boolean): Observable<DeriveStakerPoints[]> => {
@@ -26,10 +27,4 @@ export function _stakerPoints (instanceId: string, api: ApiInterfaceRx): (accoun
}); });
} }
export function stakerPoints (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, withActive?: boolean) => Observable<DeriveStakerPoints[]> { export const stakerPoints = erasHistoricApplyAccount('_stakerPoints');
return memo(instanceId, (accountId: Uint8Array | string, withActive = false): Observable<DeriveStakerPoints[]> =>
api.derive.staking.erasHistoric(withActive).pipe(
switchMap((eras) => api.derive.staking._stakerPoints(accountId, eras, withActive))
)
);
}
@@ -6,14 +6,15 @@ import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { EraIndex } from '@polkadot/types/interfaces'; import type { EraIndex } from '@polkadot/types/interfaces';
import type { DeriveStakerPrefs } from '../types'; import type { DeriveStakerPrefs } from '../types';
import { map, switchMap } from 'rxjs'; import { map } from 'rxjs';
import { memo } from '../util'; import { memo } from '../util';
import { erasHistoricApplyAccount } from './util';
export function _stakerPrefs (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, eras: EraIndex[], withActive: boolean) => Observable<DeriveStakerPrefs[]> { export function _stakerPrefs (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, eras: EraIndex[], withActive: boolean) => Observable<DeriveStakerPrefs[]> {
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
return memo(instanceId, (accountId: Uint8Array | string, eras: EraIndex[], _withActive: boolean): Observable<DeriveStakerPrefs[]> => return memo(instanceId, (accountId: Uint8Array | string, eras: EraIndex[], _withActive: boolean): Observable<DeriveStakerPrefs[]> =>
api.query.staking.erasValidatorPrefs.multi(eras.map((era) => [era, accountId])).pipe( api.query.staking.erasValidatorPrefs.multi(eras.map((e) => [e, accountId])).pipe(
map((all): DeriveStakerPrefs[] => map((all): DeriveStakerPrefs[] =>
all.map((validatorPrefs, index): DeriveStakerPrefs => ({ all.map((validatorPrefs, index): DeriveStakerPrefs => ({
era: eras[index], era: eras[index],
@@ -24,10 +25,4 @@ export function _stakerPrefs (instanceId: string, api: ApiInterfaceRx): (account
); );
} }
export function stakerPrefs (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, withActive?: boolean) => Observable<DeriveStakerPrefs[]> { export const stakerPrefs = erasHistoricApplyAccount('_stakerPrefs');
return memo(instanceId, (accountId: Uint8Array | string, withActive = false): Observable<DeriveStakerPrefs[]> =>
api.derive.staking.erasHistoric(withActive).pipe(
switchMap((eras) => api.derive.staking._stakerPrefs(accountId, eras, withActive))
)
);
}
@@ -13,7 +13,7 @@ import { combineLatest, map, of, switchMap } from 'rxjs';
import { BN_BILLION, BN_ZERO } from '@polkadot/util'; import { BN_BILLION, BN_ZERO } from '@polkadot/util';
import { memo } from '../util'; import { firstMemo, memo } from '../util';
type ErasResult = [DeriveEraPoints[], DeriveEraPrefs[], DeriveEraRewards[]]; type ErasResult = [DeriveEraPoints[], DeriveEraPrefs[], DeriveEraRewards[]];
@@ -98,7 +98,7 @@ function removeClaimed (validators: string[], queryValidators: DeriveStakingQuer
if (index !== -1) { if (index !== -1) {
const valLedger = queryValidators[index].stakingLedger; const valLedger = queryValidators[index].stakingLedger;
if (valLedger?.claimedRewards.some((era) => reward.era.eq(era))) { if (valLedger?.claimedRewards.some((e) => reward.era.eq(e))) {
rm.push(validatorId); rm.push(validatorId);
} }
} }
@@ -110,14 +110,14 @@ function removeClaimed (validators: string[], queryValidators: DeriveStakingQuer
} }
function filterRewards (eras: EraIndex[], valInfo: [string, DeriveStakingQuery][], { rewards, stakingLedger }: { rewards: DeriveStakerReward[]; stakingLedger: PalletStakingStakingLedger }): DeriveStakerReward[] { function filterRewards (eras: EraIndex[], valInfo: [string, DeriveStakingQuery][], { rewards, stakingLedger }: { rewards: DeriveStakerReward[]; stakingLedger: PalletStakingStakingLedger }): DeriveStakerReward[] {
const filter = eras.filter((era) => !stakingLedger.claimedRewards.some((e) => e.eq(era))); const filter = eras.filter((e) => !stakingLedger.claimedRewards.some((s) => s.eq(e)));
const validators = valInfo.map(([v]) => v); const validators = valInfo.map(([v]) => v);
const queryValidators = valInfo.map(([, q]) => q); const queryValidators = valInfo.map(([, q]) => q);
return rewards return rewards
.filter(({ isEmpty }) => !isEmpty) .filter(({ isEmpty }) => !isEmpty)
.filter((reward): boolean => { .filter((reward): boolean => {
if (!filter.some((filter) => reward.era.eq(filter))) { if (!filter.some((e) => reward.era.eq(e))) {
return false; return false;
} }
@@ -132,8 +132,8 @@ function filterRewards (eras: EraIndex[], valInfo: [string, DeriveStakingQuery][
})); }));
} }
export function _stakerRewardsEras (instanceId: string, api: ApiInterfaceRx): (eras: EraIndex[], withActive: boolean) => Observable<ErasResult> { export function _stakerRewardsEras (instanceId: string, api: ApiInterfaceRx): (eras: EraIndex[], withActive?: boolean) => Observable<ErasResult> {
return memo(instanceId, (eras: EraIndex[], withActive: boolean): Observable<ErasResult> => return memo(instanceId, (eras: EraIndex[], withActive = false): Observable<ErasResult> =>
combineLatest([ combineLatest([
api.derive.staking._erasPoints(eras, withActive), api.derive.staking._erasPoints(eras, withActive),
api.derive.staking._erasPrefs(eras, withActive), api.derive.staking._erasPrefs(eras, withActive),
@@ -142,8 +142,8 @@ export function _stakerRewardsEras (instanceId: string, api: ApiInterfaceRx): (e
); );
} }
export function _stakerRewards (instanceId: string, api: ApiInterfaceRx): (accountIds: (Uint8Array | string)[], eras: EraIndex[], withActive: boolean) => Observable<DeriveStakerReward[][]> { export function _stakerRewards (instanceId: string, api: ApiInterfaceRx): (accountIds: (Uint8Array | string)[], eras: EraIndex[], withActive?: boolean) => Observable<DeriveStakerReward[][]> {
return memo(instanceId, (accountIds: (Uint8Array | string)[], eras: EraIndex[], withActive: boolean): Observable<DeriveStakerReward[][]> => return memo(instanceId, (accountIds: (Uint8Array | string)[], eras: EraIndex[], withActive = false): Observable<DeriveStakerReward[][]> =>
combineLatest([ combineLatest([
api.derive.staking.queryMulti(accountIds, { withLedger: true }), api.derive.staking.queryMulti(accountIds, { withLedger: true }),
api.derive.staking._stakerExposures(accountIds, eras, withActive), api.derive.staking._stakerExposures(accountIds, eras, withActive),
@@ -184,14 +184,12 @@ export function _stakerRewards (instanceId: string, api: ApiInterfaceRx): (accou
); );
} }
export function stakerRewards (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, withActive?: boolean) => Observable<DeriveStakerReward[]> { export const stakerRewards = firstMemo(
return memo(instanceId, (accountId: Uint8Array | string, withActive = false): Observable<DeriveStakerReward[]> => (api: ApiInterfaceRx, accountId: Uint8Array | string, withActive?: boolean) =>
api.derive.staking.erasHistoric(withActive).pipe( api.derive.staking.erasHistoric(withActive).pipe(
switchMap((eras) => api.derive.staking._stakerRewards([accountId], eras, withActive)), switchMap((eras) => api.derive.staking._stakerRewards([accountId], eras, withActive))
map(([first]) => first)
) )
); );
}
export function stakerRewardsMultiEras (instanceId: string, api: ApiInterfaceRx): (accountIds: (Uint8Array | string)[], eras: EraIndex[]) => Observable<DeriveStakerReward[][]> { export function stakerRewardsMultiEras (instanceId: string, api: ApiInterfaceRx): (accountIds: (Uint8Array | string)[], eras: EraIndex[]) => Observable<DeriveStakerReward[][]> {
return memo(instanceId, (accountIds: (Uint8Array | string)[], eras: EraIndex[]): Observable<DeriveStakerReward[][]> => return memo(instanceId, (accountIds: (Uint8Array | string)[], eras: EraIndex[]): Observable<DeriveStakerReward[][]> =>
@@ -6,9 +6,10 @@ import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { EraIndex } from '@polkadot/types/interfaces'; import type { EraIndex } from '@polkadot/types/interfaces';
import type { DeriveStakerSlashes } from '../types'; import type { DeriveStakerSlashes } from '../types';
import { map, switchMap } from 'rxjs'; import { map } from 'rxjs';
import { memo } from '../util'; import { memo } from '../util';
import { erasHistoricApplyAccount } from './util';
export function _stakerSlashes (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, eras: EraIndex[], withActive: boolean) => Observable<DeriveStakerSlashes[]> { export function _stakerSlashes (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, eras: EraIndex[], withActive: boolean) => Observable<DeriveStakerSlashes[]> {
return memo(instanceId, (accountId: Uint8Array | string, eras: EraIndex[], withActive: boolean): Observable<DeriveStakerSlashes[]> => { return memo(instanceId, (accountId: Uint8Array | string, eras: EraIndex[], withActive: boolean): Observable<DeriveStakerSlashes[]> => {
@@ -25,10 +26,4 @@ export function _stakerSlashes (instanceId: string, api: ApiInterfaceRx): (accou
}); });
} }
export function stakerSlashes (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, withActive?: boolean) => Observable<DeriveStakerSlashes[]> { export const stakerSlashes = erasHistoricApplyAccount('_stakerSlashes');
return memo(instanceId, (accountId: Uint8Array | string, withActive = false): Observable<DeriveStakerSlashes[]> =>
api.derive.staking.erasHistoric(withActive).pipe(
switchMap((eras) => api.derive.staking._stakerSlashes(accountId, eras, withActive))
)
);
}
+53 -1
View File
@@ -1,8 +1,60 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors // Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx, ObsInnerType } from '@polkadot/api/types';
import type { EraIndex } from '@polkadot/types/interfaces'; import type { EraIndex } from '@polkadot/types/interfaces';
import type { ExactDerive } from '../bundle';
import { combineLatest, of, switchMap } from 'rxjs';
import { memo } from '../util';
type ApplyReturn<T extends keyof ExactDerive['staking']> = ReturnType<ExactDerive['staking'][T]>;
export function filterEras <T extends { era: EraIndex }> (eras: EraIndex[], list: T[]): EraIndex[] { export function filterEras <T extends { era: EraIndex }> (eras: EraIndex[], list: T[]): EraIndex[] {
return eras.filter((era) => !list.some((entry) => era.eq(entry.era))); return eras.filter((e) => !list.some(({ era }) => e.eq(era)));
}
export function erasHistoricApply <F extends '_erasExposure' | '_erasPoints' | '_erasPrefs' | '_erasRewards' | '_erasSlashes'> (fn: F): (instanceId: string, api: ApiInterfaceRx) => (withActive?: boolean) => ApplyReturn<F> {
return (instanceId: string, api: ApiInterfaceRx) =>
// Cannot quite get the typing right, but it is right in the code
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
memo(instanceId, (withActive = false) =>
api.derive.staking.erasHistoric(withActive).pipe(
switchMap((e) => api.derive.staking[fn](e, withActive))
)
) as any;
}
export function erasHistoricApplyAccount <F extends '_ownExposures' | '_ownSlashes' | '_stakerPoints' | '_stakerPrefs' | '_stakerSlashes'> (fn: F): (instanceId: string, api: ApiInterfaceRx) => (accountId: string | Uint8Array, withActive?: boolean) => ApplyReturn<F> {
return (instanceId: string, api: ApiInterfaceRx) =>
// Cannot quite get the typing right, but it is right in the code
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
memo(instanceId, (accountId: string | Uint8Array, withActive = false) =>
api.derive.staking.erasHistoric(withActive).pipe(
switchMap((e) => api.derive.staking[fn](accountId, e, withActive))
)
) as any;
}
export function singleEra <F extends '_eraExposure' | '_eraPrefs' | '_eraSlashes'> (fn: F): (instanceId: string, api: ApiInterfaceRx) => (era: EraIndex) => ApplyReturn<F> {
return (instanceId: string, api: ApiInterfaceRx) =>
// Cannot quite get the typing right, but it is right in the code
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
memo(instanceId, (era: EraIndex) =>
api.derive.staking[fn](era, true)
) as any;
}
export function combineEras <F extends '_eraExposure' | '_eraPrefs' | '_eraSlashes'> (fn: F): (instanceId: string, api: ApiInterfaceRx) => (eras: EraIndex[], withActive: boolean) => Observable<ObsInnerType<ApplyReturn<F>>[]> {
return (instanceId: string, api: ApiInterfaceRx) =>
// Cannot quite get the typing right, but it is right in the code
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
memo(instanceId, (eras: EraIndex[], withActive: boolean) =>
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
eras.length
? combineLatest(eras.map((e) => api.derive.staking[fn](e, withActive)))
: of([])
) as any;
} }
@@ -1,6 +1,14 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors // Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
export * from './members'; import { hasProposals as collectiveHasProposals, members as collectiveMembers, prime as collectivePrime, proposal as collectiveProposal, proposalCount as collectiveProposalCount, proposalHashes as collectiveProposalHashes, proposals as collectiveProposals } from '../collective';
export * from './prime';
export * from './proposals'; export const members = collectiveMembers('technicalCommittee');
export const hasProposals = collectiveHasProposals('technicalCommittee');
export const proposal = collectiveProposal('technicalCommittee');
export const proposalCount = collectiveProposalCount('technicalCommittee');
export const proposalHashes = collectiveProposalHashes('technicalCommittee');
export const proposals = collectiveProposals('technicalCommittee');
export const prime = collectivePrime('technicalCommittee');
@@ -1,13 +0,0 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { AccountId } from '@polkadot/types/interfaces';
import { members as collectiveMembers } from '../collective';
import { memo } from '../util';
export function members (instanceId: string, api: ApiInterfaceRx): () => Observable<AccountId[]> {
return memo(instanceId, collectiveMembers(instanceId, api, 'technicalCommittee'));
}
@@ -1,13 +0,0 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { AccountId } from '@polkadot/types/interfaces';
import { prime as collectivePrime } from '../collective';
import { memo } from '../util';
export function prime (instanceId: string, api: ApiInterfaceRx): () => Observable<AccountId | null> {
return memo(instanceId, collectivePrime(instanceId, api, 'technicalCommittee'));
}
@@ -1,31 +0,0 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { u32 } from '@polkadot/types';
import type { Hash } from '@polkadot/types/interfaces';
import type { DeriveCollectiveProposal } from '../types';
import { hasProposals as collectiveHasProposals, proposal as collectiveProposal, proposalCount as collectiveProposalCount, proposalHashes as collectiveProposalHashes, proposals as collectiveProposals } from '../collective';
import { memo } from '../util';
export function hasProposals (instanceId: string, api: ApiInterfaceRx): () => Observable<boolean> {
return memo(instanceId, collectiveHasProposals(instanceId, api, 'technicalCommittee'));
}
export function proposal (instanceId: string, api: ApiInterfaceRx): (hash: Hash | Uint8Array | string) => Observable<DeriveCollectiveProposal | null> {
return memo(instanceId, collectiveProposal(instanceId, api, 'technicalCommittee'));
}
export function proposalCount (instanceId: string, api: ApiInterfaceRx): () => Observable<u32 | null> {
return memo(instanceId, collectiveProposalCount(instanceId, api, 'technicalCommittee'));
}
export function proposalHashes (instanceId: string, api: ApiInterfaceRx): () => Observable<Hash[]> {
return memo(instanceId, collectiveProposalHashes(instanceId, api, 'technicalCommittee'));
}
export function proposals (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveCollectiveProposal[]> {
return memo(instanceId, collectiveProposals(instanceId, api, 'technicalCommittee'));
}

Some files were not shown because too many files have changed in this diff Show More