Skip to content
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
24 changes: 18 additions & 6 deletions contracts/amaci/schema/cw-amaci.json
Original file line number Diff line number Diff line change
Expand Up @@ -1086,11 +1086,11 @@
"signuped": {
"type": "object",
"required": [
"pubkey_x"
"pubkey"
],
"properties": {
"pubkey_x": {
"$ref": "#/definitions/Uint256"
"pubkey": {
"$ref": "#/definitions/PubKey"
}
},
"additionalProperties": false
Expand Down Expand Up @@ -1690,9 +1690,21 @@
},
"signuped": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Uint256",
"description": "An implementation of u256 that is using strings for JSON encoding/decoding, such that the full u256 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 out of primitive uint types or `new` to provide big endian bytes:\n\n``` # use cosmwasm_std::Uint256; let a = Uint256::from(258u128); let b = Uint256::new([ 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 2u8, ]); assert_eq!(a, b); ```",
"type": "string"
"title": "Nullable_Uint256",
"anyOf": [
{
"$ref": "#/definitions/Uint256"
},
{
"type": "null"
}
],
"definitions": {
"Uint256": {
"description": "An implementation of u256 that is using strings for JSON encoding/decoding, such that the full u256 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 out of primitive uint types or `new` to provide big endian bytes:\n\n``` # use cosmwasm_std::Uint256; let a = Uint256::from(258u128); let b = Uint256::new([ 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 2u8, ]); assert_eq!(a, b); ```",
"type": "string"
}
}
},
"vote_option_map": {
"$schema": "http://json-schema.org/draft-07/schema#",
Expand Down
6 changes: 3 additions & 3 deletions contracts/amaci/schema/raw/query.json
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,11 @@
"signuped": {
"type": "object",
"required": [
"pubkey_x"
"pubkey"
],
"properties": {
"pubkey_x": {
"$ref": "#/definitions/Uint256"
"pubkey": {
"$ref": "#/definitions/PubKey"
}
},
"additionalProperties": false
Expand Down
18 changes: 15 additions & 3 deletions contracts/amaci/schema/raw/response_to_signuped.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Uint256",
"description": "An implementation of u256 that is using strings for JSON encoding/decoding, such that the full u256 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 out of primitive uint types or `new` to provide big endian bytes:\n\n``` # use cosmwasm_std::Uint256; let a = Uint256::from(258u128); let b = Uint256::new([ 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 2u8, ]); assert_eq!(a, b); ```",
"type": "string"
"title": "Nullable_Uint256",
"anyOf": [
{
"$ref": "#/definitions/Uint256"
},
{
"type": "null"
}
],
"definitions": {
"Uint256": {
"description": "An implementation of u256 that is using strings for JSON encoding/decoding, such that the full u256 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 out of primitive uint types or `new` to provide big endian bytes:\n\n``` # use cosmwasm_std::Uint256; let a = Uint256::from(258u128); let b = Uint256::new([ 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 2u8, ]); assert_eq!(a, b); ```",
"type": "string"
}
}
}
45 changes: 37 additions & 8 deletions contracts/amaci/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,15 @@ pub fn execute_sign_up(

// Save the updated state index and number of sign-ups
NUMSIGNUPS.save(deps.storage, &num_sign_ups)?;
SIGNUPED.save(deps.storage, pubkey.x.to_be_bytes().to_vec(), &num_sign_ups)?;
// Save the actual state_index (0-based), not num_sign_ups
SIGNUPED.save(
deps.storage,
&(
pubkey.x.to_be_bytes().to_vec(),
pubkey.y.to_be_bytes().to_vec(),
),
&state_index,
)?;

// Update storage based on mode
if is_oracle_mode {
Expand Down Expand Up @@ -1395,7 +1403,15 @@ pub fn execute_add_new_key(
num_sign_ups += Uint256::from_u128(1u128);

NUMSIGNUPS.save(deps.storage, &num_sign_ups)?;
SIGNUPED.save(deps.storage, pubkey.x.to_be_bytes().to_vec(), &num_sign_ups)?;
// Save the actual state_index (0-based), not num_sign_ups
SIGNUPED.save(
deps.storage,
&(
pubkey.x.to_be_bytes().to_vec(),
pubkey.y.to_be_bytes().to_vec(),
),
&state_index,
)?;

Ok(Response::new()
.add_attribute("action", "add_new_key")
Expand Down Expand Up @@ -1520,7 +1536,15 @@ pub fn execute_pre_add_new_key(
num_sign_ups += Uint256::from_u128(1u128);

NUMSIGNUPS.save(deps.storage, &num_sign_ups)?;
SIGNUPED.save(deps.storage, pubkey.x.to_be_bytes().to_vec(), &num_sign_ups)?;
// Save the actual state_index (0-based), not num_sign_ups
SIGNUPED.save(
deps.storage,
&(
pubkey.x.to_be_bytes().to_vec(),
pubkey.y.to_be_bytes().to_vec(),
),
&state_index,
)?;

Ok(Response::new()
.add_attribute("action", "pre_add_new_key")
Expand Down Expand Up @@ -2346,11 +2370,16 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
}
QueryMsg::IsWhiteList { sender } => to_json_binary::<bool>(&is_whitelist(deps, &sender)?),
QueryMsg::IsRegister { sender } => to_json_binary::<bool>(&is_register(deps, &sender)?),
QueryMsg::Signuped { pubkey_x } => to_json_binary::<Uint256>(
&SIGNUPED
.load(deps.storage, pubkey_x.to_be_bytes().to_vec())
.unwrap(),
),
QueryMsg::Signuped { pubkey } => {
let state_idx = SIGNUPED.may_load(
deps.storage,
&(
pubkey.x.to_be_bytes().to_vec(),
pubkey.y.to_be_bytes().to_vec(),
),
)?;
to_json_binary(&state_idx)
}
QueryMsg::VoteOptionMap {} => {
to_json_binary::<Vec<String>>(&VOTEOPTIONMAP.load(deps.storage).unwrap())
}
Expand Down
4 changes: 2 additions & 2 deletions contracts/amaci/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::state::{
DelayRecords, MaciParameters, MessageData, PeriodStatus, PubKey, RoundInfo, VotingTime,

Check warning on line 2 in contracts/amaci/src/msg.rs

View workflow job for this annotation

GitHub Actions / Build WASM Contracts

unused imports: `DelayRecords`, `Whitelist`

Check warning on line 2 in contracts/amaci/src/msg.rs

View workflow job for this annotation

GitHub Actions / Build WASM Contracts

unused imports: `DelayRecords`, `Whitelist`

Check warning on line 2 in contracts/amaci/src/msg.rs

View workflow job for this annotation

GitHub Actions / Build WASM Contracts

unused imports: `DelayRecords`, `Whitelist`
Whitelist,
};
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::{Addr, Timestamp, Uint128, Uint256};

Check warning on line 6 in contracts/amaci/src/msg.rs

View workflow job for this annotation

GitHub Actions / Build WASM Contracts

unused import: `Uint128`

Check warning on line 6 in contracts/amaci/src/msg.rs

View workflow job for this annotation

GitHub Actions / Build WASM Contracts

unused import: `Uint128`

Check warning on line 6 in contracts/amaci/src/msg.rs

View workflow job for this annotation

GitHub Actions / Build WASM Contracts

unused import: `Uint128`

#[cw_serde]
pub struct InstantiateMsg {
Expand Down Expand Up @@ -206,8 +206,8 @@

// #[returns(Uint256)]
// WhiteBalanceOf { sender: String },
#[returns(Uint256)]
Signuped { pubkey_x: Uint256 },
#[returns(Option<Uint256>)]
Signuped { pubkey: PubKey },

#[returns(Vec<String>)]
VoteOptionMap {},
Expand Down
8 changes: 4 additions & 4 deletions contracts/amaci/src/multitest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,9 +715,9 @@ impl MaciContract {
.query_wasm_smart(self.addr(), &QueryMsg::GetNumSignUp {})
}

pub fn signuped(&self, app: &App, pubkey_x: Uint256) -> StdResult<Uint256> {
pub fn signuped(&self, app: &App, pubkey: PubKey) -> StdResult<Option<Uint256>> {
app.wrap()
.query_wasm_smart(self.addr(), &QueryMsg::Signuped { pubkey_x })
.query_wasm_smart(self.addr(), &QueryMsg::Signuped { pubkey })
}

pub fn vote_option_map(&self, app: &App) -> StdResult<Vec<String>> {
Expand Down Expand Up @@ -1099,9 +1099,9 @@ impl MaciContract {
.query_wasm_smart(self.addr(), &QueryMsg::GetNumSignUp {})
}

pub fn amaci_signuped(&self, app: &DefaultApp, pubkey_x: Uint256) -> StdResult<Uint256> {
pub fn amaci_signuped(&self, app: &DefaultApp, pubkey: PubKey) -> StdResult<Option<Uint256>> {
app.wrap()
.query_wasm_smart(self.addr(), &QueryMsg::Signuped { pubkey_x })
.query_wasm_smart(self.addr(), &QueryMsg::Signuped { pubkey })
}

pub fn amaci_vote_option_map(&self, app: &DefaultApp) -> StdResult<Vec<String>> {
Expand Down
Loading
Loading