Skip to content

Commit

Permalink
moved error to logic
Browse files Browse the repository at this point in the history
  • Loading branch information
miloszm committed Jan 17, 2024
1 parent 286fa2d commit 1c8c5c0
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 13 deletions.
1 change: 0 additions & 1 deletion contracts/transfer-proxy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

extern crate alloc;

mod error;
mod state;

use rusk_abi::ContractId;
Expand Down
2 changes: 0 additions & 2 deletions contracts/transfer-proxy/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
//
// Copyright (c) DUSK NETWORK. All rights reserved.

use crate::error::Error;

use alloc::vec::Vec;

use dusk_bls12_381::BlsScalar;
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions contracts/transfer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
extern crate alloc;

mod circuits;
mod error;
mod state;

use dusk_bytes::Serializable;
Expand Down
21 changes: 12 additions & 9 deletions contracts/transfer/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Copyright (c) DUSK NETWORK. All rights reserved.

use crate::circuits::*;
use crate::error::Error;

use alloc::vec::Vec;

Expand All @@ -26,11 +27,6 @@ pub const A: usize = 4;

pub struct TransferOps;

#[derive(Debug, Clone)]
pub enum Error {
ProofVerificationError,
}

impl TransferOps {
fn is_transfer_caller() -> bool {
let transfer_owner =
Expand Down Expand Up @@ -554,13 +550,14 @@ impl TransferOps {
&mut self,
contract: &ContractId,
pk: &PublicKey,
) -> Option<Message> {
) -> Result<Message, Error> {
rusk_abi::call::<(ContractId, PublicKey), Option<Message>>(
TRANSFER_DATA_CONTRACT,
"take_message_from_address_key",
&(*contract, *pk),
)
.expect("take_message_from_address_key call should succeed")
.ok_or(Error::MessageNotFound)
}

fn root_exists(&self, root: &BlsScalar) -> bool {
Expand All @@ -577,13 +574,18 @@ impl TransferOps {
self.push_note(block_height, note)
}

fn sub_balance(&mut self, address: &ContractId, value: u64) -> Option<()> {
rusk_abi::call(
fn sub_balance(
&mut self,
address: &ContractId,
value: u64,
) -> Result<(), Error> {
rusk_abi::call::<(ContractId, u64), Option<()>>(
TRANSFER_DATA_CONTRACT,
"sub_balance",
&(*address, value),
)
.expect("sub_balance call should succeed")
.ok_or(Error::NotEnoughBalance)
}

fn push_message(
Expand All @@ -600,13 +602,14 @@ impl TransferOps {
.expect("push_message call should succeed");
}

fn take_crossover(&mut self) -> Option<(Crossover, StealthAddress)> {
fn take_crossover(&mut self) -> Result<(Crossover, StealthAddress), Error> {
rusk_abi::call::<(), Option<(Crossover, StealthAddress)>>(
TRANSFER_DATA_CONTRACT,
"take_crossover",
&(),
)
.expect("take_crossover call should succeed")
.ok_or(Error::CrossoverNotFound)
}

fn assert_proof(
Expand Down
2 changes: 1 addition & 1 deletion rusk/tests/services/multi_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::common::wallet::{TestProverClient, TestStateClient, TestStore};
const BLOCK_HEIGHT: u64 = 1;
// This is purposefully chosen to be low to trigger the discarding of a
// perfectly good transaction.
const GAS_LIMIT: u64 = 16_000_000; // Lowest value for a transfer
const GAS_LIMIT: u64 = 13_000_000; // Lowest value for a transfer
const BLOCK_GAS_LIMIT: u64 = GAS_LIMIT * 23 / 10; // out of gas after 2 transactions
const INITIAL_BALANCE: u64 = 10_000_000_000;

Expand Down

0 comments on commit 1c8c5c0

Please sign in to comment.