diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1e232d6..18f251c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,7 +16,7 @@ jobs: - name: Install Rust uses: actions-rs/toolchain@v1 with: - toolchain: 1.75.0 + toolchain: stable target: wasm32-unknown-unknown override: true diff --git a/contracts/ephemeral_account/src/errors.rs b/contracts/ephemeral_account/src/errors.rs index e23e99d..a160054 100644 --- a/contracts/ephemeral_account/src/errors.rs +++ b/contracts/ephemeral_account/src/errors.rs @@ -15,4 +15,4 @@ pub enum Error { NoPaymentReceived = 10, AccountExpired = 11, InvalidStatus = 12, -} \ No newline at end of file +} diff --git a/contracts/ephemeral_account/src/events.rs b/contracts/ephemeral_account/src/events.rs index 4a75706..2652de8 100644 --- a/contracts/ephemeral_account/src/events.rs +++ b/contracts/ephemeral_account/src/events.rs @@ -57,4 +57,4 @@ pub fn emit_account_expired(env: &Env, recovery_address: Address, amount_returne amount_returned, }; env.events().publish((symbol_short!("expired"),), event); -} \ No newline at end of file +} diff --git a/contracts/ephemeral_account/src/lib.rs b/contracts/ephemeral_account/src/lib.rs index a8bc880..2c641c8 100644 --- a/contracts/ephemeral_account/src/lib.rs +++ b/contracts/ephemeral_account/src/lib.rs @@ -1,13 +1,13 @@ #![no_std] -mod storage; -mod events; mod errors; +mod events; +mod storage; -use soroban_sdk::{contract, contractimpl, contracttype, Address, Env, BytesN}; +use soroban_sdk::{contract, contractimpl, contracttype, Address, BytesN, Env}; pub use errors::Error; -pub use events::{AccountCreated, PaymentReceived, SweepExecuted, AccountExpired}; +pub use events::{AccountCreated, AccountExpired, PaymentReceived, SweepExecuted}; pub use storage::{AccountStatus, DataKey}; #[contract] @@ -16,12 +16,12 @@ pub struct EphemeralAccountContract; #[contractimpl] impl EphemeralAccountContract { /// Initialize the ephemeral account with restrictions - /// + /// /// # Arguments /// * `creator` - Address that created this account /// * `expiry_ledger` - Ledger number when account expires /// * `recovery_address` - Address to return funds if expired - /// + /// /// # Errors /// Returns Error::AlreadyInitialized if called more than once pub fn initialize( @@ -59,18 +59,14 @@ impl EphemeralAccountContract { /// Record an inbound payment to this ephemeral account /// Only the first payment is accepted - /// + /// /// # Arguments /// * `amount` - Payment amount /// * `asset` - Asset address - /// + /// /// # Errors /// Returns Error::PaymentAlreadyReceived if payment already recorded - pub fn record_payment( - env: Env, - amount: i128, - asset: Address, - ) -> Result<(), Error> { + pub fn record_payment(env: Env, amount: i128, asset: Address) -> Result<(), Error> { // Check initialized if !storage::is_initialized(&env) { return Err(Error::NotInitialized); @@ -100,19 +96,15 @@ impl EphemeralAccountContract { /// Execute sweep to destination wallet /// Transfers all funds to the specified destination - /// + /// /// # Arguments /// * `destination` - Recipient wallet address /// * `auth_signature` - Authorization signature from off-chain system - /// + /// /// # Errors /// Returns Error::Unauthorized if authorization fails /// Returns Error::AlreadySwept if sweep already executed - pub fn sweep( - env: Env, - destination: Address, - auth_signature: BytesN<64>, - ) -> Result<(), Error> { + pub fn sweep(env: Env, destination: Address, auth_signature: BytesN<64>) -> Result<(), Error> { // Check initialized if !storage::is_initialized(&env) { return Err(Error::NotInitialized); @@ -164,7 +156,7 @@ impl EphemeralAccountContract { let expiry_ledger = storage::get_expiry_ledger(&env); let current_ledger = env.ledger().sequence(); - + current_ledger >= expiry_ledger } @@ -179,7 +171,7 @@ impl EphemeralAccountContract { /// Expire the account and return funds to recovery address /// Can only be called after expiry ledger is reached - /// + /// /// # Errors /// Returns Error::NotExpired if called before expiry ledger pub fn expire(env: Env) -> Result<(), Error> { @@ -265,4 +257,4 @@ pub struct AccountInfo { pub payment_received: bool, pub payment_amount: Option, pub swept_to: Option
, -} \ No newline at end of file +} diff --git a/contracts/ephemeral_account/src/storage.rs b/contracts/ephemeral_account/src/storage.rs index 6fdce15..72ff899 100644 --- a/contracts/ephemeral_account/src/storage.rs +++ b/contracts/ephemeral_account/src/storage.rs @@ -43,20 +43,30 @@ pub fn get_creator(env: &Env) -> Address { // Expiry ledger pub fn set_expiry_ledger(env: &Env, ledger: u32) { - env.storage().instance().set(&DataKey::ExpiryLedger, &ledger); + env.storage() + .instance() + .set(&DataKey::ExpiryLedger, &ledger); } pub fn get_expiry_ledger(env: &Env) -> u32 { - env.storage().instance().get(&DataKey::ExpiryLedger).unwrap() + env.storage() + .instance() + .get(&DataKey::ExpiryLedger) + .unwrap() } // Recovery address pub fn set_recovery_address(env: &Env, address: &Address) { - env.storage().instance().set(&DataKey::RecoveryAddress, address); + env.storage() + .instance() + .set(&DataKey::RecoveryAddress, address); } pub fn get_recovery_address(env: &Env) -> Address { - env.storage().instance().get(&DataKey::RecoveryAddress).unwrap() + env.storage() + .instance() + .get(&DataKey::RecoveryAddress) + .unwrap() } // Payment @@ -65,15 +75,22 @@ pub fn has_payment_received(env: &Env) -> bool { } pub fn set_payment_received(env: &Env, value: bool) { - env.storage().instance().set(&DataKey::PaymentReceived, &value); + env.storage() + .instance() + .set(&DataKey::PaymentReceived, &value); } pub fn set_payment_amount(env: &Env, amount: i128) { - env.storage().instance().set(&DataKey::PaymentAmount, &amount); + env.storage() + .instance() + .set(&DataKey::PaymentAmount, &amount); } pub fn get_payment_amount(env: &Env) -> i128 { - env.storage().instance().get(&DataKey::PaymentAmount).unwrap_or(0) + env.storage() + .instance() + .get(&DataKey::PaymentAmount) + .unwrap_or(0) } pub fn set_payment_asset(env: &Env, asset: &Address) { @@ -81,7 +98,10 @@ pub fn set_payment_asset(env: &Env, asset: &Address) { } pub fn get_payment_asset(env: &Env) -> Address { - env.storage().instance().get(&DataKey::PaymentAsset).unwrap() + env.storage() + .instance() + .get(&DataKey::PaymentAsset) + .unwrap() } // Status @@ -103,4 +123,4 @@ pub fn set_swept_to(env: &Env, address: &Address) { pub fn get_swept_to(env: &Env) -> Option
{ env.storage().instance().get(&DataKey::SweptTo) -} \ No newline at end of file +}