Commit Graph

34 Commits

Author SHA1 Message Date
Giles Cope 8fe5ebbc00 cargo fmt 2021-09-19 10:49:24 +01:00
Giles Cope 364ed8bed1 Updated to later version of substrate so that it compiles.
(Referencing substrate this way you only have to search and replace one string to upgrade)
2021-09-17 10:52:23 +01:00
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 51c48f223a Update license header, bye bye 2020 👋 (#231) 2021-02-11 17:17:24 +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
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
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
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
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
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 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 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 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 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
Andrew Jones f2c42f88cf Update to substrate alpha.7 release (#105)
* Update to substrate alpha.7

* Remove gas limit from contracts put code

* Rename SystemEvent::ReapedAccount to KilledAccount

* Log debug event received before attempting to decode

* Temporary registration of Balance type before #102 merged

* Show contract test errors, increase instantiate gas_limit
2020-05-06 09:15:14 +01:00
Andrew Jones 194c7bcf2f Add missing license headers and CI check (#98)
* Add missing license headers and add CI check

* Remove log line

* Remove stale todos
2020-04-30 22:26:22 +01:00
David Craven 6f27489378 Double map and plain storage support, introduce macros (#93)
* Support custom clients.

* Simplify trait bounds.

* Plain and double map storage support.

* Simplify more trait bounds.

* Add proc macro.

* Add Call, Event and Store traits.

* Update proc-macros.

* Add with_system for proc-macro.

* proc-macro: test: support signature and extra fields.

* proc-macro: test: support sharing state accross steps.

* proc-macro: test: fetch state sequentially.

* Elide lifetimes.

* Add test for plain storage.

* Run rustfmt.
2020-04-28 20:04:26 +01:00
Andrew Jones b7565ff435 Latest substrate updates (#70)
* Fix compilation errors with latest substrate

* System::Account replaces FreeBalance and Nonce

* System::Account replaces FreeBalance and Nonce

* Remove Balances FreeBalance, replaced with System Account

* Update system event, fix instantiate

* reorder deps
2020-02-20 13:09:11 +00:00
Andrew Jones 253a7d8b0b Convert to std futures (#58)
* WIP

* Begin converting rpc layer to use std futures and jsonrpsee

* Convert metadata to async/await

* Convert block_hash to async/await

* Convert more methods to async/await

* Remove sp_rpc

* Fix more compilation errors

* Remove connect

* Starting to convert subscription functions

* Use jsonrpsee branch from PR for public client types

* Implement subscribe events with jsonrpsee subscription

* Converting subscriptions and wait_for_block_events

* WIP converting lib methods to async

* Use shared client reference directly for rpc call

`rpc_api!` macro currently only supports RawClient (which cannot be shared).
Also supports named params only which is not currently compatible with substrate rpd which accepts only positional params.

* Use &self instead of &mut self for shared Client

* Convert submit_and_watch to async/await

* Convert more Client fns to async

* Pin some trait futures

* Add serde error

* Fix client creation

* Fix client request compiler errors

* Unify metadata errors

* Add WS handshake error variant

* Fix some more compiler errors

* Fix more compiler errors

* Convert submit_extrinsic to async

* Convert submit and submit_and_watch

* Add Send + Sync constraints

* Clone clients

* Fix EventArg conversion error

* Fix remaining warnings/errors

* Replace deny warnings with specific lints

* Infallable subscription loops

* Use jsonrpsee wss branch

* Fix example

* Start to fix up tests

* Make contracts tests compile

* Make some more tests pass

* Fix up remaining tests

* Fmt

* Use correct event storage key type

* Fix finding events

* Use master jsonrpsee
2020-01-20 12:00:08 +00:00
Andrew Jones f998444619 Remove unwrap and format code (#62)
* Remove unwrap from metadata fetch

* Format code
2020-01-09 17:26:50 +00:00
Andrew Jones b159d0dae1 Improve dynamic events type sizes API (#61)
* Do not error if type sizes missing: log warn

* Split out EventsSubscriber, allow updating events decoder

* Format code

* Check missing type sizes after registration

* Add example which for submit and watching events
2020-01-07 15:14:30 +00:00
Andrew Jones 6561535467 Remove pallet crates to improve compilation time (#55) 2019-12-17 11:41:40 +00:00
Andrew Jones daa1415297 Fix contracts instantiation (#51)
* Move contracts tests to contracts module

* Add test for instantiating a contract

* Fix InstantiateArgs encoding

* Ignore PhantomData primitives, they are 0

* Increase endowment and log code hash

* Update SystemEvent

* Fix codec import

* Oops

* Write buffer directly to output to avoid encoding vec

* Debug with StorageChanges encoded as hex

* Logging and format code
2019-12-17 09:39:56 +00:00
Andrew Jones f1926f55cf Update substrate and codec crate aliases (#54)
* Replace substrate crate aliases with actual crate names

* Alias parity-scale-codec to just codec, like in substrate

* Format code
2019-12-16 15:57:48 +00:00
Andrew Jones c2097aa2e3 Ignore PhantomData primitives, they are 0 (#53) 2019-12-13 17:20:41 +00:00
Yuanchao Sun 5108bce467 Fix the module index used to create a encoded func (#47)
* Fix the module index used to create a encoded func

Same as Events, modules with no calls should be ignored when calculating
the module index.

* Update substrate
2019-11-28 12:46:39 +00:00
Andrew Jones 02e4826662 Update SystemEvent with DispatchInfo (#45) 2019-11-26 12:49:29 +00:00
Qinxuan Chen 4769b4b016 Use thiserror instead of derive_more (#44)
- Use thiserror instead of derive_more
- Format code
- Fix clippy warnings
- Add LICENSE_TEMPLATE

Signed-off-by: koushiro <koushiro.cqx@gmail.com>
2019-11-26 12:09:17 +00:00
Andrew Jones 55e067a294 Rename palette -> frame (#41) 2019-11-22 18:35:36 +00:00
Andrew Jones 5242939f4d Rename paint -> palette with pallets (#38) 2019-11-21 10:08:54 +00:00
Andrew Jones 593646c2bc Update default runtime types to match substrate, format code (#34)
* Update default runtime types to match latest substrate

* Format code
2019-11-15 17:57:38 +00:00
Andrew Jones b39ff1771a New substrate signing API, srml -> paint rename (#33)
* Update jsonrpc to align with substrate

* Update to new substrate signing

* Default to MultiSignature

* Add missing event type sizes

* Rename TakeFees check to ChargeTransactionPayment

* Fix extrinsic Signature

* Ignore AuthorityList type size

* Rename srml to paint (#32)
2019-11-15 15:04:06 +00:00
Andrew Jones ee6db12917 Runtime agnostic Events (#20)
* Introduce OpaqueEvent

* Look up event by module and variant

* Index events by module

* Get events by module

* Dynamically decode events

* Decode System events and EventRecord topics

* Use type sizes to decode raw events

* Remove unused imports

* rustfmt

* Unify error types, fix some compiler errors

* Make dynamic event decoding work

- fix compilation errors
- skip modules with no events when indexing
- preallocate vec for raw event data

* Remove printlns, replace where required with log

* Remove unused import

* Check missing type sizes

* Ignore unknown event arg type sizes

* Decode concrete System events, assumes every Runtime has the module

* Reorganise usings

* pub use some types

* Code docs

* Export Error

* Error Display impls

* Format code
2019-09-26 17:48:25 +01:00