Skip to content

Commit d9db781

Browse files
authored
Merge pull request Lead-Studios#66 from Kaylahray/feat/escrow-actions
Implemented escrow actions
2 parents 9a7bfa2 + 07c4ed7 commit d9db781

20 files changed

Lines changed: 5601 additions & 526 deletions

veritixpay/contract/token/src/admin.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,32 @@ use soroban_sdk::{Address, Env};
22

33
use crate::storage_types::DataKey;
44

5-
pub fn read_administrator(e: &Env) -> Address {
5+
// --- Core admin storage helpers ---
6+
7+
pub fn read_admin(e: &Env) -> Address {
68
e.storage().instance().get(&DataKey::Admin).unwrap()
79
}
810

9-
pub fn write_administrator(e: &Env, id: &Address) {
11+
pub fn write_admin(e: &Env, id: &Address) {
1012
e.storage().instance().set(&DataKey::Admin, id);
1113
}
1214

13-
pub fn has_administrator(e: &Env) -> bool {
15+
pub fn has_admin(e: &Env) -> bool {
1416
e.storage().instance().has(&DataKey::Admin)
1517
}
1618

19+
/// Verifies that `admin` is the current admin and has authorized the call.
1720
pub fn check_admin(e: &Env, admin: &Address) {
1821
admin.require_auth();
19-
let stored = read_administrator(e);
22+
let stored = read_admin(e);
2023
if admin != &stored {
2124
panic!("not authorized: caller is not the admin");
2225
}
2326
}
2427

25-
28+
/// Rotates the stored admin to `new_admin`. Must be called by the current admin.
2629
pub fn transfer_admin(e: &Env, new_admin: Address) {
27-
// 1. Verify that the current admin is authorizing this call
2830
let current_admin = read_admin(e);
2931
current_admin.require_auth();
30-
31-
// 2. Write the new admin to persistent storage
3232
write_admin(e, &new_admin);
33-
}
33+
}

veritixpay/contract/token/src/allowance.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ pub fn read_allowance(e: &Env, from: Address, spender: Address) -> AllowanceValu
66
from: from.clone(),
77
spender: spender.clone(),
88
});
9-
10-
if let Some(allowance) = e.storage().persistent().get::<DataKey, AllowanceValue>(&key) {
9+
10+
if let Some(allowance) = e
11+
.storage()
12+
.persistent()
13+
.get::<DataKey, AllowanceValue>(&key)
14+
{
1115
if allowance.expiration_ledger < e.ledger().sequence() {
1216
AllowanceValue {
1317
amount: 0,
@@ -53,15 +57,15 @@ pub fn write_allowance(
5357

5458
pub fn spend_allowance(e: &Env, from: Address, spender: Address, amount: i128) {
5559
let allowance = read_allowance(e, from.clone(), spender.clone());
56-
60+
5761
if allowance.expiration_ledger < e.ledger().sequence() {
5862
panic!("allowance is expired");
5963
}
60-
64+
6165
if allowance.amount < amount {
6266
panic!("insufficient allowance");
6367
}
64-
68+
6569
write_allowance(
6670
e,
6771
from,
Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
use crate::storage_types::{DataKey, BALANCE_LIFETIME_THRESHOLD, BALANCE_BUMP_AMOUNT};
1+
use crate::storage_types::{DataKey, BALANCE_BUMP_AMOUNT, BALANCE_LIFETIME_THRESHOLD};
22
use soroban_sdk::{Address, Env};
33

44
/// Returns the balance for an address, or 0 if not set
55
pub fn read_balance(e: &Env, addr: Address) -> i128 {
66
let key = DataKey::Balance(addr);
77
let storage = e.storage().persistent();
8-
8+
99
if let Some(balance) = storage.get::<DataKey, i128>(&key) {
1010
storage.extend_ttl(&key, BALANCE_LIFETIME_THRESHOLD, BALANCE_BUMP_AMOUNT);
1111
balance
@@ -19,24 +19,27 @@ pub fn receive_balance(e: &Env, addr: Address, amount: i128) {
1919
if crate::freeze::is_frozen(e, &addr) {
2020
panic!("account frozen");
2121
}
22-
22+
2323
let key = DataKey::Balance(addr.clone());
2424
let current_balance = read_balance(e, addr); // TTL is extended here
2525
let new_balance = current_balance + amount;
26-
26+
2727
e.storage().persistent().set(&key, &new_balance);
2828
}
2929
/// Subtracts amount from address balance — panics if insufficient
3030
pub fn spend_balance(e: &Env, addr: Address, amount: i128) {
3131
let key = DataKey::Balance(addr.clone());
3232
let current_balance = read_balance(e, addr);
33-
33+
3434
if current_balance < amount {
35-
panic!("insufficient balance: attempted to spend {} but only {} available", amount, current_balance);
35+
panic!(
36+
"insufficient balance: attempted to spend {} but only {} available",
37+
amount, current_balance
38+
);
3639
}
37-
40+
3841
let new_balance = current_balance - amount;
39-
42+
4043
let storage = e.storage().persistent();
4144
storage.set(&key, &new_balance);
4245
storage.extend_ttl(&key, BALANCE_LIFETIME_THRESHOLD, BALANCE_BUMP_AMOUNT);
@@ -46,18 +49,25 @@ pub fn spend_balance(e: &Env, addr: Address, amount: i128) {
4649
// (Make sure to import DataKey if not already imported)
4750

4851
pub fn read_total_supply(e: &Env) -> i128 {
49-
e.storage().instance().get(&DataKey::TotalSupply).unwrap_or(0)
52+
e.storage()
53+
.instance()
54+
.get(&DataKey::TotalSupply)
55+
.unwrap_or(0)
5056
}
5157

5258
pub fn increase_supply(e: &Env, amount: i128) {
5359
let supply = read_total_supply(e);
54-
e.storage().instance().set(&DataKey::TotalSupply, &(supply + amount));
60+
e.storage()
61+
.instance()
62+
.set(&DataKey::TotalSupply, &(supply + amount));
5563
}
5664

5765
pub fn decrease_supply(e: &Env, amount: i128) {
5866
let supply = read_total_supply(e);
5967
if supply < amount {
6068
panic!("supply cannot be negative");
6169
}
62-
e.storage().instance().set(&DataKey::TotalSupply, &(supply - amount));
63-
}
70+
e.storage()
71+
.instance()
72+
.set(&DataKey::TotalSupply, &(supply - amount));
73+
}

0 commit comments

Comments
 (0)