-
Notifications
You must be signed in to change notification settings - Fork 16
/
extensions.go
96 lines (84 loc) · 1.87 KB
/
extensions.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package liteclient
//go:generate go run generator.go
import (
"bytes"
"fmt"
"io"
"github.com/tonkeeper/tongo/tl"
"github.com/tonkeeper/tongo/ton"
)
var (
ErrBlockNotApplied = fmt.Errorf("block is not applied")
)
func (t LiteServerErrorC) Error() string {
return fmt.Sprintf("error code: %d message: %s", t.Code, t.Message)
}
func (t LiteServerErrorC) IsNotApplied() bool {
return t.Message == "block is not applied"
}
type LiteServerSignatureSet LiteServerSignatureSetC
func (t LiteServerSignatureSet) MarshalTL() ([]byte, error) {
var tag uint32 = 0xf644a6e6
buf := new(bytes.Buffer)
b, err := tl.Marshal(tag)
if err != nil {
return nil, err
}
_, err = buf.Write(b)
if err != nil {
return nil, err
}
b, err = tl.Marshal(LiteServerSignatureSetC(t))
if err != nil {
return nil, err
}
_, err = buf.Write(b)
if err != nil {
return nil, err
}
return buf.Bytes(), nil
}
func (t *LiteServerSignatureSet) UnmarshalTL(r io.Reader) error {
var (
res LiteServerSignatureSetC
tag uint32
)
err := tl.Unmarshal(r, &tag)
if err != nil {
return err
}
if tag != 0xf644a6e6 {
return fmt.Errorf("invalid tag")
}
err = tl.Unmarshal(r, &res)
if err != nil {
return err
}
*t = LiteServerSignatureSet(res)
return nil
}
func (t TonNodeBlockIdExtC) ToBlockIdExt() ton.BlockIDExt {
res := ton.BlockIDExt{
RootHash: ton.Bits256(t.RootHash),
FileHash: ton.Bits256(t.FileHash),
}
res.Seqno = t.Seqno
res.Shard = t.Shard
res.Workchain = int32(t.Workchain)
return res
}
func AccountID(id ton.AccountID) LiteServerAccountIdC {
return LiteServerAccountIdC{
Workchain: uint32(id.Workchain),
Id: id.Address,
}
}
func BlockIDExt(id ton.BlockIDExt) TonNodeBlockIdExtC {
return TonNodeBlockIdExtC{
Workchain: uint32(id.Workchain),
Shard: id.Shard,
Seqno: id.Seqno,
RootHash: tl.Int256(id.RootHash),
FileHash: tl.Int256(id.FileHash),
}
}