diff --git a/Cargo.lock b/Cargo.lock index a202919..908a0b9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -58,9 +58,9 @@ checksum = "722e23542a15cea1f65d4a1419c4cfd7a26706c70871a13a04238ca3f40f1661" [[package]] name = "cosmwasm-crypto" -version = "1.1.3" +version = "1.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3420be057791de6804f9220bd6c5a595cf7a01c32e9dd1bd487488d201a39db2" +checksum = "227315dc11f0bb22a273d0c43d3ba8ef52041c42cf959f09045388a89c57e661" dependencies = [ "digest 0.10.5", "ed25519-zebra", @@ -71,18 +71,18 @@ dependencies = [ [[package]] name = "cosmwasm-derive" -version = "1.1.3" +version = "1.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16d08790fafffcbf918f3911b0886b9561311d9f53becb741dff91901070742b" +checksum = "6fca30d51f7e5fbfa6440d8b10d7df0231bdf77e97fd3fe5d0cb79cc4822e50c" dependencies = [ "syn", ] [[package]] name = "cosmwasm-schema" -version = "1.1.3" +version = "1.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10919fac51da80291a3068ffe8b7a8df6a987ba265abd3b9c611a1d88412b" +checksum = "04135971e2c3b867eb793ca4e832543c077dbf72edaef7672699190f8fcdb619" dependencies = [ "cosmwasm-schema-derive", "schemars", @@ -93,9 +93,9 @@ dependencies = [ [[package]] name = "cosmwasm-schema-derive" -version = "1.1.3" +version = "1.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "183443618bb632bff30487d9a7762442d0c6118dc3c0e00e8805223e1ae0161c" +checksum = "a06c8f516a13ae481016aa35f0b5c4652459e8aee65b15b6fb51547a07cea5a0" dependencies = [ "proc-macro2", "quote", @@ -104,9 +104,9 @@ dependencies = [ [[package]] name = "cosmwasm-std" -version = "1.1.3" +version = "1.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5db87652893853c3fce979f3b687f02f1c6b1c42b99f7638d2f39fe36d81c78" +checksum = "b13d5a84d15cf7be17dc249a21588cdb0f7ef308907c50ce2723316a7d79c3dc" dependencies = [ "base64", "cosmwasm-crypto", @@ -402,15 +402,15 @@ checksum = "329c933548736bc49fd575ee68c89e8be4d260064184389a5b77517cddd99ffb" [[package]] name = "nois" -version = "0.5.1" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1eaeb48d21a9298037eeddae97b896503b35053d05524fff009c4128a5a78c3e" +checksum = "92b4f3482c5e189a5a51eb2ae3e54ddd58e7f5f63a3cb176b2d6f8709a875ce2" dependencies = [ "cosmwasm-schema", "cosmwasm-std", + "hex", "rand", "rand_xoshiro", - "schemars", "serde", "thiserror", "xxhash-rust", diff --git a/contracts/double-dice-roll/Cargo.toml b/contracts/double-dice-roll/Cargo.toml index db4b48c..6cdffd7 100644 --- a/contracts/double-dice-roll/Cargo.toml +++ b/contracts/double-dice-roll/Cargo.toml @@ -27,7 +27,7 @@ backtraces = ["cosmwasm-std/backtraces"] library = [] [dependencies] -nois = "0.5.1" +nois = "0.6.0" cosmwasm-std = "1.0.0" cw-storage-plus = "0.13.2" diff --git a/contracts/double-dice-roll/src/contract.rs b/contracts/double-dice-roll/src/contract.rs index 50af703..26000aa 100644 --- a/contracts/double-dice-roll/src/contract.rs +++ b/contracts/double-dice-roll/src/contract.rs @@ -44,8 +44,8 @@ pub fn execute( match msg { //RollDice should be called by a player who wants to roll the dice ExecuteMsg::RollDice { job_id } => execute_roll_dice(deps, env, info, job_id), - //Receive should be called by the proxy contract. The proxy is forwarding the randomness from the nois chain to this contract. - ExecuteMsg::Receive { callback } => execute_receive(deps, env, info, callback), + //NoisReceive should be called by the proxy contract. The proxy is forwarding the randomness from the nois chain to this contract. + ExecuteMsg::NoisReceive { callback } => execute_receive(deps, env, info, callback), } } @@ -108,9 +108,9 @@ pub fn execute_receive( .map_err(|_| ContractError::InvalidRandomness)?; //ints_in_range provides a list of random numbers following a uniform distribution within a range. //in this case it will provide uniformly randomized numbers between 1 and 6 - let [dice_outcome_1, dice_outcome_2] = ints_in_range(randomness, 1..=6); + let double_dice_outcome = ints_in_range(randomness, 2, 1, 6); //summing the dice to fit the real double dice probability distribution from 2 to 12 - let double_dice_outcome = dice_outcome_1 + dice_outcome_2; + let double_dice_outcome = double_dice_outcome.iter().sum(); //Preserve the immutability of the previous rounds. //So that the player cannot retry and change history. @@ -209,7 +209,7 @@ mod tests { fn proxy_cannot_bring_an_existing_job_id() { let mut deps = instantiate_proxy(); - let msg = ExecuteMsg::Receive { + let msg = ExecuteMsg::NoisReceive { callback: NoisCallback { job_id: "round_1".to_string(), randomness: HexBinary::from_hex( @@ -221,7 +221,7 @@ mod tests { let info = mock_info(PROXY_ADDRESS, &[]); execute(deps.as_mut(), mock_env(), info, msg).unwrap(); - let msg = ExecuteMsg::Receive { + let msg = ExecuteMsg::NoisReceive { callback: NoisCallback { job_id: "round_1".to_string(), randomness: HexBinary::from_hex( @@ -242,7 +242,7 @@ mod tests { fn execute_receive_fails_for_invalid_randomness() { let mut deps = instantiate_proxy(); - let msg = ExecuteMsg::Receive { + let msg = ExecuteMsg::NoisReceive { callback: NoisCallback { job_id: "round_1".to_string(), randomness: HexBinary::from_hex("ffffffff").unwrap(), @@ -258,7 +258,7 @@ mod tests { fn players_cannot_request_an_existing_job_id() { let mut deps = instantiate_proxy(); - let msg = ExecuteMsg::Receive { + let msg = ExecuteMsg::NoisReceive { callback: NoisCallback { job_id: "111".to_string(), randomness: HexBinary::from_hex( @@ -284,7 +284,7 @@ mod tests { fn execute_receive_fails_for_wrong_sender() { let mut deps = instantiate_proxy(); - let msg = ExecuteMsg::Receive { + let msg = ExecuteMsg::NoisReceive { callback: NoisCallback { job_id: "123".to_string(), randomness: HexBinary::from_hex( @@ -301,7 +301,7 @@ mod tests { fn execute_receive_works() { let mut deps = instantiate_proxy(); - let msg = ExecuteMsg::Receive { + let msg = ExecuteMsg::NoisReceive { callback: NoisCallback { job_id: "123".to_string(), randomness: HexBinary::from_hex( diff --git a/contracts/double-dice-roll/src/msg.rs b/contracts/double-dice-roll/src/msg.rs index 932ba74..e6b0303 100644 --- a/contracts/double-dice-roll/src/msg.rs +++ b/contracts/double-dice-roll/src/msg.rs @@ -15,7 +15,7 @@ pub enum ExecuteMsg { RollDice { job_id: String }, //callback contains the randomness from drand (HexBinary) and job_id //callback should only be allowed to be called by the proxy contract - Receive { callback: NoisCallback }, + NoisReceive { callback: NoisCallback }, } #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]