Skip to content

Commit

Permalink
Add upgrade target in Makefile in case of forgetting wasm upgrading (p…
Browse files Browse the repository at this point in the history
…aritytech#637)

* Add upgrade target in Makefile in case of forgetting wasm upgrading

* Refactor RPC a bit

* Add chainx_getIntentionByAccount RPC

* Rename items in genesis_node.csv
  • Loading branch information
liuchengxu authored and gguoss committed May 23, 2019
1 parent 3a3b0a0 commit 3fdea15
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 20 deletions.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,10 @@ format: pre-format

clean:
@cargo clean

upgrade:
@echo "Upgrading substrate under native..."
cargo update -p srml-system
@echo
@echo "Upgrading substrate under wasm..."
cd runtime/wasm && cargo update -p srml-system
16 changes: 8 additions & 8 deletions cli/src/genesis_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,11 @@ fn load_sdot_info() -> Result<Vec<([u8; 20], u64)>, Box<dyn std::error::Error>>
#[derive(Debug, Deserialize)]
pub struct RecordOfGenesisNode {
account_id: String,
authority_key: String,
session_key: String,
money: f64,
node_name: String,
node_url: String,
memo: String,
name: String,
url: String,
about: String,
hot_entity: String,
cold_entity: String,
}
Expand All @@ -337,12 +337,12 @@ fn load_genesis_node_info() -> Result<
let record: RecordOfGenesisNode = result?;

let account_id = hex(&record.account_id).unchecked_into();
let authority_key = hex(&record.authority_key).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 node_name = record.node_name.into_bytes();
let node_url = record.node_url.into_bytes();
let memo = record.memo.into_bytes();
let node_name = record.name.into_bytes();
let node_url = record.url.into_bytes();
let memo = record.about.into_bytes();
let get_entity = |entity: String| {
if entity.is_empty() {
None
Expand Down
2 changes: 1 addition & 1 deletion cli/src/genesis_node.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
account_id,authority_key,money,node_name,node_url,memo,hot_entity,cold_entity
account_id,session_key,endowed,name,url,about,hot_entity,cold_entity
a2308187439ac204df9e299e1e54afefafea4bf348e03dad679737c91871dc53,a2308187439ac204df9e299e1e54afefafea4bf348e03dad679737c91871dc53,10,genesis1,polkadot.network,,02a3ee44550a9c13575e99f96fc56db20e2f7f686276c82a5737bacca07163571f,02c048a87feb43fe1292c6fa36cfffce33fb77e7306aa3ee3467215d717143a577
6488ceea630000b48fed318d13248ea7c566c0f4d2b8b90d12a136ad6eb02323,6488ceea630000b48fed318d13248ea7c566c0f4d2b8b90d12a136ad6eb02323,10,genesis2,polkadot.network,,02fabd0895598ee8c11a6d4f4610a8b872fe5cefa2d62e82fef12825ec7901e32c,03622d302fdcf12dfbc558e7cca7ebaecca117249191fe54952b63824d794e87bc
56758d236714a2fa7981af8c8177dddc6907875b2c23fd5c842922c8a2c5a1be,56758d236714a2fa7981af8c8177dddc6907875b2c23fd5c842922c8a2c5a1be,10,genesis3,polkadot.network,,03c591c812d681b7b1791b2a5753f4e346eba60f3448bb1f71be93d608644bf67b,03c591c812d681b7b1791b2a5753f4e346eba60f3448bb1f71be93d608644bf67b
Expand Down
33 changes: 24 additions & 9 deletions rpc/src/chainx/impl_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,27 @@ where
Ok(Some(records))
}

fn intention(&self, who: AccountIdForRpc) -> Result<Option<Value>> {
let state = self.best_state()?;
let who: AccountId = who.unchecked_into();
let key = <xaccounts::IntentionPropertiesOf<Runtime>>::key_for(&who);
let session_key: AccountIdForRpc = if let Some(props) = Self::pickout::<
IntentionProps<AuthorityId, BlockNumber>,
>(
&state, &key, Hasher::BLAKE2256
)? {
props.session_key.unwrap_or(who.clone()).into()
} else {
return Ok(None);
};

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

fn intentions(&self) -> Result<Option<Vec<IntentionInfo>>> {
let state = self.best_state()?;
let mut intention_info = Vec::new();
Expand All @@ -257,10 +278,7 @@ where
let best_number = self.best_number()?;

// get all bridge trustee list
let all_session_info: BTreeMap<xassets::Chain, GenericAllSessionInfo<AccountId>> = self
.client
.runtime_api()
.trustee_session_info(&best_number)?;
let all_session_info = self.trustee_session_info(best_number)?;
let all_trustees = all_session_info
.into_iter()
.map(|(chain, info)| {
Expand Down Expand Up @@ -305,10 +323,7 @@ where
info.url = String::from_utf8_lossy(&props.url).into_owned();
info.is_active = props.is_active;
info.about = String::from_utf8_lossy(&props.about).into_owned();
info.session_key = match props.session_key {
Some(s) => s.into(),
None => intention.clone().into(),
};
info.session_key = props.session_key.unwrap_or(intention.clone()).into();
}

let key = <xstaking::Intentions<Runtime>>::key_for(&intention);
Expand Down Expand Up @@ -723,7 +738,7 @@ where
}
}

fn trustee_session_info(&self, chain: Chain) -> Result<Option<Value>> {
fn trustee_session_info_for(&self, chain: Chain) -> Result<Option<Value>> {
if let Some((number, info)) = self.trustee_session_info_for(self.best_number()?, chain)? {
return Ok(parse_trustee_session_info(chain, number, info));
} else {
Expand Down
8 changes: 6 additions & 2 deletions rpc/src/chainx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ pub trait ChainXApi<Number, AccountId, Balance, BlockNumber, SignedBlock> {
#[rpc(name = "chainx_getIntentions")]
fn intentions(&self) -> Result<Option<Vec<IntentionInfo>>>;

#[rpc(name = "chainx_getIntentionByAccount")]
fn intention(&self, who: AccountId) -> Result<Option<Value>>;

#[rpc(name = "chainx_getPseduIntentions")]
fn psedu_intentions(&self) -> Result<Option<Vec<PseduIntentionInfo>>>;

Expand Down Expand Up @@ -111,7 +114,7 @@ pub trait ChainXApi<Number, AccountId, Balance, BlockNumber, SignedBlock> {
fn address(&self, who: AccountId, chain: Chain) -> Result<Option<Vec<String>>>;

#[rpc(name = "chainx_getTrusteeSessionInfo")]
fn trustee_session_info(&self, chain: Chain) -> Result<Option<Value>>;
fn trustee_session_info_for(&self, chain: Chain) -> Result<Option<Value>>;

#[rpc(name = "chainx_getTrusteeInfoByAccount")]
fn trustee_info_for_accountid(&self, who: AccountId) -> Result<Option<Value>>;
Expand Down Expand Up @@ -225,6 +228,7 @@ where

// XMiningApi
fn asset_power(token: Token) -> Option<Balance>;
fn jackpot_accountid_for(who: AccountId) -> AccountId;
fn multi_jackpot_accountid_for(intentions: Vec<AccountId>) -> Vec<AccountId>;
fn multi_token_jackpot_accountid_for(tokens: Vec<Token>) -> Vec<AccountId>;

Expand All @@ -240,6 +244,6 @@ where
// XBridgeApi
fn trustee_props_for(who: AccountId) -> BTreeMap<Chain, GenericTrusteeIntentionProps>;
fn trustee_session_info_for(chain: Chain) -> Option<(u32, GenericAllSessionInfo<AccountId>)>;

fn trustee_session_info() -> BTreeMap<xassets::Chain, GenericAllSessionInfo<AccountId>>;
}
}

0 comments on commit 3fdea15

Please sign in to comment.