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
9 changes: 6 additions & 3 deletions applications/minotari_app_grpc/proto/wallet.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1065,8 +1065,10 @@ message PaymentRecipient {
}
// The type of payment to perform.
PaymentType payment_type = 5;
// Optional encrypted payment ID for reference (max 256 bytes).
bytes payment_id = 6;
// raw payment id
bytes raw_payment_id = 6;
// Optional user encrypted payment ID for reference (max 256 bytes).
UserPaymentId user_payment_id = 7;
}

message TransferResponse {
Expand Down Expand Up @@ -1136,8 +1138,9 @@ message TransactionInfo {
bool is_cancelled = 8;
bytes excess_sig = 9;
uint64 timestamp = 10;
bytes payment_id = 12;
bytes raw_payment_id = 12;
uint64 mined_in_block_height = 13;
bytes user_payment_id = 14;
}

enum TransactionDirection {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,15 +489,38 @@ impl wallet_server::Wallet for WalletGrpcServer {
.ok_or_else(|| Status::internal("Request is malformed".to_string()))?;
let address = TariAddress::from_str(&message.address)
.map_err(|_| Status::internal("Destination address is malformed".to_string()))?;

let payment_id = if !message.raw_payment_id.is_empty() {
PaymentId::from_bytes(&message.raw_payment_id)
} else if let Some(user_pay_id) = message.user_payment_id {
let bytes = match (
user_pay_id.u256.is_empty(),
user_pay_id.utf8_string.is_empty(),
user_pay_id.user_bytes.is_empty(),
) {
(false, true, true) => user_pay_id.u256,
(true, false, true) => user_pay_id.utf8_string.as_bytes().to_vec(),
(true, true, false) => user_pay_id.user_bytes,
_ => {
return Err(Status::invalid_argument(
"user_payment_id must be one of u256, utf8_string or user_bytes".to_string(),
));
},
};
PaymentId::Open {
user_data: bytes,
tx_type: TxType::ClaimAtomicSwap,
}
} else {
PaymentId::Empty
};
let mut transaction_service = self.get_transaction_service();
let response = match transaction_service
.send_sha_atomic_swap_transaction(
address.clone(),
message.amount.into(),
UtxoSelectionCriteria::default(),
message.fee_per_gram.into(),
PaymentId::from_bytes(&message.payment_id),
payment_id,
)
.await
{
Expand Down Expand Up @@ -649,6 +672,7 @@ impl wallet_server::Wallet for WalletGrpcServer {
}))
}

#[allow(clippy::too_many_lines)]
async fn transfer(&self, request: Request<TransferRequest>) -> Result<Response<TransferResponse>, Status> {
let message = request.into_inner();
let recipients = message
Expand All @@ -664,15 +688,39 @@ impl wallet_server::Wallet for WalletGrpcServer {
dest.amount,
dest.fee_per_gram,
dest.payment_type,
dest.payment_id,
dest.user_payment_id,
dest.raw_payment_id,
))
})
.collect::<Result<Vec<_>, _>>()
.map_err(Status::invalid_argument)?;

