Skip to content

Commit

Permalink
Fix return types of context::contract_id & context::msg_asset_id (Fue…
Browse files Browse the repository at this point in the history
…lLabs#59)

* style:fix weird forc fmt issue

* fix:correct the return type for context module funcs

* test:add contract and json abi file

* test:add module to harness

* build:add manifest file

* test:add tests for context module

* style:forc fmt

* style:cargo fmt

* style:formatting

* fix:remove context test_project, coming in follow-up PR

* style:forc fmt
  • Loading branch information
nfurfaro committed Mar 3, 2022
1 parent de8ee7c commit 8470621
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
17 changes: 9 additions & 8 deletions src/context.sw
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ use ::contract_id::ContractId;
/// Get the current contract's id when called in an internal context.
/// **Note !** If called in an external context, this will **not** return a contract ID.
// @dev If called externally, will actually return a pointer to the transaction ID.
pub fn contract_id() -> b256 {
asm() {
pub fn contract_id() -> ContractId {
~ContractId::from(asm() {
fp: b256
}
})
}

/// Get the current contracts balance of coin `asset_id`
pub fn this_balance(asset_id: b256) -> u64 {
asm(balance, token: asset_id) {
bal balance token fp;
let this_id = contract_id();
asm(balance, token: asset_id, contract_id: this_id) {
bal balance token contract_id;
balance: u64
}
}
Expand All @@ -36,11 +37,11 @@ pub fn msg_amount() -> u64 {
}

/// Get the asset_id of coins being sent.
pub fn msg_asset_id() -> b256 {
asm(asset_id) {
pub fn msg_asset_id() -> ContractId {
~ContractId::from(asm(asset_id) {
addi asset_id fp i32;
asset_id: b256
}
})
}

/// Get the remaining gas in the context.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_projects/token_ops/src/main.sw
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
contract;

---------use std::{address::Address,contract_id::ContractId,token::*,context::balance_of_contract};
use std::{address::Address, context::balance_of_contract, contract_id::ContractId, token::*};

/// Parameters for `force_transfer` function.
pub struct ParamsForceTransfer {
Expand Down

0 comments on commit 8470621

Please sign in to comment.