Skip to content

Commit 7826dc8

Browse files
authored
feat: add cw-json crate (#838)
1 parent 3e21636 commit 7826dc8

File tree

35 files changed

+1025
-41
lines changed

35 files changed

+1025
-41
lines changed

Cargo.lock

+14-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ andromeda-accounts = { path = "./packages/andromeda-accounts", version = "1.0.0"
4646
andromeda-math = { path = "./packages/andromeda-math", version = "1.0.0" }
4747
andromeda-testing = { path = "./packages/andromeda-testing", version = "1.0.0" }
4848
andromeda-testing-e2e = { path = "./packages/andromeda-testing-e2e", version = "1.0.0" }
49+
andromeda-cw-json = { path = "./packages/andromeda-cw-json", version = "0.1.1" }
4950

5051
strum_macros = "0.24.3"
5152
cosmwasm-std = "2.2.2"

contracts/data-storage/andromeda-primitive/src/testing/mock.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use andromeda_std::{
77
};
88
use cosmwasm_std::{
99
from_json,
10-
testing::{mock_env, message_info, MockApi, MockStorage},
10+
testing::{message_info, mock_env, MockApi, MockStorage},
1111
Coin, Deps, DepsMut, MessageInfo, OwnedDeps, Response,
1212
};
1313

contracts/finance/andromeda-conditional-splitter/src/testing/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use andromeda_std::{
88
};
99
use cosmwasm_std::{
1010
attr, from_json,
11-
testing::{mock_env, message_info, MOCK_CONTRACT_ADDR},
11+
testing::{message_info, mock_env, MOCK_CONTRACT_ADDR},
1212
to_json_binary, BankMsg, Coin, CosmosMsg, Decimal, DepsMut, Response, SubMsg, Timestamp,
1313
Uint128,
1414
};

contracts/finance/andromeda-fixed-amount-splitter/src/testing/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use andromeda_std::{
88
};
99
use cosmwasm_std::{
1010
attr, coin, coins, from_json,
11-
testing::{mock_env, message_info, MOCK_CONTRACT_ADDR},
11+
testing::{message_info, mock_env, MOCK_CONTRACT_ADDR},
1212
to_json_binary, BankMsg, Coin, CosmosMsg, DepsMut, Response, SubMsg,
1313
};
1414
pub const OWNER: &str = "creator";

contracts/finance/andromeda-rate-limiting-withdrawals/src/testing/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use andromeda_std::{
55
};
66
use cosmwasm_std::{
77
coin, from_json,
8-
testing::{mock_env, message_info},
8+
testing::{message_info, mock_env},
99
BankMsg, Binary, CosmosMsg, DepsMut, Response, Uint128, WasmMsg,
1010
};
1111
pub const OWNER: &str = "creator";

contracts/finance/andromeda-splitter/src/testing/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use andromeda_std::{
88
};
99
use cosmwasm_std::{
1010
attr, from_json,
11-
testing::{mock_env, message_info, MOCK_CONTRACT_ADDR},
11+
testing::{message_info, mock_env, MOCK_CONTRACT_ADDR},
1212
to_json_binary, BankMsg, Coin, CosmosMsg, Decimal, DepsMut, Response, SubMsg, Timestamp,
1313
};
1414
pub const OWNER: &str = "creator";

contracts/finance/andromeda-timelock/src/testing/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use andromeda_std::{
1212
};
1313
use cosmwasm_std::{
1414
attr, coin, coins, from_json,
15-
testing::{mock_env, message_info},
15+
testing::{message_info, mock_env},
1616
BankMsg, Coin, Response, Timestamp,
1717
};
1818

contracts/finance/andromeda-validator-staking/src/testing/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{
66
use andromeda_std::{error::ContractError, testing::mock_querier::MOCK_KERNEL_CONTRACT};
77
use cosmwasm_std::{
88
coin,
9-
testing::{mock_env, message_info},
9+
testing::{message_info, mock_env},
1010
Addr, DepsMut, Response, StakingMsg,
1111
};
1212

contracts/finance/andromeda-vesting/src/testing/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use andromeda_std::{
1111
};
1212
use cosmwasm_std::{
1313
coin, coins, from_json,
14-
testing::{mock_env, message_info, MOCK_CONTRACT_ADDR},
14+
testing::{message_info, mock_env, MOCK_CONTRACT_ADDR},
1515
BankMsg, Decimal, DepsMut, Response, Uint128,
1616
};
1717

contracts/fungible-tokens/andromeda-cw20-staking/src/testing/mock_querier.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use andromeda_std::testing::mock_querier::MockAndromedaQuerier;
55
use andromeda_std::testing::mock_querier::MOCK_KERNEL_CONTRACT;
66

77
use cosmwasm_std::testing::{
8-
mock_env, message_info, MockApi, MockQuerier, MockStorage, MOCK_CONTRACT_ADDR,
8+
message_info, mock_env, MockApi, MockQuerier, MockStorage, MOCK_CONTRACT_ADDR,
99
};
1010

1111
use cosmwasm_std::QuerierWrapper;

contracts/fungible-tokens/andromeda-cw20-staking/src/testing/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use andromeda_std::{
99
};
1010
use cosmwasm_std::{
1111
coin, coins, from_json,
12-
testing::{mock_dependencies, mock_env, message_info, MOCK_CONTRACT_ADDR},
12+
testing::{message_info, mock_dependencies, mock_env, MOCK_CONTRACT_ADDR},
1313
to_json_binary, Addr, BankMsg, Decimal, Decimal256, DepsMut, Response, Uint128, Uint256,
1414
WasmMsg,
1515
};

contracts/fungible-tokens/andromeda-cw20/src/testing/mock_querier.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use andromeda_std::ado_contract::ADOContract;
44
use andromeda_std::testing::mock_querier::MockAndromedaQuerier;
55

66
use andromeda_std::testing::mock_querier::MOCK_KERNEL_CONTRACT;
7-
use cosmwasm_std::testing::{mock_env, message_info, MockApi, MockQuerier, MockStorage};
7+
use cosmwasm_std::testing::{message_info, mock_env, MockApi, MockQuerier, MockStorage};
88
use cosmwasm_std::{
99
from_json, to_json_binary, Binary, Coin, ContractResult, OwnedDeps, Querier, QuerierResult,
1010
QuerierWrapper, QueryRequest, SystemError, SystemResult, WasmQuery,

contracts/fungible-tokens/andromeda-cw20/src/testing/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use andromeda_std::common::context::ExecuteContext;
1010
use andromeda_std::{error::ContractError, testing::mock_querier::MOCK_KERNEL_CONTRACT};
1111
use cosmwasm_std::{attr, Decimal, Event};
1212
use cosmwasm_std::{
13-
testing::{mock_env, message_info},
13+
testing::{message_info, mock_env},
1414
to_json_binary, Addr, DepsMut, Response, Uint128,
1515
};
1616

contracts/fungible-tokens/andromeda-lockdrop/src/testing/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use andromeda_std::{
1717
};
1818
use cosmwasm_std::{
1919
coin, coins, from_json,
20-
testing::{mock_env, message_info},
20+
testing::{message_info, mock_env},
2121
to_json_binary, Addr, BankMsg, Decimal, DepsMut, Response, Uint128, WasmMsg,
2222
};
2323

contracts/fungible-tokens/andromeda-merkle-airdrop/src/testing/mock_querier.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use andromeda_std::ado_base::InstantiateMsg;
22
use andromeda_std::ado_contract::ADOContract;
33
use andromeda_std::testing::mock_querier::{MockAndromedaQuerier, MOCK_KERNEL_CONTRACT};
44
use cosmwasm_std::testing::{
5-
mock_env, message_info, MockApi, MockQuerier, MockStorage, MOCK_CONTRACT_ADDR,
5+
message_info, mock_env, MockApi, MockQuerier, MockStorage, MOCK_CONTRACT_ADDR,
66
};
77
use cosmwasm_std::{
88
from_json, to_json_binary, Coin, ContractResult, Empty, OwnedDeps, Querier, QuerierResult,

contracts/fungible-tokens/andromeda-merkle-airdrop/src/testing/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use andromeda_std::{
1212
use cosmwasm_schema::{cw_serde, serde::Deserialize};
1313
use cosmwasm_std::{
1414
attr, coin, from_json,
15-
testing::{mock_env, message_info},
15+
testing::{message_info, mock_env},
1616
to_json_binary, BankMsg, Coin, CosmosMsg, SubMsg, Timestamp, Uint128, WasmMsg,
1717
};
1818
use cw20::Cw20ExecuteMsg;

contracts/math/andromeda-counter/src/testing/mock.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use andromeda_std::{
99
};
1010
use cosmwasm_std::{
1111
from_json,
12-
testing::{mock_env, message_info, MockApi, MockStorage},
12+
testing::{message_info, mock_env, MockApi, MockStorage},
1313
Deps, DepsMut, MessageInfo, OwnedDeps, Response,
1414
};
1515

contracts/math/andromeda-curve/src/testing/mock.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use andromeda_std::{
99
};
1010
use cosmwasm_std::{
1111
from_json,
12-
testing::{mock_env, message_info, MockApi, MockStorage},
12+
testing::{message_info, mock_env, MockApi, MockStorage},
1313
Deps, DepsMut, MessageInfo, OwnedDeps, Response,
1414
};
1515

contracts/math/andromeda-graph/src/testing/mock.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use andromeda_std::{
88
};
99
use cosmwasm_std::{
1010
from_json,
11-
testing::{mock_env, message_info, MockApi, MockStorage},
11+
testing::{message_info, mock_env, MockApi, MockStorage},
1212
Deps, DepsMut, MessageInfo, OwnedDeps, Response,
1313
};
1414

contracts/math/andromeda-graph/src/testing/mock_querier.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use andromeda_std::{
88
use cosmwasm_std::QuerierWrapper;
99
use cosmwasm_std::{
1010
from_json,
11-
testing::{mock_env, message_info, MockApi, MockQuerier, MockStorage, MOCK_CONTRACT_ADDR},
11+
testing::{message_info, mock_env, MockApi, MockQuerier, MockStorage, MOCK_CONTRACT_ADDR},
1212
Coin, ContractInfoResponse, OwnedDeps, Querier, QuerierResult, QueryRequest, SignedDecimal,
1313
SystemError, SystemResult, WasmQuery,
1414
};

contracts/math/andromeda-shunting/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ andromeda-math = { workspace = true }
2222

2323
simple-shunting = "0.1.2"
2424
serde-cw-value = "0.7.0"
25-
cw-json = { git = "https://github.com/SlayerAnsh/cw-json.git" }
25+
andromeda-cw-json = { workspace = true }
2626

2727
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
2828
cw-multi-test = { workspace = true, optional = true }

contracts/math/andromeda-shunting/src/contract.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use cw2::set_contract_version;
1818
use serde_cw_value::Value;
1919

2020
use crate::state::EXPRESSIONS;
21-
use cw_json::JSON;
21+
use andromeda_cw_json::JSON;
2222
use simple_shunting::*;
2323

2424
const CONTRACT_NAME: &str = "crates.io:andromeda-shunting";

contracts/math/andromeda-shunting/src/testing/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pub use andromeda_std::testing::mock_querier::MOCK_KERNEL_CONTRACT;
44
use andromeda_math::shunting::{EvaluateParam, InstantiateMsg, QueryMsg, ShuntingResponse};
55
use cosmwasm_std::{
66
from_json,
7-
testing::{mock_dependencies, mock_env, message_info},
7+
testing::{message_info, mock_dependencies, mock_env},
88
};
99

1010
#[test]

contracts/modules/andromeda-rates/src/testing/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use andromeda_std::{
1111
};
1212
use cosmwasm_std::{
1313
attr, coin, coins,
14-
testing::{mock_env, message_info},
14+
testing::{message_info, mock_env},
1515
BankMsg, CosmosMsg, Event, Response, SubMsg, WasmMsg,
1616
};
1717
use cw20::{Cw20Coin, Cw20ExecuteMsg};

contracts/modules/andromeda-schema/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ testing = ["cw-multi-test", "andromeda-testing"]
1818
cosmwasm-std = { workspace = true }
1919
cosmwasm-schema = { workspace = true }
2020
cw-storage-plus = { workspace = true }
21-
cw-json = { git = "https://github.com/SlayerAnsh/cw-json.git" }
21+
andromeda-cw-json = { workspace = true }
2222
serde_json = { workspace = true }
2323
test-case = { workspace = true }
2424

contracts/modules/andromeda-schema/src/contract.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ use cosmwasm_std::{
55

66
use andromeda_modules::schema::{ExecuteMsg, InstantiateMsg, QueryMsg};
77

8+
use andromeda_cw_json::JSON;
89
use andromeda_std::{
910
ado_base::{InstantiateMsg as BaseInstantiateMsg, MigrateMsg},
1011
ado_contract::ADOContract,
1112
andr_execute_fn,
1213
common::encode_binary,
1314
error::ContractError,
1415
};
15-
use cw_json::JSON;
1616
use serde_json::{from_str, Value};
1717

1818
use crate::{

contracts/modules/andromeda-schema/src/execute.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
use andromeda_cw_json::JSON;
12
use andromeda_std::{common::context::ExecuteContext, error::ContractError};
23
use cosmwasm_std::Response;
3-
use cw_json::JSON;
44
use serde_json::{from_str, Value};
55

66
use crate::state::SCHEMA;
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use cw_json::JSON;
1+
use andromeda_cw_json::JSON;
22
use cw_storage_plus::Item;
33

44
pub const SCHEMA: Item<JSON> = Item::new("schema");

packages/andromeda-cw-json/Cargo.toml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[package]
2+
name = "andromeda-cw-json"
3+
version = "0.1.1"
4+
authors = ["Anshudhar Kumar Singh <[email protected]>"]
5+
edition = "2021"
6+
7+
description = "JSON Parser for CosmWasm using serde_cw_value"
8+
readme = "README.md"
9+
keywords = ["serde", "wasm", "json"]
10+
11+
12+
[dependencies]
13+
cosmwasm-std = { workspace = true }
14+
cosmwasm-schema = { workspace = true }
15+
serde = { workspace = true, default-features = false, features = ["derive"] }
16+
serde-cw-value = { version = "^0.7.0" }
17+
thiserror = { version = "2.0.12", default-features = false }
18+
19+
20+
[dev-dependencies]
21+
serde_derive = "^1.0.210"

packages/andromeda-cw-json/README.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Andromeda CW JSON
2+
3+
A Rust library for parsing and manipulating JSON data in CosmWasm smart contracts.
4+
5+
## Overview
6+
7+
`andromeda-cw-json` provides functionality to work with JSON data structures in CosmWasm smart contracts. It allows for parsing JSON strings, accessing nested values using dot notation, and updating values within the JSON structure.
8+
9+
## Features
10+
11+
- Parse JSON strings and binary data into a structured format
12+
- Access nested values using dot notation (e.g., "data.numbers.1")
13+
- Update values within the JSON structure
14+
- Support for complex nested objects and arrays
15+
- Serialization/deserialization compatibility with CosmWasm types
16+
17+
## Usage
18+
19+
Add the dependency to your `Cargo.toml`:

0 commit comments

Comments
 (0)