Skip to content

Commit c675e45

Browse files
authored
Merge pull request #1169 from input-output-hk/add-pool-retirement-registration
Add pool retirement and pool update certificates graphql types
2 parents 0db652f + dce47eb commit c675e45

File tree

1 file changed

+62
-5
lines changed
  • jormungandr/src/explorer/graphql

1 file changed

+62
-5
lines changed

jormungandr/src/explorer/graphql/mod.rs

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ impl StakeDelegation {
505505
.map(|addr| Address::from(&ExplorerAddress::New(addr)))
506506
}
507507

508-
pub fn pool(&self, context: &Context) -> Vec<Pool> {
508+
pub fn pools(&self, context: &Context) -> Vec<Pool> {
509509
use chain_impl_mockchain::account::DelegationType;
510510
use std::iter::FromIterator as _;
511511

@@ -666,7 +666,7 @@ impl From<certificate::OwnerStakeDelegation> for OwnerStakeDelegation {
666666
Context = Context,
667667
)]
668668
impl OwnerStakeDelegation {
669-
fn pool(&self) -> Vec<Pool> {
669+
fn pools(&self) -> Vec<Pool> {
670670
use chain_impl_mockchain::account::DelegationType;
671671
use std::iter::FromIterator as _;
672672

@@ -684,12 +684,63 @@ impl OwnerStakeDelegation {
684684
}
685685
}
686686

687+
/// Retirement info for a pool
688+
struct PoolRetirement {
689+
pool_retirement: certificate::PoolRetirement,
690+
}
691+
692+
impl From<certificate::PoolRetirement> for PoolRetirement {
693+
fn from(pool_retirement: certificate::PoolRetirement) -> PoolRetirement {
694+
PoolRetirement { pool_retirement }
695+
}
696+
}
697+
698+
#[juniper::object(
699+
Context = Context,
700+
)]
701+
impl PoolRetirement {
702+
pub fn pool_id(&self) -> PoolId {
703+
PoolId(format!("{}", self.pool_retirement.pool_id))
704+
}
705+
706+
pub fn retirement_time(&self) -> TimeOffsetSeconds {
707+
self.pool_retirement.retirement_time.into()
708+
}
709+
}
710+
711+
struct PoolUpdate {
712+
pool_update: certificate::PoolUpdate,
713+
}
714+
715+
impl From<certificate::PoolUpdate> for PoolUpdate {
716+
fn from(pool_update: certificate::PoolUpdate) -> PoolUpdate {
717+
PoolUpdate { pool_update }
718+
}
719+
}
720+
721+
#[juniper::object(
722+
Context = Context,
723+
)]
724+
impl PoolUpdate {
725+
pub fn pool_id(&self) -> PoolId {
726+
PoolId(format!("{}", self.pool_update.pool_id))
727+
}
728+
729+
pub fn start_validity(&self) -> TimeOffsetSeconds {
730+
self.pool_update.start_validity.into()
731+
}
732+
733+
// TODO: Previous keys?
734+
// TODO: Updated keys?
735+
}
736+
687737
// TODO can we use jormungandr-lib Certificate ?
688738
enum Certificate {
689739
StakeDelegation(StakeDelegation),
690740
OwnerStakeDelegation(OwnerStakeDelegation),
691741
PoolRegistration(PoolRegistration),
692-
// TODO: PoolManagement
742+
PoolRetirement(PoolRetirement),
743+
PoolUpdate(PoolUpdate),
693744
}
694745

695746
impl TryFrom<chain_impl_mockchain::certificate::Certificate> for Certificate {
@@ -707,8 +758,12 @@ impl TryFrom<chain_impl_mockchain::certificate::Certificate> for Certificate {
707758
certificate::Certificate::PoolRegistration(c) => {
708759
Ok(Certificate::PoolRegistration(PoolRegistration::from(c)))
709760
}
710-
certificate::Certificate::PoolRetirement(_) => Err(ErrorKind::Unimplemented.into()),
711-
certificate::Certificate::PoolUpdate(_) => Err(ErrorKind::Unimplemented.into()),
761+
certificate::Certificate::PoolRetirement(c) => {
762+
Ok(Certificate::PoolRetirement(PoolRetirement::from(c)))
763+
}
764+
certificate::Certificate::PoolUpdate(c) => {
765+
Ok(Certificate::PoolUpdate(PoolUpdate::from(c)))
766+
}
712767
}
713768
}
714769
}
@@ -720,6 +775,8 @@ graphql_union!(Certificate: Context |&self| {
720775
&StakeDelegation => match *self { Certificate::StakeDelegation(ref c) => Some(c), _ => None },
721776
&OwnerStakeDelegation => match *self { Certificate::OwnerStakeDelegation(ref c) => Some(c), _ => None },
722777
&PoolRegistration => match *self { Certificate::PoolRegistration(ref c) => Some(c), _ => None },
778+
&PoolUpdate => match *self { Certificate::PoolUpdate(ref c) => Some(c), _ => None},
779+
&PoolRetirement => match *self { Certificate::PoolRetirement(ref c) => Some(c), _ => None}
723780
}
724781
});
725782

0 commit comments

Comments
 (0)