Skip to content

Commit

Permalink
[FIXUP] Remove payment proofs from atomic swaps
Browse files Browse the repository at this point in the history
  • Loading branch information
GeneFerneau committed May 26, 2021
1 parent b674b5e commit 40d3ba0
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 160 deletions.
166 changes: 83 additions & 83 deletions api/src/foreign_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub trait ForeignRpc {
}
}
# "#
# ,false, 0, TxFlow::Standard);
# ,false, 0, false, TxFlow::Standard);
```
*/
fn check_version(&self) -> Result<VersionInfo, ErrorKind>;
Expand Down Expand Up @@ -107,7 +107,7 @@ pub trait ForeignRpc {
}
}
# "#
# ,false, 4, TxFlow::Standard);
# ,false, 4, false, TxFlow::Standard);
```
*/

Expand Down Expand Up @@ -182,7 +182,7 @@ pub trait ForeignRpc {
}
}
# "#
# ,false, 5, TxFlow::Standard);
# ,false, 5, true, TxFlow::Standard);
```
*/
fn receive_tx(
Expand Down Expand Up @@ -211,10 +211,6 @@ pub trait ForeignRpc {
"fee": "23500000",
"id": "0436430c-2b02-624c-2032-570501212b00",
"off": "d202964900000000d302964900000000d402964900000000d502964900000000",
"proof": {
"raddr": "32cdd63928854f8b2628b1dce4626ddcdf35d56cb7cfdf7d64cca5822b78d4d3",
"saddr": "32cdd63928854f8b2628b1dce4626ddcdf35d56cb7cfdf7d64cca5822b78d4d3"
},
"sigs": [
{
"nonce": "02b57c1f4fea69a3ee070309cf8f06082022fe06f25a9be1851b56ef0fa18f25d6",
Expand All @@ -237,7 +233,6 @@ pub trait ForeignRpc {
"result": {
"Ok": {
"amt": "6000000000",
"atomic_id": "0",
"coms": [
{
"c": "091582c92b99943b57955e52b5ccf1223780c2a2e55995c00c86fca2bcb46b6b9f",
Expand All @@ -247,31 +242,25 @@ pub trait ForeignRpc {
"fee": "23500000",
"id": "0436430c-2b02-624c-2032-570501212b00",
"off": "a4f88ac429dee1d453ae33ed9f944417a52c7310477936e484fd83f0f22db483",
"proof": {
"raddr": "32cdd63928854f8b2628b1dce4626ddcdf35d56cb7cfdf7d64cca5822b78d4d3",
"rsig": "02357a13b304ba8e22f4896d5664b72ad6d1b824e88782e2b716686ea14ec47281ef5ee14c03ead84c3260f5b0c1529ad3ddae57f28f6b8b1b66532bfcb2ee0f",
"saddr": "32cdd63928854f8b2628b1dce4626ddcdf35d56cb7cfdf7d64cca5822b78d4d3"
},
"sigs": [
{
"nonce": "02b57c1f4fea69a3ee070309cf8f06082022fe06f25a9be1851b56ef0fa18f25d6",
"xs": "023878ce845727f3a4ec76ca3f3db4b38a2d05d636b8c3632108b857fed63c96de"
},
{
"atomic": "03cefcb7f65194418ee236f01638034238a7c996cd73fa9673e0c763eab828f119",
"atomic": "03e1d14f7b440af4944193b0559452651720ecf1847ef0f7092ef7e68414b8d732",
"nonce": "031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f",
"part": "8f07ddd5e9f5179cff19486034181ed76505baaad53e5d994064127b56c5841b1e25843c36d8bdcf87f208666490a16281943a6504209c3ea53fb9f1f7af0cf8",
"part": "8f07ddd5e9f5179cff19486034181ed76505baaad53e5d994064127b56c5841bf9df0f2c4d96d6bb0b2e6e0b94ad6cbbc0e3f9e5582b085b31b5c8bb0e15bd36",
"xs": "02e3c128e436510500616fef3f9a22b15ca015f407c8c5cf96c9059163c873828f"
}
],
"atomic_id": "046d7761746f6d69630000000000000000",
"sta": "A2",
"ver": "4:2"
}
}
}
# "#
# ,false, 5, TxFlow::Atomic);
# ,false, 5, true, TxFlow::Atomic);
```
*/
fn receive_atomic_tx(
Expand Down Expand Up @@ -370,7 +359,7 @@ pub trait ForeignRpc {
}
}
# "#
# ,false, 5, TxFlow::Invoice);
# ,false, 5, true, TxFlow::Invoice);
```
*/
fn finalize_tx(&self, slate: VersionedSlate) -> Result<VersionedSlate, ErrorKind>;
Expand Down Expand Up @@ -451,6 +440,7 @@ pub fn run_doctest_foreign(
test_dir: &str,
use_token: bool,
blocks_to_mine: u64,
do_tx: bool,
tx_flow: TxFlow,
) -> Result<Option<serde_json::Value>, String> {
use easy_jsonrpc_mw::Handler;
Expand Down Expand Up @@ -573,81 +563,84 @@ pub fn run_doctest_foreign(
assert!(wallet_refreshed);
}

match tx_flow {
TxFlow::Invoice => {
let amount = 60_000_000_000;
let mut slate = {
let mut w_lock = wallet2.lock();
if do_tx {
match tx_flow {
TxFlow::Invoice => {
let amount = 60_000_000_000;
let mut slate = {
let mut w_lock = wallet2.lock();
let w = w_lock.lc_provider().unwrap().wallet_inst().unwrap();
let args = IssueInvoiceTxArgs {
amount,
..Default::default()
};
api_impl::owner::issue_invoice_tx(&mut **w, (&mask2).as_ref(), args, true)
.unwrap()
};
slate = {
let mut w_lock = wallet1.lock();
let w = w_lock.lc_provider().unwrap().wallet_inst().unwrap();
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()
};
api_impl::owner::process_invoice_tx(
&mut **w,
(&mask1).as_ref(),
&slate,
args,
true,
)
.unwrap()
};
println!("INIT INVOICE SLATE");
// Spit out slate for input to finalize_tx
println!("{}", serde_json::to_string_pretty(&slate).unwrap());
}
TxFlow::Standard => {
let amount = 60_000_000_000;
let mut w_lock = wallet1.lock();
let w = w_lock.lc_provider().unwrap().wallet_inst().unwrap();
let args = IssueInvoiceTxArgs {
let args = InitTxArgs {
src_acct_name: None,
amount,
minimum_confirmations: 2,
max_outputs: 500,
num_change_outputs: 1,
selection_strategy_is_use_all: true,
..Default::default()
};
api_impl::owner::issue_invoice_tx(&mut **w, (&mask2).as_ref(), args, true).unwrap()
};
slate = {
let slate =
api_impl::owner::init_send_tx(&mut **w, (&mask1).as_ref(), args, true).unwrap();
println!("INIT SLATE");
// Spit out slate for input to finalize_tx
println!("{}", serde_json::to_string_pretty(&slate).unwrap());
}
TxFlow::Atomic => {
let amount = 60_000_000_000;
let mut w_lock = wallet1.lock();
let w = w_lock.lc_provider().unwrap().wallet_inst().unwrap();
let args = InitTxArgs {
src_acct_name: None,
amount: slate.amount,
amount,
minimum_confirmations: 2,
max_outputs: 500,
num_change_outputs: 1,
selection_strategy_is_use_all: true,
..Default::default()
};
api_impl::owner::process_invoice_tx(&mut **w, (&mask1).as_ref(), &slate, args, true)
.unwrap()
};
println!("INIT INVOICE SLATE");
// Spit out slate for input to finalize_tx
println!("{}", serde_json::to_string_pretty(&slate).unwrap());
}
TxFlow::Standard => {
let amount = 60_000_000_000;
let mut w_lock = wallet1.lock();
let w = w_lock.lc_provider().unwrap().wallet_inst().unwrap();
let args = InitTxArgs {
src_acct_name: None,
amount,
minimum_confirmations: 2,
max_outputs: 500,
num_change_outputs: 1,
selection_strategy_is_use_all: true,
..Default::default()
};
let slate =
api_impl::owner::init_send_tx(&mut **w, (&mask1).as_ref(), args, true).unwrap();
println!("INIT SLATE");
// Spit out slate for input to finalize_tx
println!("{}", serde_json::to_string_pretty(&slate).unwrap());
}
TxFlow::Atomic => {
let amount = 60_000_000_000;
let mut w_lock = wallet1.lock();
let w = w_lock.lc_provider().unwrap().wallet_inst().unwrap();
let args = InitTxArgs {
src_acct_name: None,
amount,
minimum_confirmations: 2,
max_outputs: 500,
num_change_outputs: 1,
selection_strategy_is_use_all: true,
..Default::default()
};
let derive_path = 0;
let slate = api_impl::owner::init_atomic_swap(
&mut **w,
(&mask1).as_ref(),
args,
derive_path,
true,
)
.unwrap();
println!("INIT SLATE");
// Spit out slate for input to finalize_tx
println!("{}", serde_json::to_string_pretty(&slate).unwrap());
let slate =
api_impl::owner::init_atomic_swap(&mut **w, (&mask1).as_ref(), args, true)
.unwrap();
println!("INIT SLATE");
// Spit out slate for input to finalize_tx
println!("{}", serde_json::to_string_pretty(&slate).unwrap());
}
}
}

Expand All @@ -667,7 +660,7 @@ pub fn run_doctest_foreign(
#[doc(hidden)]
#[macro_export]
macro_rules! doctest_helper_json_rpc_foreign_assert_response {
($request:expr, $expected_response:expr, $use_token:expr, $blocks_to_mine:expr, $tx_flow:expr) => {
($request:expr, $expected_response:expr, $use_token:expr, $blocks_to_mine:expr, $do_tx:expr, $tx_flow:expr) => {
// create temporary wallet, run jsonrpc request on owner api of wallet, delete wallet, return
// json response.
// In order to prevent leaking tempdirs, This function should not panic.
Expand All @@ -687,9 +680,16 @@ macro_rules! doctest_helper_json_rpc_foreign_assert_response {
let request_val: Value = serde_json::from_str($request).unwrap();
let expected_response: Value = serde_json::from_str($expected_response).unwrap();

let response = run_doctest_foreign(request_val, dir, $use_token, $blocks_to_mine, $tx_flow)
.unwrap()
.unwrap();
let response = run_doctest_foreign(
request_val,
dir,
$use_token,
$blocks_to_mine,
$do_tx,
$tx_flow,
)
.unwrap()
.unwrap();

if response != expected_response {
panic!(
Expand Down
9 changes: 1 addition & 8 deletions api/src/owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -866,18 +866,11 @@ where
&self,
keychain_mask: Option<&SecretKey>,
args: InitTxArgs,
derive_path: u32,
) -> Result<Slate, Error> {
let mut w_lock = self.wallet_inst.lock();
let w = w_lock.lc_provider()?.wallet_inst()?;
let send_args = args.send_args.clone();
let slate = owner::init_atomic_swap(
&mut **w,
keychain_mask,
args,
derive_path,
self.doctest_mode,
)?;
let slate = owner::init_atomic_swap(&mut **w, keychain_mask, args, self.doctest_mode)?;
if let Some(sa) = send_args {
let tor_config_lock = self.tor_config.lock();
let tc = tor_config_lock.clone();
Expand Down
25 changes: 6 additions & 19 deletions api/src/owner_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,8 +619,7 @@ pub trait OwnerRpc {
"payment_proof_recipient_address": "tgrin1xtxavwfgs48ckf3gk8wwgcndmn0nt4tvkl8a7ltyejjcy2mc6nfs9gm2lp",
"ttl_blocks": null,
"send_args": null
},
"derive_path": 0
}
},
"id": 1
}
Expand All @@ -633,14 +632,9 @@ pub trait OwnerRpc {
"result": {
"Ok": {
"amt": "6000000000",
"atomic_id": "046d7761746f6d69630000000000000000",
"fee": "23000000",
"id": "0436430c-2b02-624c-2032-570501212b00",
"off": "456498224e2a6850e073ab8fb5c32fcccfe70272c61759ea4ade53ae7dc367e6",
"proof": {
"raddr": "32cdd63928854f8b2628b1dce4626ddcdf35d56cb7cfdf7d64cca5822b78d4d3",
"saddr": "32cdd63928854f8b2628b1dce4626ddcdf35d56cb7cfdf7d64cca5822b78d4d3"
},
"sigs": [
{
"nonce": "031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f",
Expand All @@ -656,12 +650,8 @@ pub trait OwnerRpc {
# , 4, false, false, false, false, false);
```
*/
fn init_atomic_swap(
&self,
token: Token,
args: InitTxArgs,
derive_path: u32,
) -> Result<VersionedSlate, ErrorKind>;
fn init_atomic_swap(&self, token: Token, args: InitTxArgs)
-> Result<VersionedSlate, ErrorKind>;

