github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/feesplit/types/fee_split.go (about) 1 package types 2 3 import ( 4 "bytes" 5 6 "github.com/ethereum/go-ethereum/common" 7 sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types" 8 sdkerrors "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types/errors" 9 ) 10 11 // FeeSplit defines an instance that organizes fee distribution conditions for 12 // the owner of a given smart contract 13 type FeeSplit struct { 14 // hex address of registered contract 15 ContractAddress common.Address `json:"contract_address,omitempty"` 16 // bech32 address of contract deployer 17 DeployerAddress sdk.AccAddress `json:"deployer_address,omitempty"` 18 // bech32 address of account receiving the transaction fees it defaults to 19 // deployer_address 20 WithdrawerAddress sdk.AccAddress `json:"withdrawer_address,omitempty"` 21 } 22 23 // NewFeeSplit returns an instance of FeeSplit. If the provided withdrawer 24 // address is empty, it sets the value to an empty string. 25 func NewFeeSplit(contract common.Address, deployer, withdrawer sdk.AccAddress) FeeSplit { 26 if withdrawer.Empty() { 27 withdrawer = deployer 28 } 29 30 return FeeSplit{ 31 ContractAddress: contract, 32 DeployerAddress: deployer, 33 WithdrawerAddress: withdrawer, 34 } 35 } 36 37 // Validate performs a stateless validation of a FeeSplit 38 func (fs FeeSplit) Validate() error { 39 if bytes.Equal(fs.ContractAddress.Bytes(), common.Address{}.Bytes()) { 40 return sdkerrors.Wrapf( 41 sdkerrors.ErrInvalidAddress, "address '%s' is not a valid ethereum hex address", 42 fs.ContractAddress.String(), 43 ) 44 } 45 46 if fs.DeployerAddress.Empty() { 47 return sdkerrors.Wrapf( 48 sdkerrors.ErrInvalidAddress, "empty address string is not allowed", 49 ) 50 } 51 52 return nil 53 }