Skip to content

Commit

Permalink
feat(dr): return posted height along dr_id on post_data_request
Browse files Browse the repository at this point in the history
Also satisfy clippy.
  • Loading branch information
Thomasvdam committed Dec 2, 2024
1 parent 8a48059 commit 73e6a68
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
12 changes: 11 additions & 1 deletion contract/src/msgs/data_requests/execute/post_request.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
use serde::{Deserialize, Serialize};
use staking::state::STAKERS;

use super::*;

#[derive(Serialize, Deserialize)]
pub(crate) struct ResponsePayload {
pub dr_id: String,
pub height: u64,
}

impl ExecuteHandler for execute::post_request::Execute {
/// Posts a data request to the pool
fn execute(self, deps: DepsMut, env: Env, _info: MessageInfo) -> Result<Response, ContractError> {
Expand Down Expand Up @@ -29,7 +36,10 @@ impl ExecuteHandler for execute::post_request::Execute {
let hex_dr_id = dr_id.to_hex();
let res = Response::new()
.add_attribute("action", "post_data_request")
.set_data(to_json_binary(&hex_dr_id)?)
.set_data(to_json_binary(&ResponsePayload {
dr_id: hex_dr_id.clone(),
height: env.block.height,
})?)
.add_event(Event::new("seda-data-request").add_attributes([
("dr_id", hex_dr_id.clone()),
("exec_program_id", self.posted_dr.exec_program_id.clone()),
Expand Down
9 changes: 7 additions & 2 deletions contract/src/msgs/data_requests/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use super::{
msgs::data_requests::{execute, query, sudo},
*,
};
use crate::{TestExecutor, TestInfo};
use crate::{msgs::data_requests::execute::post_request::ResponsePayload, TestExecutor, TestInfo};

pub fn calculate_dr_id_and_args(nonce: u128, replication_factor: u16) -> PostDataRequestArgs {
let exec_program_id = nonce.to_string().hash().to_hex();
Expand Down Expand Up @@ -109,7 +109,12 @@ impl TestInfo {
// set the chain height... will effect the height in the dr for us to sign.
self.set_block_height(env_height);
// someone posts a data request
self.execute(sender, &msg)
let res: ResponsePayload = self.execute(sender, &msg)?;
assert_eq!(
env_height, res.height,
"chain height does not match data request height"
);
Ok(res.dr_id)
}

#[track_caller]
Expand Down
2 changes: 1 addition & 1 deletion contract/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl TryFrom<&[u8]> for PublicKey {
}
}

impl<'a> PrimaryKey<'a> for PublicKey {
impl PrimaryKey<'_> for PublicKey {
type Prefix = ();
type SubPrefix = ();
type Suffix = ();
Expand Down

0 comments on commit 73e6a68

Please sign in to comment.