Skip to content

Commit 41bf1ac

Browse files
authored
Merge pull request #125 from thefifthdev/issue-2-token-transfer
Fix #2: Implement actual token transfer
2 parents 3750c4d + dcfc238 commit 41bf1ac

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

contracts/src/lib.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![no_std]
22

3-
use soroban_sdk::{contract, contractimpl, contracttype, Address, Env, String, Vec};
3+
use soroban_sdk::{contract, contractimpl, contracttype, token, Address, Env, String, Vec};
44

55
/// Billing interval in seconds
66
#[contracttype]
@@ -355,6 +355,13 @@ impl SubTrackrContract {
355355
.get(&DataKey::Plan(sub.plan_id))
356356
.expect("Plan not found");
357357

358+
// Execute actual token transfer from subscriber to merchant
359+
token::Client::new(&env, &plan.token).transfer(
360+
&sub.subscriber,
361+
&plan.merchant,
362+
&plan.price,
363+
);
364+
358365
sub.last_charged_at = now;
359366
sub.next_charge_at = now + plan.interval.seconds();
360367
sub.total_paid += plan.price;
@@ -528,6 +535,14 @@ mod test {
528535
use soroban_sdk::testutils::{Address as _, Ledger};
529536
use soroban_sdk::Env;
530537

538+
#[contract]
539+
pub struct MockToken;
540+
541+
#[contractimpl]
542+
impl MockToken {
543+
pub fn transfer(_env: Env, _from: Address, _to: Address, _amount: i128) {}
544+
}
545+
531546
fn setup(
532547
env: &Env,
533548
) -> (
@@ -543,7 +558,7 @@ mod test {
543558
let admin = Address::generate(env);
544559
let merchant = Address::generate(env);
545560
let subscriber = Address::generate(env);
546-
let token = Address::generate(env);
561+
let token = env.register_contract(None, MockToken);
547562

548563
env.mock_all_auths();
549564
client.initialize(&admin);

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"extends": "expo/tsconfig.base",
33
"compilerOptions": {
4-
"strict": true
4+
"strict": true,
5+
"lib": ["es2017", "dom"]
56
}
67
}

0 commit comments

Comments
 (0)