Skip to content

Commit

Permalink
Feature/add trustee rpc (paritytech#278)
Browse files Browse the repository at this point in the history
* Sketch trustee rpc

* Fill TrusteeInfo struct

* Finish trustee rpc
  • Loading branch information
liuchengxu authored Feb 18, 2019
1 parent b167e63 commit b71d0f2
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ jsonrpc-core = "10.0.1"
jsonrpc-pubsub = "10.0.1"
jsonrpc-derive = "10.0.1"
log = "0.4"
hex = "0.3.2"
parking_lot = "0.4"
parity-codec = "3.0"
serde = "1.0"
Expand Down
22 changes: 22 additions & 0 deletions rpc/src/chainx/impl_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,28 @@ where
Ok(Some(psedu_intentions))
}

fn trustee_info(&self, who: AccountId) -> Result<Vec<TrusteeInfo>> {
let state = self.best_state()?;
let mut trustee_info = Vec::new();

for chain in Chain::iterator() {
let key = <xaccounts::TrusteeIntentionPropertiesOf<Runtime>>::key_for(&(who, *chain));

if let Some(props) = Self::pickout::<TrusteeIntentionProps>(&state, &key)? {
let hot_entity = match props.hot_entity {
TrusteeEntity::Bitcoin(pubkey) => hex::encode(&pubkey),
};
let cold_entity = match props.cold_entity {
TrusteeEntity::Bitcoin(pubkey) => hex::encode(&pubkey),
};

trustee_info.push(TrusteeInfo::new(chain.clone(), hot_entity, cold_entity))
}
}

Ok(trustee_info)
}

fn psedu_nomination_records(
&self,
who: AccountId,
Expand Down
9 changes: 6 additions & 3 deletions rpc/src/chainx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use chainx_primitives::{AccountId, Balance, BlockNumber, Timestamp};
use chainx_runtime::Runtime;
use xr_primitives::generic::b58;

use xaccounts::{self, IntentionProps};
use xaccounts::{self, IntentionProps, TrusteeEntity, TrusteeIntentionProps};
use xassets::{self, Asset, AssetType, Chain, Token};
use xbitcoin::{
self, BestIndex, BlockHeaderFor, BlockHeaderInfo, CandidateTx, IrrBlock, TxFor, TxInfo,
Expand All @@ -44,8 +44,8 @@ pub mod types;
use self::error::Result;
use self::types::{
AssetInfo, DepositInfo, IntentionInfo, NominationRecord, PageData, PairInfo,
PseduIntentionInfo, PseduNominationRecord, QuotationsList, TotalAssetInfo, WithdrawInfo,
WithdrawStatus,
PseduIntentionInfo, PseduNominationRecord, QuotationsList, TotalAssetInfo, TrusteeInfo,
WithdrawInfo, WithdrawStatus,
};
use chainx::error::ErrorKind::*;
const MAX_PAGE_SIZE: u32 = 100;
Expand Down Expand Up @@ -98,6 +98,9 @@ pub trait ChainXApi<Number, AccountId, Balance, BlockNumber, SignedBlock> {

#[rpc(name = "chainx_getAddressByAccount")]
fn address(&self, AccountId, Chain) -> Result<Option<Vec<String>>>;

#[rpc(name = "chainx_getTrusteeInfoByAccount")]
fn trustee_info(&self, AccountId) -> Result<Vec<TrusteeInfo>>;
}

/// ChainX API
Expand Down
18 changes: 18 additions & 0 deletions rpc/src/chainx/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,24 @@ pub struct IntentionInfo {
pub last_total_vote_weight_update: BlockNumber,
}

#[derive(Debug, Default, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TrusteeInfo {
chain: Chain,
hot_entity: String,
cold_entity: String,
}

impl TrusteeInfo {
pub fn new(chain: Chain, hot_entity: String, cold_entity: String) -> Self {
TrusteeInfo {
chain,
hot_entity,
cold_entity,
}
}
}

/// OrderPair info
#[derive(Debug, Default, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
Expand Down
1 change: 1 addition & 0 deletions rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
extern crate chain as btc_chain;
extern crate chainx_primitives;
extern crate chainx_runtime;
extern crate hex;
extern crate jsonrpc_core as rpc;
extern crate jsonrpc_derive;
extern crate jsonrpc_pubsub;
Expand Down

0 comments on commit b71d0f2

Please sign in to comment.