Skip to content

Commit

Permalink
Merge pull request #109 from EpicCash/from-to-address
Browse files Browse the repository at this point in the history
Add a From/To address field in wallet db
  • Loading branch information
who-biz authored Feb 27, 2024
2 parents b8ba3c9 + 41f3e04 commit a11157c
Show file tree
Hide file tree
Showing 35 changed files with 245 additions and 199 deletions.
4 changes: 3 additions & 1 deletion api/src/foreign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ where
foreign::verify_slate_messages(slate)
}

/// Recieve a tranaction created by another party, returning the modified
/// Receive a transaction created by another party, returning the modified
/// [`Slate`](../epic_wallet_libwallet/slate/struct.Slate.html) object, modified with
/// the recipient's output for the transaction amount, and public signature data. This slate can
/// then be sent back to the sender to finalize the transaction via the
Expand Down Expand Up @@ -409,12 +409,14 @@ where
Some(slate),
)?;
}

foreign::receive_tx(
&mut **w,
(&self.keychain_mask).as_ref(),
slate,
dest_acct_name,
message,
None,
self.doctest_mode,
)
}
Expand Down
17 changes: 9 additions & 8 deletions api/src/foreign_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,14 @@ pub trait ForeignRpc {
"id": 1,
"params": [
{
"version_info": {
"version": 2,
"orig_version": 2,
"block_header_version": 6
},
"num_participants": 2,
"id": "0436430c-2b02-624c-2032-570501212b00",
"tx": {
"version_info": {
"version": 2,
"orig_version": 2,
"block_header_version": 6
},
"num_participants": 2,
"id": "0436430c-2b02-624c-2032-570501212b00",
"tx": {
"offset": "d202964900000000d302964900000000d402964900000000d502964900000000",
"body": {
"inputs": [
Expand Down Expand Up @@ -271,6 +271,7 @@ pub trait ForeignRpc {
},
null,
"Thanks, Yeastplume"
]
}
# "#
Expand Down
10 changes: 6 additions & 4 deletions api/src/owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,15 +696,15 @@ where
Some(&m) => Some(m.to_owned()),
};
slate = epicbox_channel.send(wallet, km, &slate)?;
self.tx_lock_outputs(keychain_mask, &slate, 0)?;
self.tx_lock_outputs(keychain_mask, &slate, 0, Some(sa.dest))?;
return Ok(slate);
} else {
let comm_adapter = create_sender(&sa.method, &sa.dest, tor_config_lock.clone())
.map_err(|e| Error::GenericError(format!("{}", e)))?;
slate = comm_adapter.send_tx(&slate)?;
}

self.tx_lock_outputs(keychain_mask, &slate, 0)?;
self.tx_lock_outputs(keychain_mask, &slate, 0, Some(sa.dest))?;
let slate = match sa.finalize {
true => self.finalize_tx(keychain_mask, &slate)?,
false => slate,
Expand Down Expand Up @@ -849,6 +849,7 @@ where
/// * `slate` - The transaction [`Slate`](../epic_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.
/// * `addr_to` - An optional receiver address
/// 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 @@ -881,7 +882,7 @@ where
/// // Send slate somehow
/// // ...
/// // Lock our outputs if we're happy the slate was (or is being) sent
/// api_owner.tx_lock_outputs(None, &slate, 0);
/// api_owner.tx_lock_outputs(None, &slate, 0, None);
/// }
/// ```

Expand All @@ -890,10 +891,11 @@ where
keychain_mask: Option<&SecretKey>,
slate: &Slate,
participant_id: usize,
addr_to: Option<String>,
) -> Result<(), Error> {
let mut w_lock = self.wallet_inst.lock();
let w = w_lock.lc_provider()?.wallet_inst()?;
owner::tx_lock_outputs(&mut **w, keychain_mask, slate, participant_id)
owner::tx_lock_outputs(&mut **w, keychain_mask, slate, participant_id, addr_to)
}

/// Finalizes a transaction, after all parties
Expand Down
22 changes: 17 additions & 5 deletions api/src/owner_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,8 @@ pub trait OwnerRpc: Sync + Send {
"block_header_version": 6
}
},
0
0,
""
]
}
# "#
Expand All @@ -751,7 +752,12 @@ pub trait OwnerRpc: Sync + Send {
```
*/
fn tx_lock_outputs(&self, slate: VersionedSlate, participant_id: usize) -> Result<(), Error>;
fn tx_lock_outputs(
&self,
slate: VersionedSlate,
participant_id: usize,
addr_to: Option<String>,
) -> Result<(), Error>;

/**
Networked version of [Owner::finalize_tx](struct.Owner.html#method.finalize_tx).
Expand Down Expand Up @@ -1339,8 +1345,13 @@ where
Ok(VersionedSlate::into_version(out_slate, version))
}

fn tx_lock_outputs(&self, slate: VersionedSlate, participant_id: usize) -> Result<(), Error> {
Owner::tx_lock_outputs(self, None, &Slate::from(slate), participant_id)
fn tx_lock_outputs(
&self,
slate: VersionedSlate,
participant_id: usize,
addr_to: Option<String>,
) -> Result<(), Error> {
Owner::tx_lock_outputs(self, None, &Slate::from(slate), participant_id, addr_to)
}

fn cancel_tx(&self, tx_id: Option<u32>, tx_slate_id: Option<Uuid>) -> Result<(), Error> {
Expand Down Expand Up @@ -1551,14 +1562,15 @@ pub fn run_doctest_owner(
&slate,
None,
None,
None,
true,
)
.unwrap();
w2.close().unwrap();
}
// Spit out slate for input to finalize_tx
if lock_tx {
api_impl::owner::tx_lock_outputs(&mut **w, (&mask2).as_ref(), &slate, 0).unwrap();
api_impl::owner::tx_lock_outputs(&mut **w, (&mask2).as_ref(), &slate, 0, None).unwrap();
}
println!("RECEIPIENT SLATE");
println!("{}", serde_json::to_string_pretty(&slate).unwrap());
Expand Down
6 changes: 5 additions & 1 deletion api/src/owner_rpc_s.rs
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,8 @@ pub trait OwnerRpcS {
"block_header_version": 6
}
},
"participant_id": 0
"participant_id": 0,
"addr_to": "to dest"
}
}
# "#
Expand All @@ -801,6 +802,7 @@ pub trait OwnerRpcS {
token: Token,
slate: VersionedSlate,
participant_id: usize,
addr_to: Option<String>,
) -> Result<(), Error>;

/**
Expand Down Expand Up @@ -2239,12 +2241,14 @@ where
token: Token,
in_slate: VersionedSlate,
participant_id: usize,
addr_to: Option<String>,
) -> Result<(), Error> {
Owner::tx_lock_outputs(
self,
(&token.keychain_mask).as_ref(),
&Slate::from(in_slate),
participant_id,
addr_to,
)
}

Expand Down
16 changes: 8 additions & 8 deletions controller/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,16 +364,16 @@ where
match args.method.as_str() {
"emoji" => {
println!("{}", EmojiSlate().encode(&slate));
api.tx_lock_outputs(m, &slate, 0)?;
api.tx_lock_outputs(m, &slate, 0, Some(args.dest))?;
return Ok(());
}
"file" => {
PathToSlate((&args.dest).into()).put_tx(&slate)?;
api.tx_lock_outputs(m, &slate, 0)?;
api.tx_lock_outputs(m, &slate, 0, Some(args.dest))?;
return Ok(());
}
"self" => {
api.tx_lock_outputs(m, &slate, 0)?;
api.tx_lock_outputs(m, &slate, 0, Some(args.dest.clone()))?;
let km = match keychain_mask.as_ref() {
None => None,
Some(&m) => Some(m.to_owned()),
Expand All @@ -393,15 +393,15 @@ where
};
slate = epicbox_channel.send(wallet, km, &slate)?;

api.tx_lock_outputs(m, &slate, 0)?;
api.tx_lock_outputs(m, &slate, 0, Some(args.dest))?;

return Ok(());
}
method => {
let sender = create_sender(method, &args.dest, tor_config)?;

slate = sender.send_tx(&slate)?;
api.tx_lock_outputs(m, &slate, 0)?;
api.tx_lock_outputs(m, &slate, 0, Some(args.dest))?;
}
}

Expand Down Expand Up @@ -684,10 +684,10 @@ where
"file" => {
let slate_putter = PathToSlate((&args.dest).into());
slate_putter.put_tx(&slate)?;
api.tx_lock_outputs(m, &slate, 0)?;
api.tx_lock_outputs(m, &slate, 0, Some(args.dest))?;
}
"self" => {
api.tx_lock_outputs(m, &slate, 0)?;
api.tx_lock_outputs(m, &slate, 0, Some(args.dest))?;
let km = match keychain_mask.as_ref() {
None => None,
Some(&m) => Some(m.to_owned()),
Expand All @@ -700,7 +700,7 @@ where
method => {
let sender = create_sender(method, &args.dest, tor_config)?;
slate = sender.send_tx(&slate)?;
api.tx_lock_outputs(m, &slate, 0)?;
api.tx_lock_outputs(m, &slate, 0, Some(args.dest))?;
}
}
}
Expand Down
1 change: 1 addition & 0 deletions controller/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use crate::libwallet::{
address, Error, NodeClient, NodeVersionInfo, Slate, WalletInst, WalletLCProvider,
EPIC_BLOCK_HEADER_VERSION,
};

use crate::util::secp::key::SecretKey;
use crate::util::{from_hex, static_secp_instance, to_base64, Mutex};

Expand Down
10 changes: 10 additions & 0 deletions controller/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ pub fn txs(
bMG->"Type",
bMG->"Shared Transaction Id",
bMG->"Creation Time",
bMG->"From/To Address",
bMG->"TTL Cutoff Height",
bMG->"Confirmed?",
bMG->"Confirmation Time",
Expand Down Expand Up @@ -211,12 +212,19 @@ pub fn txs(
Some(_) => "Yes".to_owned(),
None => "None".to_owned(),
};

let public_addr = match t.public_addr.clone() {
Some(addr) => addr,
None => "None".to_owned(),
};

if dark_background_color_scheme {
table.add_row(row![
bFC->id,
bFC->entry_type,
bFC->slate_id,
bFB->creation_ts,
bFB->public_addr,
bFB->ttl_cutoff_height,
bFC->confirmed,
bFB->confirmation_ts,
Expand All @@ -237,6 +245,7 @@ pub fn txs(
bFb->entry_type,
bFD->slate_id,
bFB->creation_ts,
bFB->public_addr,
bFg->confirmed,
bFB->confirmation_ts,
bFD->num_inputs,
Expand All @@ -255,6 +264,7 @@ pub fn txs(
bFb->entry_type,
bFD->slate_id,
bFB->creation_ts,
bFB->public_addr,
bFR->confirmed,
bFB->confirmation_ts,
bFD->num_inputs,
Expand Down
2 changes: 1 addition & 1 deletion controller/tests/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ fn accounts_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
};
let mut slate = api.init_send_tx(m, args)?;
slate = client1.send_tx_slate_direct("wallet2", &slate)?;
api.tx_lock_outputs(m, &slate, 0)?;
api.tx_lock_outputs(m, &slate, 0, None)?;

slate = api.finalize_tx(m, &slate)?;

Expand Down
2 changes: 1 addition & 1 deletion controller/tests/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ fn scan_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
// output tx file
let send_file = format!("{}/part_tx_1.tx", test_dir);
PathToSlate(send_file.into()).put_tx(&slate)?;
api.tx_lock_outputs(m, &slate, 0)?;
api.tx_lock_outputs(m, &slate, 0, None)?;
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 @@ -122,7 +122,7 @@ fn file_exchange_test_impl(test_dir: &'static str) -> Result<(), libwallet::Erro
let mut slate = api.init_send_tx(m, args)?;
// output tx file
PathToSlate((&send_file).into()).put_tx(&mut slate)?;
api.tx_lock_outputs(m, &slate, 0)?;
api.tx_lock_outputs(m, &slate, 0, None)?;
Ok(())
})?;

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

Expand Down Expand Up @@ -186,7 +186,7 @@ fn invoice_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
..Default::default()
};
slate = api.process_invoice_tx(m, &slate, args)?;
api.tx_lock_outputs(m, &slate, 0)?;
api.tx_lock_outputs(m, &slate, 0, None)?;
Ok(())
})?;

Expand Down
4 changes: 2 additions & 2 deletions controller/tests/no_change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ fn no_change_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
};
slate = api.init_send_tx(m, args)?;
slate = client1.send_tx_slate_direct("wallet2", &slate)?;
api.tx_lock_outputs(m, &slate, 0)?;
api.tx_lock_outputs(m, &slate, 0, None)?;
slate = api.finalize_tx(m, &slate)?;
api.post_tx(m, &slate.tx, false)?;
Ok(())
Expand Down Expand Up @@ -126,7 +126,7 @@ fn no_change_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
..Default::default()
};
slate = api.process_invoice_tx(m, &slate, args)?;
api.tx_lock_outputs(m, &slate, 0)?;
api.tx_lock_outputs(m, &slate, 0, None)?;
Ok(())
})?;

Expand Down
2 changes: 1 addition & 1 deletion controller/tests/payment_proofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ fn payment_proofs_test_impl(test_dir: &'static str) -> Result<(), libwallet::Err
assert_eq!(0, slate.lock_height);

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

// Ensure what's stored in TX log for payment proof is correct
let (_, txs) = sender_api.retrieve_txs(m, true, None, Some(slate.id))?;
Expand Down
4 changes: 2 additions & 2 deletions controller/tests/repost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ fn file_repost_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
};
let slate = api.init_send_tx(m, args)?;
PathToSlate((&send_file).into()).put_tx(&slate)?;
api.tx_lock_outputs(m, &slate, 0)?;
api.tx_lock_outputs(m, &slate, 0, None)?;
Ok(())
})?;

Expand Down Expand Up @@ -210,7 +210,7 @@ fn file_repost_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
};
let slate_i = sender_api.init_send_tx(m, args)?;
slate = client1.send_tx_slate_direct("wallet2", &slate_i)?;
sender_api.tx_lock_outputs(m, &slate, 0)?;
sender_api.tx_lock_outputs(m, &slate, 0, None)?;
slate = sender_api.finalize_tx(m, &mut slate)?;
Ok(())
})?;
Expand Down
Loading

0 comments on commit a11157c

Please sign in to comment.