Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Offchain-worker: Update example-offchain-worker with implementation f…
Browse files Browse the repository at this point in the history
…or TestAuthId (#10096)

* Update example-offchain-worker to include missing implementation for TestAuthId

i tried to incorporate the off-chain worker callback demo as a custom pallet of my own Substrate-based blockchain implementation that's provided at the following links
* https://www.parity.io/blog/substrate-off-chain-workers-secure-and-efficient-computing-intensive-tasks/
* https://gnunicorn.github.io/substrate-offchain-cb/
but when i build the code with `cargo build --release`, it gave me an error:
```
error[E0277]: the trait bound `AuthorityId: AppCrypto<MultiSigner, MultiSignature>` is not satisfied
--> /Users/me/my_repo/node/runtime/src/lib.rs:1172:5
|
1172 |     type AuthorityId = AuthorityId;
|     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AppCrypto<MultiSigner, MultiSignature>` is not implemented for `AuthorityId`
|
note: required by a bound in `offchaincb::Config::AuthorityId`
--> /Users/me/my_repo/node/pallets/offchaincb/src/lib.rs:169:21
|
169  |         type AuthorityId: AppCrypto<Self::Public, Self::Signature>;
|                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `offchaincb::Config::AuthorityId`
```

where in my custom pallet i have:

pallets/offchaincb/src/lib.rs

```
...

use offchaincb::{
    crypto::{
        TestAuthId,
    },
};

...

parameter_types! {
	pub const GracePeriod: BlockNumber = 1 * MINUTES;
	pub const UnsignedInterval: BlockNumber = 1 * MINUTES;
        pub const UnsignedPriority: BlockNumber = 1 * MINUTES;
}

impl offchaincb::Config for Runtime {
    type AuthorityId = TestAuthId;
    type Call = Call;
    type Currency = Balances;
    type Event = Event;
    type GracePeriod = GracePeriod;
    type UnsignedInterval = UnsignedInterval;
    type UnsignedPriority = UnsignedPriority;
}

...
```

then i found another different off-chain workers Substrate Recipe demo from Jimmy Chu https://github.com/jimmychu0807/recipes/blob/master/pallets/ocw-demo/src/lib.rs#L73 which had an extra implementation for TestAuthId here https://github.com/jimmychu0807/recipes/blob/master/pallets/ocw-demo/src/lib.rs#L73, and when i added that it overcame the error.

so i think this change should be included in the Substrate repository

* Fix indentation

* Fix formatting

* Swap order
  • Loading branch information
ltfschoen authored Oct 25, 2021
1 parent 456509d commit 732f037
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions frame/example-offchain-worker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,19 @@ pub mod crypto {
use sp_runtime::{
app_crypto::{app_crypto, sr25519},
traits::Verify,
MultiSignature, MultiSigner,
};
app_crypto!(sr25519, KEY_TYPE);

pub struct TestAuthId;

impl frame_system::offchain::AppCrypto<MultiSigner, MultiSignature> for TestAuthId {
type RuntimeAppPublic = Public;
type GenericSignature = sp_core::sr25519::Signature;
type GenericPublic = sp_core::sr25519::Public;
}

// implemented for mock runtime in test
impl frame_system::offchain::AppCrypto<<Sr25519Signature as Verify>::Signer, Sr25519Signature>
for TestAuthId
{
Expand Down

0 comments on commit 732f037

Please sign in to comment.