osmosis_testing/
account.rs1use cosmrs::{
2 crypto::{secp256k1::SigningKey, PublicKey},
3 AccountId,
4};
5use cosmwasm_std::Coin;
6
7const ADDRESS_PREFIX: &str = "osmo";
8
9pub trait Account {
10 fn public_key(&self) -> PublicKey;
11 fn address(&self) -> String {
12 self.account_id().to_string()
13 }
14 fn account_id(&self) -> AccountId {
15 self.public_key()
16 .account_id(ADDRESS_PREFIX)
17 .expect("ADDRESS_PREFIX is constant and must valid")
18 }
19}
20pub struct SigningAccount {
21 signing_key: SigningKey,
22 fee_setting: FeeSetting,
23}
24
25impl SigningAccount {
26 pub fn new(signing_key: SigningKey, fee_setting: FeeSetting) -> Self {
27 SigningAccount {
28 signing_key,
29 fee_setting,
30 }
31 }
32
33 pub fn fee_setting(&self) -> &FeeSetting {
34 &self.fee_setting
35 }
36
37 pub fn with_fee_setting(self, fee_setting: FeeSetting) -> Self {
38 Self {
39 signing_key: self.signing_key,
40 fee_setting,
41 }
42 }
43}
44
45impl Account for SigningAccount {
46 fn public_key(&self) -> PublicKey {
47 self.signing_key.public_key()
48 }
49}
50
51impl SigningAccount {
52 pub fn signing_key(&'_ self) -> &'_ SigningKey {
53 &self.signing_key
54 }
55}
56
57#[derive(Debug, Clone, PartialEq, Eq)]
58pub struct NonSigningAccount {
59 public_key: PublicKey,
60}
61
62impl From<PublicKey> for NonSigningAccount {
63 fn from(public_key: PublicKey) -> Self {
64 NonSigningAccount { public_key }
65 }
66}
67impl From<SigningAccount> for NonSigningAccount {
68 fn from(signing_account: SigningAccount) -> Self {
69 NonSigningAccount {
70 public_key: signing_account.public_key(),
71 }
72 }
73}
74
75impl Account for NonSigningAccount {
76 fn public_key(&self) -> PublicKey {
77 self.public_key
78 }
79}
80
81#[derive(Debug, Clone, PartialEq)]
82pub enum FeeSetting {
83 Auto {
84 gas_price: Coin,
85 gas_adjustment: f64,
86 },
87 Custom {
88 amount: Coin,
89 gas_limit: u64,
90 },
91}