-
Notifications
You must be signed in to change notification settings - Fork 17
/
jettons.go
57 lines (54 loc) · 1.19 KB
/
jettons.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package precompiled
import (
"math/big"
"github.com/tonkeeper/tongo/boc"
"github.com/tonkeeper/tongo/tlb"
)
var jettonV1getWalletData = func(data *boc.Cell, args tlb.VmStack) (tlb.VmStack, error) {
var body struct {
Amount tlb.VarUInteger16
Owner tlb.MsgAddress
Master tlb.MsgAddress
Code boc.Cell `tlb:"^"`
}
err := tlb.Unmarshal(data, &body)
if err != nil {
return nil, err
}
var result = make([]tlb.VmStackValue, 4)
var b = big.Int(body.Amount)
if b.IsInt64() {
result[0] = tlb.VmStackValue{
SumType: "VmStkTinyInt",
VmStkTinyInt: b.Int64(),
}
} else {
result[0] = tlb.VmStackValue{
SumType: "VmStkInt",
VmStkInt: tlb.Int257(b),
}
}
ownerCell := boc.NewCell()
masterCell := boc.NewCell()
err = tlb.Marshal(ownerCell, body.Owner)
if err != nil {
return nil, err
}
err = tlb.Marshal(masterCell, body.Master)
if err != nil {
return nil, err
}
result[1], err = tlb.CellToVmCellSlice(ownerCell)
if err != nil {
return nil, err
}
result[2], err = tlb.CellToVmCellSlice(masterCell)
if err != nil {
return nil, err
}
result[3] = tlb.VmStackValue{
SumType: "VmStkCell",
VmStkCell: tlb.Ref[boc.Cell]{Value: body.Code},
}
return result, nil
}