Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add wallet cli command for utxo creation with aggregate public key #4759

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
62a6c03
first commit, add handle to verify aggregate signatures
jorgeantonio21 Sep 27, 2022
061f5e2
Add multisig script with agg pk
hansieodendaal Sep 26, 2022
40b3dee
add create_key_combo method for wallet cli
jorgeantonio21 Sep 28, 2022
f05444e
Merge branch 'development' into ja-multisig-op
jorgeantonio21 Sep 28, 2022
fc29b2f
execute cargo fmt
jorgeantonio21 Sep 28, 2022
d41e44a
add refactor on PR comments plus add test
jorgeantonio21 Sep 28, 2022
a2f01ad
refactor message for create key combo
jorgeantonio21 Sep 28, 2022
e79acc4
refactor clap_parses_user_defined_commands_as_expected
jorgeantonio21 Sep 28, 2022
e11ee31
address PR comments
jorgeantonio21 Sep 29, 2022
4069ab8
fix clippy
jorgeantonio21 Sep 29, 2022
6d80422
replace debug with {}
jorgeantonio21 Sep 29, 2022
45ad9df
Merge remote-tracking branch 'hansieodendaal/ho_CheckMultiSigVerifyAg…
jorgeantonio21 Sep 29, 2022
b8e40ca
add create-n-m-utxo cli command
jorgeantonio21 Sep 30, 2022
86c7017
Merge branch 'development' into ja-multisig-signature-utxo
jorgeantonio21 Sep 30, 2022
f850b11
refactor and clean code
jorgeantonio21 Sep 30, 2022
b907962
add test
jorgeantonio21 Sep 30, 2022
f783536
address some comments on PR
jorgeantonio21 Sep 30, 2022
676cfc3
refactor failing test
jorgeantonio21 Sep 30, 2022
2948a6d
refactor code according to PR comments
jorgeantonio21 Oct 3, 2022
18c915d
add further sugggestions impls
jorgeantonio21 Oct 3, 2022
547caab
add rand to [dev-dependencies] instead
jorgeantonio21 Oct 3, 2022
1b2c573
remove line
jorgeantonio21 Oct 3, 2022
57b510b
resolve conflicts
jorgeantonio21 Oct 4, 2022
28dbddb
add renaming of create key combo -> create key pair
jorgeantonio21 Oct 4, 2022
cad4fb5
add changes
jorgeantonio21 Oct 4, 2022
2e3038f
run cargo fmt
jorgeantonio21 Oct 4, 2022
2e4f7cc
add clippy allowance for many lines in create_n_m_utxo
jorgeantonio21 Oct 4, 2022
306e643
refactor test
jorgeantonio21 Oct 4, 2022
e9cd61a
Merge branch 'development' into ja-multisig-signature-utxo
jorgeantonio21 Oct 6, 2022
90def27
merge files
jorgeantonio21 Oct 6, 2022
2e2ddc6
minor changes
jorgeantonio21 Oct 6, 2022
3a137c4
merge and resolve conflicts
jorgeantonio21 Oct 6, 2022
9afb5ac
resolve further merge conflicts
jorgeantonio21 Oct 6, 2022
ea75fbe
resolve args
jorgeantonio21 Oct 6, 2022
9346207
correct remaining test
jorgeantonio21 Oct 6, 2022
dfcd081
Merge branch 'feature-m-of-n' into ja-multisig-signature-utxo
jorgeantonio21 Oct 6, 2022
b423631
refactor cargo toml
jorgeantonio21 Oct 6, 2022
b04b627
Merge branch 'feature-m-of-n' into ja-multisig-signature-utxo
jorgeantonio21 Oct 6, 2022
c82ea6e
refactor cucumber test
jorgeantonio21 Oct 6, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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