forked from tonkeeper/tonapi-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tonapi.go
55 lines (49 loc) · 1.84 KB
/
tonapi.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
package tonapi
import (
"context"
"encoding/base64"
"github.com/tonkeeper/tongo"
"github.com/tonkeeper/tongo/tlb"
)
func (c *Client) GetSeqno(ctx context.Context, account tongo.AccountID) (uint32, error) {
res, err := c.GetAccountSeqno(ctx, GetAccountSeqnoParams{AccountID: account.ToRaw()})
if err != nil {
return 0, err
}
return res.Seqno, nil
}
func (c *Client) SendMessage(ctx context.Context, payload []byte) (uint32, error) {
var req SendBlockchainMessageReq
req.Boc.SetTo(base64.StdEncoding.EncodeToString(payload))
err := c.SendBlockchainMessage(ctx, &req)
if err != nil {
return 0, err
}
return 0, nil
}
func (c *Client) GetAccountState(ctx context.Context, accountID tongo.AccountID) (tlb.ShardAccount, error) {
res, err := c.GetBlockchainRawAccount(ctx, GetBlockchainRawAccountParams{AccountID: accountID.ToRaw()})
if err != nil {
return tlb.ShardAccount{}, err
}
var shardAccount tlb.ShardAccount
shardAccount.LastTransLt = uint64(res.LastTransactionLt)
switch res.Status {
case "nonexist":
shardAccount.Account.SumType = "AccountNone"
case "uninit":
shardAccount.Account.SumType = "Account"
shardAccount.Account.Account.Addr = accountID.ToMsgAddress()
shardAccount.Account.Account.Storage.Balance.Grams = tlb.Grams(res.Balance)
shardAccount.Account.Account.Storage.State.SumType = "AccountUninit"
case "active":
shardAccount.Account.SumType = "Account"
shardAccount.Account.Account.Addr = accountID.ToMsgAddress()
shardAccount.Account.Account.Storage.Balance.Grams = tlb.Grams(res.Balance)
shardAccount.Account.Account.Storage.State.SumType = "AccountActive"
shardAccount.Account.Account.Storage.State.AccountActive.StateInit.Code.Exists = len(res.Code.Value) > 0
shardAccount.Account.Account.Storage.State.AccountActive.StateInit.Data.Exists = len(res.Data.Value) > 0
case "frozen":
}
return shardAccount, nil
}