Contracts: make_outputs takes nanogrin amounts (Vec<u64>), not a string

OutputSelectionArgs.make_outputs was a comma-separated grin string parsed inside
libwallet via amount_from_hr_string. Move that parsing to the CLI boundary and
carry explicit nanogrin u64 amounts through the API and Context instead:
- OutputSelectionArgs.make_outputs: Option<String> -> Option<Vec<u64>>;
  output_amounts() becomes a plain accessor, num_custom_outputs() uses len().
- The CLI (wallet_args) parses grin -> nanogrin per amount; ContractNewArgs and
  ContractSetupArgs carry Vec<u64> and copy it through.
- Update the two tests that supplied make_outputs as a string.

Addresses PR #754 review (types.rs, wallet_args.rs).
This commit is contained in:
jwinterm
2026-06-10 14:18:50 -04:00
parent 3fba1319fb
commit f13ea7f01f
5 changed files with 33 additions and 45 deletions
+6 -12
View File
@@ -1636,8 +1636,8 @@ pub struct ContractNewArgs {
pub as_json: bool,
/// Use the specified inputs (comma separated input commitments)
pub use_inputs: Option<String>,
/// How to separate outputs (command separated amounts)
pub make_outputs: Option<String>,
/// Output amounts in nanogrin (one entry per output)
pub make_outputs: Option<Vec<u64>>,
// Future features
/// Custom fee contribution
@@ -1679,10 +1679,7 @@ impl ContractNewArgs {
Some(v) => Some(v.to_string()),
None => None,
},
make_outputs: match self.make_outputs.as_ref() {
Some(v) => Some(v.to_string()),
None => None,
},
make_outputs: self.make_outputs.clone(),
..Default::default()
},
proof_args: Default::default(),
@@ -1734,8 +1731,8 @@ pub struct ContractSetupArgs {
pub as_json: bool,
/// Use the specified inputs (comma separated input commitments)
pub use_inputs: Option<String>,
/// How to separate outputs (command separated amounts)
pub make_outputs: Option<String>,
/// Output amounts in nanogrin (one entry per output)
pub make_outputs: Option<Vec<u64>>,
// Future features
/// Whether we should automatically sign a receive of any value
@@ -1779,10 +1776,7 @@ impl ContractSetupArgs {
Some(v) => Some(v.to_string()),
None => None,
},
make_outputs: match self.make_outputs.as_ref() {
Some(v) => Some(v.to_string()),
None => None,
},
make_outputs: self.make_outputs.clone(),
..Default::default()
},
..Default::default()
@@ -58,7 +58,14 @@ fn contract_self_spend_custom_tx_impl(test_dir: &'static str) -> Result<(), libw
let selection_args = OutputSelectionArgs {
min_input_confirmation: 0,
use_inputs: Some(use_inputs.clone()), // we will use two coinbase inputs
make_outputs: Some(String::from("88,35,3,0.2,15")), // the sum is such that it will need to pick another input making total of 3 inputs
// the sum is such that it will need to pick another input making total of 3 inputs
make_outputs: Some(vec![
88 * consensus::GRIN_BASE,
35 * consensus::GRIN_BASE,
3 * consensus::GRIN_BASE,
(0.2 * consensus::GRIN_BASE as f64) as u64,
15 * consensus::GRIN_BASE,
]),
};
wallet::controller::owner_single_use(Some(send_wallet.clone()), send_mask, None, |api, m| {
// Send wallet inititates a standard transaction with --send=0