Skip to content

Commit 7eac318

Browse files
authored
Merge pull request #1084 from input-output-hk/ratio-delegation
update chain-deps to have support for ratio delegation
2 parents b703bd8 + c024dc2 commit 7eac318

File tree

5 files changed

+39
-12
lines changed

5 files changed

+39
-12
lines changed

jcli/src/jcli_app/certificate/new_stake_delegation.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use chain_crypto::{Ed25519, PublicKey};
2+
use chain_impl_mockchain::account::DelegationType;
23
use chain_impl_mockchain::certificate::{Certificate, StakeDelegation as Delegation};
34
use chain_impl_mockchain::transaction::AccountIdentifier;
45
use jcli_app::certificate::{write_cert, Error};
@@ -25,7 +26,7 @@ impl StakeDelegation {
2526
pub fn exec(self) -> Result<(), Error> {
2627
let content = Delegation {
2728
account_id: AccountIdentifier::from_single_account(self.stake_id.into()),
28-
pool_id: self.pool_id.into(),
29+
delegation: DelegationType::Full(self.pool_id.into()),
2930
};
3031
let cert = Certificate::StakeDelegation(content);
3132
write_cert(

jormungandr-lib/src/interfaces/account_state.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl From<account::DelegationType> for DelegationType {
2323
},
2424
account::DelegationType::Ratio(v) => DelegationType {
2525
pools: v
26-
.pools
26+
.pools()
2727
.iter()
2828
.map(|(h, pp)| (h.clone().into(), *pp))
2929
.collect(),
@@ -43,14 +43,14 @@ impl From<DelegationType> for account::DelegationType {
4343
match v.try_into() {
4444
Err(_) => panic!("delegation type pool overflow"),
4545
Ok(parts) => {
46-
let ratio = account::DelegationRatio {
46+
let ratio = account::DelegationRatio::new(
4747
parts,
48-
pools: dt
49-
.pools
48+
dt.pools()
5049
.iter()
5150
.map(|(h, pp)| (h.into_digest_of(), *pp))
5251
.collect(),
53-
};
52+
)
53+
.expect("Assume this is always correct for a delegation type");
5454
account::DelegationType::Ratio(ratio)
5555
}
5656
}

jormungandr-scenario-tests/src/wallet/account.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl Wallet {
7878
pub fn delegation_cert_for_block0(&self, pool_id: PoolId) -> SignedCertificate {
7979
let stake_delegation = StakeDelegation {
8080
account_id: self.stake_key(), // 2
81-
pool_id, // 1
81+
delegation: chain_impl_mockchain::account::DelegationType::Full(pool_id), // 1
8282
};
8383
let txb = TxBuilder::new()
8484
.set_payload(&stake_delegation)

jormungandr/src/explorer/graphql/mod.rs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,21 @@ impl StakeDelegation {
471471
.map(|addr| Address::from(&addr))
472472
}
473473

474-
pub fn pool(&self, context: &Context) -> Pool {
475-
Pool::from_valid_id(self.delegation.pool_id.clone())
474+
pub fn pool(&self, context: &Context) -> Vec<Pool> {
475+
use chain_impl_mockchain::account::DelegationType;
476+
use std::iter::FromIterator as _;
477+
478+
match self.delegation.get_delegation_type() {
479+
DelegationType::NonDelegated => vec![],
480+
DelegationType::Full(id) => vec![Pool::from_valid_id(id.clone())],
481+
DelegationType::Ratio(delegation_ratio) => Vec::from_iter(
482+
delegation_ratio
483+
.pools()
484+
.iter()
485+
.cloned()
486+
.map(|(p, _)| Pool::from_valid_id(p)),
487+
),
488+
}
476489
}
477490
}
478491

@@ -542,8 +555,21 @@ impl From<certificate::OwnerStakeDelegation> for OwnerStakeDelegation {
542555
Context = Context,
543556
)]
544557
impl OwnerStakeDelegation {
545-
fn pool(&self) -> Pool {
546-
Pool::from_valid_id(self.owner_stake_delegation.pool_id.clone())
558+
fn pool(&self) -> Vec<Pool> {
559+
use chain_impl_mockchain::account::DelegationType;
560+
use std::iter::FromIterator as _;
561+
562+
match self.owner_stake_delegation.get_delegation_type() {
563+
DelegationType::NonDelegated => vec![],
564+
DelegationType::Full(id) => vec![Pool::from_valid_id(id.clone())],
565+
DelegationType::Ratio(delegation_ratio) => Vec::from_iter(
566+
delegation_ratio
567+
.pools()
568+
.iter()
569+
.cloned()
570+
.map(|(p, _)| Pool::from_valid_id(p)),
571+
),
572+
}
547573
}
548574
}
549575

0 commit comments

Comments
 (0)