Skip to content

Commit

Permalink
Fix money missing and renaming jackpot address (paritytech#640)
Browse files Browse the repository at this point in the history
* Fix money field missing

* Rename address to account in RPC

* Rename TeamAddress and CouncilAddress to TeamAccount and CouncilAccount

* Build wasm
  • Loading branch information
liuchengxu committed May 23, 2019
1 parent 3fdea15 commit d287736
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 44 deletions.
Binary file modified cli/src/chainx_runtime.compact.wasm
Binary file not shown.
6 changes: 3 additions & 3 deletions cli/src/genesis_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ fn load_sdot_info() -> Result<Vec<([u8; 20], u64)>, Box<dyn std::error::Error>>
pub struct RecordOfGenesisNode {
account_id: String,
session_key: String,
money: f64,
endowed: f64,
name: String,
url: String,
about: String,
Expand Down Expand Up @@ -339,7 +339,7 @@ fn load_genesis_node_info() -> Result<
let account_id = hex(&record.account_id).unchecked_into();
let authority_key = hex(&record.session_key).unchecked_into();

let money = (record.money * 10_u64.pow(PCX_PRECISION as u32) as f64) as u64;
let endowed = (record.endowed * 10_u64.pow(PCX_PRECISION as u32) as f64) as u64;
let node_name = record.name.into_bytes();
let node_url = record.url.into_bytes();
let memo = record.about.into_bytes();
Expand All @@ -355,7 +355,7 @@ fn load_genesis_node_info() -> Result<
res.push((
account_id,
authority_key,
money,
endowed,
node_name,
node_url,
memo,
Expand Down
49 changes: 23 additions & 26 deletions rpc/src/chainx/impl_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ use client::runtime_api::Metadata;
use primitives::crypto::UncheckedInto;
use primitives::{Blake2Hasher, H160, H256};
use runtime_primitives::generic::{BlockId, SignedBlock};
use runtime_primitives::traits::{Block as BlockT, NumberFor, Zero};
use runtime_primitives::traits::{Header, ProvideRuntimeApi};
use runtime_primitives::traits::{Block as BlockT, Header, NumberFor, ProvideRuntimeApi, Zero};
use support::storage::{StorageMap, StorageValue};
// chainx
use chainx_primitives::{AccountId, AccountIdForRpc, AuthorityId, Balance, BlockNumber};
Expand Down Expand Up @@ -259,10 +258,10 @@ where
return Ok(None);
};

let jackpot_addr = self.jackpot_accountid_for(self.best_number()?, who.clone())?;
let jackpot_account = self.jackpot_accountid_for(self.best_number()?, who.clone())?;
Ok(Some(json!({
"sessionKey": session_key,
"jackpotAddress": jackpot_addr,
"jackpotAccount": jackpot_account,
})))
}

Expand Down Expand Up @@ -303,10 +302,10 @@ where
};

let intentions = self.intention_set(best_number)?;
let jackpot_addr_list =
let jackpot_account_list =
self.multi_jackpot_accountid_for(best_number, intentions.clone())?;

for (intention, jackpot_addr) in intentions.into_iter().zip(jackpot_addr_list) {
for (intention, jackpot_account) in intentions.into_iter().zip(jackpot_account_list) {
let mut info = IntentionInfo::default();

let key = <xaccounts::IntentionNameOf<Runtime>>::key_for(&intention);
Expand All @@ -333,7 +332,7 @@ where
Hasher::BLAKE2256,
)? {
let key = (
jackpot_addr.clone(),
jackpot_account.clone(),
xassets::Module::<Runtime>::TOKEN.to_vec(),
);
let balances_key = <xassets::AssetBalance<Runtime>>::key_for(&key);
Expand All @@ -348,7 +347,7 @@ where
.map(|free| *free)
.unwrap_or_default();
info.jackpot = free;
info.jackpot_address = jackpot_addr.into();
info.jackpot_account = jackpot_account.into();
info.total_nomination = profs.total_nomination;
info.last_total_vote_weight = profs.last_total_vote_weight;
info.last_total_vote_weight_update = profs.last_total_vote_weight_update;
Expand Down Expand Up @@ -383,10 +382,10 @@ where
let best_number = self.best_number()?;
let key = <xtokens::PseduIntentions<Runtime>>::key();
if let Some(tokens) = Self::pickout::<Vec<Token>>(&state, &key, Hasher::TWOX128)? {
let jackpot_addr_list =
let jackpot_account_list =
self.multi_token_jackpot_accountid_for(best_number, tokens.clone())?;

for (token, jackpot_addr) in tokens.into_iter().zip(jackpot_addr_list) {
for (token, jackpot_account) in tokens.into_iter().zip(jackpot_account_list) {
let mut info = PseduIntentionInfo::default();

let key = <xtokens::PseduIntentionProfiles<Runtime>>::key_for(&token);
Expand All @@ -396,7 +395,7 @@ where
Hasher::BLAKE2256,
)? {
let key = (
jackpot_addr.clone(),
jackpot_account.clone(),
xassets::Module::<Runtime>::TOKEN.to_vec(),
);
let balances_key = <xassets::AssetBalance<Runtime>>::key_for(&key);
Expand All @@ -411,7 +410,7 @@ where
.map(|free| *free)
.unwrap_or_default();
info.jackpot = free;
info.jackpot_address = jackpot_addr.into();
info.jackpot_account = jackpot_account.into();
info.last_total_deposit_weight = vote_weight.last_total_deposit_weight;
info.last_total_deposit_weight_update =
vote_weight.last_total_deposit_weight_update;
Expand All @@ -432,8 +431,7 @@ where
info.price = price;
};

let b = self.best_number()?;
if let Ok(Some(power)) = self.asset_power(b, token.clone()) {
if let Ok(Some(power)) = self.asset_power(best_number, token.clone()) {
info.power = power;
};

Expand Down Expand Up @@ -766,9 +764,10 @@ where
} else {
return Err(ErrorKind::DecodeErr.into());
};
let b = self.best_number()?;

let transaction_fee = self.transaction_fee(b, call.encode(), tx_length)?;
let transaction_fee =
self.transaction_fee(self.best_number()?, call.encode(), tx_length)?;

Ok(transaction_fee)
}

Expand All @@ -791,8 +790,6 @@ where
}

fn mock_bitcoin_new_trustees(&self, candidates: Vec<AccountIdForRpc>) -> Result<Option<Value>> {
let b = self.best_number()?;

let candidates: Vec<AccountId> = candidates
.into_iter()
.map(|a| a.unchecked_into())
Expand All @@ -801,7 +798,7 @@ where
let runtime_result: result::Result<GenericAllSessionInfo<AccountId>, Vec<u8>> = self
.client
.runtime_api()
.mock_new_trustees(&b, Chain::Bitcoin, candidates)?;
.mock_new_trustees(&self.best_number()?, Chain::Bitcoin, candidates)?;

runtime_result
.map(|all_session_info| parse_trustee_session_info(Chain::Bitcoin, 0, all_session_info))
Expand All @@ -812,11 +809,11 @@ where
let state = self.best_state()?;

// team addr
let key = xaccounts::TeamAddress::<Runtime>::key();
let team_addr = Self::pickout::<AccountId>(&state, &key, Hasher::TWOX128)?;
let key = xaccounts::TeamAccount::<Runtime>::key();
let team_account = Self::pickout::<AccountId>(&state, &key, Hasher::TWOX128)?;

let key = xaccounts::CouncilAddress::<Runtime>::key();
let council_addr = Self::pickout::<AccountId>(&state, &key, Hasher::TWOX128)?;
let key = xaccounts::CouncilAccount::<Runtime>::key();
let council_account = Self::pickout::<AccountId>(&state, &key, Hasher::TWOX128)?;

let mut map = BTreeMap::new();
for chain in Chain::iterator() {
Expand All @@ -829,9 +826,9 @@ where

Ok(Some(json!(
{
"teamAddress": team_addr,
"councilAddress": council_addr,
"trusteesAddress": map
"teamAccount": team_account,
"councilAccount": council_account,
"trusteesAccount": map
}
)))
}
Expand Down
8 changes: 4 additions & 4 deletions rpc/src/chainx/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ pub struct IntentionInfo {
pub self_vote: Balance,
/// jackpot
pub jackpot: Balance,
/// jackpot address
pub jackpot_address: AccountIdForRpc,
/// jackpot account
pub jackpot_account: AccountIdForRpc,
/// total nomination from all nominators
pub total_nomination: Balance,
/// vote weight at last update
Expand Down Expand Up @@ -279,8 +279,8 @@ pub struct PseduIntentionInfo {
pub power: Balance,
/// jackpot
pub jackpot: Balance,
/// jackpot address
pub jackpot_address: AccountIdForRpc,
/// jackpot account
pub jackpot_account: AccountIdForRpc,
/// vote weight at last update
pub last_total_deposit_weight: u64,
/// last update time of vote weight
Expand Down
Binary file not shown.
4 changes: 2 additions & 2 deletions xrml/xaccounts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ decl_storage! {

pub IntentionPropertiesOf get(intention_props_of): map T::AccountId => IntentionProps<T::SessionKey, T::BlockNumber>;

pub TeamAddress get(team_address): T::AccountId;
pub CouncilAddress get(council_address): T::AccountId;
pub TeamAccount get(team_account): T::AccountId;
pub CouncilAccount get(council_account): T::AccountId;
}
}

Expand Down
2 changes: 1 addition & 1 deletion xrml/xfee/manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl<T: Trait> Module<T> {

Self::deposit_event(RawEvent::FeeForJackpot(jackpot_addr, for_jackpot));
} else {
let council = xaccounts::Module::<T>::council_address();
let council = xaccounts::Module::<T>::council_account();

warn!(
"[calc_fee]|current block not set producer!|council:{:},{:?}",
Expand Down
6 changes: 3 additions & 3 deletions xrml/xmining/staking/src/shifter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl<T: Trait> Module<T> {
my_reward: T::Balance,
validators: &mut Vec<T::AccountId>,
) {
let council = xaccounts::Module::<T>::council_address();
let council = xaccounts::Module::<T>::council_account();

// Slash 10 times per block reward for each missed block.
let missed = <MissedOfPerSession<T>>::take(who) as u64;
Expand Down Expand Up @@ -153,7 +153,7 @@ impl<T: Trait> Module<T> {
for who in inactive_slashed.iter() {
let missed = T::Balance::sa(<MissedOfPerSession<T>>::take(who) as u64);
let should_slash = missed * Self::minimum_penalty();
let council = xaccounts::Module::<T>::council_address();
let council = xaccounts::Module::<T>::council_account();

let jackpot_addr = T::DetermineIntentionJackpotAccountId::accountid_for(who);
let jackpot_balance = <xassets::Module<T>>::pcx_free_balance(&jackpot_addr);
Expand Down Expand Up @@ -186,7 +186,7 @@ impl<T: Trait> Module<T> {
let to_team = T::Balance::sa(session_reward.as_() * 2 / 10);
debug!("[reward] issue to the team: {:?}", to_team);
let _ =
<xassets::Module<T>>::pcx_issue(&xaccounts::Module::<T>::team_address(), to_team);
<xassets::Module<T>>::pcx_issue(&xaccounts::Module::<T>::team_account(), to_team);
session_reward - to_team
} else {
session_reward
Expand Down
6 changes: 3 additions & 3 deletions xrml/xmining/staking/src/vote_weight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,17 @@ impl<T: Trait> Module<T> {
}

fn channel_or_council_of(who: &T::AccountId, token: &Token) -> T::AccountId {
let council_address = xaccounts::Module::<T>::council_address();
let council_account = xaccounts::Module::<T>::council_account();

if let Some(asset_info) = <xassets::AssetInfo<T>>::get(token) {
let asset = asset_info.0;
let chain = asset.chain();

return xbridge_features::Module::<T>::get_first_binding_channel(who, chain)
.unwrap_or(council_address);
.unwrap_or(council_account);
}

return council_address;
return council_account;
}

pub fn generic_claim<U, V>(
Expand Down
4 changes: 2 additions & 2 deletions xrml/xmultisig/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,8 @@ impl<T: Trait> Module<T> {

RootAddrList::<T>::put(vec![council_multisig_addr.clone()]);

xaccounts::TeamAddress::<T>::put(&team_multisig_addr);
xaccounts::CouncilAddress::<T>::put(council_multisig_addr);
xaccounts::TeamAccount::<T>::put(&team_multisig_addr);
xaccounts::CouncilAccount::<T>::put(council_multisig_addr);

Ok(team_multisig_addr)
}
Expand Down

0 comments on commit d287736

Please sign in to comment.