Skip to content

Commit

Permalink
Merge pull request #109 from neutron-org/sdk/47
Browse files Browse the repository at this point in the history
Feat: Cosmos SDK 47
  • Loading branch information
pr0n00gler authored Dec 22, 2023
2 parents 1d65cda + 9d91a00 commit fbf2270
Show file tree
Hide file tree
Showing 48 changed files with 3,557 additions and 461 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fetch-depth: 1
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.68.2
toolchain: 1.71.0
components: clippy
profile: minimal
override: true
Expand All @@ -31,7 +31,7 @@ jobs:
fetch-depth: 1
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.68.2
toolchain: 1.71.0
components: rustfmt
profile: minimal
override: true
Expand All @@ -49,7 +49,7 @@ jobs:
fetch-depth: 1
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.68.2
toolchain: 1.71.0
profile: minimal
- run: cargo fetch --verbose
- run: cargo build
Expand Down
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ serde-json-wasm = "1.0.0"
cw-storage-plus = "1.1.0"
cosmwasm-schema = { version = "1.4.0", default-features = false }
base64 = "0.21.4"
prost = "0.12.1"
prost = "0.12.3"
prost-types = "0.12.1"
cosmos-sdk-proto = { version = "0.20.0", default-features = false }
bech32 = "0.9.1"
thiserror = "1.0.49"
protobuf = { version = "3.3.0" }
hex = "0.4.3"
tendermint-proto = "0.34"
speedate = "0.13.0"
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@ clippy:
fmt:
@cargo fmt -- --check

build_proto:
@./build_proto.sh

compile:
@./build_release.sh

