diff --git a/node/src/service.rs b/node/src/service.rs index f90d4d47..d48ad959 100644 --- a/node/src/service.rs +++ b/node/src/service.rs @@ -100,6 +100,7 @@ pub fn new_partial( justification_import: Some(Box::new(grandpa_block_import.clone())), client: client.clone(), create_inherent_data_providers: move |_, ()| async move { + // XXX how can we pass a ?? let miner = pallet_cash::internal::miner::InherentDataProvider {}; let oracle = pallet_oracle::inherent::InherentDataProvider {}; let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); diff --git a/pallets/cash/src/internal/miner.rs b/pallets/cash/src/internal/miner.rs index ddef5ec2..cf1e803b 100644 --- a/pallets/cash/src/internal/miner.rs +++ b/pallets/cash/src/internal/miner.rs @@ -1,4 +1,4 @@ -use crate::{chains::ChainAccount, Call, Config, Miner, Module}; +use crate::{chains::ChainAccount, core, Call, Config, Miner, Module}; use codec::{Decode, Encode}; use frame_support::{inherent::ProvideInherent, storage::StorageValue}; use sp_inherents::{InherentData, InherentIdentifier, IsFatalError}; @@ -39,10 +39,13 @@ impl InherentError { /// Provide chosen miner address. #[cfg(feature = "std")] -pub struct InherentDataProvider; +// XXX how do we even get a T here? +pub struct InherentDataProvider { + sentinel: std::marker::PhantomData, +} #[cfg(feature = "std")] -impl std::ops::Deref for InherentDataProvider { +impl std::ops::Deref for InherentDataProvider { type Target = (); fn deref(&self) -> &Self::Target { @@ -52,24 +55,16 @@ impl std::ops::Deref for InherentDataProvider { #[cfg(feature = "std")] #[async_trait::async_trait] -impl sp_inherents::InherentDataProvider for InherentDataProvider { +impl sp_inherents::InherentDataProvider + for InherentDataProvider +{ fn provide_inherent_data( &self, inherent_data: &mut InherentData, ) -> Result<(), sp_inherents::Error> { - let miner_address_str = runtime_interfaces::validator_config_interface::get_miner_address() - .ok_or(sp_inherents::Error::Application(Box::from( - "no miner address", - )))?; - - let miner_address = our_std::str::from_utf8(&miner_address_str).map_err(|_| { - sp_inherents::Error::Application(Box::from("invalid miner address bytes")) - })?; - - let chain_account: ChainAccount = our_std::str::FromStr::from_str(miner_address) - .map_err(|_| sp_inherents::Error::Application(Box::from("invalid miner address")))?; - - inherent_data.put_data(INHERENT_IDENTIFIER, &chain_account) + let validator = core::get_current_validator::() + .map_err(|_| sp_inherents::Error::Application(Box::from("no miner address")))?; + inherent_data.put_data(INHERENT_IDENTIFIER, &validator.miner_address()) } async fn try_handle_error( diff --git a/pallets/cash/src/types.rs b/pallets/cash/src/types.rs index e857ef70..58c8678a 100644 --- a/pallets/cash/src/types.rs +++ b/pallets/cash/src/types.rs @@ -12,7 +12,7 @@ use types_derive::{type_alias, Types}; pub use pallet_oracle::{ticker::Ticker, types::Price}; pub use crate::{ - chains::{Chain, ChainAsset, ChainBlockNumber, ChainId, Ethereum}, + chains::{Chain, ChainAccount, ChainAsset, ChainBlockNumber, ChainId, Ethereum}, factor::{BigInt, BigUint, Factor}, notices::{Notice, NoticeId}, rates::{InterestRateModel, APR}, @@ -114,6 +114,12 @@ pub struct ValidatorKeys { pub eth_address: ::Address, } +impl ValidatorKeys { + pub fn miner_address(self) -> ChainAccount { + ChainAccount::Gate(self.substrate_id.into()) + } +} + /// Type for referring to either an asset or CASH. #[derive(Copy, Clone, Eq, PartialEq, Encode, Decode, RuntimeDebug, Types)] pub enum CashOrChainAsset {