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

feat(wallet): add grpc method for setting base node #3828

Merged
merged 1 commit into from
Feb 14, 2022
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: 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