Tal Kol
3 years ago
9 changed files with 99 additions and 58 deletions
@ -0,0 +1,13 @@ |
|||||||
|
;; operations (constant values taken from crc32 on op message in the companion .tlb files and appear during build) |
||||||
|
int op::increment() asm "0x37491f2f PUSHINT"; |
||||||
|
int op::deposit() asm "0x47d54391 PUSHINT"; |
||||||
|
int op::withdraw() asm "0x41836980 PUSHINT"; |
||||||
|
int op::transfer_ownership() asm "0x2da38aaf PUSHINT"; |
||||||
|
|
||||||
|
;; errors |
||||||
|
int error::access_denied() asm "0xfffffffe PUSHINT"; |
||||||
|
int error::unknown_op() asm "0xffffffff PUSHINT"; |
||||||
|
int error::insufficient_balance() asm "101 PUSHINT"; |
||||||
|
|
||||||
|
;; other |
||||||
|
int const::min_tons_for_storage() asm "10000000 PUSHINT"; ;; 0.01 TON |
@ -0,0 +1,15 @@ |
|||||||
|
// base types defined in https://github.com/newton-blockchain/ton/blob/master/crypto/block/block.tlb |
||||||
|
|
||||||
|
// storage |
||||||
|
|
||||||
|
storage#_ owner_address:MsgAddress counter:uint64 |
||||||
|
|
||||||
|
// ops |
||||||
|
|
||||||
|
increment query_id:uint64 = InternalMsgBody |
||||||
|
|
||||||
|
deposit query_id:uint64 = InternalMsgBody |
||||||
|
|
||||||
|
withdraw query_id:uint64 withdraw_amount:Grams = InternalMsgBody |
||||||
|
|
||||||
|
transfer_ownership query_id:uint64 new_owner_address:MsgAddress = InternalMsgBody |
@ -1,20 +1,12 @@ |
|||||||
// this file assists with instantiating the contract (code and data cells)
|
|
||||||
|
|
||||||
import * as fs from "fs"; |
|
||||||
import { Cell, beginCell, Address } from "ton"; |
import { Cell, beginCell, Address } from "ton"; |
||||||
|
|
||||||
// returns contract code cell by relying on the build output in the build directory
|
// encode contract storage according to save_data() contract method
|
||||||
export function createCode() { |
export function data(params: { ownerAddress: Address; counter: number }): Cell { |
||||||
return Cell.fromBoc(fs.readFileSync(__dirname + "/../build/main.cell"))[0]; |
|
||||||
} |
|
||||||
|
|
||||||
// returns contract data cell (storage) according to save_data() contract method
|
|
||||||
export function createData(params: { ownerAddress: Address; counter: number }) { |
|
||||||
return beginCell().storeAddress(params.ownerAddress).storeUint(params.counter, 64).endCell(); |
return beginCell().storeAddress(params.ownerAddress).storeUint(params.counter, 64).endCell(); |
||||||
} |
} |
||||||
|
|
||||||
// message generators for all ops
|
// message encoders for all ops
|
||||||
|
|
||||||
export function op_increment() { |
export function increment(): Cell { |
||||||
return beginCell().storeUint(1, 32).storeUint(0, 64).endCell(); |
return beginCell().storeUint(0x37491f2f, 32).storeUint(0, 64).endCell(); |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue