/
revenue.go
62 lines (51 loc) · 1.67 KB
/
revenue.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
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
ethermint "github.com/evmos/ethermint/types"
)
// NewRevenue returns an instance of Revenue. If the provided withdrawer
// address is empty, it sets the value to an empty string.
func NewRevenue(contract common.Address, deployer, withdrawer sdk.AccAddress) Revenue {
withdrawerAddr := ""
if len(withdrawer) > 0 {
withdrawerAddr = withdrawer.String()
}
return Revenue{
ContractAddress: contract.String(),
DeployerAddress: deployer.String(),
WithdrawerAddress: withdrawerAddr,
}
}
// GetContractAddr returns the contract address
func (fs Revenue) GetContractAddr() common.Address {
return common.HexToAddress(fs.ContractAddress)
}
// GetDeployerAddr returns the contract deployer address
func (fs Revenue) GetDeployerAddr() sdk.AccAddress {
return sdk.MustAccAddressFromBech32(fs.DeployerAddress)
}
// GetWithdrawerAddr returns the account address to where the funds proceeding
// from the fees will be received. If the withdraw address is not defined, it
// defaults to the deployer address.
func (fs Revenue) GetWithdrawerAddr() sdk.AccAddress {
if fs.WithdrawerAddress == "" {
return nil
}
return sdk.MustAccAddressFromBech32(fs.WithdrawerAddress)
}
// Validate performs a stateless validation of a Revenue
func (fs Revenue) Validate() error {
if err := ethermint.ValidateNonZeroAddress(fs.ContractAddress); err != nil {
return err
}
if _, err := sdk.AccAddressFromBech32(fs.DeployerAddress); err != nil {
return err
}
if fs.WithdrawerAddress != "" {
if _, err := sdk.AccAddressFromBech32(fs.WithdrawerAddress); err != nil {
return err
}
}
return nil
}