Skip to content

Commit

Permalink
Added new grpc method to wallet to get fees of a new template registr…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
ksrichard committed Nov 27, 2024
1 parent b75d533 commit 9b538ae
Show file tree
Hide file tree
Showing 4 changed files with 354 additions and 198 deletions.
7 changes: 7 additions & 0 deletions applications/minotari_app_grpc/proto/wallet.proto
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ service Wallet {
rpc StreamTransactionEvents(TransactionEventRequest) returns (stream TransactionEventResponse);

rpc RegisterValidatorNode(RegisterValidatorNodeRequest) returns (RegisterValidatorNodeResponse);

// Get calculated fees for a `CreateTemplateRegistrationRequest`
rpc GetTemplateRegistrationFee(CreateTemplateRegistrationRequest) returns (GetTemplateRegistrationFeeResponse);
}

message GetVersionRequest {}
Expand Down Expand Up @@ -290,6 +293,10 @@ message CreateTemplateRegistrationResponse {
bytes template_address = 2;
}

message GetTemplateRegistrationFeeResponse {
uint64 fee = 1;
}

message CancelTransactionRequest {
uint64 tx_id = 1;
}
Expand Down
141 changes: 73 additions & 68 deletions applications/minotari_console_wallet/src/grpc/wallet_grpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,57 +31,7 @@ use futures::{
SinkExt,
};
use log::*;
use minotari_app_grpc::tari_rpc::{
self,
payment_recipient::PaymentType,
wallet_server,
CheckConnectivityResponse,
ClaimHtlcRefundRequest,
ClaimHtlcRefundResponse,
ClaimShaAtomicSwapRequest,
ClaimShaAtomicSwapResponse,
CoinSplitRequest,
CoinSplitResponse,
CommitmentSignature,
CreateBurnTransactionRequest,
CreateBurnTransactionResponse,
CreateTemplateRegistrationRequest,
CreateTemplateRegistrationResponse,
GetAddressResponse,
GetBalanceRequest,
GetBalanceResponse,
GetCompletedTransactionsRequest,
GetCompletedTransactionsResponse,
GetConnectivityRequest,
GetIdentityRequest,
GetIdentityResponse,
GetTransactionInfoRequest,
GetTransactionInfoResponse,
GetUnspentAmountsResponse,
GetVersionRequest,
GetVersionResponse,
ImportUtxosRequest,
ImportUtxosResponse,
RegisterValidatorNodeRequest,
RegisterValidatorNodeResponse,
RevalidateRequest,
RevalidateResponse,
SendShaAtomicSwapRequest,
SendShaAtomicSwapResponse,
SetBaseNodeRequest,
SetBaseNodeResponse,
TransactionDirection,
TransactionEvent,
TransactionEventRequest,
TransactionEventResponse,
TransactionInfo,
TransactionStatus,
TransferRequest,
TransferResponse,
TransferResult,
ValidateRequest,
ValidateResponse,
};
use minotari_app_grpc::tari_rpc::{self, payment_recipient::PaymentType, wallet_server, CheckConnectivityResponse, ClaimHtlcRefundRequest, ClaimHtlcRefundResponse, ClaimShaAtomicSwapRequest, ClaimShaAtomicSwapResponse, CoinSplitRequest, CoinSplitResponse, CommitmentSignature, CreateBurnTransactionRequest, CreateBurnTransactionResponse, CreateTemplateRegistrationRequest, CreateTemplateRegistrationResponse, GetAddressResponse, GetBalanceRequest, GetBalanceResponse, GetCompletedTransactionsRequest, GetCompletedTransactionsResponse, GetConnectivityRequest, GetIdentityRequest, GetIdentityResponse, GetTemplateRegistrationFeeResponse, GetTransactionInfoRequest, GetTransactionInfoResponse, GetUnspentAmountsResponse, GetVersionRequest, GetVersionResponse, ImportUtxosRequest, ImportUtxosResponse, RegisterValidatorNodeRequest, RegisterValidatorNodeResponse, RevalidateRequest, RevalidateResponse, SendShaAtomicSwapRequest, SendShaAtomicSwapResponse, SetBaseNodeRequest, SetBaseNodeResponse, TransactionDirection, TransactionEvent, TransactionEventRequest, TransactionEventResponse, TransactionInfo, TransactionStatus, TransferRequest, TransferResponse, TransferResult, ValidateRequest, ValidateResponse};
use minotari_wallet::{
connectivity_service::{OnlineStatus, WalletConnectivityInterface},
error::WalletStorageError,
Expand Down Expand Up @@ -366,7 +316,7 @@ impl wallet_server::Wallet for WalletGrpcServer {
is_success: true,
failure_message: Default::default(),
}
},
}
Err(e) => {
warn!(
target: LOG_TARGET,
Expand All @@ -379,7 +329,7 @@ impl wallet_server::Wallet for WalletGrpcServer {
is_success: false,
failure_message: e.to_string(),
}
},
}
};

Ok(Response::new(response))
Expand Down Expand Up @@ -424,7 +374,7 @@ impl wallet_server::Wallet for WalletGrpcServer {
failure_message: e.to_string(),
},
}
},
}
Err(e) => {
warn!(target: LOG_TARGET, "Failed to claim SHA - XTR atomic swap: {}", e);
TransferResult {
Expand All @@ -433,7 +383,7 @@ impl wallet_server::Wallet for WalletGrpcServer {
is_success: false,
failure_message: e.to_string(),
}
},
}
};

