Skip to content

Commit

Permalink
fix(cli): fix data request report for missing reveals
Browse files Browse the repository at this point in the history
  • Loading branch information
drcpu-github committed Dec 13, 2024
1 parent f754629 commit 69ceea3
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions src/cli/node/json_rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use witnet_data_structures::{
SupplyInfo, SyncStatus, ValueTransferOutput,
},
fee::Fee,
get_environment,
get_environment, get_protocol_version,
proto::{
versioning::{ProtocolInfo, ProtocolVersion},
ProtobufConvert,
Expand Down Expand Up @@ -1328,6 +1328,7 @@ pub fn data_request_report(
let response = send_request(&mut stream, &request)?;
let transaction: GetTransactionOutput = parse_response(&response)?;

let data_request_transaction_epoch = transaction.block_epoch.clone();
let data_request_transaction_block_hash = transaction.block_hash.clone();
let transaction_block_hash = if transaction.block_hash == "pending" {
None
Expand All @@ -1340,6 +1341,19 @@ pub fn data_request_report(
bail!("This is not a data request transaction");
};

let request = r#"{"jsonrpc": "2.0","method": "protocol", "id": "1"}"#;
let response = send_request(&mut stream, request)?;
let protocol_info: Option<ProtocolInfo> = parse_response(&response)?;

let version_at_epoch = if let Some(info) = protocol_info {
match data_request_transaction_epoch {
Some(epoch) => info.all_versions.version_for_epoch(epoch),
None => ProtocolVersion::default(),
}
} else {
ProtocolVersion::default()
};

let mut dr_output = dr_tx.body.dr_output;
let dr_creator_pkh = dr_tx.signatures[0].public_key.pkh();

Expand Down Expand Up @@ -1448,12 +1462,16 @@ pub fn data_request_report(
{
format!("-{}", dr_output.collateral)
} else {
let reward = tally
.outputs
.iter()
.find(|vto| vto.pkh == pkh)
.map(|vto| vto.value)
.unwrap();
let reward = if version_at_epoch >= ProtocolVersion::V2_0 {
dr_output.witness_reward + dr_output.collateral
} else {
tally
.outputs
.iter()
.find(|vto| vto.pkh == pkh)
.map(|vto| vto.value)
.unwrap()
};

let reward = reward - dr_output.collateral;

Expand Down

0 comments on commit 69ceea3

Please sign in to comment.