From dbaa79f03ebc0e4554a455c2a9328f5328a206ad Mon Sep 17 00:00:00 2001 From: Daksh Date: Wed, 1 Nov 2023 14:06:04 -0400 Subject: [PATCH] Change Crossover to CrossoverType like other wasm arguments types Fix clippy warnings --- assets/schema.json | 4 ++-- src/ffi.rs | 4 ++-- src/tx.rs | 12 ++++++------ src/types.rs | 4 ++-- src/utils.rs | 7 +++---- tests/wallet.rs | 2 +- 6 files changed, 16 insertions(+), 17 deletions(-) diff --git a/assets/schema.json b/assets/schema.json index cf46182..1f04706 100644 --- a/assets/schema.json +++ b/assets/schema.json @@ -139,7 +139,7 @@ } } }, - "Crossover": { + "CrossoverType": { "description": "The value of the Crossover and the blinder", "type": "object", "required": [ @@ -193,7 +193,7 @@ }, "crossover": { "description": "The crossover value", - "$ref": "#/definitions/Crossover" + "$ref": "#/definitions/CrossoverType" }, "fee": { "description": "A rkyv serialized Fee", diff --git a/src/ffi.rs b/src/ffi.rs index b46f7c3..82a5084 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -239,7 +239,7 @@ pub fn execute(args: i32, len: i32) -> i64 { outputs.push(o); } - let rng = &mut utils::rng(&rng_seed); + let rng = &mut utils::rng(rng_seed); let tx = tx::UnprovenTransaction::new( rng, inputs, outputs, fee, crossover, call, ); @@ -313,7 +313,7 @@ pub fn filter_notes(args: i32, len: i32) -> i64 { let notes: Vec<_> = notes .into_iter() - .zip(flags.into_iter()) + .zip(flags) .filter_map(|(n, f)| (!f).then_some(n)) .collect(); diff --git a/src/tx.rs b/src/tx.rs index 97eb280..4079adb 100644 --- a/src/tx.rs +++ b/src/tx.rs @@ -24,7 +24,7 @@ use rkyv::{Archive, Deserialize, Serialize}; use rusk_abi::hash::Hasher; use rusk_abi::{ContractId, POSEIDON_TREE_DEPTH}; -use crate::{types, types::Crossover as WasmCrossover, utils}; +use crate::{types, types::CrossoverType, utils}; /// Chosen arity for the Notes tree implementation. pub const POSEIDON_TREE_ARITY: usize = 4; @@ -94,7 +94,7 @@ pub struct Output { /// A crossover to a transaction that is yet to be proven. #[derive(Debug, Clone, Archive, Serialize, Deserialize)] #[archive_attr(derive(CheckBytes))] -pub struct Crossover { +pub struct WasmCrossover { /// Crossover value to be used in inter-contract calls. pub crossover: PhoenixCrossover, /// Value of the crossover. @@ -128,7 +128,7 @@ pub struct UnprovenTransaction { /// Fee setup for the transaction. pub fee: Fee, /// Crossover value for inter-contract calls. - pub crossover: Option, + pub crossover: Option, /// Call data payload for contract calls. pub call: Option, } @@ -144,7 +144,7 @@ impl UnprovenTransaction { inputs: I, outputs: O, fee: Fee, - crossover: Option, + crossover: Option, call: Option, ) -> Option where @@ -220,13 +220,13 @@ impl UnprovenTransaction { }); let crossover = crossover.and_then( - |WasmCrossover { + |CrossoverType { blinder, crossover, value, }| { Some({ - Crossover { + WasmCrossover { crossover: rkyv::from_bytes::( &crossover, ) diff --git a/src/types.rs b/src/types.rs index efe61ab..62409ee 100644 --- a/src/types.rs +++ b/src/types.rs @@ -33,7 +33,7 @@ pub struct BalanceResponse { } #[doc = " The value of the Crossover and the blinder"] #[derive(Clone, PartialEq, Debug, Deserialize, Serialize)] -pub struct Crossover { +pub struct CrossoverType { #[doc = " The rkyv serialized blinder of the crossover"] pub blinder: Vec, #[doc = " The rkyv serialized bytes of the crossover struct"] @@ -49,7 +49,7 @@ pub struct ExecuteArgs { pub call: Option, #[doc = " The crossover value"] #[serde(skip_serializing_if = "Option::is_none")] - pub crossover: Option, + pub crossover: Option, #[doc = " A rkyv serialized Fee"] pub fee: Vec, #[doc = " The gas limit of the transaction"] diff --git a/src/utils.rs b/src/utils.rs index 556d537..e83227c 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -101,10 +101,9 @@ where compose(true, ptr, len) } -/// Creates a secure RNG from a seed. -/// We should keep this above 64 to be secure -pub fn rng(seed: &[u8; 32]) -> ChaCha12Rng { - ChaCha12Rng::from_seed(*seed) +/// Creates a secure RNG directly a seed. +pub fn rng(seed: [u8; 32]) -> ChaCha12Rng { + ChaCha12Rng::from_seed(seed) } /// Creates a secure RNG from a seed with embedded index. diff --git a/tests/wallet.rs b/tests/wallet.rs index 4898826..8f5d23d 100644 --- a/tests/wallet.rs +++ b/tests/wallet.rs @@ -11,7 +11,7 @@ use dusk_jubjub::JubJubScalar; use dusk_pki::PublicSpendKey; use dusk_wallet_core::{ tx, - types::{self, Crossover as WasmCrossover}, + types::{self, CrossoverType as WasmCrossover}, utils, MAX_KEY, MAX_LEN, RNG_SEED, }; use phoenix_core::{Crossover, Fee};