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

[Wallet] Update wallet gRPC server to send one-sided payments #2865

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
5 changes: 5 additions & 0 deletions applications/tari_app_grpc/proto/wallet.proto
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ message PaymentRecipient {
uint64 amount = 2;
uint64 fee_per_gram = 3;
string message = 4;
enum PaymentType {
STANDARD_MIMBLEWIMBLE = 0;
sdbondi marked this conversation as resolved.
Show resolved Hide resolved
ONE_SIDED = 1;
}
PaymentType payment_type = 5;
}

message TransferResponse {
Expand Down
41 changes: 31 additions & 10 deletions applications/tari_console_wallet/src/grpc/wallet_grpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use log::*;
use tari_app_grpc::{
conversions::naive_datetime_to_timestamp,
tari_rpc::{
payment_recipient::PaymentType,
wallet_server,
CoinSplitRequest,
CoinSplitResponse,
Expand Down Expand Up @@ -123,29 +124,49 @@ impl wallet_server::Wallet for WalletGrpcServer {
.map(|(idx, dest)| -> Result<_, String> {
let pk = CommsPublicKey::from_hex(&dest.address)
.map_err(|_| format!("Destination address at index {} is malformed", idx))?;
Ok((dest.address, pk, dest.amount, dest.fee_per_gram, dest.message))
Ok((
dest.address,
pk,
dest.amount,
dest.fee_per_gram,
dest.message,
dest.payment_type,
))
})
.collect::<Result<Vec<_>, _>>()
.map_err(Status::invalid_argument)?;

let transfers = recipients
.into_iter()
.map(|(address, pk, amount, fee_per_gram, message)| {
let mut transaction_service = self.get_transaction_service();
async move {
let mut standard_transfers = Vec::new();
let mut one_sided_transfers = Vec::new();
for (address, pk, amount, fee_per_gram, message, payment_type) in recipients.into_iter() {
let mut transaction_service = self.get_transaction_service();
if payment_type == PaymentType::StandardMimblewimble as i32 {
standard_transfers.push(async move {
(
address,
transaction_service
.send_transaction(pk, amount.into(), fee_per_gram.into(), message)
.await,
)
}
});
});
} else if payment_type == PaymentType::OneSided as i32 {
one_sided_transfers.push(async move {
(
address,
transaction_service
.send_one_sided_transaction(pk, amount.into(), fee_per_gram.into(), message)
.await,
)
});
}
sdbondi marked this conversation as resolved.
Show resolved Hide resolved
}

let results = future::join_all(transfers).await;
let standard_results = future::join_all(standard_transfers).await;
let one_sided_results = future::join_all(one_sided_transfers).await;

let results = results
let results = standard_results
.into_iter()
.chain(one_sided_results.into_iter())
.map(|(address, result)| match result {
Ok(tx_id) => TransferResult {
address,
Expand Down