Skip to content

Commit

Permalink
try to fix #3821
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangcheng committed Feb 13, 2022
1 parent b1492a0 commit 6016404
Show file tree
Hide file tree
Showing 2 changed files with 29 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 {
bytes public_key = 1;
string net_address = 2;
}

message SetBaseNodeResponse{}
21 changes: 20 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 @@ -70,13 +70,15 @@ use tari_app_grpc::{
TransferRequest,
TransferResponse,
TransferResult,
SetBaseNodeRequest,
SetBaseNodeResponse,
},
};
use tari_common_types::{
array::copy_into_fixed_array,
types::{BlockHash, PublicKey, Signature},
};
use tari_comms::{types::CommsPublicKey, CommsNode};
use tari_comms::{types::CommsPublicKey, CommsNode, multiaddr::Multiaddr};
use tari_core::transactions::{
tari_amount::MicroTari,
transaction_components::{OutputFeatures, UnblindedOutput},
Expand Down Expand Up @@ -150,6 +152,23 @@ 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_bytes(message.public_key.as_slice())
.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 6016404

Please sign in to comment.