mirror of
https://github.com/danog/toncontest.git
synced 2024-11-30 04:29:14 +01:00
243 lines
8.4 KiB
Plaintext
243 lines
8.4 KiB
Plaintext
"TonUtil.fif" include
|
|
"Asm.fif" include
|
|
|
|
def? $1 { @' $1 } { "" } cond constant suffix
|
|
{ suffix $+ } : +suffix
|
|
|
|
wc_master setworkchain
|
|
-17 setglobalid // negative value means a test instance of the blockchain
|
|
|
|
// Initial state of Workchain 0 (Basic workchain)
|
|
|
|
0 mkemptyShardState
|
|
|
|
cr ."initial basechain state is:" cr dup <s csr. cr
|
|
dup dup 31 boc+>B dup Bx. cr
|
|
dup "basestate0" +suffix +".boc" tuck B>file
|
|
."(Initial basechain state saved to file " type .")" cr
|
|
Bhashu dup =: basestate0_fhash
|
|
."file hash=" dup x. space 256 u>B dup B>base64url type cr
|
|
"basestate0" +suffix +".fhash" B>file
|
|
hashu dup =: basestate0_rhash
|
|
."root hash=" dup x. space 256 u>B dup B>base64url type cr
|
|
"basestate0" +suffix +".rhash" B>file
|
|
|
|
basestate0_rhash basestate0_fhash now 0 2 32 0 add-std-workchain
|
|
config.workchains!
|
|
|
|
// SmartContract #1 (Simple wallet)
|
|
|
|
<{ SETCP0 DUP IFNOTRET // return if recv_internal
|
|
DUP 85143 INT EQUAL IFJMP:<{ // "seqno" get-method
|
|
DROP c4 PUSHCTR CTOS 32 PLDU // cnt
|
|
}>
|
|
INC 32 THROWIF // fail unless recv_external
|
|
512 INT LDSLICEX DUP 32 PLDU // sign cs cnt
|
|
c4 PUSHCTR CTOS 32 LDU 256 LDU ENDS // sign cs cnt cnt' pubk
|
|
s1 s2 XCPU // sign cs cnt pubk cnt' cnt
|
|
EQUAL 33 THROWIFNOT // ( seqno mismatch? )
|
|
s2 PUSH HASHSU // sign cs cnt pubk hash
|
|
s0 s4 s4 XC2PU // pubk cs cnt hash sign pubk
|
|
CHKSIGNU // pubk cs cnt ?
|
|
34 THROWIFNOT // signature mismatch
|
|
ACCEPT
|
|
SWAP 32 LDU NIP 8 LDU LDREF ENDS // pubk cnt mode msg
|
|
SWAP SENDRAWMSG // pubk cnt ; ( message sent )
|
|
INC NEWC 32 STU 256 STU ENDC c4 POPCTR
|
|
}>c
|
|
// code
|
|
<b 0 32 u,
|
|
"main-wallet" +suffix +".pk" load-generate-keypair drop
|
|
B,
|
|
b> // data
|
|
Libs{
|
|
x{ABACABADABACABA} s>c public_lib
|
|
x{1234} x{5678} |_ s>c private_lib
|
|
}Libs // libraries
|
|
GR$1700000000 // balance
|
|
0 // split_depth
|
|
0 // ticktock
|
|
2 // mode: create
|
|
register_smc
|
|
dup make_special dup constant smc1_addr
|
|
Masterchain over
|
|
2dup ."wallet address = " .addr cr 2dup 6 .Addr cr
|
|
"main-wallet" +suffix +".addr" save-address-verbose
|
|
|
|
// SmartContract #2 (Simple money giver for test network)
|
|
<{ SETCP0 DUP IFNOTRET // return if recv_internal
|
|
DUP 85143 INT EQUAL IFJMP:<{ // "seqno" get-method
|
|
DROP c4 PUSHCTR CTOS 32 PLDU // cnt
|
|
}>
|
|
INC 32 THROWIF // fail unless recv_external
|
|
32 LDU SWAP // cs cnt
|
|
c4 PUSHCTR CTOS 32 LDU ENDS // cs cnt cnt'
|
|
TUCK EQUAL 33 THROWIFNOT // ( seqno mismatch? )
|
|
ACCEPT // cs cnt'
|
|
SWAP 8 LDU LDREF ENDS // cnt'' mode msg
|
|
GR$20 INT 3 INT RAWRESERVE // reserve all but 20 Grams from the balance
|
|
SWAP SENDRAWMSG
|
|
INC NEWC 32 STU ENDC c4 POPCTR // store cnt''
|
|
}>c
|
|
// code
|
|
<b 0 32 u, b> // data
|
|
empty_cell // libraries
|
|
GR$1000000 // initial balance (1m test Grams)
|
|
0 0 2 register_smc
|
|
dup make_special dup constant smc2_addr
|
|
Masterchain over
|
|
2dup ."free test gram giver address = " .addr cr 2dup 6 .Addr cr
|
|
"testgiver" +suffix +".addr" save-address-verbose
|
|
|
|
// SmartContract #3
|
|
PROGRAM{
|
|
recv_internal x{} PROC
|
|
run_ticktock PROC:<{
|
|
c4 PUSHCTR CTOS 32 LDU 256 LDU ENDS
|
|
NEWC ROT INC 32 STUR OVER 256 STUR ENDC
|
|
c4 POPCTR
|
|
// first 32 bits of persistent data have been increased
|
|
// remaining 256 bits with an address have been fetched
|
|
// create new empty message with 0.1 Grams to that address
|
|
NEWC b{00100010011111111} STSLICECONST TUCK 256 STU
|
|
100000000 INT STGRAMS // store 0.1 Grams
|
|
1 4 + 4 + 64 + 32 + 1+ 1+ INT STZEROES ENDC
|
|
// send raw message from Cell
|
|
ZERO SENDRAWMSG
|
|
-17 INT 256 STIR 130000000 INT STGRAMS
|
|
107 INT STZEROES ENDC
|
|
ZERO // another message with 0.13 Grams to account -17
|
|
NEWC b{11000100100000} "test" $>s |+ STSLICECONST
|
|
123456789 INT STGRAMS
|
|
107 INT STZEROES "Hello, world!" $>s STSLICECONST ENDC
|
|
ZERO SENDRAWMSG SENDRAWMSG // external message to address "test"
|
|
}>
|
|
}END>c
|
|
// code
|
|
<b x{11EF55AA} s, smc1_addr 256 u, b> // data
|
|
// empty_cell // libraries
|
|
Libs{
|
|
x{ABACABADABACABA} s>c public_lib
|
|
x{1234} x{5678} |_ s>c public_lib
|
|
}Libs // libraries
|
|
0x333333333 // balance
|
|
0 // split_depth
|
|
3 // ticktock: tick
|
|
2 // mode: create
|
|
register_smc
|
|
dup make_special dup constant smc3_addr
|
|
."address = " x. cr
|
|
|
|
/*
|
|
*
|
|
* SmartContract #4 (elector)
|
|
*
|
|
*/
|
|
"elector-code.fif" include // code in separate source file
|
|
<b 0 1 1+ 1+ 4 + 32 + u, 0 256 u, b> // data: dict dict dict grams uint32 uint256
|
|
empty_cell // libraries
|
|
GR$10 // balance: 10 grams
|
|
0 // split_depth
|
|
2 // ticktock: tick
|
|
2 // mode: create
|
|
register_smc
|
|
dup make_special dup constant smc4_addr dup constant elector_addr
|
|
Masterchain swap
|
|
."elector smart contract address = " 2dup .addr cr 2dup 7 .Addr cr
|
|
"elector" +suffix +".addr" save-address-verbose
|
|
|
|
/*
|
|
*
|
|
* Configuration Parameters
|
|
*
|
|
*/
|
|
// version capabilities
|
|
0 capCreateStats config.version!
|
|
// max-validators max-main-validators min-validators
|
|
// 9 4 1 config.validator_num!
|
|
1000 100 5 config.validator_num!
|
|
// min-stake max-stake min-total-stake max-factor
|
|
GR$10000 GR$10000000 GR$1000000 sg~10 config.validator_stake_limits!
|
|
// elected-for elect-start-before elect-end-before stakes-frozen-for
|
|
// 400000 200000 4000 400000 config.election_params!
|
|
4000 2000 500 1000 config.election_params! // DEBUG
|
|
// config-addr = -1:5555...5555
|
|
256 1<<1- 3 / constant config_addr
|
|
config_addr config.config_smc!
|
|
// elector-addr
|
|
elector_addr config.elector_smc!
|
|
|
|
// 1 sg* 100 sg* 1000 sg* 1000000 sg* config.storage_prices! // old values (too high)
|
|
1 500 1000 500000 config.storage_prices!
|
|
config.special!
|
|
|
|
// gas_price gas_limit special_gas_limit gas_credit block_gas_limit freeze_due_limit delete_due_limit flat_gas_limit flat_gas_price --
|
|
1000 sg* 1 *M dup 10000 10 *M GR$0.1 GR$1.0 100 100000 config.gas_prices!
|
|
10000 sg* 1 *M 10 *M 10000 10 *M GR$0.1 GR$1.0 100 1000000 config.mc_gas_prices!
|
|
// lump_price bit_price cell_price ihr_factor first_frac next_frac
|
|
1000000 1000 sg* 100000 sg* 3/2 sg*/ 1/3 sg*/ 1/3 sg*/ config.fwd_prices!
|
|
10000000 10000 sg* 1000000 sg* 3/2 sg*/ 1/3 sg*/ 1/3 sg*/ config.mc_fwd_prices!
|
|
// mc-cc-lifetime sh-cc-lifetime sh-val-lifetime sh-val-num
|
|
250 250 1000 7 config.catchain_params!
|
|
// round-candidates next-cand-delay-ms consensus-timeout-ms fast-attempts attempt-duration cc-max-deps max-block-size max-collated-size
|
|
3 2000 16000 3 8 4 2 *Mi 2 *Mi config.consensus_params!
|
|
|
|
|
|
128 *Ki 512 *Ki 1 *Mi triple // [ underload soft hard ] : block bytes limit
|
|
100000 500000 1000000 triple // gas limits
|
|
1000 5000 10000 triple // lt limits
|
|
triple dup untriple config.mc_block_limits!
|
|
untriple config.block_limits!
|
|
|
|
GR$1.7 GR$1 config.block_create_fees!
|
|
// smc1_addr config.collector_smc!
|
|
smc1_addr config.minter_smc!
|
|
|
|
1000000000000 -17 of-cc 666666666666 239 of-cc cc+ config.to_mint!
|
|
|
|
"validator-keys" +suffix +".pk" load-generate-keypair drop
|
|
{ dup Blen } { 32 B| swap dup ."Validator public key = " Bx. cr
|
|
17 add-validator } while drop
|
|
// newkeypair nip dup ."Validator #1 public key = " Bx. cr
|
|
// 17 add-validator
|
|
// newkeypair nip dup ."Validator #2 public key = " Bx. cr
|
|
// 239 add-validator
|
|
// 100000 =: orig_vset_valid_for
|
|
100 =: orig_vset_valid_for // original validator set valid 100 seconds only (DEBUG)
|
|
now dup orig_vset_valid_for + 0 config.validators!
|
|
|
|
/*
|
|
*
|
|
* SmartContract #5 (Configuration smart contract)
|
|
*
|
|
*/
|
|
"config-code.fif" include // code in separate source file
|
|
<b 0 32 u,
|
|
"config-master" +suffix +".pk" load-generate-keypair drop
|
|
B,
|
|
configdict ref,
|
|
b> // data
|
|
empty_cell // libraries
|
|
GR$10 // balance
|
|
0 1 config_addr 6 register_smc // tock
|
|
dup set_config_smc
|
|
Masterchain swap
|
|
."config smart contract address = " 2dup .addr cr 2dup 7 .Addr cr
|
|
"config-master" +suffix +".addr" save-address-verbose
|
|
// Other data
|
|
|
|
create_state
|
|
cr cr ."new state is:" cr dup <s csr. cr
|
|
dup 31 boc+>B dup Bx. cr
|
|
dup "zerostate" +suffix +".boc" tuck B>file
|
|
."(Initial masterchain state saved to file " type .")" cr
|
|
Bhashu dup =: zerostate_fhash
|
|
."file hash= " dup X. space 256 u>B dup B>base64url type cr
|
|
"zerostate" +suffix +".fhash" B>file
|
|
hashu dup =: zerostate_rhash ."root hash= " dup X. space 256 u>B dup B>base64url type cr
|
|
"zerostate" +suffix +".rhash" B>file
|
|
basestate0_rhash ."Basestate0 root hash= " dup X. space 256 u>B B>base64url type cr
|
|
basestate0_fhash ."Basestate0 file hash= " dup X. space 256 u>B B>base64url type cr
|
|
zerostate_rhash ."Zerostate root hash= " dup X. space 256 u>B B>base64url type cr
|
|
zerostate_fhash ."Zerostate file hash= " dup X. space 256 u>B B>base64url type cr
|