Skip to content

Commit

Permalink
Split up the token interface trait
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmcculloch committed Jun 23, 2023
1 parent c20b456 commit 398980b
Showing 1 changed file with 43 additions and 36 deletions.
79 changes: 43 additions & 36 deletions soroban-sdk/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ use crate::{contractclient, contractspecfn, Address, Env, String};
// 2. The implementations have been replaced with a panic.
// 3. &Host type usage are replaced with Env

/// Spec contains the contract spec of Token contracts, such as the Stellar
/// Asset Contract.
/// Spec contains the contract spec of Token contracts, including the general
/// interface, as well as the admin interface, such as the Stellar Asset
/// Contract.
pub struct Spec;

/// Interface for Token contracts, such as the Stellar Asset Contract.
Expand Down Expand Up @@ -156,6 +157,46 @@ pub trait Interface {
/// i128]`
fn burn_from(env: Env, spender: Address, from: Address, amount: i128);

/// Returns the number of decimals used to represent amounts of this token.
///
/// # Panics
///
/// If the contract has not yet been initialized.
fn decimals(env: Env) -> u32;

/// Returns the name for this token.
///
/// # Panics
///
/// If the contract has not yet been initialized.
fn name(env: Env) -> String;

/// Returns the symbol for this token.
///
/// # Panics
///
/// If the contract has not yet been initialized.
fn symbol(env: Env) -> String;
}

/// Interface for admin capabilities for Token contracts, such as the Stellar
/// Asset Contract.
#[contractspecfn(name = "Spec", export = false)]
#[contractclient(crate_path = "crate", name = "AdminClient")]
pub trait AdminInterface {
/// Sets the administrator to the specified address `new_admin`.
///
/// # Arguments
///
/// * `new_admin` - The address which will henceforth be the administrator
/// of this token contract.
///
/// # Events
///
/// Emits an event with topics `["set_admin", admin: Address], data =
/// [new_admin: Address]`
fn set_admin(env: Env, new_admin: Address);

/// Sets whether the account is authorized to use its balance. If
/// `authorized` is true, `id` should be able to use its balance.
///
Expand Down Expand Up @@ -197,40 +238,6 @@ pub trait Interface {
/// Emits an event with topics `["clawback", admin: Address, to: Address],
/// data = [amount: i128]`
fn clawback(env: Env, from: Address, amount: i128);

/// Sets the administrator to the specified address `new_admin`.
///
/// # Arguments
///
/// * `new_admin` - The address which will henceforth be the administrator
/// of this token contract.
///
/// # Events
///
/// Emits an event with topics `["set_admin", admin: Address], data =
/// [new_admin: Address]`
fn set_admin(env: Env, new_admin: Address);

/// Returns the number of decimals used to represent amounts of this token.
///
/// # Panics
///
/// If the contract has not yet been initialized.
fn decimals(env: Env) -> u32;

/// Returns the name for this token.
///
/// # Panics
///
/// If the contract has not yet been initialized.
fn name(env: Env) -> String;

/// Returns the symbol for this token.
///
/// # Panics
///
/// If the contract has not yet been initialized.
fn symbol(env: Env) -> String;
}

pub(crate) const SPEC_XDR_INPUT: &[&[u8]] = &[
Expand Down

0 comments on commit 398980b

Please sign in to comment.