Commit Graph

110 Commits

Author SHA1 Message Date
Andrew Jones de859e7396 Add hooks to register event types for decoding (#227)
* Global registration of type segmenters for event decoding

* Perform type sizes check when building client

* Introduce EventTypeRegistry for global runtime type sizes

* Fmt

* Register runtime type sizes on creation of EventTypeRegistry

* Register more default dispatch types

* Add missing type sizes

* fmt

* Fix up register_type_size builder method

* Update doc comments

* Make register_default_type_sizes public

* Don't allow duplicate registered types

* Remove call to supertraits type registration, done manually in Runtime

* Fix tests and warnings

* Fix duplicate type registration

* Fmt

* review: use is_empty()

Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>

* Add panic docs

Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
2021-02-18 10:28:40 +00:00
Andrew Jones 2c8e5211aa Substrate 3.0 (#232)
* Update substrate deps to 3.0.0 and 0.9.0

* Update substrate wasm tools

* Fixing errors for 3.0.0 compat

* Fixing more errors for 3.0.0 compat

* Use MultiAddress for test runtime

* Fmt

* Fix node test

* Pin Funty

* Update AccountInfo struct

* Add comment about funty pin
2021-02-17 16:45:05 +00:00
Andrew Jones 51c48f223a Update license header, bye bye 2020 👋 (#231) 2021-02-11 17:17:24 +00:00
h4x3rotab f3ece6d933 Fix the wrong rpc call in query_storage_at() (#223) 2021-01-27 08:57:47 +00:00
h4x3rotab 3c46002e67 Refactor event type decoding and declaration (#221)
* Refactor event type decoding hand declartion

Fixes #196, #181, #28

## Dyanmic sized types

Before this change, the event decoder assume all the event types
have fixed sizes. Some counterexamples are: Hashes, AuthorityList.

In this change, instead of decoding by skipping the fixed-length bytes,
we introduce `type_segmenter` registry which decodes the raw event
bytes with the actual scale codec. So variable length types can be
handled correctly.

## New attribute for pallet type definition

In the past, trait associated type is the only way to add types to
the EventsDecoder implementation of a pallet. But in reality it's
common that the events in a pallet references some types not defined
in the trait associated types. Some examples are: `IdentificationTuple`
and `SessionIndex` in Session pallet.

In this change, we introduce more attributes to add the types:

```rust
#[module]
trait Pallet: System {
    #![event_type(SomeType)]
    #![event_alias(TypeNameAlias = SomeType)]
    #![event_alias(SomeOtherAlias = TypeWithAssociatedTypes<T>)]
}
```

## Tested

Compile with `nightly-2020-10-01`; smoke test to sync a full
Phala bockchain.

* Format code

* Make rustfmt::skip an outer attribute

* Ignore the sample code

* Alias the event segmenter closure

* Copy AuthorityList from sp_finality_grandpa

* Remove the unused static event type size

* Make segmenter as a trait, resue grandpa::Public

* Wrap PhantomData in struct TypeMarker
2021-01-20 09:41:58 +00:00
Liu-Cheng Xu 5a0201c130 Add Balances Locks (#197)
* Add Balances Locks

* Pass fmt

* Add tests for Balances Locks

In order to write this test, I just added the new staking::BondCall :).

* .

* In case you want to run multiple tests at the same time

* Return Result in integration test
2021-01-15 09:34:35 +00:00
h4x3rotab 754b184363 Add event Phase::Initialization (#215) 2021-01-14 16:51:10 +00:00
Caio c2cc7afbc1 Make type explicit (#217) 2021-01-14 16:50:16 +00:00
Caio 5595b1e82f Export extra types (#212) 2021-01-05 17:26:13 +00:00
Zeke Mostov 0a926ef4c4 Enable retrieval of constants from rutnime metadata (#207) 2020-12-17 10:23:46 +00:00
Greg Hill 80aff7eb6e register type sizes for u64 and u128 (#200)
Signed-off-by: Gregory Hill <gregorydhill@outlook.com>
2020-12-09 15:09:29 +00:00
Andrew Jones 0b3c8d4523 Remove some substrate dependencies to improve compile time (#194)
* Copy ReadProof and TransactionStatus types

* Define local app crypto types

* Fmt

* Restore logging and add comments
2020-12-03 13:20:50 +00:00
Greg Hill 27c377a9d6 propagate 'RuntimeError's to 'decode_raw_bytes' caller (#189)
Signed-off-by: Gregory Hill <gregorydhill@outlook.com>
2020-11-13 17:16:14 +00:00
Qinxuan Chen 7655caac0f Derive Clone for PairSigner (#184)
* Derive `Clone` for `PairSigner`

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* Specify the date of nightly toolchain to fix CI

Signed-off-by: koushiro <koushiro.cqx@gmail.com>
2020-10-20 10:57:27 +01:00
Demi Marie Obenour cd7bb6041b Remove unnecessary Sync requirements (#172)
This is needed for Ledgeracio, as Ledgeracio’s signer is now no longer
`Send`.
2020-09-25 08:18:26 +01:00
Andrew Jones 385d214217 Call a contract (#165)
* Revert contracts put_code test to pure code (not using the macro)

* Test contract instantiate

* Fmt

* Extract put_code and new_client functions

* Generate fresh accounts for contract tests to allow reruns without a chain purge

* Fetch and increment nonce to allow concurrent test runs

* fmt

* Failing contract call test

* Fmt and fix compilation

* Fix error message for contract call

* Fix call test

* Update contract execution event comment

* Remove redundant feature flags, now on module

* Update event data comment

* Use fetch_add

* Fmt
2020-09-24 18:21:51 +02:00
David 8e2a4f06ee Upgrade to substrate 2.0.0 (#173)
* Upgrade to substrate 2.0.0

* WIP implement Subcommand manually (see https://github.com/paritytech/substrate/pull/6894#issuecomment-676060197)

* Add pallet-staking/std to the std feature

* Sort out the subcommand impl

* Sort out the module index (ty @ascjones)
Sort out the RefCount type (ty @dvc94ch)
Random tweaks to make test-node more similar to the vanilla node-template

* obey the fmt

* cleanup

* more cleanup
2020-09-24 12:57:35 +01:00
David 56bd633706 Address review grumbles from #99 (#171)
* Address review grumbles from #99

* obey the fmt
2020-09-22 16:29:29 +01:00
Demi Obenour f9f69b8c3b Staking support (#99)
* Initial Staking API

* Add more staking types

* Reformat

* Remove dead code

* Fix missing documentation

* Reformat

* Staking: use proc macros

* Add partial session support

* Reformat

* Try to implement nomination

This currently fails with compilation errors I do not understand.

* Use the #[module] macro

This fixes a compile error

* Explain undefined method diagnostics

* Use ‘#[module]’ and implement session for Kusama

* Don’t impl ‘Staking’ for all ‘T: System’

* Add staking payout support

* Fix compilation errors and remove useless lifetimes

* Respond to code review

This fixes most of the issues found during review, with the exception of
tests.

* Make signing fallable and asynchronous

This is needed for hardware wallets, which require human confirmation to
sign transactions.  Blocking on a human to sign transactions is not a
good idea, and the signing might fail for many reasons (device
unplugged, authorization not granted, etc).

* Reformat

* Refactor as suggested by Andrew Jones (@ascjones).

* Reformat

* Refactor as suggested by Andrew Jones (@ascjones).

* Trait cleanups

* Make the `Signer` impl require Send + Sync

This is what Ledgeracio needs.

* Use the correct key for staking maps

They use the key type, not ‘PhantomData’.

* Implement set_payee call

* Switch to associated types for Staking

* Implement `set_keys`

This is needed for Ledgeracio.

* Remove impl of Signer for Box<dyn Signer + Send + Sync>

It isn’t needed, since Box implements Deref.

* Fix Polkadot and Kusama ‘SessionKey’ structs

I had failed to include the ‘Parachains’ component, which the default
Substrate runtime doesn’t have.

* Include a copy of `ValidatorId`

This avoids needing to depend on Polkadot.

* Fix syntax error in Cargo.toml

* Fix compile errors

* Add Debug impls

* Fix return type of `BondedStore`

* Use some upstream type definitions

Also add `Default` impls.

* Bump deps and fix build

* Remove last reference to Kusama feature

* Fix compilation errors

* Implement the `concat` in `twox_64_concat`

* Expose properties and per-era preferences

* Era rewards point support

I also did some refactoring.

* Expose clipped exposure

* Era reward points support

* Make `PayoutStakersCall` public

* Add in all default features for debugging

* Chill support and update to latest Substrate

* If property fetch fails, use dummy values

* Fix tests

* Fix header

* Remove some code Ledgeracio does not need

* More deletions

* Remove more code not needed for Ledgeracio

* Remove a pointless change in Cargo.toml

w.r.t. upstream.

* Remove more junk

* Revert contracts put_code test to pure code (not using the macro)

* Test contract instantiate

* Fmt

* WIP

* Add some more submission tests

* Reformat

* More tests

* Cleanup

* Hopefully fix CI

* Remove dead code

* Test chill

* Add missing docs

* Remove unnecessary use

* Revert "Remove unnecessary use"

This reverts commit bc8bc36bde581f1892ea88a778dfe0fe5bff24d7.

* Retry on temporary failures

* Ignore the staking tests on CI

* Obey the fmt

* Run CI with at most one test thread

* Implement tests for staking

* More tests

* Remove unhelpful println!

* Revert changes in contract tests

* Reformat

* Remove spurious diff

* More tests

Co-authored-by: Demi M. Obenour <demiobenour@gmail.com>
Co-authored-by: David Palm <dvdplm@gmail.com>
Co-authored-by: Andrew Jones <ascjones@gmail.com>
2020-09-21 13:15:46 -04:00
Liu-Cheng Xu 0c7454dfcd Display RawEvent data in hex (#168)
So that printing the RawEvent won't comsume more than the whole screen.
2020-09-21 10:32:41 +01:00
Liu-Cheng Xu e843bd670f Add SudoUncheckedWeightCall (#167)
* Add SudoUncheckedWeightCall

* Add test_sudo_unchecked_weight()

* Fix CI

Use nightly fmt.

* .
2020-09-21 09:22:57 +01:00
Liu-Cheng Xu ce22986a75 Add SetCodeWithoutChecksCall (#166) 2020-09-17 15:20:48 +01:00
Andrew Jones 4ed8e37ffe Fix up contracts pallet tests (#163)
* Revert contracts put_code test to pure code (not using the macro)

* Test contract instantiate

* Fmt
2020-09-15 08:32:33 +01:00
Greg Hill 2829d7d7c1 fix option decoding and add basic sanity test (#161)
Signed-off-by: Gregory Hill <gregorydhill@outlook.com>
2020-09-15 08:24:05 +01:00
David Ackerman f2cf79847a Remove visibility limiter pub (crate) from Metadata (#162)
* Remove visibility limiter `pub (crate)`

* Run fmt

* Add comments
2020-09-14 15:51:42 +01:00
Greg Hill e85d01ed08 decode option event arg (#158)
Signed-off-by: Gregory Hill <gregorydhill@outlook.com>
2020-09-07 14:58:45 +01:00
David Craven e9c50e21d0 Only return an error if the extrinsic failed. (#156) 2020-09-01 11:15:04 +01:00
David Craven eac2ce3b2a Different assert. (#153) 2020-08-17 09:14:26 +01:00
Yuanchao Sun 59b9c117b7 Add a method to fetch an unhashed key, close #100 (#152)
* Add a method to fetch an unhashed key, close #100

* Return decoded value

* Refactoring
2020-08-13 21:06:30 +01:00
David Craven 9aa32ef63d Fix port number. (#151) 2020-08-13 16:04:30 +01:00
Demi Obenour 511e6f5a16 Implement the concat in twox_64_concat (#150)
Co-authored-by: Demi M. Obenour <demiobenour@gmail.com>
2020-08-10 11:05:17 +01:00
David Craven 271775bf99 Storage map iter (#148)
* Add example file

* Fmt

* Add KeyIter.

* Add iter method to store proc-macro.

* Fetch all values at once.

* Update docs.

* Run rustfmt.

Co-authored-by: Andrew Jones <ascjones@gmail.com>
2020-08-05 09:08:12 +01:00
Andrew Jones 663934ca37 Fetch paged storage keys 2020-08-03 12:40:37 +01:00
David Craven e6f3a82f99 Rc5 (#143)
* Update to rc6.

* Update runtime.

* Update node to rc6.

* Update client.

* Fix node.

* Add option to enable telemetry.
2020-07-27 08:53:02 +01:00
Andrew Jones cd6b8f43f1 Refactor: extract functions and types for creating extrinsics (#138)
* Extract extrinsic

* Extract extrinsic types to own module

* Fix compiler errors

* Fix warnings

* Fmt

* Pin wabt-sys to 0.7.1, it fails (on my machine) with 0.7.2

* Fix up tests

* Fmt

* Reexport RuntimeVersion
2020-07-20 09:17:19 +01:00
David 536c54c843 Document the #[module] macro (#135)
* Document the #[module] macro

* Obey the fmt

* Review feedback

* More docs

* Tweak wording

* tweak wording

* whitespace

* Tweak docstring
2020-07-07 08:19:44 +01:00
David Craven c6350fcc11 Support authors api. (#134) 2020-07-01 15:27:14 +01:00
Andrew Jones d3e9e3f757 Upgrade to substrate rc4 release (#131)
* Upgrade to substrate rc4 release

* Fix up test-node/service

* Fix up client node config

* Fix up remaining compilation errors

* Fmt

* Remove fixme

* Fix test

* Release v0.10.0
2020-06-29 09:32:07 +01:00
David Craven 4ee7fb11ad Support unsigned extrinsics. (#130) 2020-06-26 07:38:37 +01:00
David Craven 7f0847107c Events sub (#126)
* Make event subscription logic more generic.

* Fix build.

* Add test-node.

* Update deps.

* Address review comments.
2020-06-25 07:05:00 +01:00
David Craven 3080ec91a6 Improve error handling in proc-macros, handle DispatchError etc. (#123)
* Improve error handling.

* Fix build.

* Handle runtime errors.

* Add runtime trait for better type inference.

* Use runtime trait part 1.

* wip

* Add support for sudo.

* Finish error handling.

* Fix tests.

* Fix clippy warnings.
2020-06-22 07:39:40 +01:00
David Craven 21d07c6c24 Support embedded full/light node clients. (#91)
* Add support for light clients.

* Add wasm toolchain to ci.

* Fix ci tests.

* Address review comments.

* Use expect instead of unwrap.

* Purge light client chain too.

* Add README section.
2020-06-15 08:01:16 +01:00
David Craven 91203b91d3 Zero sized types (#121)
* Fix zero sized types.

* Cleanup.

* Expose genesis hash.

* Fix clippy warnings.

* Readd default type sizes for now.

* Cleanup ret type.
2020-06-08 12:25:51 +01:00
David Craven 26ada75dec Fix optional store items. (#120)
* Fix optional store items.

* Support querying a block hash.
2020-06-01 12:24:56 +01:00
Demi Obenour a2eead0c3d Make signing fallable and asynchronous (#119)
* Make signing fallable and asynchronous

This is needed for hardware wallets, which require human confirmation to
sign transactions.  Blocking on a human to sign transactions is not a
good idea, and the signing might fail for many reasons (device
unplugged, authorization not granted, etc).

* Reformat

* Refactor as suggested by Andrew Jones (@ascjones).

* Use future::ok

Co-authored-by: Andrew Jones <ascjones@gmail.com>
2020-05-29 08:49:27 +01:00
Andrew Jones 0d58f4b67c Update to Substrate release candidate (#116)
* Substrate rc1

* Add tx version extra

* Remove CheckBlockGasLimit

* Substrate rc2
2020-05-26 13:53:08 +01:00
David Craven 4dadb2c9b5 Update to alpha.8 (#114) 2020-05-26 10:55:54 +01:00
David Craven 67f3ce529e Refactors the api (#113)
* Refactor api.

* Try fix ci.

* Fix test.

* Address review comments.
2020-05-26 10:04:44 +01:00
David Craven f861f3fac4 Split subxt (#102)
* Proc macro improvements.

* Use proc-macros.

* Update examples.

* Fix build.

* Run rustfmt.

* Fix total issuance test.

* Remove gas limit from put code call.

* Handle runtime errors.

* Fix tests.

* Make test more reliable.

* Revert "Handle runtime errors."

This reverts commit 26f30a9f4cfcfddfb3e49308cded46cfe6468697.

* Use expect instead of unwrap.

* Parse marker type.

* Fetch doesn't fail.
2020-05-12 12:25:22 +01:00
Yuanchao Sun 825f3ab64c Add support for RPC state_getReadProof (#106)
* Add support for RPC `state_getReadProof`

* Format code

* Add test
2020-05-07 07:41:27 +01:00