forked from blocktree/go-owcdrivers
/
msg-send.go
42 lines (33 loc) · 897 Bytes
/
msg-send.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
package binancechainTransaction
import (
"github.com/binance-chain/go-sdk/common/bech32"
ctypes "github.com/binance-chain/go-sdk/common/types"
"github.com/binance-chain/go-sdk/types/msg"
"github.com/pkg/errors"
)
func CreateSendMsg(fromAddress, toAddress, denom string, amount int64) (*msg.SendMsg, error) {
prefix, from, err := bech32.DecodeAndConvert(fromAddress)
if err != nil {
return nil, err
}
if prefix != Bech32Prefix {
return nil, errors.New("Invalid address!")
}
prefix, to, err := bech32.DecodeAndConvert(toAddress)
if err != nil {
return nil, err
}
if prefix != Bech32Prefix {
return nil, errors.New("Invalid address!")
}
coin := ctypes.Coin{
Denom:denom,
Amount:amount,
}
transfer := msg.Transfer{
ToAddr:to,
Coins:ctypes.Coins{coin},
}
sendMsg := msg.CreateSendMsg(from, ctypes.Coins{coin},[]msg.Transfer{transfer})
return &sendMsg, nil
}