Skip to content

Commit

Permalink
feat(wallet): add grpc method for setting base node
Browse files Browse the repository at this point in the history
Description
---
Aim to resolve #3821

Motivation and Context
---
Learning via "good first issue"

How Has This Been Tested?
---
Manual test with `grpcurl`
  • Loading branch information
zhangcheng committed Feb 14, 2022
1 parent c39520e commit 9fbe1e7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
9 changes: 9 additions & 0 deletions applications/tari_app_grpc/proto/wallet.proto
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ service Wallet {
rpc MintTokens(MintTokensRequest) returns (MintTokensResponse);

rpc GetOwnedTokens(GetOwnedTokensRequest) returns (GetOwnedTokensResponse);

rpc SetBaseNode(SetBaseNodeRequest) returns (SetBaseNodeResponse);
}

message GetVersionRequest { }
Expand Down Expand Up @@ -335,3 +337,10 @@ message CancelTransactionResponse {
message RevalidateRequest{}

message RevalidateResponse{}

message SetBaseNodeRequest {
string public_key_hex = 1;
string net_address = 2;
}

message SetBaseNodeResponse{}
27 changes: 26 additions & 1 deletion applications/tari_console_wallet/src/grpc/wallet_grpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ use tari_app_grpc::{
RevalidateResponse,
SendShaAtomicSwapRequest,
SendShaAtomicSwapResponse,
SetBaseNodeRequest,
SetBaseNodeResponse,
TransactionDirection,
TransactionInfo,
TransactionStatus,
Expand All @@ -76,7 +78,7 @@ use tari_common_types::{
array::copy_into_fixed_array,
types::{BlockHash, PublicKey, Signature},
};
use tari_comms::{types::CommsPublicKey, CommsNode};
use tari_comms::{multiaddr::Multiaddr, types::CommsPublicKey, CommsNode};
use tari_core::transactions::{
tari_amount::MicroTari,
transaction_components::{OutputFeatures, UnblindedOutput},
Expand Down Expand Up @@ -150,6 +152,29 @@ impl wallet_server::Wallet for WalletGrpcServer {
}))
}

async fn set_base_node(
&self,
request: Request<SetBaseNodeRequest>,
) -> Result<Response<SetBaseNodeResponse>, Status> {
let message = request.into_inner();
let public_key = PublicKey::from_hex(&message.public_key_hex)
.map_err(|e| Status::invalid_argument(format!("Base node public key was not a valid pub key: {}", e)))?;
let net_address = message
.net_address
.parse::<Multiaddr>()
.map_err(|e| Status::invalid_argument(format!("Base node net address was not valid: {}", e)))?;

println!("Setting base node peer...");
println!("{}::{}", public_key, net_address);
let mut wallet = self.wallet.clone();
wallet
.set_base_node_peer(public_key.clone(), net_address.clone())
.await
.map_err(|e| Status::internal(format!("{:?}", e)))?;

Ok(Response::new(SetBaseNodeResponse {}))
}

async fn get_balance(&self, _request: Request<GetBalanceRequest>) -> Result<Response<GetBalanceResponse>, Status> {
let mut output_service = self.get_output_manager_service();
let balance;
Expand Down

0 comments on commit 9fbe1e7

Please sign in to comment.