Skip to content

Commit 541c731

Browse files
author
danielsanchezq
committed
Request fees through rest API
1 parent 68d9804 commit 541c731

File tree

3 files changed

+46
-10
lines changed

3 files changed

+46
-10
lines changed

jcli/src/jcli_lib/rest/v0/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub mod message;
66
mod network;
77
mod node;
88
mod rewards;
9-
mod settings;
9+
pub mod settings;
1010
mod shutdown;
1111
mod stake;
1212
mod stake_pool;

jcli/src/jcli_lib/rest/v0/settings/mod.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use crate::jcli_lib::rest::{Error, RestArgs};
22
use crate::jcli_lib::utils::OutputFormat;
3+
use jormungandr_lib::interfaces::SettingsDto;
4+
35
use structopt::StructOpt;
46

57
#[derive(StructOpt)]
@@ -20,9 +22,14 @@ impl Settings {
2022
args,
2123
output_format,
2224
} = self;
23-
let response = args.client()?.get(&["v0", "settings"]).execute()?.json()?;
24-
let formatted = output_format.format_json(response)?;
25+
let settings = request_settings(args)?;
26+
let formatted = output_format.format_json(serde_json::to_value(&settings)?)?;
2527
println!("{}", formatted);
2628
Ok(())
2729
}
2830
}
31+
32+
pub fn request_settings(args: RestArgs) -> Result<SettingsDto, Error> {
33+
serde_json::from_str(&(args.client()?.get(&["v0", "settings"]).execute()?.text()?))
34+
.map_err(Error::SerdeError)
35+
}

jcli/src/jcli_lib/transaction/simplified.rs

+36-7
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
use crate::jcli_lib::rest::RestArgs;
22
use crate::jcli_lib::transaction::{common, Error};
3-
use chain_crypto::{Ed25519, Ed25519Extended, PublicKey, SecretKey};
4-
53
use crate::transaction::mk_witness::WitnessType;
64
use crate::transaction::staging::Staging;
75
use crate::utils::key_parser::read_ed25519_secret_key_from_file;
86
use crate::utils::AccountId;
97
use crate::{rest, transaction};
108
use chain_addr::Kind;
119
use chain_core::property::FromStr;
10+
use chain_crypto::{Ed25519, Ed25519Extended, PublicKey, SecretKey};
1211
use chain_impl_mockchain::account::SpendingCounter;
1312
use chain_impl_mockchain::key::EitherEd25519SecretKey;
1413
use chain_impl_mockchain::transaction::Output;
1514
use jormungandr_lib::interfaces;
15+
16+
use crate::transaction::common::CommonFees;
17+
use jormungandr_lib::interfaces::SettingsDto;
1618
use rand::rngs::OsRng;
1719
use rand::SeedableRng;
1820
use rand_chacha::ChaChaRng;
@@ -42,9 +44,6 @@ pub struct MakeTransaction {
4244
#[structopt(flatten)]
4345
pub common: common::CommonTransaction,
4446

45-
#[structopt(flatten)]
46-
pub fee: common::CommonFees,
47-
4847
#[structopt(flatten)]
4948
rest_args: RestArgs,
5049
}
@@ -58,7 +57,6 @@ impl MakeTransaction {
5857
receiver_address,
5958
secret_key,
6059
self.value,
61-
self.fee,
6260
&self.block0_hash,
6361
self.rest_args.clone(),
6462
self.change,
@@ -90,13 +88,41 @@ fn create_receiver_secret_key_and_address(
9088
Ok((sk, address))
9189
}
9290

91+
fn common_fee_from_settings(settings: &SettingsDto) -> CommonFees {
92+
let fees = settings.fees;
93+
CommonFees {
94+
constant: fees.constant,
95+
coefficient: fees.coefficient,
96+
certificate: fees.certificate,
97+
certificate_pool_registration: fees
98+
.per_certificate_fees
99+
.certificate_pool_registration
100+
.map(Into::into),
101+
certificate_stake_delegation: fees
102+
.per_certificate_fees
103+
.certificate_owner_stake_delegation
104+
.map(Into::into),
105+
certificate_owner_stake_delegation: fees
106+
.per_certificate_fees
107+
.certificate_owner_stake_delegation
108+
.map(Into::into),
109+
certificate_vote_plan: fees
110+
.per_vote_certificate_fees
111+
.certificate_vote_plan
112+
.map(Into::into),
113+
certificate_vote_cast: fees
114+
.per_vote_certificate_fees
115+
.certificate_vote_cast
116+
.map(Into::into),
117+
}
118+
}
119+
93120
#[allow(clippy::too_many_arguments)]
94121
pub fn make_transaction(
95122
sender_account: interfaces::Address,
96123
receiver_address: interfaces::Address,
97124
secret_key: EitherEd25519SecretKey,
98125
value: interfaces::Value,
99-
fee: common::CommonFees,
100126
block0_hash: &str,
101127
rest_args: RestArgs,
102128
change: Option<interfaces::Address>,
@@ -112,6 +138,9 @@ pub fn make_transaction(
112138
value: value.into(),
113139
})?;
114140

141+
let settings = rest::v0::settings::request_settings(rest_args.clone())?;
142+
let fee = common_fee_from_settings(&settings);
143+
115144
// finalize
116145
transaction::finalize::finalize(fee, change, &mut transaction)?;
117146

0 commit comments

Comments
 (0)