Skip to content

Commit

Permalink
#2020 - changed BASE_ASSET_ID type to ContractId (#2137)
Browse files Browse the repository at this point in the history
* #2020 - changed BASE_ASSET_ID type to ContractId

* Fix identity example

* Changes after review
  • Loading branch information
r-sitko authored Jun 28, 2022
1 parent 69122c8 commit 2264b2d
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 13 deletions.
6 changes: 3 additions & 3 deletions examples/identity/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ storage {
impl IdentityExample for Contract {
fn cast_to_identity() {
// ANCHOR: cast_to_identity
let my_address: Address = ~Address::from(BASE_ASSET_ID);
let my_identity: Identity = Identity::Address(my_address);
let raw_address: b256 = 0xddec0e7e6a9a4a4e3e57d08d080d71a299c628a46bc609aab4627695679421ca;
let my_identity: Identity = Identity::Address(~Address::from(raw_address));
// ANCHOR_END: cast_to_identity
}

Expand All @@ -45,7 +45,7 @@ impl IdentityExample for Contract {

fn different_executions(my_identity: Identity) {
let amount = 1;
let token_id = ~ContractId::from(BASE_ASSET_ID);
let token_id = BASE_ASSET_ID;

// ANCHOR: different_executions
match my_identity {
Expand Down
4 changes: 2 additions & 2 deletions examples/wallet_smart_contract/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ abi Wallet {

impl Wallet for Contract {
#[storage(read, write)]fn receive_funds() {
if msg_asset_id() == ~ContractId::from(BASE_ASSET_ID) {
if msg_asset_id() == BASE_ASSET_ID {
// If we received `BASE_ASSET_ID` then keep track of the balance.
// Otherwise, we're receiving other native assets and don't care
// about our balance of tokens.
Expand Down Expand Up @@ -54,6 +54,6 @@ impl Wallet for Contract {
// Note: `transfer_to_output()` is not a call and thus not an
// interaction. Regardless, this code conforms to
// checks-effects-interactions to avoid re-entrancy.
transfer_to_output(amount_to_send, ~ContractId::from(BASE_ASSET_ID), recipient_address);
transfer_to_output(amount_to_send, BASE_ASSET_ID, recipient_address);
}
}
4 changes: 3 additions & 1 deletion sway-lib-std/src/constants.sw
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
library constants;

const BASE_ASSET_ID = 0x0000000000000000000000000000000000000000000000000000000000000000;
use ::contract_id::ContractId;

const BASE_ASSET_ID = ~ContractId::from(0x0000000000000000000000000000000000000000000000000000000000000000);
2 changes: 1 addition & 1 deletion sway-lib-std/src/lib.sw
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ dep option;
dep result;
dep mem;
dep alloc;
dep constants;
dep contract_id;
dep constants;
dep context;
dep hash;
dep r#storage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,28 @@ fn main() -> bool {
let gas: u64 = 1000;
let amount: u64 = 11;
let other_contract_id = ~ContractId::from(0x189a69c7ffc261ec84769563bdde047e592a33456acc079f189332c2837cba6b);
let base_asset_id = ~ContractId::from(BASE_ASSET_ID);
let base_asset_id = BASE_ASSET_ID;

let test_contract = abi(ContextTesting, other_contract_id.into());

// test Context::contract_id():
let returned_contract_id = test_contract.get_id {
gas: gas, coins: 0, asset_id: BASE_ASSET_ID
gas: gas, coins: 0, asset_id: BASE_ASSET_ID.into()
}
();
assert(returned_contract_id.into() == other_contract_id.into());

// @todo set up a test contract to mint some tokens for testing balances.
// test Context::this_balance():
let returned_this_balance = test_contract.get_this_balance {
gas: gas, coins: 0, asset_id: BASE_ASSET_ID
gas: gas, coins: 0, asset_id: BASE_ASSET_ID.into()
}
(base_asset_id);
assert(returned_this_balance == 0);

// test Context::balance_of_contract():
let returned_contract_balance = test_contract.get_balance_of_contract {
gas: gas, coins: 0, asset_id: BASE_ASSET_ID
gas: gas, coins: 0, asset_id: BASE_ASSET_ID.into()
}
(base_asset_id, other_contract_id);
assert(returned_contract_balance == 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ fn main() -> bool {
let id_2 = ~ContractId::from(0x0000000000000000000000000000000000000000000000000000000000000000);

assert(id_1 == id_2);
assert(id_1 == ~ContractId::from(BASE_ASSET_ID));
assert(id_1.into() == BASE_ASSET_ID);
assert(id_1 == BASE_ASSET_ID);
assert(0x0000000000000000000000000000000000000000000000000000000000000000 == id_1.into());

true
}

0 comments on commit 2264b2d

Please sign in to comment.