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

♻️ Split seda-chain-contracts into DataRequests and Staking #61

Merged
merged 6 commits into from
Sep 25, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/Basic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
run: cargo clippy -- -D warnings

- name: Generate Schema
run: cargo schema --locked
run: cargo schema --locked --package proxy-contract

- name: Schema Changes
# fails if any changes not committed
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/Deploy-WASM-Storage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
name: Deploy WASM storage to testnet

jobs:
check_pass:
check_pass:
name: Check password
runs-on: ubuntu-latest
outputs:
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/Deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ on:
type: choice
options:
- proxy_contract
- seda_chain_contracts
- data_requests
- staking
password:
required: true
proxy:
required: false

name: Deploy Seda Contract
name: Deploy SEDA Contract

jobs:
check_pass:
Expand Down Expand Up @@ -136,7 +137,7 @@ jobs:
devAccount=${{ env.DEV_ACCOUNT }}
if [[ "${{ github.event.inputs.contract }}" != "proxy_contract" ]]; then
proxy=${{ github.event.inputs.proxy }}
OUTPUT=$(./seda-chaind tx wasm instantiate ${{ env.code_id }} '{"token":"aseda","proxy":"${proxy}"}' --no-admin --from ${devAccount} --node ${nodeUrl} --keyring-dir . --keyring-backend test --label ${{ env.code_id }} --gas-prices 0.1aseda --gas auto --gas-adjustment 1.3 -y --output json)
OUTPUT=$(./seda-chaind tx wasm instantiate ${{ env.code_id }} '{"token":"aseda", "proxy": ${{ toJSON(github.event.inputs.proxy) }} }' --no-admin --from ${devAccount} --node ${nodeUrl} --keyring-dir . --keyring-backend test --label ${{ env.code_id }} --gas-prices 0.1aseda --gas auto --gas-adjustment 1.3 -y --output json)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha nice!

