Skip to content

Commit

Permalink
Publish events using the token sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
sisuresh committed Aug 21, 2023
1 parent 7737470 commit c4596c5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 47 deletions.
24 changes: 14 additions & 10 deletions token/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use crate::admin::{has_administrator, read_administrator, write_administrator};
use crate::allowance::{read_allowance, spend_allowance, write_allowance};
use crate::balance::{is_authorized, write_authorization};
use crate::balance::{read_balance, receive_balance, spend_balance};
use crate::event;
use crate::metadata::{read_decimal, read_name, read_symbol, write_metadata};
use crate::storage_types::INSTANCE_BUMP_AMOUNT;
use soroban_sdk::{contract, contractimpl, Address, Env, String};
use soroban_token_sdk::metadata::TokenMetadata;
use soroban_token_sdk::TokenUtils;

pub trait TokenTrait {
fn initialize(e: Env, admin: Address, decimal: u32, name: String, symbol: String);
Expand Down Expand Up @@ -89,7 +89,9 @@ impl TokenTrait for Token {
e.storage().instance().bump(INSTANCE_BUMP_AMOUNT);

write_allowance(&e, from.clone(), spender.clone(), amount, expiration_ledger);
event::approve(&e, from, spender, amount, expiration_ledger);
TokenUtils::new(&e)
.events()
.approve(from, spender, amount, expiration_ledger);
}

fn balance(e: Env, id: Address) -> i128 {
Expand All @@ -116,7 +118,7 @@ impl TokenTrait for Token {

spend_balance(&e, from.clone(), amount);
receive_balance(&e, to.clone(), amount);
event::transfer(&e, from, to, amount);
TokenUtils::new(&e).events().transfer(from, to, amount);
}

fn transfer_from(e: Env, spender: Address, from: Address, to: Address, amount: i128) {
Expand All @@ -129,7 +131,7 @@ impl TokenTrait for Token {
spend_allowance(&e, from.clone(), spender, amount);
spend_balance(&e, from.clone(), amount);
receive_balance(&e, to.clone(), amount);
event::transfer(&e, from, to, amount)
TokenUtils::new(&e).events().transfer(from, to, amount)
}

fn burn(e: Env, from: Address, amount: i128) {
Expand All @@ -140,7 +142,7 @@ impl TokenTrait for Token {
e.storage().instance().bump(INSTANCE_BUMP_AMOUNT);

spend_balance(&e, from.clone(), amount);
event::burn(&e, from, amount);
TokenUtils::new(&e).events().burn(from, amount);
}

fn burn_from(e: Env, spender: Address, from: Address, amount: i128) {
Expand All @@ -152,7 +154,7 @@ impl TokenTrait for Token {

spend_allowance(&e, from.clone(), spender, amount);
spend_balance(&e, from.clone(), amount);
event::burn(&e, from, amount)
TokenUtils::new(&e).events().burn(from, amount)
}

fn clawback(e: Env, from: Address, amount: i128) {
Expand All @@ -163,7 +165,7 @@ impl TokenTrait for Token {
e.storage().instance().bump(INSTANCE_BUMP_AMOUNT);

spend_balance(&e, from.clone(), amount);
event::clawback(&e, admin, from, amount);
TokenUtils::new(&e).events().clawback(admin, from, amount);
}

fn set_authorized(e: Env, id: Address, authorize: bool) {
Expand All @@ -173,7 +175,9 @@ impl TokenTrait for Token {
e.storage().instance().bump(INSTANCE_BUMP_AMOUNT);

write_authorization(&e, id.clone(), authorize);
event::set_authorized(&e, admin, id, authorize);
TokenUtils::new(&e)
.events()
.set_authorized(admin, id, authorize);
}

fn mint(e: Env, to: Address, amount: i128) {
Expand All @@ -184,7 +188,7 @@ impl TokenTrait for Token {
e.storage().instance().bump(INSTANCE_BUMP_AMOUNT);

receive_balance(&e, to.clone(), amount);
event::mint(&e, admin, to, amount);
TokenUtils::new(&e).events().mint(admin, to, amount);
}

fn set_admin(e: Env, new_admin: Address) {
Expand All @@ -194,7 +198,7 @@ impl TokenTrait for Token {
e.storage().instance().bump(INSTANCE_BUMP_AMOUNT);

write_administrator(&e, &new_admin);
event::set_admin(&e, admin, new_admin);
TokenUtils::new(&e).events().set_admin(admin, new_admin);
}

fn decimals(e: Env) -> u32 {
Expand Down
36 changes: 0 additions & 36 deletions token/src/event.rs

This file was deleted.

1 change: 0 additions & 1 deletion token/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ mod admin;
mod allowance;
mod balance;
mod contract;
mod event;
mod metadata;
mod storage_types;
mod test;
Expand Down

0 comments on commit c4596c5

Please sign in to comment.