|
| 1 | +use catalyst_toolbox::snapshot::CatalystRegistration; |
| 2 | +use chain_addr::Discrimination; |
| 3 | +use jormungandr_lib::crypto::account::SigningKey; |
| 4 | +use vitup::config::Block0Initial; |
| 5 | + |
| 6 | +pub struct MainnetWallet { |
| 7 | + inner: thor::Wallet, |
| 8 | + reward_address: String, |
| 9 | + stake_public_key: String, |
| 10 | + stake: u64, |
| 11 | +} |
| 12 | + |
| 13 | +impl MainnetWallet { |
| 14 | + pub fn new(stake: u64) -> Self { |
| 15 | + let mut rng = rand::thread_rng(); |
| 16 | + Self { |
| 17 | + inner: thor::Wallet::new_account(&mut rng, Discrimination::Production), |
| 18 | + stake, |
| 19 | + reward_address: "0x".to_owned() |
| 20 | + + &SigningKey::generate_extended(&mut rng) |
| 21 | + .identifier() |
| 22 | + .to_hex(), |
| 23 | + stake_public_key: "0x".to_owned() |
| 24 | + + &SigningKey::generate_extended(&mut rng) |
| 25 | + .identifier() |
| 26 | + .to_hex(), |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + pub fn reward_address(&self) -> String { |
| 31 | + self.reward_address.clone() |
| 32 | + } |
| 33 | + |
| 34 | + pub fn stake_public_key(&self) -> String { |
| 35 | + self.stake_public_key.clone() |
| 36 | + } |
| 37 | + |
| 38 | + pub fn catalyst_secret_key(&self) -> chain_crypto::SecretKey<chain_crypto::Ed25519Extended> { |
| 39 | + self.inner.secret_key() |
| 40 | + } |
| 41 | + |
| 42 | + pub fn as_voting_registration(&self) -> CatalystRegistration { |
| 43 | + CatalystRegistration { |
| 44 | + stake_public_key: self.stake_public_key(), |
| 45 | + voting_power: self.stake.into(), |
| 46 | + reward_address: self.reward_address(), |
| 47 | + voting_public_key: self.inner.identifier().into(), |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + pub fn as_initial_entry(&self) -> Block0Initial { |
| 52 | + Block0Initial::External { |
| 53 | + address: self.inner.address().to_string(), |
| 54 | + funds: self.stake, |
| 55 | + role: Default::default(), |
| 56 | + } |
| 57 | + } |
| 58 | +} |
0 commit comments