-
Notifications
You must be signed in to change notification settings - Fork 46
/
models_dtag_requests.go
51 lines (40 loc) · 1.27 KB
/
models_dtag_requests.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
package types
// DONTCOVER
import (
"fmt"
"strings"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
)
func NewDTagTransferRequest(dTagToTrade string, sender, receiver string) DTagTransferRequest {
return DTagTransferRequest{
DTagToTrade: dTagToTrade,
Receiver: receiver,
Sender: sender,
}
}
// Validate checks the request validity
func (request DTagTransferRequest) Validate() error {
_, err := sdk.AccAddressFromBech32(request.Sender)
if err != nil {
return fmt.Errorf("invalid DTag transfer request sender address: %s", request.Sender)
}
_, err = sdk.AccAddressFromBech32(request.Receiver)
if err != nil {
return fmt.Errorf("invalid receiver address: %s", request.Receiver)
}
if request.Receiver == request.Sender {
return fmt.Errorf("the sender and receiver must be different")
}
if strings.TrimSpace(request.DTagToTrade) == "" {
return fmt.Errorf("invalid DTag to trade: %s", request.DTagToTrade)
}
return nil
}
// MustUnmarshalDTagTransferRequest unmarshalls the given byte array as a DTagTransferRequest
// using the provided marshaller
func MustUnmarshalDTagTransferRequest(cdc codec.BinaryCodec, bz []byte) DTagTransferRequest {
var request DTagTransferRequest
cdc.MustUnmarshal(bz, &request)
return request
}