/**
Networked version of [Owner::countersign_atomic_swap](struct.Owner.html#method.countersign_atomic_swap).
Expand Down Expand Up @@ -714,7 +704,6 @@ pub trait OwnerRpc {
"result": {
"Ok": {
"amt": "60000000000",
"atomic_id": "046d7761746f6d69630000000000000000",
"coms": [
{
"c": "087df32304c5d4ae8b2af0bc31e700019d722910ef87dd4eec3197b80b207e3045",
Expand Down Expand Up @@ -2000,11 +1989,9 @@ where
&self,
token: Token,
args: InitTxArgs,
derive_path: u32,
) -> Result<VersionedSlate, ErrorKind> {
let out_slate =
Owner::init_atomic_swap(self, (&token.keychain_mask).as_ref(), args, derive_path)
.map_err(|e| e.kind())?;
let out_slate = Owner::init_atomic_swap(self, (&token.keychain_mask).as_ref(), args)
.map_err(|e| e.kind())?;
let version = SlateVersion::V4;
Ok(VersionedSlate::into_version(out_slate, version).map_err(|e| e.kind())?)
}
Expand Down Expand Up @@ -2484,7 +2471,7 @@ pub fn run_doctest_owner(
..Default::default()
};
let mut slate = if countersign_atomic {
api_impl::owner::init_atomic_swap(&mut **w, (&mask1).as_ref(), args, 0, true).unwrap()
api_impl::owner::init_atomic_swap(&mut **w, (&mask1).as_ref(), args, true).unwrap()
} else {
api_impl::owner::init_send_tx(&mut **w, (&mask1).as_ref(), args, true).unwrap()
};
Expand Down
2 changes: 1 addition & 1 deletion api/tests/slate_versioning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fn _receive_versioned_slate() {
let request_val: Value = serde_json::from_str(v1_req).unwrap();
let expected_response: Value = serde_json::from_str(v1_resp).unwrap();

let response = run_doctest_foreign(request_val, dir, false, 5, TxFlow::Standard)
let response = run_doctest_foreign(request_val, dir, false, 5, false, TxFlow::Standard)
.unwrap()
.unwrap();

Expand Down
5 changes: 2 additions & 3 deletions controller/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ where
C: NodeClient + 'static,
K: keychain::Keychain + 'static,
{
let derive_path = args.derive_path.unwrap_or(0);
let mut slate = Slate::blank(2, tx_flow.clone());
controller::owner_single_use(None, keychain_mask, Some(owner_api), |api, m| {
if args.estimate_selection_strategies {
Expand All @@ -295,7 +294,7 @@ where
};
let slate = match tx_flow {
TxFlow::Standard => api.init_send_tx(m, init_args)?,
TxFlow::Atomic => api.init_atomic_swap(m, init_args, derive_path)?,
TxFlow::Atomic => api.init_atomic_swap(m, init_args)?,
_ => api.init_send_tx(m, init_args)?,
};

Expand All @@ -321,7 +320,7 @@ where
};
let result = match tx_flow {
TxFlow::Standard => api.init_send_tx(m, init_args),
TxFlow::Atomic => api.init_atomic_swap(m, init_args, derive_path),
TxFlow::Atomic => api.init_atomic_swap(m, init_args),
_ => api.init_send_tx(m, init_args),
};
slate = match result {
Expand Down
Loading

0 comments on commit 40d3ba0

Please sign in to comment.