forked from byeongsu-hong/terra.go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
token.go
47 lines (36 loc) · 937 Bytes
/
token.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
package cw20
import (
"context"
"fmt"
"github.com/cawabunga/terra.go/bind"
"github.com/airbloc/logger"
cosmostypes "github.com/cosmos/cosmos-sdk/types"
"github.com/pkg/errors"
)
type Token interface {
Name() string
Symbol() string
bind.BaseContract
Executor
ExecutorMsg
Querier
}
type token struct {
name string
symbol string
logger logger.Logger
bind.BaseContract
}
func (t token) Name() string { return t.name }
func (t token) Symbol() string { return t.symbol }
func NewTokenContract(ctx context.Context, addr cosmostypes.AccAddress, client terra.Client) (Token, error) {
t := token{BaseContract: bind.NewBaseContract(addr, client)}
tokenInfoResp, err := t.GetTokenInfo(ctx)
if err != nil {
return nil, errors.Wrap(err, "fetch token info")
}
t.name = tokenInfoResp.Name
t.symbol = tokenInfoResp.Symbol
t.logger = logger.New(fmt.Sprintf("anchor/cw20/%s", tokenInfoResp.Symbol))
return t, nil
}