else
OUTPUT=$(./seda-chaind tx wasm instantiate ${{ env.code_id }} '{"token":"aseda"}' --no-admin --from ${devAccount} --node ${nodeUrl} --keyring-dir . --keyring-backend test --label ${{ env.code_id }} --gas-prices 0.1aseda --gas auto --gas-adjustment 1.3 -y --output json)
fi
Expand Down
58 changes: 35 additions & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[workspace]
resolver = "2"
members = [
"packages/seda-chain-contracts",
"packages/staking",
"packages/data-requests",
"packages/wasm-bin-storage",
"packages/integration-tests",
"packages/proxy"
Expand All @@ -28,7 +29,8 @@ cw2 = "1.1"
hex = "0.4.3"
proxy-contract = { path = "./packages/proxy" }
schemars = "0.8.10"
seda-chain-contracts = { path = "./packages/seda-chain-contracts" }
data-requests = { path = "./packages/data-requests" }
staking = { path = "./packages/staking" }
serde = { version = "1.0.145", default-features = false, features = ["derive"] }
sha3 = "0.10.8"
thiserror = { version = "1.0.31" }
Expand Down
2 changes: 1 addition & 1 deletion DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ We must mount the contract code to `/code`. You can use a absolute path instead

This is rather slow compared to local compilations, especially the first compile of a given contract. The use of the two volume caches is very useful to speed up following compiles of the same contract.

This produces an `artifacts` directory with a `seda_chain_contracts.wasm`, as well as `checksums.txt`, containing the Sha256 hash of the wasm file. The wasm file is compiled deterministically (anyone else running the same docker on the same git commit should get the identical file with the same Sha256 hash). It is also stripped and minimized for upload to a blockchain (we will also gzip it in the uploading process to make it even smaller).
This produces an `artifacts` directory including a WASM binary for each contract, as well as `checksums.txt`, containing the Sha256 hash of the wasm file. The wasm file is compiled deterministically (anyone else running the same docker on the same git commit should get the identical file with the same Sha256 hash). It is also stripped and minimized for upload to a blockchain (we will also gzip it in the uploading process to make it even smaller).

## Verification

Expand Down
20 changes: 18 additions & 2 deletions packages/common/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct PostDataRequestArgs {
}

#[cw_serde]
pub enum ExecuteMsg {
pub enum DataRequestsExecuteMsg {
PostDataRequest {
posted_dr: PostDataRequestArgs,
},
Expand All @@ -34,6 +34,10 @@ pub enum ExecuteMsg {
reveal: Reveal,
sender: Option<String>,
},
}

#[cw_serde]
pub enum StakingExecuteMsg {
RegisterDataRequestExecutor {
p2p_multi_address: Option<String>,
sender: Option<String>,
Expand All @@ -56,7 +60,7 @@ pub enum ExecuteMsg {

#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
pub enum DataRequestsQueryMsg {
#[returns(GetDataRequestResponse)]
GetDataRequest { dr_id: Hash },
#[returns(GetDataRequestsFromPoolResponse)]
Expand All @@ -74,8 +78,15 @@ pub enum QueryMsg {
GetRevealedDataResults { dr_id: Hash },
#[returns(GetResolvedDataResultResponse)]
GetResolvedDataResult { dr_id: Hash },
}

#[cw_serde]
#[derive(QueryResponses)]
pub enum StakingQueryMsg {
#[returns(GetDataRequestExecutorResponse)]
GetDataRequestExecutor { executor: Addr },
#[returns(IsDataRequestExecutorEligibleResponse)]
IsDataRequestExecutorEligible { executor: Addr },
}

#[cw_serde]
Expand Down Expand Up @@ -126,3 +137,8 @@ pub struct GetDataRequestExecutorResponse {
pub struct GetCommittedExecutorsResponse {
pub value: Vec<String>,
}

#[cw_serde]
pub struct IsDataRequestExecutorEligibleResponse {
pub value: bool,
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "seda-chain-contracts"
name = "data-requests"
version = "0.1.0"
edition = "2021"

Expand Down Expand Up @@ -39,6 +39,3 @@ schemars = { workspace = true }
serde = { workspace = true }
sha3 = { workspace = true }
thiserror = { workspace = true }

[dev-dependencies]
cw-multi-test = "0.16.2"
12 changes: 12 additions & 0 deletions packages/data-requests/src/bin/schema.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use cosmwasm_schema::write_api;

use common::msg::{DataRequestsExecuteMsg, DataRequestsQueryMsg};
use data_requests::msg::InstantiateMsg;

fn main() {
write_api! {
instantiate: InstantiateMsg,
execute: DataRequestsExecuteMsg,
query: DataRequestsQueryMsg,
}
}
104 changes: 104 additions & 0 deletions packages/data-requests/src/contract.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
use common::msg::DataRequestsExecuteMsg as ExecuteMsg;
use common::msg::DataRequestsQueryMsg as QueryMsg;
#[cfg(not(feature = "library"))]
use cosmwasm_std::{entry_point, to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response};
use cw2::set_contract_version;

use crate::data_request::data_requests;
use crate::error::ContractError;
use crate::msg::InstantiateMsg;
use crate::state::{DATA_REQUESTS_COUNT, PROXY_CONTRACT, TOKEN};

use crate::data_request_result::data_request_results;
use cosmwasm_std::StdResult;

// version info for migration info
const CONTRACT_NAME: &str = "data-requests";
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn instantiate(
deps: DepsMut,
_env: Env,
_info: MessageInfo,
msg: InstantiateMsg,
) -> Result<Response, ContractError> {
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
DATA_REQUESTS_COUNT.save(deps.storage, &0)?;
TOKEN.save(deps.storage, &msg.token)?;
PROXY_CONTRACT.save(deps.storage, &deps.api.addr_validate(&msg.proxy)?)?;
Ok(Response::new().add_attribute("method", "instantiate"))
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn execute(
deps: DepsMut,
env: Env,
info: MessageInfo,
msg: ExecuteMsg,
) -> Result<Response, ContractError> {
match msg {
ExecuteMsg::PostDataRequest { posted_dr } => {
data_requests::post_data_request(deps, info, posted_dr)
}
ExecuteMsg::CommitDataResult {
dr_id,
commitment,
sender,
} => data_request_results::commit_result(deps, info, dr_id, commitment, sender),
ExecuteMsg::RevealDataResult {
dr_id,
reveal,
sender,
} => data_request_results::reveal_result(deps, info, env, dr_id, reveal, sender),
}
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
QueryMsg::GetDataRequest { dr_id } => {
to_binary(&data_requests::get_data_request(deps, dr_id)?)
}
QueryMsg::GetDataRequestsFromPool { position, limit } => to_binary(
&data_requests::get_data_requests_from_pool(deps, position, limit)?,
),
QueryMsg::GetCommittedDataResult { dr_id, executor } => to_binary(
&data_request_results::get_committed_data_result(deps, dr_id, executor)?,
),
QueryMsg::GetCommittedDataResults { dr_id } => to_binary(
&data_request_results::get_committed_data_results(deps, dr_id)?,
),
QueryMsg::GetRevealedDataResult { dr_id, executor } => to_binary(
&data_request_results::get_revealed_data_result(deps, dr_id, executor)?,
),
QueryMsg::GetRevealedDataResults { dr_id } => to_binary(
&data_request_results::get_revealed_data_results(deps, dr_id)?,
),
QueryMsg::GetResolvedDataResult { dr_id } => to_binary(
&data_request_results::get_resolved_data_result(deps, dr_id)?,
),
}
}

#[cfg(test)]
mod init_tests {
use super::*;
use cosmwasm_std::coins;
use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info};

#[test]
fn proper_initialization() {
let mut deps = mock_dependencies();

let msg = InstantiateMsg {
token: "token".to_string(),
proxy: "proxy".to_string(),
};
let info = mock_info("creator", &coins(1000, "token"));

// we can just call .unwrap() to assert this was a success
let res = instantiate(deps.as_mut(), mock_env(), info, msg).unwrap();
assert_eq!(0, res.messages.len());
}
}
Loading