Skip to content

Commit

Permalink
Add one-sided coinbase
Browse files Browse the repository at this point in the history
Added one-sided and stealth coinbase transactions. Coinbases can now only be paid to a
nominated wallet address directly.
  • Loading branch information
hansieodendaal committed Nov 20, 2023
1 parent 14e334a commit 2bc4e36
Show file tree
Hide file tree
Showing 128 changed files with 1,844 additions and 3,414 deletions.
6 changes: 6 additions & 0 deletions Cargo.lock

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

14 changes: 0 additions & 14 deletions applications/minotari_app_grpc/proto/wallet.proto
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ service Wallet {
rpc Identify (GetIdentityRequest) returns (GetIdentityResponse);
// This returns the tari address
rpc GetAddress (Empty) returns (GetAddressResponse);
// This returns a coinbase transaction
rpc GetCoinbase (GetCoinbaseRequest) returns (GetCoinbaseResponse);
// Send Minotari to a number of recipients
rpc Transfer (TransferRequest) returns (TransferResponse);
// Returns the transaction details for the given transaction IDs
Expand Down Expand Up @@ -244,17 +242,6 @@ message GetUnspentAmountsResponse {
repeated uint64 amount = 1;
}

message GetCoinbaseRequest {
uint64 reward = 1;
uint64 fee = 2;
uint64 height = 3;
bytes extra = 4;
}

message GetCoinbaseResponse {
Transaction transaction = 1;
}

message CoinSplitRequest {
uint64 amount_per_split = 1;
uint64 split_count = 2;
Expand Down Expand Up @@ -329,7 +316,6 @@ message TransactionEvent {
string direction = 6;
uint64 amount = 7;
string message = 8;
bool is_coinbase = 9;
}

message TransactionEventResponse {
Expand Down
12 changes: 6 additions & 6 deletions applications/minotari_console_wallet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,13 @@ Total value of UTXOs: 36105.165440 T
example output - `--csv-file` (contents of `utxos.csv`)

```
"#","Value (uT)","Spending Key","Commitment","Flags","Maturity"
"1","121999250","0b0ce2add569845ec8bb84256b731e644e2224580b568e75666399e868ea5701","22514e279bd7e7e0a6e45905e07323b16f6114e300bcc02f36b2baf44a17b43d","(empty)","0"
"2","124000000","8829254b5267de26fe926f30518604abeec156740abe64b435ac6081269f2f0d","88f4e7216353032b90bee1c8b4243c3f25b357902a5cb145fda1c98316525214","(empty)","0"
"3","125000000","295853fad02d56313920130c3a5fa3aa8be54297ee5375aa2d788f4e49f08309","72a42d2db4f8eebbc4d0074fcb04338b8caa22312ce6a68e8798c2452b52e465","(empty)","0"
"#","Value (uT)","Spending Key","Commitment","Maturity"
"1","121999250","0b0ce2add569845ec8bb84256b731e644e2224580b568e75666399e868ea5701","22514e279bd7e7e0a6e45905e07323b16f6114e300bcc02f36b2baf44a17b43d","0"
"2","124000000","8829254b5267de26fe926f30518604abeec156740abe64b435ac6081269f2f0d","88f4e7216353032b90bee1c8b4243c3f25b357902a5cb145fda1c98316525214","0"
"3","125000000","295853fad02d56313920130c3a5fa3aa8be54297ee5375aa2d788f4e49f08309","72a42d2db4f8eebbc4d0074fcb04338b8caa22312ce6a68e8798c2452b52e465","0"
...
"10","5513131148","a6323f62ef21c45f03c73b424d9823b1a0f44a4408be688e5f6fde6419a11407","dcec835619474a62b5cef8227481cebd5831aec515e85286f3932c8093e9d06b","COINBASE_OUTPUT","10655"
"11","5513145680","5af45bff0f533999c94ec799aa4789260a1b989207363c33ec6ec388899ec906","7ec353f1f005637192d50104b3c5b4621d1ebdafb5c5cc078cf3f86754669352","COINBASE_OUTPUT","10649"
"10","5513131148","a6323f62ef21c45f03c73b424d9823b1a0f44a4408be688e5f6fde6419a11407","dcec835619474a62b5cef8227481cebd5831aec515e85286f3932c8093e9d06b","10655"
"11","5513145680","5af45bff0f533999c94ec799aa4789260a1b989207363c33ec6ec388899ec906","7ec353f1f005637192d50104b3c5b4621d1ebdafb5c5cc078cf3f86754669352","10649"
```

- **count-utxos**
Expand Down
6 changes: 0 additions & 6 deletions applications/minotari_console_wallet/src/grpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ pub fn convert_to_transaction_event(event: String, source: TransactionWrapper) -
direction: completed.direction.to_string(),
amount: completed.amount.as_u64(),
message: completed.message.to_string(),
is_coinbase: completed.is_coinbase(),
},
TransactionWrapper::Outbound(outbound) => TransactionEvent {
event,
Expand All @@ -40,7 +39,6 @@ pub fn convert_to_transaction_event(event: String, source: TransactionWrapper) -
direction: "outbound".to_string(),
amount: outbound.amount.as_u64(),
message: outbound.message,
is_coinbase: false,
},
TransactionWrapper::Inbound(inbound) => TransactionEvent {
event,
Expand All @@ -51,10 +49,6 @@ pub fn convert_to_transaction_event(event: String, source: TransactionWrapper) -
direction: "inbound".to_string(),
amount: inbound.amount.as_u64(),
message: inbound.message.clone(),
// The coinbase are technically Inbound.
// To determine whether a transaction is coinbase
// we will check whether the message contains `Coinbase`.
is_coinbase: inbound.message.to_lowercase().contains("coinbase"),
},
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ use minotari_app_grpc::tari_rpc::{
GetAddressResponse,
GetBalanceRequest,
GetBalanceResponse,
GetCoinbaseRequest,
GetCoinbaseResponse,
GetCompletedTransactionsRequest,
GetCompletedTransactionsResponse,
GetConnectivityRequest,
Expand Down Expand Up @@ -309,24 +307,6 @@ impl wallet_server::Wallet for WalletGrpcServer {
Ok(Response::new(RevalidateResponse {}))
}

async fn get_coinbase(
&self,
request: Request<GetCoinbaseRequest>,
) -> Result<Response<GetCoinbaseResponse>, Status> {
let request = request.into_inner();
let mut tx_service = self.get_transaction_service();

let coinbase = tx_service
.generate_coinbase_transaction(request.reward.into(), request.fee.into(), request.height, request.extra)
.await
.map_err(|err| Status::unknown(err.to_string()))?;

let coinbase = coinbase.try_into().map_err(Status::internal)?;
Ok(Response::new(GetCoinbaseResponse {
transaction: Some(coinbase),
}))
}

async fn send_sha_atomic_swap_transaction(
&self,
request: Request<SendShaAtomicSwapRequest>,
Expand Down Expand Up @@ -1090,7 +1070,6 @@ fn simple_event(event: &str) -> TransactionEvent {
direction: event.to_string(),
amount: 0,
message: String::default(),
is_coinbase: false,
}
}

Expand Down
1 change: 0 additions & 1 deletion applications/minotari_console_wallet/src/init/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ fn display_password_feedback(passphrase: &SafePassword) -> bool {
"The password you chose is weak; a determined attacker with access to your device may be able to guess it."
);
println!("You may want to consider changing it to a stronger one.");
println!("Here are some suggestions:");
for suggestion in feedback {
println!("- {}", suggestion);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,7 @@ impl TransactionsTab {
Style::default().fg(text_color),
)));

let status = if matches!(t.cancelled, Some(TxCancellationReason::AbandonedCoinbase)) {
"Abandoned".to_string()
} else if matches!(t.cancelled, Some(TxCancellationReason::UserCancelled)) {
let status = if matches!(t.cancelled, Some(TxCancellationReason::UserCancelled)) {
"Cancelled".to_string()
} else if t.cancelled.is_some() {
"Rejected".to_string()
Expand Down Expand Up @@ -364,9 +362,7 @@ impl TransactionsTab {
let amount = tx.amount.to_string();
let content = &amount;
let amount = Span::styled(content, Style::default().fg(Color::White));
let fee_details = if tx.is_coinbase {
Span::raw("")
} else {
let fee_details = {
Span::styled(
format!(
" (weight: {}g, #inputs: {}, #outputs: {})",
Expand Down Expand Up @@ -602,7 +598,6 @@ impl<B: Backend> Component<B> for TransactionsTab {
error!(target: LOG_TARGET, "Error rebroadcasting transactions: {}", e);
}
},
'a' => app_state.toggle_abandoned_coinbase_filter(),
'\n' => match self.selected_tx_list {
SelectedTransactionList::None => {},
SelectedTransactionList::PendingTxs => {
Expand Down
32 changes: 1 addition & 31 deletions applications/minotari_console_wallet/src/ui/state/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use std::{
time::{Duration, Instant},
};

use bitflags::bitflags;
use chrono::{DateTime, Local, NaiveDateTime};
use log::*;
use minotari_wallet::{
Expand Down Expand Up @@ -97,7 +96,6 @@ pub struct AppState {
inner: Arc<RwLock<AppStateInner>>,
cached_data: AppStateData,
cache_update_cooldown: Option<Instant>,
completed_tx_filter: TransactionFilter,
config: AppStateConfig,
wallet_config: WalletConfig,
wallet_connectivity: WalletConnectivityHandle,
Expand All @@ -122,7 +120,6 @@ impl AppState {
inner: inner.clone(),
cached_data,
cache_update_cooldown: None,
completed_tx_filter: TransactionFilter::ABANDONED_COINBASES,
config: AppStateConfig::default(),
wallet_connectivity,
balance_enquiry_debouncer: BalanceEnquiryDebouncer::new(
Expand Down Expand Up @@ -559,19 +556,7 @@ impl AppState {
}

pub fn get_completed_txs(&self) -> Vec<&CompletedTransactionInfo> {
if self
.completed_tx_filter
.contains(TransactionFilter::ABANDONED_COINBASES)
{
self.cached_data
.completed_txs
.iter()
.filter(|tx| !matches!(tx.cancelled, Some(TxCancellationReason::AbandonedCoinbase)))
.filter(|tx| !matches!(tx.status, TransactionStatus::Coinbase))
.collect()
} else {
self.cached_data.completed_txs.iter().collect()
}
self.cached_data.completed_txs.iter().collect()
}

pub fn get_confirmations(&self, tx_id: TxId) -> Option<&u64> {
Expand Down Expand Up @@ -657,10 +642,6 @@ impl AppState {
self.wallet_config.num_required_confirmations
}

pub fn toggle_abandoned_coinbase_filter(&mut self) {
self.completed_tx_filter.toggle(TransactionFilter::ABANDONED_COINBASES);
}

pub fn get_notifications(&self) -> &[(DateTime<Local>, String)] {
&self.cached_data.notifications
}
Expand Down Expand Up @@ -1166,7 +1147,6 @@ pub struct CompletedTransactionInfo {
pub cancelled: Option<TxCancellationReason>,
pub direction: TransactionDirection,
pub mined_height: Option<u64>,
pub is_coinbase: bool,
pub weight: u64,
pub inputs_count: usize,
pub outputs_count: usize,
Expand All @@ -1182,7 +1162,6 @@ impl CompletedTransactionInfo {
.first_kernel_excess_sig()
.map(|s| s.get_signature().to_hex())
.unwrap_or_default();
let is_coinbase = tx.is_coinbase();
let weight = tx.transaction.calculate_weight(transaction_weighting)?;
let inputs_count = tx.transaction.body.inputs().len();
let outputs_count = tx.transaction.body.outputs().len();
Expand All @@ -1208,7 +1187,6 @@ impl CompletedTransactionInfo {
cancelled: tx.cancelled,
direction: tx.direction,
mined_height: tx.mined_height,
is_coinbase,
weight,
inputs_count,
outputs_count,
Expand Down Expand Up @@ -1344,14 +1322,6 @@ pub enum UiTransactionBurnStatus {
Error(String),
}

bitflags! {
#[derive(Clone)]
pub struct TransactionFilter: u8 {
const NONE = 0b0000_0000;
const ABANDONED_COINBASES = 0b0000_0001;
}
}

#[derive(Clone)]
struct AppStateConfig {
pub cache_update_cooldown: Duration,
Expand Down
4 changes: 4 additions & 0 deletions applications/minotari_merge_mining_proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ default = []

[dependencies]
tari_common = { path = "../../common" }
tari_common_types = { path = "../../base_layer/common_types" }
tari_comms = { path = "../../comms/core" }
tari_core = { path = "../../base_layer/core", default-features = false, features = ["transactions"] }
minotari_app_utilities = { path = "../minotari_app_utilities" }
tari_utilities = { version = "0.6" }
minotari_node_grpc_client = { path = "../../clients/rust/base_node_grpc_client" }
minotari_wallet_grpc_client = { path = "../../clients/rust/wallet_grpc_client" }
minotari_app_grpc = { path = "../minotari_app_grpc" }
tari_key_manager = { path = "../../base_layer/key_manager", features = ["key_manager_service"] }
tari_crypto = { version = "0.19", features = ["borsh"] }

anyhow = "1.0.53"
crossterm = { version = "0.25.0" }
Expand All @@ -41,6 +44,7 @@ tokio = { version = "1.23", features = ["macros"] }
tonic = "0.6.2"
tracing = "0.1"
url = "2.1.1"
rand = "0.8"

[build-dependencies]
tari_features = { path = "../../common/tari_features"}
Loading

0 comments on commit 2bc4e36

Please sign in to comment.