Skip to content

Commit 972feff

Browse files
authored
Make --cost functional. (#2257)
1 parent d939099 commit 972feff

10 files changed

Lines changed: 210 additions & 29 deletions

File tree

cmd/soroban-cli/src/commands/contract/deploy/asset.rs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use clap::{arg, command, Parser};
1010
use std::convert::Infallible;
1111
use std::{array::TryFromSliceError, fmt::Debug, num::ParseIntError};
1212

13+
use crate::commands::tx::fetch;
1314
use crate::{
1415
assembled::simulate_and_assemble_transaction,
1516
commands::{
@@ -29,24 +30,39 @@ use crate::commands::contract::deploy::utils::alias_validator;
2930
pub enum Error {
3031
#[error("error parsing int: {0}")]
3132
ParseIntError(#[from] ParseIntError),
33+
3234
#[error(transparent)]
3335
Client(#[from] SorobanRpcError),
36+
3437
#[error("internal conversion error: {0}")]
3538
TryFromSliceError(#[from] TryFromSliceError),
39+
3640
#[error("xdr processing error: {0}")]
3741
Xdr(#[from] XdrError),
42+
3843
#[error(transparent)]
3944
Config(#[from] config::Error),
45+
4046
#[error(transparent)]
4147
Data(#[from] data::Error),
48+
4249
#[error(transparent)]
4350
Network(#[from] network::Error),
51+
4452
#[error(transparent)]
4553
Builder(#[from] builder::Error),
54+
4655
#[error(transparent)]
4756
Asset(#[from] builder::asset::Error),
57+
4858
#[error(transparent)]
4959
Locator(#[from] locator::Error),
60+
61+
#[error(transparent)]
62+
Fee(#[from] fetch::fee::Error),
63+
64+
#[error(transparent)]
65+
Fetch(#[from] fetch::Error),
5066
}
5167

5268
impl From<Infallible> for Error {
@@ -152,16 +168,19 @@ impl NetworkRunnable for Cmd {
152168
return Ok(TxnResult::Txn(Box::new(tx)));
153169
}
154170

155-
let txn =
171+
let assembled =
156172
simulate_and_assemble_transaction(&client, &tx, self.fee.resource_config()).await?;
157-
let txn = self.fee.apply_to_assembled_txn(txn).transaction().clone();
173+
let assembled = self.fee.apply_to_assembled_txn(assembled);
174+
175+
let txn = assembled.transaction().clone();
158176
let get_txn_resp = client
159177
.send_transaction_polling(&self.config.sign(txn).await?)
160-
.await?
161-
.try_into()?;
178+
.await?;
179+
180+
self.fee.print_cost_info(&get_txn_resp)?;
162181

163182
if args.is_none_or(|a| !a.no_cache) {
164-
data::write(get_txn_resp, &network.rpc_uri()?)?;
183+
data::write(get_txn_resp.clone().try_into()?, &network.rpc_uri()?)?;
165184
}
166185

167186
Ok(TxnResult::Res(stellar_strkey::Contract(contract_id.0)))

cmd/soroban-cli/src/commands/contract/deploy/wasm.rs

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ use crate::xdr::{
1414
use clap::{arg, command, Parser};
1515
use rand::Rng;
1616

17-
use soroban_spec_tools::contract as contract_spec;
18-
17+
use crate::commands::tx::fetch;
1918
use crate::{
2019
assembled::simulate_and_assemble_transaction,
2120
commands::{
@@ -30,6 +29,7 @@ use crate::{
3029
utils::{self, rpc::get_remote_wasm_from_hash},
3130
wasm,
3231
};
32+
use soroban_spec_tools::contract as contract_spec;
3333

3434
pub const CONSTRUCTOR_FUNCTION_NAME: &str = "__constructor";
3535

@@ -74,52 +74,78 @@ pub struct Cmd {
7474
pub enum Error {
7575
#[error(transparent)]
7676
Install(#[from] upload::Error),
77+
7778
#[error("error parsing int: {0}")]
7879
ParseIntError(#[from] ParseIntError),
80+
7981
#[error("internal conversion error: {0}")]
8082
TryFromSliceError(#[from] TryFromSliceError),
83+
8184
#[error("xdr processing error: {0}")]
8285
Xdr(#[from] XdrError),
86+
8387
#[error("jsonrpc error: {0}")]
8488
JsonRpc(#[from] jsonrpsee_core::Error),
89+
8590
#[error("cannot parse salt: {salt}")]
8691
CannotParseSalt { salt: String },
92+
8793
#[error("cannot parse contract ID {contract_id}: {error}")]
8894
CannotParseContractId {
8995
contract_id: String,
9096
error: stellar_strkey::DecodeError,
9197
},
98+
9299
#[error("cannot parse WASM hash {wasm_hash}: {error}")]
93100
CannotParseWasmHash {
94101
wasm_hash: String,
95102
error: stellar_strkey::DecodeError,
96103
},
104+
97105
#[error("Must provide either --wasm or --wash-hash")]
98106
WasmNotProvided,
107+
99108
#[error(transparent)]
100109
Rpc(#[from] rpc::Error),
110+
101111
#[error(transparent)]
102112
Config(#[from] config::Error),
113+
103114
#[error(transparent)]
104115
StrKey(#[from] stellar_strkey::DecodeError),
116+
105117
#[error(transparent)]
106118
Infallible(#[from] std::convert::Infallible),
119+
107120
#[error(transparent)]
108121
WasmId(#[from] contract::id::wasm::Error),
122+
109123
#[error(transparent)]
110124
Data(#[from] data::Error),
125+
111126
#[error(transparent)]
112127
Network(#[from] network::Error),
128+
113129
#[error(transparent)]
114130
Wasm(#[from] wasm::Error),
131+
115132
#[error(transparent)]
116133
Locator(#[from] locator::Error),
134+
117135
#[error(transparent)]
118136
ContractSpec(#[from] contract_spec::Error),
137+
119138
#[error(transparent)]
120139
ArgParse(#[from] arg_parsing::Error),
140+
121141
#[error("Only ed25519 accounts are allowed")]
122142
OnlyEd25519AccountsAllowed,
143+
144+
#[error(transparent)]
145+
Fee(#[from] fetch::fee::Error),
146+
147+
#[error(transparent)]
148+
Fetch(#[from] fetch::Error),
123149
}
124150

125151
impl Cmd {
@@ -282,21 +308,22 @@ impl NetworkRunnable for Cmd {
282308

283309
print.infoln("Simulating deploy transaction…");
284310

285-
let txn =
311+
let assembled =
286312
simulate_and_assemble_transaction(&client, &txn, self.fee.resource_config()).await?;
287-
let txn = Box::new(self.fee.apply_to_assembled_txn(txn).transaction().clone());
313+
let assembled = self.fee.apply_to_assembled_txn(assembled);
314+
315+
let txn = Box::new(assembled.transaction().clone());
288316

289317
print.log_transaction(&txn, &network, true)?;
290318
let signed_txn = &config.sign(*txn).await?;
291319
print.globeln("Submitting deploy transaction…");
292320

293-
let get_txn_resp = client
294-
.send_transaction_polling(signed_txn)
295-
.await?
296-
.try_into()?;
321+
let get_txn_resp = client.send_transaction_polling(signed_txn).await?;
322+
323+
self.fee.print_cost_info(&get_txn_resp)?;
297324

298325
if global_args.is_none_or(|a| !a.no_cache) {
299-
data::write(get_txn_resp, &network.rpc_uri()?)?;
326+
data::write(get_txn_resp.clone().try_into()?, &network.rpc_uri()?)?;
300327
}
301328

302329
if let Some(url) = utils::explorer_url_for_contract(&network, &contract_id) {

cmd/soroban-cli/src/commands/contract/extend.rs

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::{
1414
};
1515
use clap::{command, Parser};
1616

17+
use crate::commands::tx::fetch;
1718
use crate::{
1819
assembled::simulate_and_assemble_transaction,
1920
commands::{
@@ -31,13 +32,17 @@ pub struct Cmd {
3132
/// Number of ledgers to extend the entries
3233
#[arg(long, required = true)]
3334
pub ledgers_to_extend: u32,
35+
3436
/// Only print the new Time To Live ledger
3537
#[arg(long)]
3638
pub ttl_ledger_only: bool,
39+
3740
#[command(flatten)]
3841
pub key: key::Args,
42+
3943
#[command(flatten)]
4044
pub config: config::Args,
45+
4146
#[command(flatten)]
4247
pub fee: crate::fee::Args,
4348
}
@@ -64,37 +69,57 @@ pub enum Error {
6469
key: String,
6570
error: soroban_spec_tools::Error,
6671
},
72+
6773
#[error("parsing XDR key {key}: {error}")]
6874
CannotParseXdrKey { key: String, error: XdrError },
6975

7076
#[error(transparent)]
7177
Config(#[from] config::Error),
78+
7279
#[error("either `--key` or `--key-xdr` are required")]
7380
KeyIsRequired,
81+
7482
#[error("xdr processing error: {0}")]
7583
Xdr(#[from] XdrError),
84+
7685
#[error("Ledger entry not found")]
7786
LedgerEntryNotFound,
87+
7888
#[error("missing operation result")]
7989
MissingOperationResult,
90+
8091
#[error(transparent)]
8192
Rpc(#[from] rpc::Error),
93+
8294
#[error(transparent)]
8395
Wasm(#[from] wasm::Error),
96+
8497
#[error(transparent)]
8598
Key(#[from] key::Error),
99+
86100
#[error(transparent)]
87101
Data(#[from] data::Error),
102+
88103
#[error(transparent)]
89104
Network(#[from] network::Error),
105+
90106
#[error(transparent)]
91107
Locator(#[from] locator::Error),
108+
92109
#[error(transparent)]
93110
IntError(#[from] TryFromIntError),
111+
94112
#[error("Failed to fetch state archival settings from network")]
95113
StateArchivalSettingsNotFound,
114+
96115
#[error("Ledgers to extend ({requested}) exceeds network maximum ({max})")]
97116
LedgersToExtendTooLarge { requested: u32, max: u32 },
117+
118+
#[error(transparent)]
119+
Fee(#[from] fetch::fee::Error),
120+
121+
#[error(transparent)]
122+
Fetch(#[from] fetch::Error),
98123
}
99124

100125
impl Cmd {
@@ -210,13 +235,15 @@ impl NetworkRunnable for Cmd {
210235
if self.fee.build_only {
211236
return Ok(TxnResult::Txn(tx));
212237
}
213-
let tx = simulate_and_assemble_transaction(&client, &tx, self.fee.resource_config())
214-
.await?
215-
.transaction()
216-
.clone();
238+
let assembled =
239+
simulate_and_assemble_transaction(&client, &tx, self.fee.resource_config()).await?;
240+
241+
let tx = assembled.transaction().clone();
217242
let res = client
218243
.send_transaction_polling(&config.sign(tx).await?)
219244
.await?;
245+
self.fee.print_cost_info(&res)?;
246+
220247
if args.is_none_or(|a| !a.no_cache) {
221248
data::write(res.clone().try_into()?, &network.rpc_uri()?)?;
222249
}

0 commit comments

Comments
 (0)