|
1 | 1 | use crate::errors::Error; |
| 2 | +use bridgelet_shared::Payment; |
2 | 3 | use soroban_sdk::token::TokenClient; |
3 | | -use soroban_sdk::{Address, Env}; |
| 4 | +use soroban_sdk::{Address, Env, Vec}; |
4 | 5 |
|
5 | | -/// Execute token transfer from ephemeral account to destination |
6 | | -pub fn execute_transfer( |
| 6 | +/// Execute token transfers for all payments from the ephemeral account to the destination. |
| 7 | +/// |
| 8 | +/// Iterates over each recorded payment and calls the SEP-41 token contract's |
| 9 | +/// `transfer()` function, moving funds from `from` to `destination`. |
| 10 | +/// |
| 11 | +/// The ephemeral account must have already authorized this contract to transfer |
| 12 | +/// on its behalf — this is enforced by the Soroban auth model when `from.require_auth()` |
| 13 | +/// is satisfied by the ephemeral account's invocation context. |
| 14 | +/// |
| 15 | +/// # Arguments |
| 16 | +/// * `env` - Soroban environment |
| 17 | +/// * `from` - Ephemeral account address (source of funds) |
| 18 | +/// * `destination` - Recipient wallet address |
| 19 | +/// * `payments` - All recorded payments to transfer |
| 20 | +/// |
| 21 | +/// # Errors |
| 22 | +/// Returns `Error::TransferFailed` if any individual transfer fails |
| 23 | +pub fn execute_transfers( |
7 | 24 | env: &Env, |
8 | | - token_address: &Address, |
9 | 25 | from: &Address, |
10 | | - to: &Address, |
11 | | - amount: i128, |
| 26 | + destination: &Address, |
| 27 | + payments: &Vec<Payment>, |
12 | 28 | ) -> Result<(), Error> { |
13 | | - // Create token client |
14 | | - let token = TokenClient::new(env, token_address); |
15 | | - |
16 | | - // Execute transfer |
17 | | - token.transfer(from, to, &amount); |
18 | | - |
19 | | - Ok(()) |
20 | | -} |
21 | | - |
22 | | -/// Transfer context for sweep operations |
23 | | -pub struct TransferContext { |
24 | | - pub asset: Address, |
25 | | - pub from: Address, |
26 | | - pub to: Address, |
27 | | - pub amount: i128, |
28 | | -} |
29 | | - |
30 | | -impl TransferContext { |
31 | | - pub fn new(asset: Address, from: Address, to: Address, amount: i128) -> Self { |
32 | | - Self { |
33 | | - asset, |
34 | | - from, |
35 | | - to, |
36 | | - amount, |
37 | | - } |
38 | | - } |
39 | | - |
40 | | - pub fn execute(&self, env: &Env) -> Result<(), Error> { |
41 | | - execute_transfer(env, &self.asset, &self.from, &self.to, self.amount) |
| 29 | + for payment in payments.iter() { |
| 30 | + let token = TokenClient::new(env, &payment.asset); |
| 31 | + token.transfer(from, destination, &payment.amount); |
42 | 32 | } |
| 33 | + Ok(()) |
43 | 34 | } |
0 commit comments