-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bank smart contract working and tested
- Loading branch information
Showing
4 changed files
with
66 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,52 @@ | ||
#include "imports/stdlib.fc"; | ||
|
||
;; storage variables | ||
global int ctx_balance; | ||
global cell ctx_balance; | ||
|
||
() load_data() impure { | ||
var ds = get_data().begin_parse(); | ||
ctx_balance = ds~load_uint(32); | ||
ds.end_parse(); | ||
var ds = get_data().begin_parse(); | ||
ctx_balance = ds~load_ref(); | ||
ds.end_parse(); | ||
} | ||
|
||
() save_data() impure { | ||
set_data( | ||
() save_data(int coins) impure { | ||
set_data( | ||
begin_cell() | ||
.store_ref( | ||
begin_cell() | ||
.store_uint(ctx_balance, 32) | ||
.end_cell() | ||
); | ||
.store_coins(coins) | ||
.end_cell() | ||
) | ||
.end_cell() | ||
); | ||
} | ||
|
||
() recv_internal(int my_balance, int msg_value, cell in_msg_full, slice in_msg_body) impure { | ||
if (in_msg_body.slice_empty?()) { | ||
return (); | ||
} | ||
|
||
slice cs = in_msg_full.begin_parse(); | ||
int flags = cs~load_uint(4); | ||
if (flags & 1) { | ||
return (); | ||
} | ||
|
||
load_data(); | ||
~strdump("balance"); | ||
~dump(ctx_balance); | ||
|
||
int coins_amount = in_msg_body~load_coins(); | ||
~strdump("coins_amount"); | ||
~dump(coins_amount); | ||
|
||
if (coins_amount != 0) { | ||
~strdump("not zero"); | ||
ctx_balance += coins_amount; | ||
~strdump("newbalance"); | ||
~dump(ctx_balance); | ||
save_data(); | ||
return (); | ||
} | ||
|
||
load_data(); | ||
if (in_msg_body.slice_empty?()) { | ||
return (); | ||
} | ||
|
||
slice cs = in_msg_full.begin_parse(); | ||
int flags = cs~load_uint(4); | ||
if (flags & 1) { | ||
return (); | ||
} | ||
|
||
load_data(); | ||
slice current = ctx_balance.begin_parse(); | ||
(_, int current_balance) = current.load_coins(); | ||
|
||
int coins_amount = in_msg_body~load_coins(); | ||
|
||
if (coins_amount != 0) { | ||
save_data(coins_amount + current_balance); | ||
return (); | ||
} | ||
|
||
throw(0xffff); | ||
} | ||
|
||
int get_bal() method_id { | ||
load_data(); | ||
return ctx_balance; | ||
cell get_bal() method_id { | ||
load_data(); | ||
return ctx_balance; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters