From 9fbe1e7fea1d8acfca62b58dd397c1aebe69fdfb Mon Sep 17 00:00:00 2001 From: ZHANG Cheng Date: Sun, 13 Feb 2022 16:38:37 +0800 Subject: [PATCH] feat(wallet): add grpc method for setting base node Description --- Aim to resolve #3821 Motivation and Context --- Learning via "good first issue" How Has This Been Tested? --- Manual test with `grpcurl` --- applications/tari_app_grpc/proto/wallet.proto | 9 +++++++ .../src/grpc/wallet_grpc_server.rs | 27 ++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/applications/tari_app_grpc/proto/wallet.proto b/applications/tari_app_grpc/proto/wallet.proto index edb4a6957d..29c9f8b00b 100644 --- a/applications/tari_app_grpc/proto/wallet.proto +++ b/applications/tari_app_grpc/proto/wallet.proto @@ -77,6 +77,8 @@ service Wallet { rpc MintTokens(MintTokensRequest) returns (MintTokensResponse); rpc GetOwnedTokens(GetOwnedTokensRequest) returns (GetOwnedTokensResponse); + + rpc SetBaseNode(SetBaseNodeRequest) returns (SetBaseNodeResponse); } message GetVersionRequest { } @@ -335,3 +337,10 @@ message CancelTransactionResponse { message RevalidateRequest{} message RevalidateResponse{} + +message SetBaseNodeRequest { + string public_key_hex = 1; + string net_address = 2; +} + +message SetBaseNodeResponse{} diff --git a/applications/tari_console_wallet/src/grpc/wallet_grpc_server.rs b/applications/tari_console_wallet/src/grpc/wallet_grpc_server.rs index 68fe030250..b9aff22252 100644 --- a/applications/tari_console_wallet/src/grpc/wallet_grpc_server.rs +++ b/applications/tari_console_wallet/src/grpc/wallet_grpc_server.rs @@ -64,6 +64,8 @@ use tari_app_grpc::{ RevalidateResponse, SendShaAtomicSwapRequest, SendShaAtomicSwapResponse, + SetBaseNodeRequest, + SetBaseNodeResponse, TransactionDirection, TransactionInfo, TransactionStatus, @@ -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}, @@ -150,6 +152,29 @@ impl wallet_server::Wallet for WalletGrpcServer { })) } + async fn set_base_node( + &self, + request: Request, + ) -> Result, 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::() + .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) -> Result, Status> { let mut output_service = self.get_output_manager_service(); let balance;