Skip to content

Commit

Permalink
WIP before migrating to async api client
Browse files Browse the repository at this point in the history
  • Loading branch information
brenzi committed Mar 2, 2024
1 parent 6d09425 commit 8413e95
Show file tree
Hide file tree
Showing 8 changed files with 217 additions and 364 deletions.
299 changes: 47 additions & 252 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pallet-encointer-scheduler = { default-features = false, version = "7.0.0" }
# substrate deps
frame-benchmarking = { default-features = false, version = "30.0.0" }
frame-benchmarking-cli = { version = "34.0.0" }
frame-executive = { version = "30.0.0" }
frame-executive = { version = "30.0.0", default-features = false }
frame-support = { default-features = false, version = "30.0.0" }
frame-system = { default-features = false, version = "30.0.0" }
frame-system-benchmarking = { version = "30.0.0", default-features = false }
Expand Down Expand Up @@ -95,7 +95,7 @@ sp-consensus = { version = "0.34.0" }
sp-consensus-aura = { version = "0.34.0", default-features = false }
sp-consensus-grandpa = { version = "15.0.0" }
sp-core = { default-features = false, version = "30.0.0" }
sp-inherents = "28.0.0"
sp-inherents = { default-features = false, version = "28.0.0" }
sp-io = { default-features = false, version = "32.0.0" }
sp-keyring = "33.0.0"
sp-keystore = "0.36.0"
Expand All @@ -114,7 +114,7 @@ substrate-frame-rpc-system = { version = "30.0.0" }
substrate-wasm-builder = "19.0.0"
substrate-build-script-utils = "11.0.0"

substrate-api-client = { version = "0.17.0", features = ["ws-client"] }
substrate-api-client = { version = "0.17.0", features = ["jsonrpsee-client"] }
substrate-client-keystore = "0.10.0"


Expand Down
1 change: 1 addition & 0 deletions client/encointer-api-client-extension/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ log = { workspace = true }
parity-scale-codec = { workspace = true }
serde = { workspace = true, features = ["std"] }
serde_json = { workspace = true }
tokio = { workspace = true }

