Skip to content

Commit

Permalink
transfer-contract: charge and allowance in gas points
Browse files Browse the repository at this point in the history
  • Loading branch information
miloszm committed May 20, 2024
1 parent 63e9abc commit 3e4ae93
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
22 changes: 11 additions & 11 deletions contracts/transfer/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,12 @@ impl TransferState {
&mut self,
contract_id: &ContractId,
charge: u64,
ges_spent: u64,
gas_spent: u64,
gas_price: u64,
) -> u64 {
let cost = ges_spent * gas_price;
let cost = gas_spent * gas_price;
if charge > cost {
let earning = charge - cost;
let earning = charge * gas_price - cost;
self.add_balance(*contract_id, earning);
rusk_abi::emit(
"earning",
Expand All @@ -288,11 +288,11 @@ impl TransferState {
"earning",
EconomicEvent {
module: contract_id.to_bytes(),
value: charge,
value: charge * gas_price,
result: EconomicResult::ChargeNotSufficient,
},
);
ges_spent
gas_spent
}
}

Expand All @@ -307,20 +307,20 @@ impl TransferState {
&mut self,
contract_id: &ContractId,
allowance: u64,
ges_spent: u64,
gas_spent: u64,
gas_price: u64,
) -> u64 {
let spent = ges_spent * gas_price;
if allowance < spent {
let spent = gas_spent * gas_price;
if allowance * gas_price < spent {
rusk_abi::emit(
"sponsoring",
EconomicEvent {
module: contract_id.to_bytes(),
value: allowance,
value: allowance * gas_price,
result: EconomicResult::AllowanceNotSufficient,
},
);
spent
gas_spent
} else {
let contract_balance = self.balance(contract_id);
if spent > contract_balance {
Expand All @@ -332,7 +332,7 @@ impl TransferState {
result: EconomicResult::BalanceNotSufficient,
},
);
spent
gas_spent
} else {
self.sub_balance(contract_id, spent).expect(
"Subtracting callee contract balance should succeed",
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 @@ -562,7 +562,7 @@ fn contract_earns_fee() {
assert_eq!(
execution_result.economic_mode,
EconomicMode::Charge(
balance_delta + execution_result.gas_spent * GAS_PRICE
balance_delta / GAS_PRICE + execution_result.gas_spent
)
);
}
Expand Down

0 comments on commit 3e4ae93

Please sign in to comment.