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

Oracle pallet cleanup. #92

Merged
merged 1 commit into from
Jan 16, 2023
Merged
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
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ members = [
"gn-frontend",
"gn-node",
"gn-oracle",
"gn-pallets/pallet-chainlink",
"gn-pallets/pallet-oracle",
"gn-pallets/pallet-guild",
"gn-pallets/pallet-test-caller",
"gn-runtime",
Expand All @@ -19,7 +19,7 @@ default-members = [
"gn-common",
"gn-node",
"gn-oracle",
"gn-pallets/pallet-chainlink",
"gn-pallets/pallet-oracle",
"gn-pallets/pallet-guild",
"gn-pallets/pallet-test-caller",
"gn-runtime",
Expand Down
Binary file modified gn-client/artifacts/metadata.scale
Binary file not shown.
2 changes: 1 addition & 1 deletion gn-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub type BlockNumber = u32;
pub type BlockSubscription = Subscription<BlockHeader>;
pub type GuildCall = runtime::runtime_types::pallet_guild::pallet::Call;
pub type Index = u32;
pub type OracleRequest = runtime::runtime_types::pallet_chainlink::pallet::GenericRequest<
pub type OracleRequest = runtime::runtime_types::pallet_oracle::pallet::GenericRequest<
AccountId,
GuildCall,
u32,
Expand Down
6 changes: 3 additions & 3 deletions gn-client/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct GuildFilter {
}

pub async fn registered_operators(api: Api) -> Result<Vec<AccountId>, SubxtError> {
let operators = runtime::storage().chainlink().operators();
let operators = runtime::storage().oracle().operators();
Ok(api
.storage()
.fetch(&operators, None)
Expand Down Expand Up @@ -136,7 +136,7 @@ pub async fn role_id(
}

pub async fn oracle_request(api: Api, id: RequestIdentifier) -> Result<Request, SubxtError> {
let key = runtime::storage().chainlink().requests(id);
let key = runtime::storage().oracle().requests(id);
let request = api
.storage()
.fetch(&key, None)
Expand All @@ -152,7 +152,7 @@ pub async fn oracle_requests(
api: Api,
page_size: u32,
) -> Result<BTreeMap<RequestIdentifier, AccountId>, SubxtError> {
let root = runtime::storage().chainlink().requests_root();
let root = runtime::storage().oracle().requests_root();

let mut map = BTreeMap::new();
let mut iter = api.storage().iter(root, page_size, None).await?;
Expand Down
4 changes: 2 additions & 2 deletions gn-client/src/transactions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ pub fn fund_account(account: &AccountId, amount: u128) -> impl TxPayload {
}

pub fn register_operator() -> impl TxPayload {
runtime::tx().chainlink().register_operator()
runtime::tx().oracle().register_operator()
}

pub fn oracle_callback(request_id: u64, data: Vec<u8>) -> impl TxPayload {
runtime::tx().chainlink().callback(request_id, data)
runtime::tx().oracle().callback(request_id, data)
}

pub fn create_guild(guild: Guild) -> Result<impl TxPayload, serde_cbor::Error> {
Expand Down
2 changes: 1 addition & 1 deletion gn-oracle/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use futures::StreamExt;
use gn_client::queries::{oracle_request, requirements, user_identity};
use gn_client::runtime::chainlink::events::OracleRequest;
use gn_client::runtime::oracle::events::OracleRequest;
use gn_client::transactions::{
oracle_callback, register_operator, send_tx_in_block, send_tx_ready,
};
Expand Down
24 changes: 0 additions & 24 deletions gn-pallets/pallet-chainlink/LICENSE

This file was deleted.

122 changes: 0 additions & 122 deletions gn-pallets/pallet-chainlink/README.md

This file was deleted.

4 changes: 2 additions & 2 deletions gn-pallets/pallet-guild/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ std = [
"frame-support/std",
"frame-system/std",
"gn-common/std",
"pallet-chainlink/std",
"pallet-oracle/std",
"scale-info/std",
"sp-std/std",
]
Expand All @@ -25,7 +25,7 @@ frame-benchmarking = { default-features = false, version = "4.0.0-dev", git = "h
frame-support = { default-features = false, version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.25" }
frame-system = { default-features = false, version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.25" }
hashbrown = "0.13.1"
pallet-chainlink = { version = "3.0.0-alpha", default-features = false, path = "../pallet-chainlink" }
pallet-oracle = { version = "0.0.1-alpha", default-features = false, path = "../pallet-oracle" }
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
sp-std = { default-features = false, version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.25" }

Expand Down
10 changes: 5 additions & 5 deletions gn-pallets/pallet-guild/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use frame_support::traits::Currency;
use frame_system::RawOrigin;
use gn_common::identities::IdentityWithAuth;
use gn_common::RequestData;
use pallet_chainlink::Pallet as Chainlink;
use pallet_oracle::Pallet as Oracle;
use sp_std::vec;

benchmarks! {
Expand All @@ -32,7 +32,7 @@ benchmarks! {
let operator: T::AccountId = whitelisted_caller();

T::Currency::make_free_balance_be(&caller, T::Currency::minimum_balance() + 2_000_000_000u32.into());
Chainlink::<T>::register_operator(RawOrigin::Signed(operator).into())?;
Oracle::<T>::register_operator(RawOrigin::Signed(operator).into())?;
}: _(
RawOrigin::Signed(caller),
RequestData::Register(vec![
Expand All @@ -45,7 +45,7 @@ benchmarks! {
])
)
verify {
assert!(Chainlink::<T>::request(0).is_some())
assert!(Oracle::<T>::request(0).is_some())
}

join_guild {
Expand All @@ -61,10 +61,10 @@ benchmarks! {
}

T::Currency::make_free_balance_be(&caller, T::Currency::minimum_balance() + 2_000_000_000u32.into());
Chainlink::<T>::register_operator(RawOrigin::Signed(operator).into())?;
Oracle::<T>::register_operator(RawOrigin::Signed(operator).into())?;
Guild::<T>::create_guild(RawOrigin::Signed(caller.clone()).into(), guild_name, guild_metadata, roles)?;
}: _(RawOrigin::Signed(caller), RequestData::Join { guild: guild_name, role: [10u8; 32] })
verify {
assert!(Chainlink::<T>::request(0).is_some());
assert!(Oracle::<T>::request(0).is_some());
}
}
24 changes: 11 additions & 13 deletions gn-pallets/pallet-guild/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ pub mod pallet {
use gn_common::identities::Platform;
use gn_common::utils::detect_duplicates;
use gn_common::{GuildName, Request, RequestData, RequestIdentifier, RoleName};
use pallet_chainlink::{CallbackWithParameter, Config as ChainlinkConfig};
use pallet_oracle::{CallbackWithParameter, Config as OracleConfig, OracleAnswer};
use sp_std::vec::Vec as SpVec;

type BalanceOf<T> = <<T as pallet_chainlink::Config>::Currency as Currency<
type BalanceOf<T> = <<T as OracleConfig>::Currency as Currency<
<T as frame_system::Config>::AccountId,
>>::Balance;

Expand Down Expand Up @@ -101,7 +101,7 @@ pub mod pallet {
StorageMap<_, Blake2_128Concat, T::AccountId, SpVec<Identity>, OptionQuery>;

#[pallet::config]
pub trait Config: ChainlinkConfig<Callback = Call<Self>> + frame_system::Config {
pub trait Config: OracleConfig<Callback = Call<Self>> + frame_system::Config {
type WeightInfo: WeightInfo;
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
type MyRandomness: Randomness<Self::Hash, Self::BlockNumber>;
Expand Down Expand Up @@ -192,12 +192,11 @@ pub mod pallet {

let request = Request::<T::AccountId> { requester, data };

let call: <T as ChainlinkConfig>::Callback = Call::callback {
let call: <T as OracleConfig>::Callback = Call::callback {
result: SpVec::new(),
};
// TODO set unique fee
let fee = BalanceOf::<T>::unique_saturated_from(100_000_000u32);
<pallet_chainlink::Pallet<T>>::initiate_request(origin, call, request.encode(), fee)?;
let fee = BalanceOf::<T>::unique_saturated_from(<T as OracleConfig>::MinimumFee::get());
<pallet_oracle::Pallet<T>>::initiate_request(origin, call, request.encode(), fee)?;

Ok(())
}
Expand Down Expand Up @@ -262,12 +261,11 @@ pub mod pallet {
// after all successful checks, we can create our request
let request = Request::<T::AccountId> { requester, data };

let call: <T as ChainlinkConfig>::Callback = Call::callback {
let call: <T as OracleConfig>::Callback = Call::callback {
result: SpVec::new(),
};
// TODO set unique fee
let fee = BalanceOf::<T>::unique_saturated_from(100_000_000u32);
<pallet_chainlink::Pallet<T>>::initiate_request(origin, call, request.encode(), fee)?;
let fee = BalanceOf::<T>::unique_saturated_from(<T as OracleConfig>::MinimumFee::get());
<pallet_oracle::Pallet<T>>::initiate_request(origin, call, request.encode(), fee)?;

Ok(())
}
Expand All @@ -280,8 +278,8 @@ pub mod pallet {

// cannot wrap codec::Error in this error type because
// it doesn't implement the required traits
let answer = pallet_chainlink::OracleAnswer::decode(&mut result.as_slice())
.map_err(|_| Error::<T>::CodecError)?;
let answer =
OracleAnswer::decode(&mut result.as_slice()).map_err(|_| Error::<T>::CodecError)?;

ensure!(answer.result.len() == 1, Error::<T>::InvalidOracleAnswer);

Expand Down
Loading