Skip to content

Commit

Permalink
fix(validator-node): return error if contract_id empty for publish_co…
Browse files Browse the repository at this point in the history
…ntract_acceptance grpc (#4191)

Description
---
Returns invalid argument if contract id is not provided
Log error if publishing fails

Motivation and Context
---
If contract_id was not provided, a zero hash would be used and published.

How Has This Been Tested?
---
Manually
  • Loading branch information
sdbondi authored Jun 15, 2022
1 parent e324b80 commit 8874114
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use tari_dan_core::{
use tokio::{task, time};
use tonic::{Request, Response, Status};

const _LOG_TARGET: &str = "tari::validator_node::grpc";
const LOG_TARGET: &str = "tari::validator_node::grpc";

pub struct ValidatorNodeGrpcServer<TServiceSpecification: ServiceSpecification> {
node_identity: NodeIdentity,
Expand Down Expand Up @@ -77,7 +77,8 @@ impl<TServiceSpecification: ServiceSpecification + 'static> rpc::validator_node_
) -> Result<Response<rpc::PublishContractAcceptanceResponse>, tonic::Status> {
let mut wallet_client = self.wallet_client.clone();
let request = request.into_inner();
let contract_id = FixedHash::try_from(request.contract_id).unwrap_or_default();
let contract_id =
FixedHash::try_from(request.contract_id).map_err(|err| tonic::Status::invalid_argument(err.to_string()))?;
let validator_node_public_key = self.node_identity.public_key();
let signature = Signature::default();

Expand All @@ -89,10 +90,13 @@ impl<TServiceSpecification: ServiceSpecification + 'static> rpc::validator_node_
tx_id,
status: "Accepted".to_string(),
})),
Err(_) => Ok(Response::new(rpc::PublishContractAcceptanceResponse {
status: "Errored".to_string(),
tx_id: 0_u64,
})),
Err(err) => {
log::error!(target: LOG_TARGET, "publish_contract_acceptance: {}", err);
Ok(Response::new(rpc::PublishContractAcceptanceResponse {
status: "Errored".to_string(),
tx_id: 0_u64,
}))
},
}
}

Expand Down

0 comments on commit 8874114

Please sign in to comment.