Skip to content

Commit b71d0f2

Browse files
authored
Feature/add trustee rpc (paritytech#278)
* Sketch trustee rpc * Fill TrusteeInfo struct * Finish trustee rpc
1 parent b167e63 commit b71d0f2

File tree

6 files changed

+49
-3
lines changed

6 files changed

+49
-3
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rpc/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ jsonrpc-core = "10.0.1"
99
jsonrpc-pubsub = "10.0.1"
1010
jsonrpc-derive = "10.0.1"
1111
log = "0.4"
12+
hex = "0.3.2"
1213
parking_lot = "0.4"
1314
parity-codec = "3.0"
1415
serde = "1.0"

rpc/src/chainx/impl_rpc.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,28 @@ where
426426
Ok(Some(psedu_intentions))
427427
}
428428

429+
fn trustee_info(&self, who: AccountId) -> Result<Vec<TrusteeInfo>> {
430+
let state = self.best_state()?;
431+
let mut trustee_info = Vec::new();
432+
433+
for chain in Chain::iterator() {
434+
let key = <xaccounts::TrusteeIntentionPropertiesOf<Runtime>>::key_for(&(who, *chain));
435+
436+
if let Some(props) = Self::pickout::<TrusteeIntentionProps>(&state, &key)? {
437+
let hot_entity = match props.hot_entity {
438+
TrusteeEntity::Bitcoin(pubkey) => hex::encode(&pubkey),
439+
};
440+
let cold_entity = match props.cold_entity {
441+
TrusteeEntity::Bitcoin(pubkey) => hex::encode(&pubkey),
442+
};
443+
444+
trustee_info.push(TrusteeInfo::new(chain.clone(), hot_entity, cold_entity))
445+
}
446+
}
447+
448+
Ok(trustee_info)
449+
}
450+
429451
fn psedu_nomination_records(
430452
&self,
431453
who: AccountId,

rpc/src/chainx/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use chainx_primitives::{AccountId, Balance, BlockNumber, Timestamp};
2222
use chainx_runtime::Runtime;
2323
use xr_primitives::generic::b58;
2424

25-
use xaccounts::{self, IntentionProps};
25+
use xaccounts::{self, IntentionProps, TrusteeEntity, TrusteeIntentionProps};
2626
use xassets::{self, Asset, AssetType, Chain, Token};
2727
use xbitcoin::{
2828
self, BestIndex, BlockHeaderFor, BlockHeaderInfo, CandidateTx, IrrBlock, TxFor, TxInfo,
@@ -44,8 +44,8 @@ pub mod types;
4444
use self::error::Result;
4545
use self::types::{
4646
AssetInfo, DepositInfo, IntentionInfo, NominationRecord, PageData, PairInfo,
47-
PseduIntentionInfo, PseduNominationRecord, QuotationsList, TotalAssetInfo, WithdrawInfo,
48-
WithdrawStatus,
47+
PseduIntentionInfo, PseduNominationRecord, QuotationsList, TotalAssetInfo, TrusteeInfo,
48+
WithdrawInfo, WithdrawStatus,
4949
};
5050
use chainx::error::ErrorKind::*;
5151
const MAX_PAGE_SIZE: u32 = 100;
@@ -98,6 +98,9 @@ pub trait ChainXApi<Number, AccountId, Balance, BlockNumber, SignedBlock> {
9898

9999
#[rpc(name = "chainx_getAddressByAccount")]
100100
fn address(&self, AccountId, Chain) -> Result<Option<Vec<String>>>;
101+
102+
#[rpc(name = "chainx_getTrusteeInfoByAccount")]
103+
fn trustee_info(&self, AccountId) -> Result<Vec<TrusteeInfo>>;
101104
}
102105

103106
/// ChainX API

rpc/src/chainx/types.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,24 @@ pub struct IntentionInfo {
9595
pub last_total_vote_weight_update: BlockNumber,
9696
}
9797

98+
#[derive(Debug, Default, PartialEq, Serialize, Deserialize)]
99+
#[serde(rename_all = "camelCase")]
100+
pub struct TrusteeInfo {
101+
chain: Chain,
102+
hot_entity: String,
103+
cold_entity: String,
104+
}
105+
106+
impl TrusteeInfo {
107+
pub fn new(chain: Chain, hot_entity: String, cold_entity: String) -> Self {
108+
TrusteeInfo {
109+
chain,
110+
hot_entity,
111+
cold_entity,
112+
}
113+
}
114+
}
115+
98116
/// OrderPair info
99117
#[derive(Debug, Default, PartialEq, Serialize, Deserialize)]
100118
#[serde(rename_all = "camelCase")]

rpc/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
extern crate chain as btc_chain;
1919
extern crate chainx_primitives;
2020
extern crate chainx_runtime;
21+
extern crate hex;
2122
extern crate jsonrpc_core as rpc;
2223
extern crate jsonrpc_derive;
2324
extern crate jsonrpc_pubsub;

0 commit comments

Comments
 (0)