mirror of
https://github.com/jwinterm/grin-wallet.git
synced 2026-10-17 07:11:36 +02:00
lock contract selection
This commit is contained in:
+6
-6
@@ -32,12 +32,12 @@ can still receive; the fee is then taken from the received output. `--no-payjoin
|
||||
the receiver from adding an input and cannot be used together with `--use-inputs`.
|
||||
|
||||
Inputs and outputs are normally picked when signing. `--add-outputs` picks and locks them
|
||||
during `new`, but they are still only added to the slate when signing. `--use-inputs` and
|
||||
`--make-outputs` limit the selection but do not lock anything early. Each party chooses
|
||||
`--min_conf` when it first joins and cannot change it later. The same limit is used for the fee
|
||||
estimate, so any required inputs need enough confirmations at that point. A value of `0` allows
|
||||
unconfirmed non-coinbase outputs. Open contracts do not reserve funds, so a late-locked contract
|
||||
can fail if another transaction spends the available outputs first.
|
||||
during `new`. Prepared outputs appear as unconfirmed in the wallet, but are only added to
|
||||
the slate when signing. Using `--use-inputs` or `--make-outputs` during `new` does the same.
|
||||
Each party chooses `--min_conf` when it first joins and cannot change it later. The same limit
|
||||
is used for the fee estimate, so any required inputs need enough confirmations at that point.
|
||||
A value of `0` allows unconfirmed non-coinbase outputs. Open contracts do not reserve funds,
|
||||
so a late-locked contract can fail if another transaction spends the available outputs first.
|
||||
|
||||
## View and revoke
|
||||
|
||||
|
||||
@@ -37,8 +37,6 @@ Separating side effects until the 'save_step' part would make these functions mu
|
||||
|
||||
#### TODOs
|
||||
|
||||
- Decide whether `--use-inputs` or `--make-outputs` should imply early locking; currently
|
||||
only `--add-outputs` locks during `new`.
|
||||
- Reserve funds across open late-locked contracts, or make the possible signing failure
|
||||
clearer to callers.
|
||||
- Handle the coinbase flows. Coinbase inputs are built into the slate, but nothing else
|
||||
|
||||
@@ -1032,7 +1032,6 @@ pub fn parse_contract_new_args(
|
||||
parse_required(args, "minimum_confirmations")?,
|
||||
"minimum_confirmations",
|
||||
)?;
|
||||
let add_outputs = args.is_present("add-outputs");
|
||||
let as_json = args.is_present("as-json");
|
||||
let no_payjoin = args.is_present("no-payjoin");
|
||||
let use_inputs = match args.value_of("use-inputs") {
|
||||
@@ -1065,6 +1064,10 @@ pub fn parse_contract_new_args(
|
||||
}
|
||||
None => None,
|
||||
};
|
||||
// Check the flags because use_inputs also contains the payjoin default.
|
||||
let add_outputs = args.is_present("add-outputs")
|
||||
|| args.is_present("use-inputs")
|
||||
|| args.is_present("make-outputs");
|
||||
|
||||
let num_participants = match args.value_of("num-participants") {
|
||||
Some(v) => v.parse::<u8>().map_err(|e| {
|
||||
|
||||
@@ -257,3 +257,22 @@ fn parses_contract_min_confirmations() {
|
||||
let parsed = grin_wallet::cmd::wallet_args::parse_contract_setup_args(sign_args).unwrap();
|
||||
assert_eq!(parsed.minimum_confirmations, Some(3));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn selection_locks_early() {
|
||||
let yml = load_yaml!("../src/bin/grin-wallet.yml");
|
||||
let app = App::from_yaml(yml);
|
||||
let account = "default".to_string();
|
||||
let parse = |extra: &[&str]| {
|
||||
let mut command = vec!["grin-wallet", "contract", "new", "--send", "1"];
|
||||
command.extend_from_slice(extra);
|
||||
let args = app.clone().get_matches_from_safe(command).unwrap();
|
||||
let contract = args.subcommand_matches("contract").unwrap();
|
||||
let new_args = contract.subcommand_matches("new").unwrap();
|
||||
grin_wallet::cmd::wallet_args::parse_contract_new_args(new_args, &account).unwrap()
|
||||
};
|
||||
|
||||
assert!(!parse(&[]).add_outputs);
|
||||
assert!(parse(&["--use-inputs", "commitment"]).add_outputs);
|
||||
assert!(parse(&["--make-outputs", "1"]).add_outputs);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user