# encointer deps
encointer-ceremonies-assignment = { workspace = true, features = ["std"] }
Expand Down
3 changes: 2 additions & 1 deletion client/encointer-api-client-extension/src/ceremonies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ pub trait CeremoniesApi {

impl CeremoniesApi for Api {
fn get_assignments(&self, community_ceremony: &CommunityCeremony) -> Result<Assignment> {
tokio::try!(
self.get_storage_map(ENCOINTER_CEREMONIES, "Assignments", community_ceremony, None)?
.ok_or_else(|| ApiClientError::Other("Assignments don't exist".into()))
.ok_or_else(|| ApiClientError::Other("Assignments don't exist".into())))
}

fn get_assignment_counts(
Expand Down
8 changes: 4 additions & 4 deletions client/encointer-api-client-extension/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
use extrinsic_params::CommunityCurrencyTipExtrinsicParams;
use substrate_api_client::{
ac_primitives::{Config, ExtrinsicSigner, SubstrateKitchensinkConfig, WithExtrinsicParams},
ac_primitives::{Config, DefaultRuntimeConfig, ExtrinsicSigner, WithExtrinsicParams},
rpc::JsonrpseeClient,
};

pub use encointer_node_notee_runtime::Runtime;
pub use substrate_api_client::{api::error::Error as ApiClientError, Result};

pub type EncointerConfig = WithExtrinsicParams<
SubstrateKitchensinkConfig,
CommunityCurrencyTipExtrinsicParams<SubstrateKitchensinkConfig>,
DefaultRuntimeConfig,
CommunityCurrencyTipExtrinsicParams<DefaultRuntimeConfig>,
>;

pub type Api = substrate_api_client::Api<EncointerConfig, JsonrpseeClient>;

pub type ParentchainExtrinsicSigner = ExtrinsicSigner<SubstrateKitchensinkConfig>;
pub type ParentchainExtrinsicSigner = ExtrinsicSigner<DefaultRuntimeConfig>;
pub type ExtrinsicAddress = <EncointerConfig as Config>::Address;

pub use ceremonies::*;
Expand Down
71 changes: 34 additions & 37 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#[cfg(feature = "std")]
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));

use frame_support::{
traits::{tokens::ConversionToAssetBalance, ConstU128, EqualPrivilegeOnly, InstanceFilter},
RuntimeDebug,
use frame_support::derive_impl;
use frame_support::traits::{
tokens::ConversionToAssetBalance, ConstU128, EqualPrivilegeOnly, InstanceFilter,
};
use pallet_grandpa::{
fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList,
Expand All @@ -22,7 +22,7 @@ use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, IdentifyAccount, NumberFor, Verify},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, MultiSignature,
ApplyExtrinsicResult, MultiSignature, RuntimeDebug,
};
use sp_std::prelude::*;
#[cfg(feature = "std")]
Expand Down Expand Up @@ -67,8 +67,10 @@ pub use encointer_primitives::{
communities::{CommunityIdentifier, Location},
scheduler::CeremonyPhaseType,
};
use frame_support::traits::tokens::{ConversionFromAssetBalance, PayFromAccount};
use frame_support::traits::ConstBool;
use frame_system::{EnsureRoot, EnsureSigned};
use sp_runtime::traits::IdentityLookup;

mod weights;

Expand Down Expand Up @@ -206,9 +208,9 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
ProxyType::NonTransfer => matches!(c, RuntimeCall::EncointerBazaar(..)),
ProxyType::BazaarEdit => matches!(
c,
RuntimeCall::EncointerBazaar(EncointerBazaarCall::create_offering { .. }) |
RuntimeCall::EncointerBazaar(EncointerBazaarCall::update_offering { .. }) |
RuntimeCall::EncointerBazaar(EncointerBazaarCall::delete_offering { .. })
RuntimeCall::EncointerBazaar(EncointerBazaarCall::create_offering { .. })
| RuntimeCall::EncointerBazaar(EncointerBazaarCall::update_offering { .. })
| RuntimeCall::EncointerBazaar(EncointerBazaarCall::delete_offering { .. })
),
}
}
Expand Down Expand Up @@ -254,7 +256,7 @@ parameter_types! {
}

// Configure FRAME pallets to include in runtime.

