Skip to content

Commit

Permalink
Change Crossover to CrossoverType like other wasm arguments types
Browse files Browse the repository at this point in the history
Fix clippy warnings
  • Loading branch information
Daksh14 committed Nov 1, 2023
1 parent 709b1c4 commit dbaa79f
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 17 deletions.
4 changes: 2 additions & 2 deletions assets/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
}
}
},
"Crossover": {
"CrossoverType": {
"description": "The value of the Crossover and the blinder",
"type": "object",
"required": [
Expand Down Expand Up @@ -193,7 +193,7 @@
},
"crossover": {
"description": "The crossover value",
"$ref": "#/definitions/Crossover"
"$ref": "#/definitions/CrossoverType"
},
"fee": {
"description": "A rkyv serialized Fee",
Expand Down
4 changes: 2 additions & 2 deletions src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down Expand Up @@ -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();

Expand Down
12 changes: 6 additions & 6 deletions src/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -128,7 +128,7 @@ pub struct UnprovenTransaction {
/// Fee setup for the transaction.
pub fee: Fee,
/// Crossover value for inter-contract calls.
pub crossover: Option<Crossover>,
pub crossover: Option<WasmCrossover>,
/// Call data payload for contract calls.
pub call: Option<CallData>,
}
Expand All @@ -144,7 +144,7 @@ impl UnprovenTransaction {
inputs: I,
outputs: O,
fee: Fee,
crossover: Option<WasmCrossover>,
crossover: Option<CrossoverType>,
call: Option<types::ExecuteCall>,
) -> Option<Self>
where
Expand Down Expand Up @@ -220,13 +220,13 @@ impl UnprovenTransaction {
});

let crossover = crossover.and_then(
|WasmCrossover {
|CrossoverType {
blinder,
crossover,
value,
}| {
Some({
Crossover {
WasmCrossover {
crossover: rkyv::from_bytes::<PhoenixCrossover>(
&crossover,
)
Expand Down
4 changes: 2 additions & 2 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>,
#[doc = " The rkyv serialized bytes of the crossover struct"]
Expand All @@ -49,7 +49,7 @@ pub struct ExecuteArgs {
pub call: Option<ExecuteCall>,
#[doc = " The crossover value"]
#[serde(skip_serializing_if = "Option::is_none")]
pub crossover: Option<Crossover>,
pub crossover: Option<CrossoverType>,
#[doc = " A rkyv serialized Fee"]
pub fee: Vec<u8>,
#[doc = " The gas limit of the transaction"]
Expand Down
7 changes: 3 additions & 4 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion tests/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down

0 comments on commit dbaa79f

Please sign in to comment.