mirror of
https://github.com/jwinterm/grin-wallet.git
synced 2026-10-17 15:21:39 +02:00
Proof of Payment Command Line (#260)
* refactor address generation code into libwallet, bool to flag whether to include proof, add sender address in init_send_tx * rustfmt * require payment proof addr as part of init_tx * rustfmt * store payment proof on sender transaction side * rustfmt * change sig to ed25519 sig * rustfmt * add message creation and signature * rustfmt * add payment proof verification function * rustfmt * validate proof on sender side, store proof * rustfmt * fix json tests * fixes and updates to tests * added API functions for converting and retrieving proof addresses * rustfmt * add payment proof to init_send_tx example * rustfmt * incorrect comment * add commands for requesting payment proofs * rustfmt * wire up payment proofs into command line * rustfmt * add address command * rustfmt * added tor sending from owner api * rustfmt
This commit is contained in:
@@ -21,9 +21,11 @@ use crate::error::{Error, ErrorKind};
|
||||
use crate::impls::{create_sender, KeybaseAllChannels, SlateGetter as _, SlateReceiver as _};
|
||||
use crate::impls::{PathToSlate, SlatePutter};
|
||||
use crate::keychain;
|
||||
use crate::libwallet::{InitTxArgs, IssueInvoiceTxArgs, NodeClient, WalletInst, WalletLCProvider};
|
||||
use crate::libwallet::{
|
||||
address, InitTxArgs, IssueInvoiceTxArgs, NodeClient, WalletInst, WalletLCProvider,
|
||||
};
|
||||
use crate::util::secp::key::SecretKey;
|
||||
use crate::util::{Mutex, ZeroingString};
|
||||
use crate::util::{to_hex, Mutex, ZeroingString};
|
||||
use crate::{controller, display};
|
||||
use serde_json as json;
|
||||
use std::fs::File;
|
||||
@@ -173,6 +175,7 @@ pub fn owner_api<L, C, K>(
|
||||
wallet: Arc<Mutex<Box<dyn WalletInst<'static, L, C, K>>>>,
|
||||
keychain_mask: Option<SecretKey>,
|
||||
config: &WalletConfig,
|
||||
tor_config: &TorConfig,
|
||||
g_args: &GlobalArgs,
|
||||
) -> Result<(), Error>
|
||||
where
|
||||
@@ -190,6 +193,7 @@ where
|
||||
g_args.api_secret.clone(),
|
||||
g_args.tls_conf.clone(),
|
||||
config.owner_api_include_foreign.clone(),
|
||||
Some(tor_config.clone()),
|
||||
);
|
||||
if let Err(e) = res {
|
||||
return Err(ErrorKind::LibWallet(e.kind(), e.cause_string()).into());
|
||||
@@ -254,6 +258,7 @@ pub struct SendArgs {
|
||||
pub fluff: bool,
|
||||
pub max_outputs: usize,
|
||||
pub target_slate_version: Option<u16>,
|
||||
pub payment_proof_address: Option<String>,
|
||||
}
|
||||
|
||||
pub fn send<L, C, K>(
|
||||
@@ -289,6 +294,10 @@ where
|
||||
.collect();
|
||||
display::estimate(args.amount, strategies, dark_scheme);
|
||||
} else {
|
||||
let payment_proof_recipient_address = match args.payment_proof_address {
|
||||
Some(ref p) => Some(address::ed25519_parse_pubkey(p)?),
|
||||
None => None,
|
||||
};
|
||||
let init_args = InitTxArgs {
|
||||
src_acct_name: None,
|
||||
amount: args.amount,
|
||||
@@ -298,6 +307,7 @@ where
|
||||
selection_strategy_is_use_all: args.selection_strategy == "all",
|
||||
message: args.message.clone(),
|
||||
target_slate_version: args.target_slate_version,
|
||||
payment_proof_recipient_address,
|
||||
send_args: None,
|
||||
..Default::default()
|
||||
};
|
||||
@@ -722,6 +732,7 @@ where
|
||||
// should only be one here, but just in case
|
||||
for tx in txs {
|
||||
display::tx_messages(&tx, dark_scheme)?;
|
||||
display::payment_proof(&tx)?;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -874,3 +885,41 @@ where
|
||||
})?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Payment Proof Address
|
||||
pub fn address<L, C, K>(
|
||||
wallet: Arc<Mutex<Box<dyn WalletInst<'static, L, C, K>>>>,
|
||||
g_args: &GlobalArgs,
|
||||
keychain_mask: Option<&SecretKey>,
|
||||
) -> Result<(), Error>
|
||||
where
|
||||
L: WalletLCProvider<'static, C, K> + 'static,
|
||||
C: NodeClient + 'static,
|
||||
K: keychain::Keychain + 'static,
|
||||
{
|
||||
controller::owner_single_use(wallet.clone(), keychain_mask, |api, m| {
|
||||
// Just address at derivation index 0 for now
|
||||
let pub_key = api.get_public_proof_address(m, 0)?;
|
||||
let result = address::onion_v3_from_pubkey(&pub_key);
|
||||
match result {
|
||||
Ok(a) => {
|
||||
println!();
|
||||
println!("Public Proof Address for account - {}", g_args.account);
|
||||
println!("-------------------------------------");
|
||||
println!("{}", to_hex(pub_key.as_bytes().to_vec()));
|
||||
println!();
|
||||
println!("TOR Onion V3 Address for account - {}", g_args.account);
|
||||
println!("-------------------------------------");
|
||||
println!("{}", a);
|
||||
println!();
|
||||
Ok(())
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Addres retrieval failed: {}", e);
|
||||
error!("Backtrace: {}", e.backtrace().unwrap());
|
||||
Err(e)
|
||||
}
|
||||
}
|
||||
})?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
//! Controller for wallet.. instantiates and handles listeners (or single-run
|
||||
//! invocations) as needed.
|
||||
use crate::api::{self, ApiServer, BasicAuthMiddleware, ResponseFuture, Router, TLSConfig};
|
||||
use crate::config::TorConfig;
|
||||
use crate::keychain::Keychain;
|
||||
use crate::libwallet::{
|
||||
address, Error, ErrorKind, NodeClient, NodeVersionInfo, Slate, WalletInst, WalletLCProvider,
|
||||
@@ -168,6 +169,7 @@ pub fn owner_listener<L, C, K>(
|
||||
api_secret: Option<String>,
|
||||
tls_config: Option<TLSConfig>,
|
||||
owner_api_include_foreign: Option<bool>,
|
||||
tor_config: Option<TorConfig>,
|
||||
) -> Result<(), Error>
|
||||
where
|
||||
L: WalletLCProvider<'static, C, K> + 'static,
|
||||
@@ -191,8 +193,12 @@ where
|
||||
}
|
||||
|
||||
let api_handler_v2 = OwnerAPIHandlerV2::new(wallet.clone());
|
||||
let api_handler_v3 =
|
||||
OwnerAPIHandlerV3::new(wallet.clone(), keychain_mask.clone(), running_foreign);
|
||||
let api_handler_v3 = OwnerAPIHandlerV3::new(
|
||||
wallet.clone(),
|
||||
keychain_mask.clone(),
|
||||
tor_config,
|
||||
running_foreign,
|
||||
);
|
||||
|
||||
router
|
||||
.add_route("/v2/owner", Arc::new(api_handler_v2))
|
||||
@@ -593,9 +599,12 @@ where
|
||||
pub fn new(
|
||||
wallet: Arc<Mutex<Box<dyn WalletInst<'static, L, C, K> + 'static>>>,
|
||||
keychain_mask: Arc<Mutex<Option<SecretKey>>>,
|
||||
tor_config: Option<TorConfig>,
|
||||
running_foreign: bool,
|
||||
) -> OwnerAPIHandlerV3<L, C, K> {
|
||||
let owner_api = Arc::new(Owner::new(wallet.clone()));
|
||||
let owner_api = Owner::new(wallet.clone());
|
||||
owner_api.set_tor_config(tor_config);
|
||||
let owner_api = Arc::new(owner_api);
|
||||
OwnerAPIHandlerV3 {
|
||||
wallet,
|
||||
owner_api,
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
use crate::core::core::{self, amount_to_hr_string};
|
||||
use crate::core::global;
|
||||
use crate::libwallet::{
|
||||
AcctPathMapping, Error, OutputCommitMapping, OutputStatus, TxLogEntry, WalletInfo,
|
||||
address, AcctPathMapping, Error, OutputCommitMapping, OutputStatus, TxLogEntry, WalletInfo,
|
||||
};
|
||||
use crate::util;
|
||||
use prettytable;
|
||||
@@ -160,6 +160,7 @@ pub fn txs(
|
||||
bMG->"Amount \nDebited",
|
||||
bMG->"Fee",
|
||||
bMG->"Net \nDifference",
|
||||
bMG->"Payment \nProof",
|
||||
bMG->"Kernel",
|
||||
bMG->"Tx \nData",
|
||||
]);
|
||||
@@ -201,6 +202,10 @@ pub fn txs(
|
||||
Some(e) => util::to_hex(e.0.to_vec()),
|
||||
None => "None".to_owned(),
|
||||
};
|
||||
let payment_proof = match t.payment_proof {
|
||||
Some(_) => "Yes".to_owned(),
|
||||
None => "None".to_owned(),
|
||||
};
|
||||
if dark_background_color_scheme {
|
||||
table.add_row(row![
|
||||
bFC->id,
|
||||
@@ -215,6 +220,7 @@ pub fn txs(
|
||||
bFR->amount_debited_str,
|
||||
bFR->fee,
|
||||
bFY->net_diff,
|
||||
bfG->payment_proof,
|
||||
bFB->kernel_excess,
|
||||
bFb->tx_data,
|
||||
]);
|
||||
@@ -233,6 +239,7 @@ pub fn txs(
|
||||
bFD->amount_debited_str,
|
||||
bFD->fee,
|
||||
bFG->net_diff,
|
||||
bfG->payment_proof,
|
||||
bFB->kernel_excess,
|
||||
bFB->tx_data,
|
||||
]);
|
||||
@@ -250,6 +257,7 @@ pub fn txs(
|
||||
bFD->amount_debited_str,
|
||||
bFD->fee,
|
||||
bFG->net_diff,
|
||||
bfG->payment_proof,
|
||||
bFB->kernel_excess,
|
||||
bFB->tx_data,
|
||||
]);
|
||||
@@ -498,3 +506,73 @@ pub fn tx_messages(tx: &TxLogEntry, dark_background_color_scheme: bool) -> Resul
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Display individual Payment Proof
|
||||
pub fn payment_proof(tx: &TxLogEntry) -> Result<(), Error> {
|
||||
let title = format!("Payment Proof - Transaction '{}'", tx.id,);
|
||||
println!();
|
||||
if term::stdout().is_none() {
|
||||
println!("Could not open terminal");
|
||||
return Ok(());
|
||||
}
|
||||
let mut t = term::stdout().unwrap();
|
||||
t.fg(term::color::MAGENTA).unwrap();
|
||||
writeln!(t, "{}", title).unwrap();
|
||||
t.reset().unwrap();
|
||||
|
||||
let pp = match &tx.payment_proof {
|
||||
None => {
|
||||
writeln!(t, "{}", "None").unwrap();
|
||||
t.reset().unwrap();
|
||||
return Ok(());
|
||||
}
|
||||
Some(p) => p.clone(),
|
||||
};
|
||||
|
||||
t.fg(term::color::WHITE).unwrap();
|
||||
writeln!(t).unwrap();
|
||||
let receiver_address = util::to_hex(pp.receiver_address.to_bytes().to_vec());
|
||||
let receiver_onion_address = address::onion_v3_from_pubkey(&pp.receiver_address)?;
|
||||
let receiver_signature = match pp.receiver_signature {
|
||||
Some(s) => util::to_hex(s.to_bytes().to_vec()),
|
||||
None => "None".to_owned(),
|
||||
};
|
||||
let fee = match tx.fee {
|
||||
Some(f) => f,
|
||||
None => 0,
|
||||
};
|
||||
let amount = if tx.amount_credited >= tx.amount_debited {
|
||||
core::amount_to_hr_string(tx.amount_credited - tx.amount_debited, true)
|
||||
} else {
|
||||
format!(
|
||||
"{}",
|
||||
core::amount_to_hr_string(tx.amount_debited - tx.amount_credited - fee, true)
|
||||
)
|
||||
};
|
||||
|
||||
let sender_address = util::to_hex(pp.sender_address.to_bytes().to_vec());
|
||||
let sender_onion_address = address::onion_v3_from_pubkey(&pp.sender_address)?;
|
||||
let sender_signature = match pp.sender_signature {
|
||||
Some(s) => util::to_hex(s.to_bytes().to_vec()),
|
||||
None => "None".to_owned(),
|
||||
};
|
||||
let kernel_excess = match tx.kernel_excess {
|
||||
Some(e) => util::to_hex(e.0.to_vec()),
|
||||
None => "None".to_owned(),
|
||||
};
|
||||
|
||||
writeln!(t, "Receiver Address: {}", receiver_address).unwrap();
|
||||
writeln!(t, "Receiver Address (Onion V3): {}", receiver_onion_address).unwrap();
|
||||
writeln!(t, "Receiver Signature: {}", receiver_signature).unwrap();
|
||||
writeln!(t, "Amount: {}", amount).unwrap();
|
||||
writeln!(t, "Kernel Excess: {}", kernel_excess).unwrap();
|
||||
writeln!(t, "Sender Address: {}", sender_address).unwrap();
|
||||
writeln!(t, "Sender Signature: {}", sender_signature).unwrap();
|
||||
writeln!(t, "Sender Address (Onion V3): {}", sender_onion_address).unwrap();
|
||||
|
||||
t.reset().unwrap();
|
||||
|
||||
println!();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user