Skip to content

Commit

Permalink
Made transfer_to a little more generic (FuelLabs#1853)
Browse files Browse the repository at this point in the history
Braqzen authored Jun 5, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 257f1d7 commit cee607d
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions sway-lib-std/src/token.sw
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ use ::identity::Identity;
/// Mint `amount` coins of the current contract's `asset_id` and transfer them to `destination` by calling either force_transfer_to_contract() or transfer_to_output(), depending on the type of `Identity`.
pub fn mint_to(amount: u64, recipient: Identity) {
mint(amount);
transfer_to(amount, recipient);
transfer(recipient, amount, contract_id());
}

/// Mint `amount` coins of the current contract's `asset_id` and send them (!!! UNCONDITIONALLY !!!) to the contract at `destination`.
@@ -42,15 +42,12 @@ pub fn burn(amount: u64) {
}
}

/// Transfer `amount` coins of the current contract's `asset_id` and send them to `destination` by calling either force_transfer_to_contract() or transfer_to_output(), depending on the type of `Identity`.
pub fn transfer_to(amount: u64, recipient: Identity) {
match recipient {
Identity::Address(addr) => {
transfer_to_output(amount, contract_id(), addr);
},
Identity::ContractId(id) => {
force_transfer_to_contract(amount, contract_id(), id);
},
/// Transfer `amount` coins of the specified `asset` and send them to `to` by calling either
/// force_transfer_to_contract() or transfer_to_output(), depending on the type of `Identity`.
pub fn transfer(to: Identity, amount: u64, asset: ContractId) {
match to {
Identity::Address(address) => transfer_to_output(amount, asset, address),
Identity::ContractId(id) => force_transfer_to_contract(amount, asset, id),
}
}

0 comments on commit cee607d

Please sign in to comment.