let mut transfers = Vec::new();
for (hex_address, address, amount, fee_per_gram, payment_type, payment_id) in recipients {
let payment_id = PaymentId::from_bytes(&payment_id);
for (hex_address, address, amount, fee_per_gram, payment_type, user_payment_id, raw_payment_id) in recipients {
let payment_id = if !raw_payment_id.is_empty() {
PaymentId::from_bytes(&raw_payment_id)
} else if let Some(user_pay_id) = user_payment_id {
let bytes = match (
user_pay_id.u256.is_empty(),
user_pay_id.utf8_string.is_empty(),
user_pay_id.user_bytes.is_empty(),
) {
(false, true, true) => user_pay_id.u256,
(true, false, true) => user_pay_id.utf8_string.as_bytes().to_vec(),
(true, true, false) => user_pay_id.user_bytes,
_ => {
return Err(Status::invalid_argument(
"user_payment_id must be one of u256, utf8_string or user_bytes".to_string(),
));
},
};
PaymentId::Open {
user_data: bytes,
tx_type: TxType::PaymentToOther,
}
} else {
PaymentId::Empty
};
let mut transaction_service = self.get_transaction_service();
transfers.push(async move {
(
Expand Down Expand Up @@ -971,7 +1019,8 @@ impl wallet_server::Wallet for WalletGrpcServer {
.unwrap_or(&Signature::default())
.get_signature()
.to_vec(),
payment_id: txn.payment_id.to_bytes(),
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),
}),
};
Expand Down Expand Up @@ -1321,7 +1370,8 @@ fn convert_wallet_transaction_into_transaction_info(
fee: 0,
excess_sig: Default::default(),
timestamp: tx.timestamp.timestamp() as u64,
payment_id: tx.payment_id.to_bytes(),
raw_payment_id: tx.payment_id.to_bytes(),
user_payment_id: tx.payment_id.user_data_as_bytes(),
mined_in_block_height: 0,
},
PendingOutbound(tx) => TransactionInfo {
Expand All @@ -1335,7 +1385,8 @@ fn convert_wallet_transaction_into_transaction_info(
fee: tx.fee.into(),
excess_sig: Default::default(),
timestamp: tx.timestamp.timestamp() as u64,
payment_id: tx.payment_id.to_bytes(),
raw_payment_id: tx.payment_id.to_bytes(),
user_payment_id: tx.payment_id.user_data_as_bytes(),
mined_in_block_height: 0,
},
Completed(tx) => TransactionInfo {
Expand All @@ -1353,7 +1404,8 @@ fn convert_wallet_transaction_into_transaction_info(
.first_kernel_excess_sig()
.map(|s| s.get_signature().to_vec())
.unwrap_or_default(),
payment_id: tx.payment_id.to_bytes(),
raw_payment_id: tx.payment_id.to_bytes(),
user_payment_id: tx.payment_id.user_data_as_bytes(),
mined_in_block_height: tx.mined_height.unwrap_or(0),
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,13 @@ where TContactServiceDbConnection: PooledDbConnection<Error = SqliteStorageError
let stored_contact = ContactSql::find_by_node_id(&c.node_id.to_vec(), &mut conn)?;
let stored_address = TariAddress::from_bytes(stored_contact.address.as_slice())
.map_err(|_| ContactsServiceStorageError::ConversionError)?;
let new_address = TariAddress::combine_addresses(&stored_address, &k)
let mut new_address = TariAddress::combine_addresses(&stored_address, &k)
.map_err(|_| ContactsServiceStorageError::ConversionError)?;
if !k.get_payment_id_user_data_bytes().is_empty() {
new_address = new_address
.with_payment_id_user_data(k.get_payment_id_user_data_bytes())
.map_err(|_| ContactsServiceStorageError::ConversionError)?;
}
ContactSql::set_address_of_node_id(&c.node_id.to_vec(), &new_address.to_vec(), &mut conn)?;
}
},
Expand Down
2 changes: 1 addition & 1 deletion base_layer/wallet/src/base_node_service/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ where T: WalletBackend + 'static
&mut self,
request: BaseNodeServiceRequest,
) -> Result<BaseNodeServiceResponse, BaseNodeServiceError> {
debug!(
trace!(
target: LOG_TARGET,
"Handling Wallet Base Node Service Request: {:?}", request
);
Expand Down
4 changes: 2 additions & 2 deletions base_layer/wallet/src/connectivity_service/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ impl WalletConnectivityService {
match self.pools.get(&node_id) {
Some(pools) => match pools.base_node_wallet_rpc_client.get().await {
Ok(client) => {
debug!(target: LOG_TARGET, "Obtained pool RPC 'wallet' connection to base node '{}'", node_id);
trace!(target: LOG_TARGET, "Obtained pool RPC 'wallet' connection to base node '{}'", node_id);
let _result = reply.send(client);
},
Err(e) => {
Expand Down Expand Up @@ -247,7 +247,7 @@ impl WalletConnectivityService {
match self.pools.get(&node_id) {
Some(pools) => match pools.base_node_sync_rpc_client.get().await {
Ok(client) => {
debug!(target: LOG_TARGET, "Obtained pool RPC 'sync' connection to base node '{}'", node_id);
trace!(target: LOG_TARGET, "Obtained pool RPC 'sync' connection to base node '{}'", node_id);
let _result = reply.send(client);
},
Err(e) => {
Expand Down
12 changes: 8 additions & 4 deletions base_layer/wallet/src/transaction_service/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,7 @@ where
>,
reply_channel: oneshot::Sender<Result<TransactionServiceResponse, TransactionServiceError>>,
) -> Result<(), TransactionServiceError> {
debug!(target: LOG_TARGET, "Sending transaction to {} with {}", destination, amount);
let tx_id = TxId::new_random();
if let Err(e) = self.verify_send(&destination, TariAddressFeatures::create_interactive_only()) {
let err = match e {
Expand All @@ -1159,6 +1160,11 @@ where
});
return Err(e);
}
// let override the payment_id if the address says we should
if destination.features().contains(TariAddressFeatures::PAYMENT_ID) {
debug!(target: LOG_TARGET, "Address contains memo, overriding memo {} with {:?}", payment_id, destination.get_payment_id_user_data_bytes());
payment_id = PaymentId::open(destination.get_payment_id_user_data_bytes(), TxType::PaymentToOther);
}
// If we're paying ourselves, let's complete and submit the transaction immediately
if &self
.resources
Expand Down Expand Up @@ -1219,10 +1225,6 @@ where

return Ok(());
}
// let override the payment_id if the address says we should
if destination.features().contains(TariAddressFeatures::PAYMENT_ID) {
payment_id = PaymentId::open(destination.get_payment_id_user_data_bytes(), TxType::PaymentToOther);
}
let (tx_reply_sender, tx_reply_receiver) = mpsc::channel(100);
let (cancellation_sender, cancellation_receiver) = oneshot::channel();
self.pending_transaction_reply_senders.insert(tx_id, tx_reply_sender);
Expand Down Expand Up @@ -1773,9 +1775,11 @@ where
recipient_script: Option<TariScript>,
mut payment_id: PaymentId,
) -> Result<TxId, TransactionServiceError> {
debug!(target: LOG_TARGET, "Sending one sided transaction to {} with {}", dest_address, amount);
let tx_id = TxId::new_random();
// let override the payment_id if the address says we should
if dest_address.features().contains(TariAddressFeatures::PAYMENT_ID) {
debug!(target: LOG_TARGET, "Address contains memo, overriding memo {} with {:?}", payment_id, dest_address.get_payment_id_user_data_bytes());
payment_id = PaymentId::open(dest_address.get_payment_id_user_data_bytes(), TxType::PaymentToOther);
}
let payment_id = match payment_id.clone() {
Expand Down
Loading
Loading