Skip to content

Commit

Permalink
transfer-contract: optionality of gas_price, comments
Browse files Browse the repository at this point in the history
  • Loading branch information
miloszm committed May 22, 2024
1 parent 64860f4 commit 677a39d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
25 changes: 14 additions & 11 deletions contracts/transfer/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub const A: usize = 4;
/// Number of roots stored
pub const MAX_ROOTS: usize = 5000;

// estimated cost of returning from the execute method
// Estimated cost of returning from the execute method
const SURCHARGE_POINTS: u64 = 10000;

pub struct TransferState {
Expand Down Expand Up @@ -274,10 +274,11 @@ impl TransferState {
result.map(|r| r.data)
}

/// Applies contract's charge.
/// Caller of the contract will pay a larger fee
/// so that contract can earn the difference between charge
/// and the actual cost of the call.
/// Applies contract's charge. Caller of the contract will pay a
/// larger fee so that contract can earn the difference between
/// charge and the actual cost of the call.
/// Charge has no effect if the actual cost of the call is greater
/// than the charge.
fn apply_charge(
&mut self,
contract_id: &ContractId,
Expand Down Expand Up @@ -309,10 +310,10 @@ impl TransferState {
}
}

/// Applies contract's allowance.
/// Caller of the contract's method won't pay a fee
/// and all the cost will be covered by the contract.
/// Allowance has no effect if contract does not have enough funds.
/// Applies contract's allowance. Caller of the contract's method
/// won't pay a fee and all the cost will be covered by the contract.
/// Allowance has no effect if contract does not have enough funds or
/// if the actual cost of the call is greater than allowance.
fn apply_allowance(
&mut self,
contract_id: &ContractId,
Expand Down Expand Up @@ -467,8 +468,10 @@ impl TransferState {

/// Return the current gas price as set by the execute method.
/// Returns none outside of the lifetime of the execute method.
pub fn gas_price(&self) -> Option<u64> {
self.gas_price
pub fn gas_price(&self) -> u64 {
self.gas_price.expect(
"During transaction execution host should always set the gas price",
)
}

fn get_note(&self, pos: u64) -> Option<Note> {
Expand Down
7 changes: 3 additions & 4 deletions contracts/transfer/tests/common/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ use std::sync::mpsc;
use dusk_bls12_381::BlsScalar;
use dusk_plonk::prelude::*;
use phoenix_core::transaction::*;
use phoenix_core::transaction::{TreeLeaf, TRANSFER_TREE_DEPTH};
use phoenix_core::{Note, ViewKey};
use poseidon_merkle::Opening as PoseidonOpening;
use rusk_abi::TRANSFER_CONTRACT;
use rusk_abi::{ContractError, ContractId, Session};
use rusk_abi::{EconomicMode, Error};
use rusk_abi::{
ContractError, ContractId, EconomicMode, Error, Session, TRANSFER_CONTRACT,
};

const POINT_LIMIT: u64 = 0x10_000_000;

Expand Down
2 changes: 1 addition & 1 deletion contracts/transfer/tests/scenario3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ fn instantiate<Rng: RngCore + CryptoRng>(

/// Transfers value from given note into contract's account.
/// Expects transparent note which will fund the subsidy and a subsidy value
/// which is be smaller or equal to the value of the note.
/// which is smaller or equal to the value of the note.
/// Returns the gas spent on the operation.
fn subsidize_contract<R: RngCore + CryptoRng>(
rng: &mut R,
Expand Down

0 comments on commit 677a39d

Please sign in to comment.