check_contracts:
@cargo install cosmwasm-check
@cosmwasm-check --available-capabilities iterator,staking,stargate,neutron artifacts/*.wasm

build: build_proto schema clippy test fmt compile check_contracts
build: schema clippy test fmt compile check_contracts
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The Neutron SDK is contained inside `packages` folder and consists of the follow
| Neutron Bindings | https://github.com/neutron-org/neutron-sdk/tree/main/packages/neutron-sdk/src/bindings | Structures and helper methods for interacting with Neutron blockchain |
| Neutron Sudo | https://github.com/neutron-org/neutron-sdk/tree/main/packages/neutron-sdk/src/sudo | Structures for Sudo Contract callbacks from Neutron blockchain |
| Neutron Errors | https://github.com/neutron-org/neutron-sdk/tree/main/packages/neutron-sdk/src/errors | Structures and helpers for Neutron specific error and result types |
| Neutron Proto Types | https://github.com/neutron-org/neutron-sdk/tree/main/packages/neutron-sdk/src/proto_types | Neutron specific protobuf types. |
| Neutron Stargate | https://github.com/neutron-org/neutron-sdk/tree/main/packages/neutron-sdk/src/stargate | Structures and helpers for interacting with Neutron via Stargate |

### Example Contracts

Expand Down
8 changes: 0 additions & 8 deletions build_proto.sh

This file was deleted.

6 changes: 3 additions & 3 deletions contracts/ibc_transfer/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cosmwasm_std::{
coin, entry_point, from_binary, Binary, CosmosMsg, Deps, DepsMut, Env, MessageInfo, Reply,
coin, entry_point, from_json, Binary, CosmosMsg, Deps, DepsMut, Env, MessageInfo, Reply,
Response, StdError, StdResult, SubMsg,
};
use cw2::set_contract_version;
Expand Down Expand Up @@ -112,8 +112,8 @@ fn msg_with_sudo_callback<C: Into<CosmosMsg<T>>, T>(
// and process this payload when an acknowledgement for the SubmitTx message is received in Sudo handler
fn prepare_sudo_payload(mut deps: DepsMut, _env: Env, msg: Reply) -> StdResult<Response> {
let payload = read_reply_payload(deps.storage, msg.id)?;
let resp: MsgIbcTransferResponse = from_binary(
&msg.result
let resp: MsgIbcTransferResponse = from_json(
msg.result
.into_result()
.map_err(StdError::generic_err)?
.data
Expand Down
10 changes: 5 additions & 5 deletions contracts/ibc_transfer/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cosmwasm_std::{from_binary, to_vec, Binary, StdResult, Storage};
use cosmwasm_std::{from_json, to_json_vec, Binary, StdResult, Storage};
use cw_storage_plus::{Item, Map};

use crate::contract::SudoPayload;
Expand Down Expand Up @@ -28,13 +28,13 @@ pub fn get_next_id(store: &mut dyn Storage) -> StdResult<u64> {

pub fn save_reply_payload(store: &mut dyn Storage, payload: SudoPayload) -> StdResult<u64> {
let id = get_next_id(store)?;
REPLY_QUEUE_ID.save(store, id, &to_vec(&payload)?)?;
REPLY_QUEUE_ID.save(store, id, &to_json_vec(&payload)?)?;
Ok(id)
}

pub fn read_reply_payload(store: &dyn Storage, id: u64) -> StdResult<SudoPayload> {
let data = REPLY_QUEUE_ID.load(store, id)?;
from_binary(&Binary(data))
from_json(Binary(data))
}

/// SUDO_PAYLOAD - tmp storage for sudo handler payloads
Expand All @@ -50,7 +50,7 @@ pub fn save_sudo_payload(
seq_id: u64,
payload: SudoPayload,
) -> StdResult<()> {
SUDO_PAYLOAD.save(store, (channel_id, seq_id), &to_vec(&payload)?)
SUDO_PAYLOAD.save(store, (channel_id, seq_id), &to_json_vec(&payload)?)
}

pub fn read_sudo_payload(
Expand All @@ -59,5 +59,5 @@ pub fn read_sudo_payload(
seq_id: u64,
) -> StdResult<SudoPayload> {
let data = SUDO_PAYLOAD.load(store, (channel_id, seq_id))?;
from_binary(&Binary(data))
from_json(Binary(data))
}
30 changes: 15 additions & 15 deletions contracts/neutron_interchain_queries/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use cosmos_sdk_proto::cosmos::bank::v1beta1::MsgSend;
use cosmos_sdk_proto::cosmos::tx::v1beta1::{TxBody, TxRaw};
use cosmos_sdk_proto::traits::Message;
use cosmwasm_std::{
entry_point, to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult,
Uint128,
entry_point, to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdError,
StdResult, Uint128,
};
use cw2::set_contract_version;

Expand Down Expand Up @@ -250,27 +250,27 @@ pub fn remove_interchain_query(query_id: u64) -> NeutronResult<Response<NeutronM
pub fn query(deps: Deps<NeutronQuery>, env: Env, msg: QueryMsg) -> NeutronResult<Binary> {
match msg {
//TODO: check if query.result.height is too old (for all interchain queries)
QueryMsg::Balance { query_id } => Ok(to_binary(&query_balance(deps, env, query_id)?)?),
QueryMsg::Balance { query_id } => Ok(to_json_binary(&query_balance(deps, env, query_id)?)?),
QueryMsg::BankTotalSupply { query_id } => {
Ok(to_binary(&query_bank_total(deps, env, query_id)?)?)
Ok(to_json_binary(&query_bank_total(deps, env, query_id)?)?)
}
QueryMsg::DistributionFeePool { query_id } => Ok(to_binary(&query_distribution_fee_pool(
deps, env, query_id,
)?)?),
QueryMsg::StakingValidators { query_id } => {
Ok(to_binary(&query_staking_validators(deps, env, query_id)?)?)
}
QueryMsg::GovernmentProposals { query_id } => Ok(to_binary(&query_government_proposals(
QueryMsg::DistributionFeePool { query_id } => Ok(to_json_binary(
&query_distribution_fee_pool(deps, env, query_id)?,
)?),
QueryMsg::StakingValidators { query_id } => Ok(to_json_binary(&query_staking_validators(
deps, env, query_id,
)?)?),
QueryMsg::GovernmentProposals { query_id } => Ok(to_json_binary(
&query_government_proposals(deps, env, query_id)?,
)?),
QueryMsg::GetDelegations { query_id } => {
Ok(to_binary(&query_delegations(deps, env, query_id)?)?)
Ok(to_json_binary(&query_delegations(deps, env, query_id)?)?)
}
QueryMsg::Cw20Balance { query_id } => {
Ok(to_binary(&query_cw20_balance(deps, env, query_id)?)?)
Ok(to_json_binary(&query_cw20_balance(deps, env, query_id)?)?)
}
QueryMsg::GetRegisteredQuery { query_id } => {
Ok(to_binary(&get_registered_query(deps, query_id)?)?)
Ok(to_json_binary(&get_registered_query(deps, query_id)?)?)
}
QueryMsg::GetRecipientTxs { recipient } => query_recipient_txs(deps, recipient),
}
Expand All @@ -280,7 +280,7 @@ fn query_recipient_txs(deps: Deps<NeutronQuery>, recipient: String) -> NeutronRe
let txs = RECIPIENT_TXS
.load(deps.storage, &recipient)
.unwrap_or_default();
Ok(to_binary(&GetRecipientTxsResponse { transfers: txs })?)
Ok(to_json_binary(&GetRecipientTxsResponse { transfers: txs })?)
}

pub fn query_cw20_balance(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::marker::PhantomData;

use cosmwasm_std::testing::{MockApi, MockQuerier, MockStorage};
use cosmwasm_std::{
from_slice, Binary, Coin, ContractResult, CustomQuery, FullDelegation, OwnedDeps, Querier,
from_json, Binary, Coin, ContractResult, CustomQuery, FullDelegation, OwnedDeps, Querier,
QuerierResult, QueryRequest, SystemError, SystemResult, Uint128, Validator,
};
use schemars::JsonSchema;
Expand Down Expand Up @@ -43,7 +43,7 @@ pub struct WasmMockQuerier {

impl Querier for WasmMockQuerier {
fn raw_query(&self, bin_request: &[u8]) -> QuerierResult {
let request: QueryRequest<NeutronQuery> = match from_slice(bin_request) {
let request: QueryRequest<NeutronQuery> = match from_json(bin_request) {
Ok(v) => v,
Err(e) => {
return QuerierResult::Err(SystemError::InvalidRequest {
Expand Down
24 changes: 12 additions & 12 deletions contracts/neutron_interchain_queries/src/testing/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use cosmos_sdk_proto::traits::Message;
use cosmos_sdk_proto::Any;
use cosmwasm_std::testing::{mock_env, mock_info, MockApi, MockStorage};
use cosmwasm_std::{
from_binary, to_binary, Addr, Binary, Coin, Decimal, Delegation, Env, MessageInfo, OwnedDeps,
StdError, Uint128,
from_json, to_json_binary, Addr, Binary, Coin, Decimal, Delegation, Env, MessageInfo,
OwnedDeps, StdError, Uint128,
};
use neutron_sdk::bindings::query::{
NeutronQuery, QueryRegisteredQueryResponse, QueryRegisteredQueryResultResponse,
Expand Down Expand Up @@ -257,7 +257,7 @@ fn test_query_balance() {
);
let query_balance = QueryMsg::Balance { query_id: 1 };
let resp: BalanceResponse =
from_binary(&query(deps.as_ref(), mock_env(), query_balance).unwrap()).unwrap();
from_json(query(deps.as_ref(), mock_env(), query_balance).unwrap()).unwrap();
assert_eq!(
resp,
BalanceResponse {
Expand Down Expand Up @@ -304,11 +304,11 @@ fn test_bank_total_supply_query() {

deps.querier.add_registered_queries(1, registered_query);
deps.querier
.add_query_response(1, to_binary(&total_supply_response).unwrap());
.add_query_response(1, to_json_binary(&total_supply_response).unwrap());
let bank_total_balance = QueryMsg::BankTotalSupply { query_id: 1 };

let resp: TotalSupplyResponse =
from_binary(&query(deps.as_ref(), mock_env(), bank_total_balance).unwrap()).unwrap();
from_json(query(deps.as_ref(), mock_env(), bank_total_balance).unwrap()).unwrap();
assert_eq!(
resp,
TotalSupplyResponse {
Expand Down Expand Up @@ -347,7 +347,7 @@ fn test_distribution_fee_pool_query() {
);
let fee_pool_balance = QueryMsg::DistributionFeePool { query_id: 1 };
let resp: FeePoolResponse =
from_binary(&query(deps.as_ref(), mock_env(), fee_pool_balance).unwrap()).unwrap();
from_json(query(deps.as_ref(), mock_env(), fee_pool_balance).unwrap()).unwrap();
assert_eq!(
resp,
FeePoolResponse {
Expand Down Expand Up @@ -393,11 +393,11 @@ fn test_gov_proposals_query() {

deps.querier.add_registered_queries(1, registered_query);
deps.querier
.add_query_response(1, to_binary(&proposals_response).unwrap());
.add_query_response(1, to_json_binary(&proposals_response).unwrap());

let government_proposal = QueryMsg::GovernmentProposals { query_id: 1 };
let resp: ProposalResponse =
from_binary(&query(deps.as_ref(), mock_env(), government_proposal).unwrap()).unwrap();
from_json(query(deps.as_ref(), mock_env(), government_proposal).unwrap()).unwrap();
assert_eq!(
resp,
ProposalResponse {
Expand Down Expand Up @@ -503,10 +503,10 @@ fn test_staking_validators_query() {

deps.querier.add_registered_queries(1, registered_query);
deps.querier
.add_query_response(1, to_binary(&validators_response).unwrap());
.add_query_response(1, to_json_binary(&validators_response).unwrap());
let staking_validators = QueryMsg::StakingValidators { query_id: 1 };
let resp: ValidatorResponse =
from_binary(&query(deps.as_ref(), mock_env(), staking_validators).unwrap()).unwrap();
from_json(query(deps.as_ref(), mock_env(), staking_validators).unwrap()).unwrap();
assert_eq!(
resp,
ValidatorResponse {
Expand Down Expand Up @@ -649,12 +649,12 @@ fn test_query_delegator_delegations() {
build_registered_query_response(1, QueryParam::Keys(keys.0), QueryType::KV, 987);

deps.querier
.add_query_response(1, to_binary(&delegations_response).unwrap());
.add_query_response(1, to_json_binary(&delegations_response).unwrap());
deps.querier.add_registered_queries(1, registered_query);

let query_delegations = QueryMsg::GetDelegations { query_id: 1 };
let resp: DelegatorDelegationsResponse =
from_binary(&query(deps.as_ref(), mock_env(), query_delegations).unwrap()).unwrap();
from_json(query(deps.as_ref(), mock_env(), query_delegations).unwrap()).unwrap();

assert_eq!(
resp,
Expand Down
32 changes: 30 additions & 2 deletions contracts/neutron_interchain_txs/schema/execute_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,21 @@
"type": "object",
"required": [
"connection_id",
"interchain_account_id"
"interchain_account_id",
"register_fee"
],
"properties": {
"connection_id": {
"type": "string"
},
"interchain_account_id": {
"type": "string"
},
"register_fee": {
"type": "array",
"items": {
"$ref": "#/definitions/Coin"
}
}
}
}
Expand Down Expand Up @@ -110,5 +117,26 @@
},
"additionalProperties": false
}
]
],
"definitions": {
"Coin": {
"type": "object",
"required": [
"amount",
"denom"
],
"properties": {
"amount": {
"$ref": "#/definitions/Uint128"
},
"denom": {
"type": "string"
}
}
},
"Uint128": {
"description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```",
"type": "string"
}
}
}
Loading

0 comments on commit fbf2270

Please sign in to comment.