Skip to content

Commit d04d6df

Browse files
author
Hansie Odendaal
committed
Add block hash to grpc method
Added optional block hash to grpc method GetCompletedTransactionsRequest
1 parent a6c0199 commit d04d6df

File tree

12 files changed

+188
-71
lines changed

12 files changed

+188
-71
lines changed

applications/minotari_app_grpc/proto/wallet.proto

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ service Wallet {
4949
// ```
5050

5151
rpc GetVersion (GetVersionRequest) returns (GetVersionResponse);
52+
5253
// Returns the current operational state of the wallet.
5354
//
5455
// This RPC provides an overview of the wallet's internal status, including:
@@ -84,6 +85,7 @@ service Wallet {
8485
// }
8586
// ```
8687
rpc GetState (GetStateRequest) returns (GetStateResponse);
88+
8789
// This RPC returns a lightweight response indicating whether the wallet is connected to the network, attempting to connect, or currently offline. This is useful for UIs or clients to determine if network interactions like transactions or syncs are possible.
8890
//
8991
// Example usage (JavaScript):
@@ -99,8 +101,10 @@ service Wallet {
99101
// }
100102
// ```
101103
rpc CheckConnectivity(GetConnectivityRequest) returns (CheckConnectivityResponse);
104+
102105
// Check for new updates
103106
rpc CheckForUpdates (Empty) returns (SoftwareUpdate);
107+
104108
// The `Identify` RPC call returns the identity information of the wallet node.
105109
// This includes:
106110
// - **Public Key**: The wallet’s cryptographic public key.
@@ -129,6 +133,7 @@ service Wallet {
129133
// }
130134
// ```
131135
rpc Identify (GetIdentityRequest) returns (GetIdentityResponse);
136+
132137
// This RPC returns two types of wallet addresses: interactive and one-sided addresses.
133138
// It provides these addresses in byte format as part of the response.
134139
// - **Interactive Address**: This is a type of address used for interaction and communication with the wallet.
@@ -153,6 +158,7 @@ service Wallet {
153158
// }
154159
// ```
155160
rpc GetAddress (Empty) returns (GetAddressResponse);
161+
156162
// This RPC returns addresses generated for a specific payment ID. It provides both the interactive
157163
// and one-sided addresses for the given payment ID, along with their respective representations in
158164
// base58 and emoji formats.
@@ -188,6 +194,7 @@ service Wallet {
188194
//```
189195
//
190196
rpc GetPaymentIdAddress (GetPaymentIdAddressRequest) returns (GetCompleteAddressResponse);
197+
191198
// This RPC call that retrieves the current wallet's interactive and one-sided addresses in multiple formats and returns them in a structured response.
192199
// The response includes:
193200
// - Raw binary
@@ -216,6 +223,7 @@ service Wallet {
216223
// }
217224
// ```
218225
rpc GetCompleteAddress (Empty) returns (GetCompleteAddressResponse);
226+
219227
// This call supports standard interactive transactions (Mimblewimble),
220228
// one-sided transactions, and one-sided-to-stealth-address transactions.
221229
// Each recipient must include a valid Tari address, amount, fee, and payment type.
@@ -304,6 +312,7 @@ service Wallet {
304312
// }
305313
// ```
306314
rpc GetTransactionInfo (GetTransactionInfoRequest) returns (GetTransactionInfoResponse);
315+
307316
// Streams completed transactions for a given user payment ID.
308317
//
309318
// The `GetCompletedTransactions` call retrieves all completed wallet transactions,
@@ -361,6 +370,7 @@ service Wallet {
361370
// }
362371
// ```
363372
rpc GetCompletedTransactions (GetCompletedTransactionsRequest) returns (stream GetCompletedTransactionsResponse);
373+
364374
// Returns the wallet balance details.
365375
//
366376
// The `GetBalance` call retrieves the current balance status of the wallet,
@@ -406,6 +416,7 @@ service Wallet {
406416
// }
407417
// ```
408418
rpc GetBalance (GetBalanceRequest) returns (GetBalanceResponse);
419+
409420
// Returns the total value of unspent outputs in the wallet.
410421
//
411422
// The `GetUnspentAmounts` call retrieves the sum of all unspent output amounts
@@ -435,6 +446,7 @@ service Wallet {
435446
// }
436447
// ```
437448
rpc GetUnspentAmounts (Empty) returns (GetUnspentAmountsResponse);
449+
438450
// Creates a transaction that splits funds into multiple smaller outputs.
439451
//
440452
// The `CoinSplit` call initiates a transaction that divides wallet funds into several equal-sized outputs.
@@ -492,6 +504,7 @@ service Wallet {
492504
// }
493505
// ```
494506
rpc CoinSplit (CoinSplitRequest) returns (CoinSplitResponse);
507+
495508
// Imports UTXOs into the wallet as spendable outputs.
496509
//
497510
// The `ImportUtxos` call allows you to manually insert one or more previously received UTXOs
@@ -535,6 +548,7 @@ service Wallet {
535548
// }
536549
// ```
537550
rpc ImportUtxos (ImportUtxosRequest) returns (ImportUtxosResponse);
551+
538552
// Returns the wallet's current network connectivity status.
539553
//
540554
// The `GetNetworkStatus` call provides a snapshot of the wallet’s connection to the Tari network,
@@ -583,6 +597,7 @@ service Wallet {
583597
// - This status means the wallet is unable to communicate with the network and cannot perform any network-related operations.
584598
//
585599
rpc GetNetworkStatus(Empty) returns (NetworkStatusResponse);
600+
586601
// Returns a list of peers currently connected to the wallet.
587602
//
588603
// The `ListConnectedPeers` call retrieves information about peers that the wallet is currently
@@ -647,6 +662,7 @@ service Wallet {
647662
// }
648663
// ```
649664
rpc ListConnectedPeers(Empty) returns (ListConnectedPeersResponse);
665+
650666
// Cancels a specific transaction by its ID.
651667
//
652668
// The `CancelTransaction` call allows a transaction to be cancelled by its unique transaction ID (TxId).
@@ -683,10 +699,13 @@ service Wallet {
683699
// }
684700
// ```
685701
rpc CancelTransaction (CancelTransactionRequest) returns (CancelTransactionResponse);
702+
686703
// Will trigger a complete revalidation of all wallet outputs.
687704
rpc RevalidateAllTransactions (RevalidateRequest) returns (RevalidateResponse);
705+
688706
// Will trigger a validation of all wallet outputs.
689707
rpc ValidateAllTransactions (ValidateRequest) returns (ValidateResponse);
708+
690709
// Sends a XTR SHA Atomic Swap transaction.
691710
//
692711
// The `SendShaAtomicSwapTransaction` call is used to initiate an Atomic Swap
@@ -731,6 +750,7 @@ service Wallet {
731750
// "failure_message": ""
732751
// }
733752
rpc SendShaAtomicSwapTransaction(SendShaAtomicSwapRequest) returns (SendShaAtomicSwapResponse);
753+
734754
// Creates a burn transaction for burning a specified amount of Tari currency.
735755
//
736756
// The `CreateBurnTransaction` call facilitates burning a certain amount of Tari
@@ -778,6 +798,7 @@ service Wallet {
778798
// "reciprocal_claim_public_key": "0xreciprocalpublickey"
779799
// }
780800
rpc CreateBurnTransaction(CreateBurnTransactionRequest) returns (CreateBurnTransactionResponse);
801+
781802
// Claims a SHA Atomic Swap transaction using a pre-image and output hash.
782803
//
783804
// The `ClaimShaAtomicSwapTransaction` call allows the user to unlock and claim funds from
@@ -822,6 +843,7 @@ service Wallet {
822843
// }
823844
// }
824845
rpc ClaimShaAtomicSwapTransaction(ClaimShaAtomicSwapRequest) returns (ClaimShaAtomicSwapResponse);
846+
825847
// Claims an HTLC refund transaction after the timelock period has passed.
826848
//
827849
// The `ClaimHtlcRefundTransaction` call enables the original sender of a Hash Time-Locked Contract (HTLC)
@@ -862,8 +884,10 @@ service Wallet {
862884
// }
863885
// }
864886
rpc ClaimHtlcRefundTransaction(ClaimHtlcRefundRequest) returns (ClaimHtlcRefundResponse);
887+
865888
// Creates a transaction with a template registration output
866889
rpc CreateTemplateRegistration(CreateTemplateRegistrationRequest) returns (CreateTemplateRegistrationResponse);
890+
867891
// The SetBaseNode call configures the base node peer for the wallet.
868892
//
869893
// This RPC sets the public key and network address of the base node peer that the wallet should communicate with.
@@ -898,6 +922,7 @@ service Wallet {
898922
// {}
899923
// ```
900924
rpc SetBaseNode(SetBaseNodeRequest) returns (SetBaseNodeResponse);
925+
901926
// Streams real-time wallet transaction events to the client.
902927
//
903928
// The `StreamTransactionEvents` RPC provides a continuous stream of transaction events as they occur within the wallet.
@@ -1141,6 +1166,11 @@ enum TransactionStatus {
11411166

11421167
message GetCompletedTransactionsRequest {
11431168
UserPaymentId payment_id = 1;
1169+
BlockHashHex block_hash = 2;
1170+
}
1171+
1172+
message BlockHashHex {
1173+
string hash = 1;
11441174
}
11451175

11461176
message GetCompletedTransactionsResponse {

applications/minotari_console_wallet/src/grpc/wallet_grpc_server.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,9 +930,18 @@ impl wallet_server::Wallet for WalletGrpcServer {
930930
} else {
931931
None
932932
};
933+
let block_hash = if let Some(hash) = message.block_hash {
934+
Some(
935+
BlockHash::from_hex(&hash.hash)
936+
.map_err(|_| Status::internal("Output hash is malformed".to_string()))?,
937+
)
938+
} else {
939+
None
940+
};
941+
933942
let mut transaction_service = self.get_transaction_service();
934943
let transactions = transaction_service
935-
.get_completed_transactions(payment_id)
944+
.get_completed_transactions(payment_id, block_hash)
936945
.await
937946
.map_err(|err| Status::not_found(format!("No completed transactions found: {:?}", err)))?;
938947
debug!(

applications/minotari_console_wallet/src/ui/state/app_state.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,12 @@ impl AppStateInner {
751751
.collect::<Result<Vec<_>, _>>()?;
752752

753753
let mut completed_transactions: Vec<CompletedTransaction> = Vec::new();
754-
completed_transactions.extend(self.wallet.transaction_service.get_completed_transactions(None).await?);
754+
completed_transactions.extend(
755+
self.wallet
756+
.transaction_service
757+
.get_completed_transactions(None, None)
758+
.await?,
759+
);
755760

756761
completed_transactions.extend(
757762
self.wallet

base_layer/wallet/src/transaction_service/handle.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ use crate::{
7979
pub enum TransactionServiceRequest {
8080
GetPendingInboundTransactions,
8181
GetPendingOutboundTransactions,
82-
GetCompletedTransactions(Option<Vec<u8>>),
82+
GetCompletedTransactions {
83+
payment_id: Option<Vec<u8>>,
84+
block_hash: Option<FixedHash>,
85+
},
8386
GetCancelledPendingInboundTransactions,
8487
GetCancelledPendingOutboundTransactions,
8588
GetCancelledCompletedTransactions,
@@ -208,7 +211,7 @@ impl fmt::Display for TransactionServiceRequest {
208211
match self {
209212
Self::GetPendingInboundTransactions => write!(f, "GetPendingInboundTransactions"),
210213
Self::GetPendingOutboundTransactions => write!(f, "GetPendingOutboundTransactions"),
211-
Self::GetCompletedTransactions(_) => write!(f, "GetCompletedTransactions"),
214+
Self::GetCompletedTransactions { .. } => write!(f, "GetCompletedTransactions"),
212215
Self::ImportTransaction(tx) => write!(f, "ImportTransaction: {:?}", tx),
213216
Self::GetCancelledPendingInboundTransactions => write!(f, "GetCancelledPendingInboundTransactions"),
214217
Self::GetCancelledPendingOutboundTransactions => write!(f, "GetCancelledPendingOutboundTransactions"),
@@ -963,10 +966,11 @@ impl TransactionServiceHandle {
963966
pub async fn get_completed_transactions(
964967
&mut self,
965968
payment_id: Option<Vec<u8>>,
969+
block_hash: Option<FixedHash>,
966970
) -> Result<Vec<CompletedTransaction>, TransactionServiceError> {
967971
match self
968972
.handle
969-
.call(TransactionServiceRequest::GetCompletedTransactions(payment_id))
973+
.call(TransactionServiceRequest::GetCompletedTransactions { payment_id, block_hash })
970974
.await??
971975
{
972976
TransactionServiceResponse::CompletedTransactions(c) => Ok(c),

base_layer/wallet/src/transaction_service/service.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -891,9 +891,11 @@ where
891891
TransactionServiceResponse::PendingOutboundTransactions(self.db.get_pending_outbound_transactions()?),
892892
),
893893

894-
TransactionServiceRequest::GetCompletedTransactions(payment_id) => Ok(
895-
TransactionServiceResponse::CompletedTransactions(self.db.get_completed_transactions(payment_id)?),
896-
),
894+
TransactionServiceRequest::GetCompletedTransactions { payment_id, block_hash } => {
895+
Ok(TransactionServiceResponse::CompletedTransactions(
896+
self.db.get_completed_transactions(payment_id, block_hash)?,
897+
))
898+
},
897899
TransactionServiceRequest::GetCancelledPendingInboundTransactions => {
898900
Ok(TransactionServiceResponse::PendingInboundTransactions(
899901
self.db.get_cancelled_pending_inbound_transactions()?,

base_layer/wallet/src/transaction_service/storage/database.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use log::*;
3131
use tari_common_types::{
3232
tari_address::TariAddress,
3333
transaction::{TransactionDirection, TransactionStatus, TxId},
34-
types::{BlockHash, PrivateKey},
34+
types::{BlockHash, FixedHash, PrivateKey},
3535
};
3636
use tari_core::transactions::{
3737
tari_amount::MicroMinotari,
@@ -156,9 +156,10 @@ pub trait TransactionBackend: Send + Sync + Clone {
156156
height: u64,
157157
) -> Result<Vec<CompletedTransaction>, TransactionStorageError>;
158158

159-
fn find_completed_transactions_for_payment_id(
159+
fn find_completed_transactions_filter_payment_id_block_hash(
160160
&self,
161-
payment_id: Vec<u8>,
161+
payment_id: Option<Vec<u8>>,
162+
block_hash: Option<FixedHash>,
162163
) -> Result<Vec<CompletedTransaction>, TransactionStorageError>;
163164
}
164165

@@ -482,11 +483,14 @@ where T: TransactionBackend + 'static
482483
Ok(t)
483484
}
484485

485-
pub fn get_completed_transactions_by_payment_id(
486+
pub fn get_completed_transactions_filter_payment_id_block_hash(
486487
&self,
487-
payment_id: Vec<u8>,
488+
payment_id: Option<Vec<u8>>,
489+
block_hash: Option<FixedHash>,
488490
) -> Result<Vec<CompletedTransaction>, TransactionStorageError> {
489-
let t = self.db.find_completed_transactions_for_payment_id(payment_id)?;
491+
let t = self
492+
.db
493+
.find_completed_transactions_filter_payment_id_block_hash(payment_id, block_hash)?;
490494
Ok(t)
491495
}
492496

@@ -599,12 +603,13 @@ where T: TransactionBackend + 'static
599603
pub fn get_completed_transactions(
600604
&self,
601605
payment_id: Option<Vec<u8>>,
606+
block_hash: Option<FixedHash>,
602607
) -> Result<Vec<CompletedTransaction>, TransactionStorageError> {
603-
self.get_completed_transactions_by_cancelled(payment_id, false)
608+
self.get_completed_transactions_by_cancelled(payment_id, false, block_hash)
604609
}
605610

606611
pub fn get_cancelled_completed_transactions(&self) -> Result<Vec<CompletedTransaction>, TransactionStorageError> {
607-
self.get_completed_transactions_by_cancelled(None, true)
612+
self.get_completed_transactions_by_cancelled(None, true, None)
608613
}
609614

610615
pub fn get_any_transaction(&self, tx_id: TxId) -> Result<Option<WalletTransaction>, TransactionStorageError> {
@@ -630,15 +635,15 @@ where T: TransactionBackend + 'static
630635
&self,
631636
payment_id: Option<Vec<u8>>,
632637
cancelled: bool,
638+
block_hash: Option<FixedHash>,
633639
) -> Result<Vec<CompletedTransaction>, TransactionStorageError> {
634640
let key = if cancelled {
635641
DbKey::CancelledCompletedTransactions
636642
} else {
637643
DbKey::CompletedTransactions
638644
};
639-
match payment_id {
640-
Some(payment_id) => self.db.find_completed_transactions_for_payment_id(payment_id),
641-
None => {
645+
match (payment_id.is_none(), block_hash.is_none()) {
646+
(true, true) => {
642647
let t = match self.db.fetch(&key) {
643648
Ok(None) => log_error(
644649
key,
@@ -652,6 +657,9 @@ where T: TransactionBackend + 'static
652657
}?;
653658
Ok(t)
654659
},
660+
(_, _) => self
661+
.db
662+
.find_completed_transactions_filter_payment_id_block_hash(payment_id, block_hash),
655663
}
656664
}
657665

0 commit comments

Comments
 (0)