#[derive_impl(frame_system::config_preludes::SolochainDefaultConfig as frame_system::DefaultConfig)]
impl frame_system::Config for Runtime {
/// The basic call filter to use in dispatchable.
type BaseCallFilter = frame_support::traits::Everything;
Expand All @@ -266,42 +268,20 @@ impl frame_system::Config for Runtime {
type BlockLength = BlockLength;
/// The identifier used to distinguish between accounts.
type AccountId = AccountId;
/// The aggregated dispatch type that is available for extrinsics.
type RuntimeCall = RuntimeCall;
/// The lookup mechanism to get account ID from whatever is passed in dispatchers.
type Lookup = AccountIdLookup<AccountId, ()>;
/// The index type for storing how many extrinsics an account has signed.
type Nonce = Index;
/// The type for hashing blocks and tries.
type Hash = Hash;
/// The hashing algorithm used.
type Hashing = BlakeTwo256;
/// The ubiquitous event type.
type RuntimeEvent = RuntimeEvent;
/// The ubiquitous origin type.
type RuntimeOrigin = RuntimeOrigin;
/// Maximum number of block number to block hash mappings to keep (oldest pruned first).
type BlockHashCount = BlockHashCount;
/// The weight of database operations that the runtime can invoke.
type DbWeight = RocksDbWeight;
/// Version of the runtime.
type Version = Version;
/// Converts a module to the index of the module in `construct_runtime!`.
///
/// This type is being generated by `construct_runtime!`.
type PalletInfo = PalletInfo;
/// What to do if a new account is created.
type OnNewAccount = ();
/// What to do if an account is fully reaped from the system.
type OnKilledAccount = ();
/// The data to be stored in an account.
type AccountData = pallet_balances::AccountData<Balance>;
/// Weight information for the extrinsics of this pallet.
type SystemWeightInfo = frame_system::weights::SubstrateWeight<Runtime>;
/// This is used as an identifier of the chain. 42 is the generic substrate prefix.
type SS58Prefix = SS58Prefix;
/// The set code logic, just the default since we're not a parachain.
type OnSetCode = ();
type MaxConsumers = frame_support::traits::ConstU32<16>;
}

Expand All @@ -323,13 +303,11 @@ impl pallet_aura::Config for Runtime {

impl pallet_grandpa::Config for Runtime {
type RuntimeEvent = RuntimeEvent;

type KeyOwnerProof = <() as KeyOwnerProofSystem<(KeyTypeId, GrandpaId)>>::Proof;

type EquivocationReportSystem = ();

type WeightInfo = (); // grandpa has default non-zero implementations for `()`
type MaxAuthorities = MaxAuthorities;
type MaxNominators = ConstU32<0>;
type MaxSetIdSessionEntries = MaxSetIdSessionEntries;
}

Expand Down Expand Up @@ -365,8 +343,8 @@ impl pallet_balances::Config for Runtime {
type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>;
type RuntimeHoldReason = ();
type FreezeIdentifier = ();
type MaxHolds = ConstU32<0>;
type MaxFreezes = ConstU32<0>;
type RuntimeFreezeReason = ();
}

parameter_types! {
Expand Down Expand Up @@ -487,9 +465,21 @@ parameter_types! {
pub const ProposalBondMinimum: Balance = 100 * MILLICENTS;
pub const ProposalBondMaximum: Balance = 500 * CENTS;
pub const SpendPeriod: BlockNumber = 6 * DAYS;
pub const PayoutSpendPeriod: BlockNumber = 6 * DAYS;
pub const Burn: Permill = Permill::from_percent(1);
pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry");
pub const MaxApprovals: u32 = 10;
pub TreasuryAccount: AccountId = Treasury::account_id();
}

pub struct NoConversion;
impl ConversionFromAssetBalance<u128, (), u128> for NoConversion {
type Error = ();
fn from_asset_balance(balance: Balance, _asset_id: ()) -> Result<Balance, Self::Error> {
return Ok(balance);
}
#[cfg(feature = "runtime-benchmarks")]
fn ensure_successful(_: ()) {}
}

impl pallet_treasury::Config for Runtime {
Expand All @@ -509,6 +499,14 @@ impl pallet_treasury::Config for Runtime {
type MaxApprovals = MaxApprovals;
type WeightInfo = weights::pallet_treasury::WeightInfo<Runtime>;
type SpendOrigin = frame_support::traits::NeverEnsureOrigin<Balance>; //No spend, no bounty
type AssetKind = ();
type Beneficiary = AccountId;
type BeneficiaryLookup = IdentityLookup<Self::Beneficiary>;
type Paymaster = PayFromAccount<Balances, TreasuryAccount>;
type BalanceConverter = NoConversion;
type PayoutPeriod = PayoutSpendPeriod;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
}

impl pallet_encointer_reputation_commitments::Config for Runtime {
Expand All @@ -526,15 +524,14 @@ impl pallet_encointer_faucet::Config for Runtime {

parameter_types! {
pub const ConfirmationPeriod:BlockNumber = 20;
pub const ProposalLifetime: BlockNumber = 40;
pub const ProposalLifetime: Moment = 20 * 60 * 1000; // [ms]
}

impl pallet_encointer_democracy::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type MaxReputationVecLength = ConstU32<1024>;
type MaxReputationVecLength = ConstU32<64>;
type ConfirmationPeriod = ConfirmationPeriod;
type ProposalLifetime = ProposalLifetime;
type ProposalLifetimeCycles = ConstU32<1>;
type MinTurnout = ConstU128<1>;
type WeightInfo = weights::pallet_encointer_democracy::WeightInfo<Runtime>;
}
Expand Down
Loading

0 comments on commit 8413e95

Please sign in to comment.