Skip to content

Commit

Permalink
feat: add wallet cli command for utxo creation with aggregate public …
Browse files Browse the repository at this point in the history
…key (#4759)

Description
---
The goal of the current PR is to add a cli command such that a wallet can create a utxo with a spend `CheckMultiSigVerifyAggregatePubKey` script that requires the a m-of-n list of keys to spend.
It should be merged after #4742 and #4751.

Motivation and Context
---
It addresses `Step 2` in the following [MvP](https://demo.hedgedoc.org/rgLUGP_YRiGKjKkgehiG4w#Step-2).

How Has This Been Tested?
---
Unit tests
  • Loading branch information
jorgeantonio21 authored Oct 10, 2022
1 parent 0531da1 commit 8ae6fbd
Show file tree
Hide file tree
Showing 11 changed files with 408 additions and 35 deletions.
1 change: 0 additions & 1 deletion applications/tari_app_grpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,3 @@ zeroize = "1.3"

[build-dependencies]
tonic-build = "0.6.2"

4 changes: 2 additions & 2 deletions applications/tari_console_wallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ tari_p2p = { path = "../../base_layer/p2p", features = ["auto-update"] }
tari_app_grpc = { path = "../tari_app_grpc" }
tari_shutdown = { path = "../../infrastructure/shutdown" }
tari_key_manager = { path = "../../base_layer/key_manager" }
tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.7" }
zeroize = "1.3"
tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag = "v0.4.7" }

# Uncomment for tokio tracing via tokio-console (needs "tracing" featurs)
#console-subscriber = "0.1.3"
Expand Down Expand Up @@ -53,6 +52,7 @@ tracing-opentelemetry = "0.15.0"
tracing-subscriber = "0.2.20"
unicode-segmentation = "1.6.0"
unicode-width = "0.1"
zeroize = "1.3"

# network tracing, rt-tokio for async batch export
opentelemetry = { version = "0.16", default-features = false, features = ["trace", "rt-tokio"] }
Expand Down
47 changes: 46 additions & 1 deletion applications/tari_console_wallet/src/automation/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use std::{
convert::TryInto,
convert::{From, TryInto},
fs,
fs::File,
io,
Expand Down Expand Up @@ -86,6 +86,7 @@ pub enum WalletCommand {
SendTari,
SendOneSided,
CreateKeyPair,
CreateAggregateSignatureUtxo,
MakeItRain,
CoinSplit,
DiscoverPeer,
Expand Down Expand Up @@ -141,6 +142,24 @@ pub async fn burn_tari(
.map_err(CommandError::TransactionServiceError)
}

pub async fn create_aggregate_signature_utxo(
mut wallet_transaction_service: TransactionServiceHandle,
amount: MicroTari,
fee_per_gram: MicroTari,
n: u8,
m: u8,
public_keys: Vec<PublicKey>,
message: String,
) -> Result<(TxId, FixedHash), CommandError> {
let mut msg = [0u8; 32];
msg.copy_from_slice(message.as_bytes());

wallet_transaction_service
.create_aggregate_signature_utxo(amount, fee_per_gram, n, m, public_keys, msg)
.await
.map_err(CommandError::TransactionServiceError)
}

/// publishes a tari-SHA atomic swap HTLC transaction
pub async fn init_sha_atomic_swap(
mut wallet_transaction_service: TransactionServiceHandle,
Expand Down Expand Up @@ -652,6 +671,32 @@ pub async fn command_runner(
},
Err(e) => eprintln!("CreateKeyPair error! {}", e),
},
CreateAggregateSignatureUtxo(args) => match create_aggregate_signature_utxo(
transaction_service.clone(),
args.amount,
args.fee_per_gram,
args.n,
args.m,
args.public_keys
.iter()
.map(|pk| PublicKey::from(pk.clone()))
.collect::<Vec<_>>(),
args.message,
)
.await
{
Ok((tx_id, output_hash)) => {
println!(
"Create a utxo with n-of-m aggregate public key, with:
1. n = {},
2. m = {},
3. tx id = {},
4. output hash = {}",
args.n, args.m, tx_id, output_hash
)
},
Err(e) => eprintln!("CreateAggregateSignatureUtxo error! {}", e),
},
SendTari(args) => {
match send_tari(
transaction_service.clone(),
Expand Down
12 changes: 12 additions & 0 deletions applications/tari_console_wallet/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ pub enum CliCommands {
SendTari(SendTariArgs),
BurnTari(BurnTariArgs),
CreateKeyPair(CreateKeyPairArgs),
CreateAggregateSignatureUtxo(CreateAggregateSignatureUtxoArgs),
SendOneSided(SendTariArgs),
SendOneSidedToStealthAddress(SendTariArgs),
MakeItRain(MakeItRainArgs),
Expand Down Expand Up @@ -161,6 +162,17 @@ pub struct CreateKeyPairArgs {
pub key_branch: String,
}

#[derive(Debug, Args, Clone)]
pub struct CreateAggregateSignatureUtxoArgs {
pub amount: MicroTari,
pub fee_per_gram: MicroTari,
pub n: u8,
pub m: u8,
pub message: String,
#[clap(long)]
pub public_keys: Vec<UniPublicKey>,
}

#[derive(Debug, Args, Clone)]
pub struct MakeItRainArgs {
pub destination: UniPublicKey,
Expand Down
7 changes: 7 additions & 0 deletions applications/tari_console_wallet/src/wallet_modes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,10 @@ mod test {
create-key-pair pie
create-aggregate-signature-utxo 125T 100 10 1 ff \
--public-keys=5c4f2a4b3f3f84e047333218a84fd24f581a9d7e4f23b78e3714e9d174427d61 \
--public-keys=f6b2ca781342a3ebe30ee1643655c96f1d7c14f4d49f077695395de98ae73665
coin-split --message Make_many_dust_UTXOs! --fee-per-gram 2 0.001T 499
make-it-rain --duration 100 --transactions-per-second 10 --start-amount 0.009200T --increase-amount 0T \
Expand All @@ -445,6 +449,7 @@ mod test {
let mut send_tari = false;
let mut burn_tari = false;
let mut create_key_pair = false;
let mut create_aggregate_signature_utxo = false;
let mut make_it_rain = false;
let mut coin_split = false;
let mut discover_peer = false;
Expand All @@ -455,6 +460,7 @@ mod test {
CliCommands::SendTari(_) => send_tari = true,
CliCommands::BurnTari(_) => burn_tari = true,
CliCommands::CreateKeyPair(_) => create_key_pair = true,
CliCommands::CreateAggregateSignatureUtxo(_) => create_aggregate_signature_utxo = true,
CliCommands::SendOneSided(_) => {},
CliCommands::SendOneSidedToStealthAddress(_) => {},
CliCommands::MakeItRain(_) => make_it_rain = true,
Expand All @@ -479,6 +485,7 @@ mod test {
send_tari &&
burn_tari &&
create_key_pair &&
create_aggregate_signature_utxo &&
make_it_rain &&
coin_split &&
discover_peer &&
Expand Down
48 changes: 47 additions & 1 deletion base_layer/wallet/src/transaction_service/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use chacha20poly1305::XChaCha20Poly1305;
use chrono::NaiveDateTime;
use tari_common_types::{
transaction::{ImportStatus, TxId},
types::PublicKey,
types::{FixedHash, PublicKey},
};
use tari_comms::types::CommsPublicKey;
use tari_core::{
Expand Down Expand Up @@ -88,6 +88,14 @@ pub enum TransactionServiceRequest {
fee_per_gram: MicroTari,
message: String,
},
CreateNMUtxo {
amount: MicroTari,
fee_per_gram: MicroTari,
n: u8,
m: u8,
public_keys: Vec<PublicKey>,
message: [u8; 32],
},
SendOneSidedTransaction {
dest_pubkey: CommsPublicKey,
amount: MicroTari,
Expand Down Expand Up @@ -156,6 +164,17 @@ impl fmt::Display for TransactionServiceRequest {
message
)),
Self::BurnTari { amount, message, .. } => f.write_str(&format!("Burning Tari ({}, {})", amount, message)),
Self::CreateNMUtxo {
amount,
fee_per_gram: _,
n,
m,
public_keys: _,
message: _,
} => f.write_str(&format!(
"Creating a new n-of-m aggregate uxto with: amount = {}, n = {}, m = {}",
amount, n, m
)),
Self::SendOneSidedTransaction {
dest_pubkey,
amount,
Expand Down Expand Up @@ -228,6 +247,7 @@ impl fmt::Display for TransactionServiceRequest {
#[derive(Debug)]
pub enum TransactionServiceResponse {
TransactionSent(TxId),
TransactionSentWithOutputHash(TxId, FixedHash),
TransactionCancelled,
PendingInboundTransactions(HashMap<TxId, InboundTransaction>),
PendingOutboundTransactions(HashMap<TxId, OutboundTransaction>),
Expand Down Expand Up @@ -504,6 +524,32 @@ impl TransactionServiceHandle {
}
}

pub async fn create_aggregate_signature_utxo(
&mut self,
amount: MicroTari,
fee_per_gram: MicroTari,
n: u8,
m: u8,
public_keys: Vec<PublicKey>,
message: [u8; 32],
) -> Result<(TxId, FixedHash), TransactionServiceError> {
match self
.handle
.call(TransactionServiceRequest::CreateNMUtxo {
amount,
fee_per_gram,
n,
m,
public_keys,
message,
})
.await??
{
TransactionServiceResponse::TransactionSentWithOutputHash(tx_id, output_hash) => Ok((tx_id, output_hash)),
_ => Err(TransactionServiceError::UnexpectedApiResponse),
}
}

pub async fn send_one_sided_to_stealth_address_transaction(
&mut self,
dest_pubkey: CommsPublicKey,
Expand Down
Loading

0 comments on commit 8ae6fbd

Please sign in to comment.