@@ -4,6 +4,8 @@ import { SmartContract } from 'ton-contract-executor'
4
4
import { encodeRaffleStorage , RaffleStorage } from './raffle.storage'
5
5
import * as fs from 'fs'
6
6
import BN from 'bn.js'
7
+ import { compileFunc } from "../../utils/compileFunc" ;
8
+ import { RaffleSource } from './raffle.source'
7
9
8
10
9
11
@@ -21,12 +23,15 @@ type StateResponse = {
21
23
leftCoinsGot : BN ,
22
24
rightCoinsGot : BN ,
23
25
coinsForNft : BN ,
24
- leftNfts : Map < string , boolean > | null ,
25
- rightNfts : Map < string , boolean > | null ,
26
+ nfts : Map < string , number > | null ,
26
27
raffledNfts : Map < string , boolean > | null
27
28
}
28
29
29
- function DictToMap ( slice : Slice ) : boolean {
30
+ function DictToMapN ( slice : Slice ) : number {
31
+ return slice . readUint ( 4 ) . toNumber ( ) . valueOf ( )
32
+ }
33
+
34
+ function DictToMapB ( slice : Slice ) : boolean {
30
35
return slice . readBit ( )
31
36
}
32
37
@@ -47,23 +52,18 @@ export class RaffleLocal {
47
52
const [ state , rightNftsCount , rightNftsReceived , leftNftsCount ,
48
53
leftNftsReceived , leftUser , rightUser , superUser , leftCommission ,
49
54
rightCommission , leftCoinsGot , rightCoinsGot ,
50
- coinsForNft , leftNfts , rightNfts , raffledNfts ] = res . result as [ BN , BN ,
55
+ coinsForNft , nfts , raffledNfts ] = res . result as [ BN , BN ,
51
56
BN , BN ,
52
57
BN , Slice , Slice , Slice , BN , BN , BN , BN , BN , Cell , Cell , Cell ]
53
- const leftMap = leftNfts ? parseDict < boolean > (
54
- leftNfts . beginParse ( ) ,
55
- 256 ,
56
- DictToMap
57
- ) : null
58
- const rightMap = rightNfts ? parseDict < boolean > (
59
- rightNfts . beginParse ( ) ,
58
+ const nftMap = nfts ? parseDict < number > (
59
+ nfts . beginParse ( ) ,
60
60
256 ,
61
- DictToMap
61
+ DictToMapN
62
62
) : null
63
63
const raffledMap = raffledNfts ? parseDict < boolean > (
64
64
raffledNfts . beginParse ( ) ,
65
65
256 ,
66
- DictToMap
66
+ DictToMapB
67
67
) : null
68
68
return {
69
69
state : state ? state . toNumber ( ) : 0 ,
@@ -79,21 +79,15 @@ export class RaffleLocal {
79
79
leftCoinsGot : leftCoinsGot ,
80
80
rightCoinsGot : rightCoinsGot ,
81
81
coinsForNft : coinsForNft ,
82
- leftNfts : leftMap ,
83
- rightNfts : rightMap ,
82
+ nfts : nftMap ,
84
83
raffledNfts : raffledMap
85
84
}
86
85
}
87
86
88
- static bocFileToTCell ( filename : string ) : Cell {
89
- const file = fs . readFileSync ( filename )
90
- return Cell . fromBoc ( file ) [ 0 ]
91
- }
92
-
93
87
static async createFromConfig ( raffleStorage : RaffleStorage ) {
94
- const code = RaffleLocal . bocFileToTCell ( './packages/contracts/sources/nft-raffle/code.boc' )
88
+ const code = await compileFunc ( RaffleSource )
95
89
const data = encodeRaffleStorage ( raffleStorage )
96
- const smc = await SmartContract . fromCell ( code , data )
90
+ const smc = await SmartContract . fromCell ( code . cell , data )
97
91
98
92
const address = contractAddress ( {
99
93
workchain : 0 ,
0 commit comments