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

Return posted height along dr_id on post_data_request #235

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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