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(validator): add grpc identity rpc #3731

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 8 additions & 0 deletions applications/tari_app_grpc/proto/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -411,3 +411,11 @@ message SoftwareUpdate {
string sha = 3;
string download_url = 4;
}

message GetIdentityRequest { }

message GetIdentityResponse {
bytes public_key = 1;
string public_address = 2;
bytes node_id = 3;
}
2 changes: 2 additions & 0 deletions applications/tari_app_grpc/proto/validator_node.proto
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ import "types.proto";
package tari.rpc;

service ValidatorNode {
rpc GetIdentity(GetIdentityRequest) returns (GetIdentityResponse);
rpc GetMetadata(GetMetadataRequest) returns (GetMetadataResponse);
rpc GetTokenData(GetTokenDataRequest) returns (GetTokenDataResponse);
// rpc ExecuteInstruction(ExecuteInstructionRequest) returns (ExecuteInstructionResponse);
rpc InvokeReadMethod(InvokeReadMethodRequest) returns (InvokeReadMethodResponse);
rpc InvokeMethod(InvokeMethodRequest) returns (InvokeMethodResponse);
}


message GetMetadataRequest {
// empty
}
Expand Down
7 changes: 0 additions & 7 deletions applications/tari_app_grpc/proto/wallet.proto
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,6 @@ service Wallet {

message GetVersionRequest { }

message GetIdentityRequest { }

message GetIdentityResponse {
bytes public_key = 1;
string public_address = 2;
bytes node_id = 3;
}

message GetVersionResponse {
string version = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
use tari_app_grpc::tari_rpc as rpc;
use tari_common_types::types::PublicKey;
use tari_comms::NodeIdentity;
use tari_crypto::tari_utilities::ByteArray;
use tari_dan_core::{
models::TemplateId,
Expand All @@ -30,18 +31,21 @@ use tari_dan_core::{
use tonic::{Request, Response, Status};

pub struct ValidatorNodeGrpcServer<TServiceSpecification: ServiceSpecification> {
node_identity: NodeIdentity,
db_factory: TServiceSpecification::DbFactory,
asset_processor: TServiceSpecification::AssetProcessor,
asset_proxy: TServiceSpecification::AssetProxy,
}

impl<TServiceSpecification: ServiceSpecification> ValidatorNodeGrpcServer<TServiceSpecification> {
pub fn new(
node_identity: NodeIdentity,
db_factory: TServiceSpecification::DbFactory,
asset_processor: TServiceSpecification::AssetProcessor,
asset_proxy: TServiceSpecification::AssetProxy,
) -> Self {
Self {
node_identity,
db_factory,
asset_processor,
asset_proxy,
Expand All @@ -53,6 +57,18 @@ impl<TServiceSpecification: ServiceSpecification> ValidatorNodeGrpcServer<TServi
impl<TServiceSpecification: ServiceSpecification + 'static> rpc::validator_node_server::ValidatorNode
for ValidatorNodeGrpcServer<TServiceSpecification>
{
async fn get_identity(
&self,
_request: tonic::Request<rpc::GetIdentityRequest>,
) -> Result<tonic::Response<rpc::GetIdentityResponse>, tonic::Status> {
let response = rpc::GetIdentityResponse {
public_key: self.node_identity.public_key().to_vec(),
public_address: self.node_identity.public_address().to_string(),
node_id: self.node_identity.node_id().to_vec(),
};
Ok(Response::new(response))
}

async fn get_token_data(
&self,
request: tonic::Request<rpc::GetTokenDataRequest>,
Expand Down
8 changes: 6 additions & 2 deletions applications/tari_validator_node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,12 @@ async fn run_node(config: GlobalConfig, create_id: bool) -> Result<(), ExitCodes
db_factory.clone(),
);

let grpc_server: ValidatorNodeGrpcServer<DefaultServiceSpecification> =
ValidatorNodeGrpcServer::new(db_factory.clone(), asset_processor, asset_proxy);
let grpc_server: ValidatorNodeGrpcServer<DefaultServiceSpecification> = ValidatorNodeGrpcServer::new(
node_identity.as_ref().clone(),
db_factory.clone(),
asset_processor,
asset_proxy,
);
let grpc_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 18144);

task::spawn(run_grpc(grpc_server, grpc_addr, shutdown.to_signal()));
Expand Down