Ok(Response::new(ClaimShaAtomicSwapResponse {
Expand Down Expand Up @@ -474,7 +424,7 @@ impl wallet_server::Wallet for WalletGrpcServer {
failure_message: e.to_string(),
},
}
},
}
Err(e) => {
warn!(target: LOG_TARGET, "Failed to claim HTLC refund transaction: {}", e);
TransferResult {
Expand All @@ -483,7 +433,7 @@ impl wallet_server::Wallet for WalletGrpcServer {
is_success: false,
failure_message: e.to_string(),
}
},
}
};

Ok(Response::new(ClaimHtlcRefundResponse {
Expand Down Expand Up @@ -584,7 +534,7 @@ impl wallet_server::Wallet for WalletGrpcServer {
is_success: false,
failure_message: err.to_string(),
}
},
}
})
.collect();

Expand Down Expand Up @@ -635,15 +585,15 @@ impl wallet_server::Wallet for WalletGrpcServer {
range_proof: proof.range_proof.to_vec(),
reciprocal_claim_public_key: proof.reciprocal_claim_public_key.to_vec(),
}
},
}
Err(e) => {
warn!(target: LOG_TARGET, "Failed to burn Tarid: {}", e);
CreateBurnTransactionResponse {
is_success: false,
failure_message: e.to_string(),
..Default::default()
}
},
}
};

Ok(Response::new(response))
Expand Down Expand Up @@ -803,17 +753,17 @@ impl wallet_server::Wallet for WalletGrpcServer {
i + 1,
transactions.len()
);
},
}
Err(err) => {
warn!(target: LOG_TARGET, "Error sending transaction via GRPC: {}", err);
match sender.send(Err(Status::unknown("Error sending data"))).await {
Ok(_) => (),
Err(send_err) => {
warn!(target: LOG_TARGET, "Error sending error to GRPC client: {}", send_err)
},
}
}
return;
},
}
}
}
});
Expand Down Expand Up @@ -947,13 +897,13 @@ impl wallet_server::Wallet for WalletGrpcServer {
is_success: true,
failure_message: "".to_string(),
}))
},
}
Err(e) => {
return Ok(Response::new(tari_rpc::CancelTransactionResponse {
is_success: false,
failure_message: e.to_string(),
}))
},
}
}
}

Expand Down Expand Up @@ -1071,10 +1021,65 @@ impl wallet_server::Wallet for WalletGrpcServer {
is_success: false,
failure_message: e.to_string(),
}
},
}
};
Ok(Response::new(response))
}

async fn get_template_registration_fee(&self, request: Request<CreateTemplateRegistrationRequest>)
-> Result<Response<GetTemplateRegistrationFeeResponse>, Status> {
let message = request.into_inner();
let mut transaction_service = self.wallet.transaction_service.clone();
let fee_per_gram = message.fee_per_gram.into();
let fee = transaction_service.code_template_fee(
message
.template_name
.try_into()
.map_err(|_| Status::invalid_argument("template name is too long"))?,
message
.template_version
.try_into()
.map_err(|_| Status::invalid_argument("template version is too large for a u16"))?,
if let Some(tt) = message.template_type {
tt.try_into()
.map_err(|_| Status::invalid_argument("template type is invalid"))?
} else {
return Err(Status::invalid_argument("template type is missing"));
},
if let Some(bi) = message.build_info {
bi.try_into()
.map_err(|_| Status::invalid_argument("build info is invalid"))?
} else {
return Err(Status::invalid_argument("build info is missing"));
},
message
.binary_sha
.try_into()
.map_err(|_| Status::invalid_argument("binary sha is malformed"))?,
message
.binary_url
.try_into()
.map_err(|_| Status::invalid_argument("binary URL is too long"))?,
fee_per_gram,
if message.sidechain_deployment_key.is_empty() {
None
} else {
Some(
RistrettoSecretKey::from_canonical_bytes(&message.sidechain_deployment_key)
.map_err(|_| Status::invalid_argument("sidechain_deployment_key is malformed"))?,
)
},
).await
.map_err(|e| Status::internal(e.to_string()))?;

Ok(
Response::new(
GetTemplateRegistrationFeeResponse {
fee: fee.as_u64(),
}
)
)
}
}

async fn handle_completed_tx(
Expand All @@ -1088,7 +1093,7 @@ async fn handle_completed_tx(
let transaction_event =
convert_to_transaction_event(event.to_string(), TransactionWrapper::Completed(Box::new(completed)));
send_transaction_event(transaction_event, sender).await;
},
}
Err(e) => error!(target: LOG_TARGET, "Transaction service error: {}", e),
}
}
Expand All @@ -1108,7 +1113,7 @@ async fn handle_pending_outbound(
} else {
error!(target: LOG_TARGET, "Not found in pending outbound set tx_id: {}", tx_id);
}
},
}
Err(e) => error!(target: LOG_TARGET, "Transaction service error: {}", e),
}
}
Expand Down
Loading

0 comments on commit 9b538ae

Please sign in to comment.