/
message_claim_contract_income.go
66 lines (49 loc) · 1.56 KB
/
message_claim_contract_income.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
package types
import (
"fmt"
"cosmossdk.io/errors"
"github.com/arkeonetwork/arkeo/common/cosmos"
sdk "github.com/cosmos/cosmos-sdk/types"
)
const TypeMsgClaimContractIncome = "claim_contract_income"
var _ sdk.Msg = &MsgClaimContractIncome{}
func NewMsgClaimContractIncome(creator cosmos.AccAddress, contractId uint64, nonce int64, sig []byte) *MsgClaimContractIncome {
return &MsgClaimContractIncome{
Creator: creator,
ContractId: contractId,
Nonce: nonce,
Signature: sig,
}
}
func (msg *MsgClaimContractIncome) Route() string {
return RouterKey
}
func (msg *MsgClaimContractIncome) Type() string {
return TypeMsgClaimContractIncome
}
func (msg *MsgClaimContractIncome) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{msg.Creator}
}
func (msg *MsgClaimContractIncome) MustGetSigner() sdk.AccAddress {
return msg.Creator
}
func (msg *MsgClaimContractIncome) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}
func (msg *MsgClaimContractIncome) GetBytesToSign() []byte {
return GetBytesToSign(msg.ContractId, msg.Nonce)
}
func GetBytesToSign(contractId uint64, nonce int64) []byte {
return []byte(fmt.Sprintf("%d:%d", contractId, nonce))
}
func (msg *MsgClaimContractIncome) ValidateBasic() error {
// anyone can make the claim on a contract, but of course the payout would only happen to the provider
if len(msg.Signature) > 100 {
return errors.Wrap(ErrClaimContractIncomeInvalidSignature, "too long")
}
if msg.Nonce <= 0 {
return errors.Wrap(ErrClaimContractIncomeBadNonce, "")
}
return nil
}