Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 12 additions & 0 deletions applications/minotari_app_grpc/proto/wallet.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,9 @@ service Wallet {
rpc RegisterValidatorNode(RegisterValidatorNodeRequest) returns (RegisterValidatorNodeResponse);

rpc ImportTransactions(ImportTransactionsRequest) returns (ImportTransactionsResponse);

// Get all completed transactions including cancelled ones, sorted by timestamp and paginated
rpc GetAllCompletedTransactions(GetAllCompletedTransactionsRequest) returns (GetAllCompletedTransactionsResponse);
}


Expand Down Expand Up @@ -1417,6 +1420,15 @@ message ImportTransactionsResponse {
repeated uint64 tx_ids = 1;
}

message GetAllCompletedTransactionsRequest {
uint64 offset = 1;
uint64 limit = 2;
}

message GetAllCompletedTransactionsResponse {
repeated TransactionInfo transactions = 1;
}

// Request message for getting transactions at a specific block height
message GetBlockHeightTransactionsRequest {
// The block height to fetch transactions for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ use minotari_app_grpc::tari_rpc::{
CreateTemplateRegistrationRequest,
CreateTemplateRegistrationResponse,
GetAddressResponse,
GetAllCompletedTransactionsRequest,
GetAllCompletedTransactionsResponse,
GetBalanceRequest,
GetBalanceResponse,
GetBlockHeightTransactionsRequest,
Expand Down Expand Up @@ -1056,6 +1058,81 @@ impl wallet_server::Wallet for WalletGrpcServer {
Ok(Response::new(receiver))
}

async fn get_all_completed_transactions(
&self,
request: Request<GetAllCompletedTransactionsRequest>,
) -> Result<Response<GetAllCompletedTransactionsResponse>, Status> {
let start = std::time::Instant::now();
trace!(
target: LOG_TARGET,
"GetAllCompletedTransactions: Incoming GRPC request"
);
let mut transaction_service = self.get_transaction_service();

let mut completed_transactions = transaction_service
.get_completed_transactions(None, None, None)
.await
.map_err(|err| {
Status::not_found(format!(
"GetAllCompletedTransactions: Error found for get_completed_transactions: {:?}",
err
))
})?;
completed_transactions.extend(
transaction_service
.get_cancelled_completed_transactions()
.await
.map_err(|err| {
Status::not_found(format!(
"GetAllCompletedTransactions: Error found for get_cancelled_completed_transactions: {:?}",
err
))
})?,
);

completed_transactions.sort_by(|a, b| {
b.timestamp
.partial_cmp(&a.timestamp)
.expect("Should be able to compare timestamps")
});

let req = request.into_inner();
let offset = usize::try_from(req.offset).unwrap_or(0);
let limit = if req.limit > 0 {
usize::try_from(req.limit).unwrap_or(usize::MAX)
} else {
usize::MAX
};
let transactions = completed_transactions
.into_iter()
.skip(offset)
.take(limit)
.map(|txn| TransactionInfo {
tx_id: txn.tx_id.into(),
source_address: txn.source_address.to_vec(),
dest_address: txn.destination_address.to_vec(),
status: TransactionStatus::from(txn.status.clone()) as i32,
amount: txn.amount.into(),
is_cancelled: txn.cancelled.is_some(),
direction: TransactionDirection::from(txn.direction.clone()) as i32,
fee: txn.fee.into(),
timestamp: txn.timestamp.timestamp() as u64,
excess_sig: txn
.transaction
.first_kernel_excess_sig()
.unwrap_or(&Signature::default())
.get_signature()
.to_vec(),
raw_payment_id: txn.payment_id.to_bytes(),
user_payment_id: txn.payment_id.user_data_as_bytes(),
mined_in_block_height: txn.mined_height.unwrap_or(0),
})
.collect();

trace!(target: LOG_TARGET, "'GetAllCompletedTransactions' completed in {:.2?}", start.elapsed());
Ok(Response::new(GetAllCompletedTransactionsResponse { transactions }))
}

async fn get_block_height_transactions(
&self,
request: Request<GetBlockHeightTransactionsRequest>,
Expand Down
Loading