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
+10 -8
View File
@@ -1020,12 +1020,13 @@ pub fn parse_contract_new_args(
};
let make_outputs = match args.value_of("make-outputs") {
Some(v) => {
// Validate each comma-separated amount here so a bad value returns a
// ParseError instead of panicking later in output_amounts().
// Parse each comma-separated grin amount into nanogrin at the CLI boundary,
// so the API and Context carry explicit u64 amounts.
let mut amounts = Vec::new();
for amt in v.split(',') {
parse_grin_amount(amt, "make-outputs")?;
amounts.push(parse_grin_amount(amt, "make-outputs")?);
}
Some(String::from(v))
Some(amounts)
}
None => None,
};
@@ -1096,12 +1097,13 @@ pub fn parse_contract_setup_args(
};
let make_outputs = match args.value_of("make-outputs") {
Some(v) => {
// Validate each comma-separated amount here so a bad value returns a
// ParseError instead of panicking later in output_amounts().
// Parse each comma-separated grin amount into nanogrin at the CLI boundary,
// so the API and Context carry explicit u64 amounts.
let mut amounts = Vec::new();
for amt in v.split(',') {
parse_grin_amount(amt, "make-outputs")?;
amounts.push(parse_grin_amount(amt, "make-outputs")?);
}
Some(String::from(v))
Some(amounts)
}
None => None,
};