@@ -6,7 +6,6 @@ use crate::{
66 address:: { Address , ShelleyAddress , StakeAddress } ,
77 protocol_params,
88 rational_number:: RationalNumber ,
9- AddressNetwork , StakeAddressPayload ,
109} ;
1110use anyhow:: { anyhow, bail, Error , Result } ;
1211use bech32:: { Bech32 , Hrp } ;
@@ -26,6 +25,16 @@ pub enum NetworkId {
2625 Mainnet ,
2726}
2827
28+ impl From < String > for NetworkId {
29+ fn from ( s : String ) -> Self {
30+ match s. as_str ( ) {
31+ "testnet" => NetworkId :: Testnet ,
32+ "mainnet" => NetworkId :: Mainnet ,
33+ _ => NetworkId :: Mainnet ,
34+ }
35+ }
36+ }
37+
2938/// Protocol era
3039#[ derive(
3140 Debug , Clone , Copy , PartialEq , Eq , PartialOrd , Ord , serde:: Serialize , serde:: Deserialize ,
@@ -613,20 +622,6 @@ impl Credential {
613622
614623pub type StakeCredential = Credential ;
615624
616- impl StakeCredential {
617- pub fn to_stake_address ( & self , network : Option < AddressNetwork > ) -> StakeAddress {
618- let payload = match self {
619- StakeCredential :: AddrKeyHash ( hash) => StakeAddressPayload :: StakeKeyHash (
620- hash. clone ( ) . try_into ( ) . expect ( "Invalid hash length" ) ,
621- ) ,
622- StakeCredential :: ScriptHash ( hash) => StakeAddressPayload :: ScriptHash (
623- hash. clone ( ) . try_into ( ) . expect ( "Invalid hash length" ) ,
624- ) ,
625- } ;
626- StakeAddress :: new ( network. unwrap_or ( AddressNetwork :: Main ) , payload)
627- }
628- }
629-
630625/// Relay single host address
631626#[ derive( Debug , Default , Clone , serde:: Serialize , serde:: Deserialize , Eq , PartialEq ) ]
632627pub struct SingleHostAddr {
@@ -739,7 +734,7 @@ pub struct PoolRegistration {
739734 /// Pool owners by their key hash
740735 // #[serde_as(as = "Vec<Hex>")]
741736 #[ n( 6 ) ]
742- pub pool_owners : Vec < Credential > ,
737+ pub pool_owners : Vec < StakeAddress > ,
743738
744739 // Relays
745740 #[ n( 7 ) ]
@@ -824,8 +819,8 @@ pub struct PoolEpochState {
824819/// Stake delegation data
825820#[ derive( Debug , Clone , serde:: Serialize , serde:: Deserialize ) ]
826821pub struct StakeDelegation {
827- /// Stake credential
828- pub credential : StakeCredential ,
822+ /// Stake address
823+ pub stake_address : StakeAddress ,
829824
830825 /// Pool ID to delegate to
831826 pub operator : KeyHash ,
@@ -877,7 +872,7 @@ pub enum InstantaneousRewardSource {
877872/// Target of a MIR
878873#[ derive( Debug , Clone , serde:: Serialize , serde:: Deserialize ) ]
879874pub enum InstantaneousRewardTarget {
880- StakeCredentials ( Vec < ( StakeCredential , i64 ) > ) ,
875+ StakeAddresses ( Vec < ( StakeAddress , i64 ) > ) ,
881876 OtherAccountingPot ( u64 ) ,
882877}
883878
@@ -894,8 +889,8 @@ pub struct MoveInstantaneousReward {
894889/// Register stake (Conway version) = 'reg_cert'
895890#[ derive( Debug , Clone , serde:: Serialize , serde:: Deserialize ) ]
896891pub struct Registration {
897- /// Stake credential
898- pub credential : StakeCredential ,
892+ /// Stake address
893+ pub stake_address : StakeAddress ,
899894
900895 /// Deposit paid
901896 pub deposit : Lovelace ,
@@ -904,8 +899,8 @@ pub struct Registration {
904899/// Deregister stake (Conway version) = 'unreg_cert'
905900#[ derive( Debug , Clone , serde:: Serialize , serde:: Deserialize ) ]
906901pub struct Deregistration {
907- /// Stake credential
908- pub credential : StakeCredential ,
902+ /// Stake address
903+ pub stake_address : StakeAddress ,
909904
910905 /// Deposit to be refunded
911906 pub refund : Lovelace ,
@@ -930,8 +925,8 @@ pub enum DRepChoice {
930925/// Vote delegation (simple, existing registration) = vote_deleg_cert
931926#[ derive( Debug , Clone , serde:: Serialize , serde:: Deserialize ) ]
932927pub struct VoteDelegation {
933- /// Stake credential
934- pub credential : StakeCredential ,
928+ /// Stake address
929+ pub stake_address : StakeAddress ,
935930
936931 // DRep choice
937932 pub drep : DRepChoice ,
@@ -940,8 +935,8 @@ pub struct VoteDelegation {
940935/// Stake+vote delegation (to SPO and DRep) = stake_vote_deleg_cert
941936#[ derive( Debug , Clone , serde:: Serialize , serde:: Deserialize ) ]
942937pub struct StakeAndVoteDelegation {
943- /// Stake credential
944- pub credential : StakeCredential ,
938+ /// Stake address
939+ pub stake_address : StakeAddress ,
945940
946941 /// Pool
947942 pub operator : KeyHash ,
@@ -953,8 +948,8 @@ pub struct StakeAndVoteDelegation {
953948/// Stake delegation to SPO + registration = stake_reg_deleg_cert
954949#[ derive( Debug , Clone , serde:: Serialize , serde:: Deserialize ) ]
955950pub struct StakeRegistrationAndDelegation {
956- /// Stake credential
957- pub credential : StakeCredential ,
951+ /// Stake address
952+ pub stake_address : StakeAddress ,
958953
959954 /// Pool
960955 pub operator : KeyHash ,
@@ -966,8 +961,8 @@ pub struct StakeRegistrationAndDelegation {
966961/// Vote delegation to DRep + registration = vote_reg_deleg_cert
967962#[ derive( Debug , Clone , serde:: Serialize , serde:: Deserialize ) ]
968963pub struct StakeRegistrationAndVoteDelegation {
969- /// Stake credential
970- pub credential : StakeCredential ,
964+ /// Stake address
965+ pub stake_address : StakeAddress ,
971966
972967 /// DRep choice
973968 pub drep : DRepChoice ,
@@ -982,7 +977,7 @@ pub struct StakeRegistrationAndVoteDelegation {
982977#[ derive( Debug , Clone , serde:: Serialize , serde:: Deserialize ) ]
983978pub struct StakeRegistrationAndStakeAndVoteDelegation {
984979 /// Stake credential
985- pub credential : StakeCredential ,
980+ pub stake_address : StakeAddress ,
986981
987982 /// Pool
988983 pub operator : KeyHash ,
@@ -1660,8 +1655,8 @@ pub struct GovernanceOutcome {
16601655}
16611656
16621657#[ derive( Debug , Clone , serde:: Serialize , serde:: Deserialize ) ]
1663- pub struct StakeCredentialWithPos {
1664- pub stake_credential : StakeCredential ,
1658+ pub struct StakeAddressWithPos {
1659+ pub stake_address : StakeAddress ,
16651660 pub tx_index : u64 ,
16661661 pub cert_index : u64 ,
16671662}
@@ -1673,10 +1668,10 @@ pub enum TxCertificate {
16731668 None ( ( ) ) ,
16741669
16751670 /// Stake registration
1676- StakeRegistration ( StakeCredentialWithPos ) ,
1671+ StakeRegistration ( StakeAddressWithPos ) ,
16771672
16781673 /// Stake de-registration
1679- StakeDeregistration ( StakeCredential ) ,
1674+ StakeDeregistration ( StakeAddress ) ,
16801675
16811676 /// Stake Delegation to a pool
16821677 StakeDelegation ( StakeDelegation ) ,
0 commit comments