Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate pallet-example-offchain-worker & pallet-example-tasks to umbrella crate. #7004

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion substrate/frame/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ frame-system = { workspace = true }
# primitive types used for developing FRAME runtimes.
sp-version = { optional = true, workspace = true }
sp-api = { optional = true, workspace = true }
sp-application-crypto = { optional = true, workspace = true }
sp-block-builder = { optional = true, workspace = true }
sp-transaction-pool = { optional = true, workspace = true }
sp-offchain = { optional = true, workspace = true }
Expand All @@ -48,6 +49,7 @@ sp-genesis-builder = { optional = true, workspace = true }
sp-inherents = { optional = true, workspace = true }
sp-storage = { optional = true, workspace = true }
sp-keyring = { optional = true, workspace = true }
sp-keystore = { optional = true, workspace = true }

frame-executive = { optional = true, workspace = true }
frame-system-rpc-runtime-api = { optional = true, workspace = true }
Expand All @@ -67,17 +69,19 @@ pallet-examples = { workspace = true }

[features]
default = ["runtime", "std"]
experimental = ["frame-support/experimental"]
experimental = ["frame-support/experimental", "frame-system/experimental"]
runtime = [
"frame-executive",
"frame-system-rpc-runtime-api",
"sp-api",
"sp-application-crypto",
"sp-block-builder",
"sp-consensus-aura",
"sp-consensus-grandpa",
"sp-genesis-builder",
"sp-inherents",
"sp-keyring",
"sp-keystore",
"sp-offchain",
"sp-session",
"sp-storage",
Expand All @@ -96,6 +100,7 @@ std = [
"log/std",
"scale-info/std",
"sp-api?/std",
"sp-application-crypto?/std",
"sp-arithmetic/std",
"sp-block-builder?/std",
"sp-consensus-aura?/std",
Expand All @@ -105,6 +110,7 @@ std = [
"sp-inherents?/std",
"sp-io/std",
"sp-keyring?/std",
"sp-keystore?/std",
"sp-offchain?/std",
"sp-runtime/std",
"sp-session?/std",
Expand Down
18 changes: 3 additions & 15 deletions substrate/frame/examples/offchain-worker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,17 @@ codec = { workspace = true }
lite-json = { workspace = true }
log = { workspace = true }
scale-info = { features = ["derive"], workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
sp-core = { workspace = true }
sp-io = { workspace = true }
sp-keystore = { optional = true, workspace = true }
sp-runtime = { workspace = true }
frame = { workspace = true, features = ["experimental", "runtime"] }

[features]
default = ["std"]
std = [
"codec/std",
"frame-support/std",
"frame-system/std",
"frame/std",
"lite-json/std",
"log/std",
"scale-info/std",
"sp-core/std",
"sp-io/std",
"sp-keystore/std",
"sp-runtime/std",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"sp-runtime/try-runtime",
"frame/try-runtime",
]
40 changes: 23 additions & 17 deletions substrate/frame/examples/offchain-worker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ extern crate alloc;

use alloc::vec::Vec;
use codec::{Decode, Encode};
use frame::prelude::*;
/*
use frame_support::traits::Get;
use frame_system::{
self as system,
Expand All @@ -58,7 +60,9 @@ use frame_system::{
},
pallet_prelude::BlockNumberFor,
};
*/
use lite_json::json::JsonValue;
/*
use sp_core::crypto::KeyTypeId;
use sp_runtime::{
offchain::{
Expand All @@ -70,6 +74,7 @@ use sp_runtime::{
transaction_validity::{InvalidTransaction, TransactionValidity, ValidTransaction},
RuntimeDebug,
};
*/

#[cfg(test)]
mod tests;
Expand All @@ -87,40 +92,41 @@ pub const KEY_TYPE: KeyTypeId = KeyTypeId(*b"btc!");
/// We can use from supported crypto kinds (`sr25519`, `ed25519` and `ecdsa`) and augment
/// the types with this pallet-specific identifier.
pub mod crypto {
use super::KEY_TYPE;
use sp_core::sr25519::Signature as Sr25519Signature;
use super::*;
//use sp_core::sr25519::Signature as Sr25519Signature;
/*
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 {
impl AppCrypto<MultiSigner, MultiSignature> for TestAuthId {
type RuntimeAppPublic = Public;
type GenericSignature = sp_core::sr25519::Signature;
type GenericPublic = sp_core::sr25519::Public;
type GenericSignature = Sr25519Signature;
type GenericPublic = Sr25519Public;
}

// implemented for mock runtime in test
impl frame_system::offchain::AppCrypto<<Sr25519Signature as Verify>::Signer, Sr25519Signature>
impl AppCrypto<<Sr25519Signature as Verify>::Signer, Sr25519Signature>
for TestAuthId
{
type RuntimeAppPublic = Public;
type GenericSignature = sp_core::sr25519::Signature;
type GenericPublic = sp_core::sr25519::Public;
type GenericSignature = Sr25519Signature;
type GenericPublic = Sr25519Public;
}
}

pub use pallet::*;

#[frame_support::pallet]
#[frame::pallet]
pub mod pallet {
use super::*;
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
// use frame_support::pallet_prelude::*;
// use frame_system::pallet_prelude::*;

/// This pallet's configuration trait
#[pallet::config]
Expand Down Expand Up @@ -187,7 +193,7 @@ pub mod pallet {
// to the storage and other included pallets.
//
// We can easily import `frame_system` and retrieve a block hash of the parent block.
let parent_hash = <system::Pallet<T>>::block_hash(block_number - 1u32.into());
let parent_hash = <frame_system::Pallet<T>>::block_hash(block_number - 1u32.into());
log::debug!("Current block: {:?} (parent hash: {:?})", block_number, parent_hash);

// It's a good practice to keep `fn offchain_worker()` function minimal, and move most
Expand Down Expand Up @@ -271,7 +277,7 @@ pub mod pallet {
// Add the price to the on-chain list, but mark it as coming from an empty address.
Self::add_price(None, price);
// now increment the block number at which we expect next unsigned transaction.
let current_block = <system::Pallet<T>>::block_number();
let current_block = <frame_system::Pallet<T>>::block_number();
<NextUnsignedAt<T>>::put(current_block + T::UnsignedInterval::get());
Ok(().into())
}
Expand All @@ -288,7 +294,7 @@ pub mod pallet {
// Add the price to the on-chain list, but mark it as coming from an empty address.
Self::add_price(None, price_payload.price);
// now increment the block number at which we expect next unsigned transaction.
let current_block = <system::Pallet<T>>::block_number();
let current_block = <frame_system::Pallet<T>>::block_number();
<NextUnsignedAt<T>>::put(current_block + T::UnsignedInterval::get());
Ok(().into())
}
Expand Down Expand Up @@ -579,7 +585,7 @@ impl<T: Config> Pallet<T> {
// deadline to 2s to complete the external call.
// You can also wait indefinitely for the response, however you may still get a timeout
// coming from the host machine.
let deadline = sp_io::offchain::timestamp().add(Duration::from_millis(2_000));
let deadline = offchain::timestamp().add(Duration::from_millis(2_000));
// Initiate an external HTTP GET request.
// This is using high-level wrappers from `sp_runtime`, for the low-level calls that
// you can find in `sp_io`. The API is trying to be similar to `request`, but
Expand Down Expand Up @@ -685,7 +691,7 @@ impl<T: Config> Pallet<T> {
return InvalidTransaction::Stale.into()
}
// Let's make sure to reject transactions from the future.
let current_block = <system::Pallet<T>>::block_number();
let current_block = <frame_system::Pallet<T>>::block_number();
if &current_block < block_number {
return InvalidTransaction::Future.into()
}
Expand Down
Loading