Skip to content

Commit

Permalink
feat!: add tari address for wallet to use (#4881)
Browse files Browse the repository at this point in the history
Description
---
This changes the address used by the wallet to not just use the pubkey of another wallet, to a new custom address scheme.

Changes:
- Includes new address scheme : [version][network][pub_key]
- Replaces wallet pubkey with new address all over
- Calculate what address should be is message is received from network public key. 
- Cleans up database to remove broken fields and defunct tables

Motivation and Context
---
We need the wallets to be able to verify that the addresses used by the wallets are for the correct network and are wallets. In interactive transactions, transactions using the wrong pubkeys, will result in transactions eventually being self-canceled by the wallet as they are stale. But one-sided and stealth these will be sent and never recoverable. 

Using the new scheme wallets can verify addresses are on the correct network, and because base_nodes still use pubkeys the addresses differ between base_nodes and wallets. 

How Has This Been Tested?
---
All unit tests passed


Fixes: #4888 
Fixes: #4886 


BREAKING: This changes how the wallet accepts and presents addresses
  • Loading branch information
SWvheerden authored Nov 15, 2022
1 parent 39d53c8 commit 26aacc7
Show file tree
Hide file tree
Showing 56 changed files with 1,841 additions and 902 deletions.
1 change: 1 addition & 0 deletions .license.ignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
./applications/tari_base_node/osx-pkg/scripts/preinstall
./applications/tari_console_wallet/linux/start_tari_console_wallet
./base_layer/key_manager/Makefile
./base_layer/wallet/src/schema.rs
./base_layer/p2p/src/dns/roots/tls.rs
./buildtools/docker/torrc
./docs/src/theme/book.js
Expand Down
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions applications/tari_app_grpc/proto/wallet.proto
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ message GetTransactionInfoResponse {

message TransactionInfo {
uint64 tx_id = 1;
bytes source_pk = 2;
bytes dest_pk = 3;
bytes source_address = 2;
bytes dest_address = 3;
TransactionStatus status = 4;
TransactionDirection direction = 5;
uint64 amount = 6;
Expand Down Expand Up @@ -310,8 +310,8 @@ message TransactionEventRequest{
message TransactionEvent {
string event = 1;
string tx_id = 2;
bytes source_pk = 3;
bytes dest_pk = 4;
bytes source_address = 3;
bytes dest_address = 4;
string status = 5;
string direction = 6;
uint64 amount = 7;
Expand Down
37 changes: 19 additions & 18 deletions applications/tari_console_wallet/src/automation/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ use strum_macros::{Display, EnumIter, EnumString};
use tari_app_grpc::authentication::salted_password::create_salted_hashed_password;
use tari_common_types::{
emoji::EmojiId,
tari_address::TariAddress,
transaction::TxId,
types::{CommitmentFactory, FixedHash, PublicKey, Signature},
};
Expand Down Expand Up @@ -112,12 +113,12 @@ pub async fn send_tari(
mut wallet_transaction_service: TransactionServiceHandle,
fee_per_gram: u64,
amount: MicroTari,
dest_pubkey: PublicKey,
destination: TariAddress,
message: String,
) -> Result<TxId, CommandError> {
wallet_transaction_service
.send_transaction(
dest_pubkey,
destination,
amount,
UtxoSelectionCriteria::default(),
OutputFeatures::default(),
Expand Down Expand Up @@ -146,11 +147,11 @@ pub async fn init_sha_atomic_swap(
fee_per_gram: u64,
amount: MicroTari,
selection_criteria: UtxoSelectionCriteria,
dest_pubkey: PublicKey,
dest_address: TariAddress,
message: String,
) -> Result<(TxId, PublicKey, TransactionOutput), CommandError> {
let (tx_id, pre_image, output) = wallet_transaction_service
.send_sha_atomic_swap_transaction(dest_pubkey, amount, selection_criteria, fee_per_gram * uT, message)
.send_sha_atomic_swap_transaction(dest_address, amount, selection_criteria, fee_per_gram * uT, message)
.await
.map_err(CommandError::TransactionServiceError)?;
Ok((tx_id, pre_image, output))
Expand Down Expand Up @@ -217,12 +218,12 @@ pub async fn send_one_sided(
fee_per_gram: u64,
amount: MicroTari,
selection_criteria: UtxoSelectionCriteria,
dest_pubkey: PublicKey,
dest_address: TariAddress,
message: String,
) -> Result<TxId, CommandError> {
wallet_transaction_service
.send_one_sided_transaction(
dest_pubkey,
dest_address,
amount,
selection_criteria,
OutputFeatures::default(),
Expand All @@ -238,12 +239,12 @@ pub async fn send_one_sided_to_stealth_address(
fee_per_gram: u64,
amount: MicroTari,
selection_criteria: UtxoSelectionCriteria,
dest_pubkey: PublicKey,
dest_address: TariAddress,
message: String,
) -> Result<TxId, CommandError> {
wallet_transaction_service
.send_one_sided_to_stealth_address_transaction(
dest_pubkey,
dest_address,
amount,
selection_criteria,
OutputFeatures::default(),
Expand Down Expand Up @@ -340,7 +341,7 @@ pub async fn make_it_rain(
start_amount: MicroTari,
increase_amount: MicroTari,
start_time: DateTime<Utc>,
destination: PublicKey,
destination: TariAddress,
transaction_type: MakeItRainTransactionType,
message: String,
) -> Result<(), CommandError> {
Expand Down Expand Up @@ -403,22 +404,22 @@ pub async fn make_it_rain(
let delayed_for = Instant::now();
let sender_clone = sender.clone();
let fee = fee_per_gram;
let pk = destination.clone();
let address = destination.clone();
let msg = message.clone();
tokio::task::spawn(async move {
let spawn_start = Instant::now();
// Send transaction
let tx_id = match transaction_type {
MakeItRainTransactionType::Interactive => {
send_tari(tx_service, fee, amount, pk.clone(), msg.clone()).await
send_tari(tx_service, fee, amount, address.clone(), msg.clone()).await
},
MakeItRainTransactionType::OneSided => {
send_one_sided(
tx_service,
fee,
amount,
UtxoSelectionCriteria::default(),
pk.clone(),
address.clone(),
msg.clone(),
)
.await
Expand All @@ -429,7 +430,7 @@ pub async fn make_it_rain(
fee,
amount,
UtxoSelectionCriteria::default(),
pk.clone(),
address.clone(),
msg.clone(),
)
.await
Expand Down Expand Up @@ -663,7 +664,7 @@ pub async fn command_runner(
transaction_service.clone(),
config.fee_per_gram,
args.amount,
args.destination.into(),
args.destination,
args.message,
)
.await
Expand All @@ -681,7 +682,7 @@ pub async fn command_runner(
config.fee_per_gram,
args.amount,
UtxoSelectionCriteria::default(),
args.destination.into(),
args.destination,
args.message,
)
.await
Expand All @@ -699,7 +700,7 @@ pub async fn command_runner(
config.fee_per_gram,
args.amount,
UtxoSelectionCriteria::default(),
args.destination.into(),
args.destination,
args.message,
)
.await
Expand All @@ -724,7 +725,7 @@ pub async fn command_runner(
args.start_amount,
args.increase_amount,
args.start_time.unwrap_or_else(Utc::now),
args.destination.into(),
args.destination,
transaction_type,
args.message,
)
Expand Down Expand Up @@ -864,7 +865,7 @@ pub async fn command_runner(
config.fee_per_gram,
args.amount,
UtxoSelectionCriteria::default(),
args.destination.into(),
args.destination,
args.message,
)
.await
Expand Down
5 changes: 3 additions & 2 deletions applications/tari_console_wallet/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use chrono::{DateTime, Utc};
use clap::{Args, Parser, Subcommand};
use tari_app_utilities::{common_cli_args::CommonCliArgs, utilities::UniPublicKey};
use tari_common::configuration::{ConfigOverrideProvider, Network};
use tari_common_types::tari_address::TariAddress;
use tari_comms::multiaddr::Multiaddr;
use tari_core::transactions::{tari_amount, tari_amount::MicroTari};
use tari_utilities::{
Expand Down Expand Up @@ -142,7 +143,7 @@ pub struct DiscoverPeerArgs {
#[derive(Debug, Args, Clone)]
pub struct SendTariArgs {
pub amount: MicroTari,
pub destination: UniPublicKey,
pub destination: TariAddress,
#[clap(short, long, default_value = "<No message>")]
pub message: String,
}
Expand All @@ -156,7 +157,7 @@ pub struct BurnTariArgs {

#[derive(Debug, Args, Clone)]
pub struct MakeItRainArgs {
pub destination: UniPublicKey,
pub destination: TariAddress,
#[clap(short, long, alias="amount", default_value_t = tari_amount::T)]
pub start_amount: MicroTari,
#[clap(short, long, alias = "tps", default_value_t = 25)]
Expand Down
13 changes: 6 additions & 7 deletions applications/tari_console_wallet/src/grpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
mod wallet_grpc_server;

use tari_app_grpc::tari_rpc::TransactionEvent;
use tari_utilities::hex::Hex;
use tari_wallet::transaction_service::storage::models::{
CompletedTransaction,
InboundTransaction,
Expand All @@ -24,8 +23,8 @@ pub fn convert_to_transaction_event(event: String, source: TransactionWrapper) -
TransactionWrapper::Completed(completed) => TransactionEvent {
event,
tx_id: completed.tx_id.to_string(),
source_pk: completed.source_public_key.to_hex().into_bytes(),
dest_pk: completed.destination_public_key.to_hex().into_bytes(),
source_address: completed.source_address.to_bytes().to_vec(),
dest_address: completed.destination_address.to_bytes().to_vec(),
status: completed.status.to_string(),
direction: completed.direction.to_string(),
amount: completed.amount.as_u64(),
Expand All @@ -35,8 +34,8 @@ pub fn convert_to_transaction_event(event: String, source: TransactionWrapper) -
TransactionWrapper::Outbound(outbound) => TransactionEvent {
event,
tx_id: outbound.tx_id.to_string(),
source_pk: vec![],
dest_pk: outbound.destination_public_key.to_hex().into_bytes(),
source_address: vec![],
dest_address: outbound.destination_address.to_bytes().to_vec(),
status: outbound.status.to_string(),
direction: "outbound".to_string(),
amount: outbound.amount.as_u64(),
Expand All @@ -46,8 +45,8 @@ pub fn convert_to_transaction_event(event: String, source: TransactionWrapper) -
TransactionWrapper::Inbound(inbound) => TransactionEvent {
event,
tx_id: inbound.tx_id.to_string(),
source_pk: inbound.source_public_key.to_hex().into_bytes(),
dest_pk: vec![],
source_address: inbound.source_address.to_bytes().to_vec(),
dest_address: vec![],
status: inbound.status.to_string(),
direction: "inbound".to_string(),
amount: inbound.amount.as_u64(),
Expand Down
Loading

0 comments on commit 26aacc7

Please sign in to comment.