From 732f0371c2d4da7b0ec326c681e0c1d360fc1bd8 Mon Sep 17 00:00:00 2001 From: Luke Schoen Date: Mon, 25 Oct 2021 23:49:43 +1100 Subject: [PATCH] Offchain-worker: Update example-offchain-worker with implementation for 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` is not satisfied --> /Users/me/my_repo/node/runtime/src/lib.rs:1172:5 | 1172 | type AuthorityId = AuthorityId; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AppCrypto` 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; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 --- frame/example-offchain-worker/src/lib.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/frame/example-offchain-worker/src/lib.rs b/frame/example-offchain-worker/src/lib.rs index 644e1ca299a3c..9b63ffa663ee2 100644 --- a/frame/example-offchain-worker/src/lib.rs +++ b/frame/example-offchain-worker/src/lib.rs @@ -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 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<::Signer, Sr25519Signature> for TestAuthId {