Skip to content

Commit c35567b

Browse files
authored
Move ChainWithBalances::NativeBalance -> Chain::Balance (paritytech#990)
* move ChainWithBalances::NativeBalance -> Chain::Balance * dummy commit * Revert "dummy commit" This reverts commit c006421.
1 parent 1bfece1 commit c35567b

File tree

12 files changed

+27
-28
lines changed

12 files changed

+27
-28
lines changed

relays/bin-substrate/src/cli/estimate_fee.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::cli::bridge::FullBridge;
1818
use crate::cli::{Balance, CliChain, HexBytes, HexLaneId, SourceConnectionParams};
1919
use crate::select_full_bridge;
2020
use codec::{Decode, Encode};
21-
use relay_substrate_client::{Chain, ChainWithBalances};
21+
use relay_substrate_client::Chain;
2222
use structopt::StructOpt;
2323

2424
/// Estimate Delivery & Dispatch Fee command.
@@ -52,7 +52,7 @@ impl EstimateFee {
5252
let lane = lane.into();
5353
let payload = Source::encode_message(payload).map_err(|e| anyhow::format_err!("{:?}", e))?;
5454

55-
let fee: <Source as ChainWithBalances>::NativeBalance =
55+
let fee: <Source as Chain>::Balance =
5656
estimate_message_delivery_and_dispatch_fee(&source_client, ESTIMATE_MESSAGE_FEE_METHOD, lane, payload)
5757
.await?;
5858

relays/bin-substrate/src/cli/send_message.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,12 @@ impl SendMessage {
130130
let fee = match self.fee {
131131
Some(fee) => fee,
132132
None => Balance(
133-
estimate_message_delivery_and_dispatch_fee::<
134-
<Source as relay_substrate_client::ChainWithBalances>::NativeBalance,
135-
_,
136-
_,
137-
>(&source_client, ESTIMATE_MESSAGE_FEE_METHOD, lane, payload.clone())
133+
estimate_message_delivery_and_dispatch_fee::<<Source as Chain>::Balance, _, _>(
134+
&source_client,
135+
ESTIMATE_MESSAGE_FEE_METHOD,
136+
lane,
137+
payload.clone(),
138+
)
138139
.await? as _,
139140
),
140141
};

relays/client-kusama/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ impl Chain for Kusama {
4141
type Index = bp_kusama::Nonce;
4242
type SignedBlock = bp_kusama::SignedBlock;
4343
type Call = ();
44+
type Balance = bp_kusama::Balance;
4445
}
4546

4647
/// Kusama header type used in headers sync.

relays/client-millau/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,10 @@ impl Chain for Millau {
4444
type Index = millau_runtime::Index;
4545
type SignedBlock = millau_runtime::SignedBlock;
4646
type Call = millau_runtime::Call;
47+
type Balance = millau_runtime::Balance;
4748
}
4849

4950
impl ChainWithBalances for Millau {
50-
type NativeBalance = millau_runtime::Balance;
51-
5251
fn account_info_storage_key(account_id: &Self::AccountId) -> StorageKey {
5352
use frame_support::storage::generator::StorageMap;
5453
StorageKey(frame_system::Account::<millau_runtime::Runtime>::storage_map_final_key(

relays/client-polkadot/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ impl Chain for Polkadot {
4141
type Index = bp_polkadot::Nonce;
4242
type SignedBlock = bp_polkadot::SignedBlock;
4343
type Call = ();
44+
type Balance = bp_polkadot::Balance;
4445
}
4546

4647
/// Polkadot header type used in headers sync.

relays/client-rialto/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,10 @@ impl Chain for Rialto {
4444
type Index = rialto_runtime::Index;
4545
type SignedBlock = rialto_runtime::SignedBlock;
4646
type Call = rialto_runtime::Call;
47+
type Balance = rialto_runtime::Balance;
4748
}
4849

4950
impl ChainWithBalances for Rialto {
50-
type NativeBalance = rialto_runtime::Balance;
51-
5251
fn account_info_storage_key(account_id: &Self::AccountId) -> StorageKey {
5352
use frame_support::storage::generator::StorageMap;
5453
StorageKey(frame_system::Account::<rialto_runtime::Runtime>::storage_map_final_key(

relays/client-rococo/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,10 @@ impl Chain for Rococo {
4747
type Index = bp_rococo::Index;
4848
type SignedBlock = bp_rococo::SignedBlock;
4949
type Call = bp_rococo::Call;
50+
type Balance = bp_rococo::Balance;
5051
}
5152

5253
impl ChainWithBalances for Rococo {
53-
type NativeBalance = bp_rococo::Balance;
54-
5554
fn account_info_storage_key(account_id: &Self::AccountId) -> StorageKey {
5655
StorageKey(bp_rococo::account_info_storage_key(account_id))
5756
}

relays/client-substrate/src/chain.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,16 @@ pub trait Chain: ChainBase + Clone {
5454
type SignedBlock: Member + Serialize + DeserializeOwned + BlockWithJustification<Self::Header>;
5555
/// The aggregated `Call` type.
5656
type Call: Dispatchable + Debug;
57+
/// Balance of an account in native tokens.
58+
///
59+
/// The chain may suport multiple tokens, but this particular type is for token that is used
60+
/// to pay for transaction dispatch, to reward different relayers (headers, messages), etc.
61+
type Balance: Parameter + Member + DeserializeOwned + Clone + Copy + CheckedSub + PartialOrd + Zero;
5762
}
5863

5964
/// Substrate-based chain with `frame_system::Config::AccountData` set to
60-
/// the `pallet_balances::AccountData<NativeBalance>`.
65+
/// the `pallet_balances::AccountData<Balance>`.
6166
pub trait ChainWithBalances: Chain {
62-
/// Balance of an account in native tokens.
63-
type NativeBalance: Parameter + Member + DeserializeOwned + Clone + Copy + CheckedSub + PartialOrd + Zero;
64-
6567
/// Return runtime storage key for getting `frame_system::AccountInfo` of given account.
6668
fn account_info_storage_key(account_id: &Self::AccountId) -> StorageKey;
6769
}

relays/client-substrate/src/client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ impl<C: Chain> Client<C> {
208208
}
209209

210210
/// Return native tokens balance of the account.
211-
pub async fn free_native_balance(&self, account: C::AccountId) -> Result<C::NativeBalance>
211+
pub async fn free_native_balance(&self, account: C::AccountId) -> Result<C::Balance>
212212
where
213213
C: ChainWithBalances,
214214
{
@@ -217,7 +217,7 @@ impl<C: Chain> Client<C> {
217217
.await?
218218
.ok_or(Error::AccountDoesNotExist)?;
219219
let decoded_account_data =
220-
AccountInfo::<C::Index, AccountData<C::NativeBalance>>::decode(&mut &encoded_account_data.0[..])
220+
AccountInfo::<C::Index, AccountData<C::Balance>>::decode(&mut &encoded_account_data.0[..])
221221
.map_err(Error::ResponseParseFailed)?;
222222
Ok(decoded_account_data.data.free)
223223
}

relays/client-substrate/src/guard.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub trait Environment<C: ChainWithBalances>: Send + Sync + 'static {
3333
/// Return current runtime version.
3434
async fn runtime_version(&mut self) -> Result<RuntimeVersion, String>;
3535
/// Return free native balance of the account on the chain.
36-
async fn free_native_balance(&mut self, account: C::AccountId) -> Result<C::NativeBalance, String>;
36+
async fn free_native_balance(&mut self, account: C::AccountId) -> Result<C::Balance, String>;
3737

3838
/// Return current time.
3939
fn now(&self) -> Instant {
@@ -85,7 +85,7 @@ pub fn abort_on_spec_version_change<C: ChainWithBalances>(mut env: impl Environm
8585
pub fn abort_when_account_balance_decreased<C: ChainWithBalances>(
8686
mut env: impl Environment<C>,
8787
account_id: C::AccountId,
88-
maximal_decrease: C::NativeBalance,
88+
maximal_decrease: C::Balance,
8989
) {
9090
const DAY: Duration = Duration::from_secs(60 * 60 * 24);
9191

@@ -155,7 +155,7 @@ impl<C: ChainWithBalances> Environment<C> for Client<C> {
155155
Client::<C>::runtime_version(self).await.map_err(|e| e.to_string())
156156
}
157157

158-
async fn free_native_balance(&mut self, account: C::AccountId) -> Result<C::NativeBalance, String> {
158+
async fn free_native_balance(&mut self, account: C::AccountId) -> Result<C::Balance, String> {
159159
Client::<C>::free_native_balance(self, account)
160160
.await
161161
.map_err(|e| e.to_string())
@@ -191,11 +191,10 @@ mod tests {
191191
type SignedBlock =
192192
sp_runtime::generic::SignedBlock<sp_runtime::generic::Block<Self::Header, sp_runtime::OpaqueExtrinsic>>;
193193
type Call = ();
194+
type Balance = u32;
194195
}
195196

196197
impl ChainWithBalances for TestChain {
197-
type NativeBalance = u32;
198-
199198
fn account_info_storage_key(_account_id: &u32) -> sp_core::storage::StorageKey {
200199
unreachable!()
201200
}

0 commit comments

Comments
 (0)