Skip to content

Commit

Permalink
Add participant ID as part of key to stored private transaction conte…
Browse files Browse the repository at this point in the history
…xt data (mimblewimble#117)

* add participant_id to saved tranasction context data

* rustfmt?

* change participant id for command line pay command
  • Loading branch information
yeastplume authored May 23, 2019
1 parent db818ac commit 85b55f5
Show file tree
Hide file tree
Showing 19 changed files with 144 additions and 59 deletions.
20 changes: 11 additions & 9 deletions api/src/owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ where
/// // Send slate somehow
/// // ...
/// // Lock our outputs if we're happy the slate was (or is being) sent
/// api_owner.tx_lock_outputs(&slate);
/// api_owner.tx_lock_outputs(&slate, 0);
/// }
/// ```

Expand Down Expand Up @@ -513,7 +513,7 @@ where
))?;
}
}
self.tx_lock_outputs(&slate)?;
self.tx_lock_outputs(&slate, 0)?;
let slate = match sa.finalize {
true => self.finalize_tx(&slate)?,
false => slate,
Expand Down Expand Up @@ -645,6 +645,8 @@ where
///
/// # Arguments
/// * `slate` - The transaction [`Slate`](../grin_wallet_libwallet/slate/struct.Slate.html). All
/// * `participant_id` - The participant id, generally 0 for the party putting in funds, 1 for the
/// party receiving.
/// elements in the `input` vector of the `tx` field that are found in the wallet's currently
/// active account will be set to status `Locked`
///
Expand Down Expand Up @@ -676,14 +678,14 @@ where
/// // Send slate somehow
/// // ...
/// // Lock our outputs if we're happy the slate was (or is being) sent
/// api_owner.tx_lock_outputs(&slate);
/// api_owner.tx_lock_outputs(&slate, 0);
/// }
/// ```

pub fn tx_lock_outputs(&self, slate: &Slate) -> Result<(), Error> {
pub fn tx_lock_outputs(&self, slate: &Slate, participant_id: usize) -> Result<(), Error> {
let mut w = self.wallet.lock();
w.open_with_credentials()?;
let res = owner::tx_lock_outputs(&mut *w, slate);
let res = owner::tx_lock_outputs(&mut *w, slate, participant_id);
w.close()?;
res
}
Expand Down Expand Up @@ -734,7 +736,7 @@ where
/// // Send slate somehow
/// // ...
/// // Lock our outputs if we're happy the slate was (or is being) sent
/// let res = api_owner.tx_lock_outputs(&slate);
/// let res = api_owner.tx_lock_outputs(&slate, 0);
/// //
/// // Retrieve slate back from recipient
/// //
Expand Down Expand Up @@ -791,7 +793,7 @@ where
/// // Send slate somehow
/// // ...
/// // Lock our outputs if we're happy the slate was (or is being) sent
/// let res = api_owner.tx_lock_outputs(&slate);
/// let res = api_owner.tx_lock_outputs(&slate, 0);
/// //
/// // Retrieve slate back from recipient
/// //
Expand Down Expand Up @@ -852,7 +854,7 @@ where
/// // Send slate somehow
/// // ...
/// // Lock our outputs if we're happy the slate was (or is being) sent
/// let res = api_owner.tx_lock_outputs(&slate);
/// let res = api_owner.tx_lock_outputs(&slate, 0);
/// //
/// // We didn't get the slate back, or something else went wrong
/// //
Expand Down Expand Up @@ -945,7 +947,7 @@ where
/// // Send slate somehow
/// // ...
/// // Lock our outputs if we're happy the slate was (or is being) sent
/// let res = api_owner.tx_lock_outputs(&slate);
/// let res = api_owner.tx_lock_outputs(&slate, 0);
/// //
/// // Retrieve slate back from recipient
/// //
Expand Down
11 changes: 6 additions & 5 deletions api/src/owner_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,8 @@ pub trait OwnerRpc {
"orig_version": 2,
"version": 2
}
}
},
0
]
}
# "#
Expand All @@ -708,7 +709,7 @@ pub trait OwnerRpc {
```
*/
fn tx_lock_outputs(&self, slate: Slate) -> Result<(), ErrorKind>;
fn tx_lock_outputs(&self, slate: Slate, participant_id: usize) -> Result<(), ErrorKind>;

/**
Networked version of [Owner::finalize_tx](struct.Owner.html#method.finalize_tx).
Expand Down Expand Up @@ -1293,8 +1294,8 @@ where
Owner::finalize_tx(self, &mut slate).map_err(|e| e.kind())
}

fn tx_lock_outputs(&self, mut slate: Slate) -> Result<(), ErrorKind> {
Owner::tx_lock_outputs(self, &mut slate).map_err(|e| e.kind())
fn tx_lock_outputs(&self, mut slate: Slate, participant_id: usize) -> Result<(), ErrorKind> {
Owner::tx_lock_outputs(self, &mut slate, participant_id).map_err(|e| e.kind())
}

fn cancel_tx(&self, tx_id: Option<u32>, tx_slate_id: Option<Uuid>) -> Result<(), ErrorKind> {
Expand Down Expand Up @@ -1420,7 +1421,7 @@ pub fn run_doctest_owner(
// Spit out slate for input to finalize_tx
println!("{}", serde_json::to_string_pretty(&slate).unwrap());
if lock_tx {
api_impl::owner::tx_lock_outputs(&mut *w, &slate).unwrap();
api_impl::owner::tx_lock_outputs(&mut *w, &slate, 0).unwrap();
}
if finalize_tx {
api_impl::owner::finalize_tx(&mut *w, &slate).unwrap();
Expand Down
8 changes: 4 additions & 4 deletions controller/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ pub fn send(
};
if adapter.supports_sync() {
slate = adapter.send_tx_sync(&args.dest, &slate)?;
api.tx_lock_outputs(&slate)?;
api.tx_lock_outputs(&slate, 0)?;
if args.method == "self" {
controller::foreign_single_use(wallet, |api| {
slate = api.receive_tx(&slate, Some(&args.dest), None)?;
Expand All @@ -314,7 +314,7 @@ pub fn send(
slate = api.finalize_tx(&slate)?;
} else {
adapter.send_tx_async(&args.dest, &slate)?;
api.tx_lock_outputs(&slate)?;
api.tx_lock_outputs(&slate, 0)?;
}
if adapter.supports_sync() {
let result = api.post_tx(&slate.tx, args.fluff);
Expand Down Expand Up @@ -536,7 +536,7 @@ pub fn process_invoice(
};
if adapter.supports_sync() {
slate = adapter.send_tx_sync(&args.dest, &slate)?;
api.tx_lock_outputs(&slate)?;
api.tx_lock_outputs(&slate, 0)?;
if args.method == "self" {
controller::foreign_single_use(wallet, |api| {
slate = api.finalize_invoice_tx(&slate)?;
Expand All @@ -545,7 +545,7 @@ pub fn process_invoice(
}
} else {
adapter.send_tx_async(&args.dest, &slate)?;
api.tx_lock_outputs(&slate)?;
api.tx_lock_outputs(&slate, 0)?;
}
}
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion controller/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ where
))?;
}
}
api.tx_lock_outputs(&slate)?;
api.tx_lock_outputs(&slate, 0)?;
if args.method != "file" {
slate = api.finalize_tx(&slate)?;
}
Expand Down
2 changes: 1 addition & 1 deletion controller/tests/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ fn accounts_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
};
let mut slate = api.init_send_tx(args)?;
slate = client1.send_tx_slate_direct("wallet2", &slate)?;
api.tx_lock_outputs(&slate)?;
api.tx_lock_outputs(&slate, 0)?;
slate = api.finalize_tx(&slate)?;
api.post_tx(&slate.tx, false)?;
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion controller/tests/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ fn check_repair_impl(test_dir: &str) -> Result<(), libwallet::Error> {
let file_adapter = FileWalletCommAdapter::new();
let send_file = format!("{}/part_tx_1.tx", test_dir);
file_adapter.send_tx_async(&send_file, &mut slate)?;
api.tx_lock_outputs(&slate)?;
api.tx_lock_outputs(&slate, 0)?;
Ok(())
})?;

Expand Down
2 changes: 1 addition & 1 deletion controller/tests/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ fn file_exchange_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
// output tx file
let file_adapter = FileWalletCommAdapter::new();
file_adapter.send_tx_async(&send_file, &mut slate)?;
api.tx_lock_outputs(&slate)?;
api.tx_lock_outputs(&slate, 0)?;
Ok(())
})?;

Expand Down
42 changes: 38 additions & 4 deletions controller/tests/invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ fn invoice_tx_impl(test_dir: &str) -> Result<(), libwallet::Error> {
..Default::default()
};
slate = api.process_invoice_tx(&slate, args)?;
api.tx_lock_outputs(&slate)?;
api.tx_lock_outputs(&slate, 0)?;
Ok(())
})?;

Expand Down Expand Up @@ -160,9 +160,6 @@ fn invoice_tx_impl(test_dir: &str) -> Result<(), libwallet::Error> {
Ok(())
})?;

// let logging finish
thread::sleep(Duration::from_millis(200));

// Check transaction log for wallet 1, ensure only 1 entry
// exists
wallet::controller::owner_single_use(wallet1.clone(), |api| {
Expand All @@ -176,7 +173,44 @@ fn invoice_tx_impl(test_dir: &str) -> Result<(), libwallet::Error> {
);
Ok(())
})?;

// Test self-sending
wallet::controller::owner_single_use(wallet1.clone(), |api| {
// Wallet 1 inititates an invoice transaction, requesting payment
let args = IssueInvoiceTxArgs {
amount: reward * 2,
..Default::default()
};
slate = api.issue_invoice_tx(args)?;
// Wallet 1 receives the invoice transaction
let args = InitTxArgs {
src_acct_name: None,
amount: slate.amount,
minimum_confirmations: 2,
max_outputs: 500,
num_change_outputs: 1,
selection_strategy_is_use_all: true,
..Default::default()
};
slate = api.process_invoice_tx(&slate, args)?;
api.tx_lock_outputs(&slate, 0)?;
Ok(())
})?;

// wallet 1 finalizes and posts
wallet::controller::foreign_single_use(wallet1.clone(), |api| {
// Wallet 2 receives the invoice transaction
slate = api.finalize_invoice_tx(&slate)?;
Ok(())
})?;

let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 3, false);
//bh += 3;

// let logging finish
thread::sleep(Duration::from_millis(200));
}

teardown(test_dir);
Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions controller/tests/repost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ fn file_repost_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
// output tx file
let file_adapter = FileWalletCommAdapter::new();
file_adapter.send_tx_async(&send_file, &mut slate)?;
api.tx_lock_outputs(&slate)?;
api.tx_lock_outputs(&slate, 0)?;
Ok(())
})?;

Expand Down Expand Up @@ -211,7 +211,7 @@ fn file_repost_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
};
let slate_i = sender_api.init_send_tx(args)?;
slate = client1.send_tx_slate_direct("wallet2", &slate_i)?;
sender_api.tx_lock_outputs(&slate)?;
sender_api.tx_lock_outputs(&slate, 0)?;
slate = sender_api.finalize_tx(&mut slate)?;
Ok(())
})?;
Expand Down
8 changes: 4 additions & 4 deletions controller/tests/restore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ fn setup_restore(test_dir: &str) -> Result<(), libwallet::Error> {
};
let slate_i = sender_api.init_send_tx(args)?;
slate = client1.send_tx_slate_direct("wallet2", &slate_i)?;
sender_api.tx_lock_outputs(&slate)?;
sender_api.tx_lock_outputs(&slate, 0)?;
slate = sender_api.finalize_tx(&slate)?;
sender_api.post_tx(&slate.tx, false)?;
Ok(())
Expand All @@ -270,7 +270,7 @@ fn setup_restore(test_dir: &str) -> Result<(), libwallet::Error> {
};
let slate_i = sender_api.init_send_tx(args)?;
slate = client1.send_tx_slate_direct("wallet3", &slate_i)?;
sender_api.tx_lock_outputs(&slate)?;
sender_api.tx_lock_outputs(&slate, 0)?;
slate = sender_api.finalize_tx(&slate)?;
sender_api.post_tx(&slate.tx, false)?;
Ok(())
Expand All @@ -293,7 +293,7 @@ fn setup_restore(test_dir: &str) -> Result<(), libwallet::Error> {
};
let slate_i = sender_api.init_send_tx(args)?;
slate = client3.send_tx_slate_direct("wallet2", &slate_i)?;
sender_api.tx_lock_outputs(&slate)?;
sender_api.tx_lock_outputs(&slate, 0)?;
slate = sender_api.finalize_tx(&slate)?;
sender_api.post_tx(&slate.tx, false)?;
Ok(())
Expand Down Expand Up @@ -322,7 +322,7 @@ fn setup_restore(test_dir: &str) -> Result<(), libwallet::Error> {
};
let slate_i = sender_api.init_send_tx(args)?;
slate = client3.send_tx_slate_direct("wallet2", &slate_i)?;
sender_api.tx_lock_outputs(&slate)?;
sender_api.tx_lock_outputs(&slate, 0)?;
slate = sender_api.finalize_tx(&slate)?;
sender_api.post_tx(&slate.tx, false)?;
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion controller/tests/self_send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ fn self_send_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
..Default::default()
};
let mut slate = api.init_send_tx(args)?;
api.tx_lock_outputs(&slate)?;
api.tx_lock_outputs(&slate, 0)?;
// Send directly to self
wallet::controller::foreign_single_use(wallet1.clone(), |api| {
slate = api.receive_tx(&slate, Some("listener"), None)?;
Expand Down
6 changes: 3 additions & 3 deletions controller/tests/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ fn basic_transaction_api(test_dir: &str) -> Result<(), libwallet::Error> {
assert_eq!(0, slate.lock_height);

slate = client1.send_tx_slate_direct("wallet2", &slate_i)?;
sender_api.tx_lock_outputs(&slate)?;
sender_api.tx_lock_outputs(&slate, 0)?;
slate = sender_api.finalize_tx(&slate)?;

// Check we have a single kernel and that it is a Plain kernel (no lock_height).
Expand Down Expand Up @@ -297,7 +297,7 @@ fn basic_transaction_api(test_dir: &str) -> Result<(), libwallet::Error> {
};
let slate_i = sender_api.init_send_tx(args)?;
slate = client1.send_tx_slate_direct("wallet2", &slate_i)?;
sender_api.tx_lock_outputs(&slate)?;
sender_api.tx_lock_outputs(&slate, 0)?;
slate = sender_api.finalize_tx(&slate)?;
Ok(())
})?;
Expand Down Expand Up @@ -397,7 +397,7 @@ fn tx_rollback(test_dir: &str) -> Result<(), libwallet::Error> {

let slate_i = sender_api.init_send_tx(args)?;
slate = client1.send_tx_slate_direct("wallet2", &slate_i)?;
sender_api.tx_lock_outputs(&slate)?;
sender_api.tx_lock_outputs(&slate, 0)?;
slate = sender_api.finalize_tx(&slate)?;
Ok(())
})?;
Expand Down
Loading

0 comments on commit 85b55f5

Please sign in to comment.