-
Notifications
You must be signed in to change notification settings - Fork 199
/
claimDeveloperRewards.go
61 lines (50 loc) · 1.58 KB
/
claimDeveloperRewards.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
package builtInFunctions
import (
"bytes"
"math/big"
"github.com/ElrondNetwork/elrond-go/core/check"
"github.com/ElrondNetwork/elrond-go/data/state"
"github.com/ElrondNetwork/elrond-go/process"
vmcommon "github.com/ElrondNetwork/elrond-vm-common"
)
type claimDeveloperRewards struct {
gasCost uint64
}
// NewClaimDeveloperRewardsFunc returns a new developer rewards implementation
func NewClaimDeveloperRewardsFunc(gasCost uint64) *claimDeveloperRewards {
return &claimDeveloperRewards{gasCost: gasCost}
}
// ProcessBuiltinFunction processes the protocol built-in smart contract function
func (c *claimDeveloperRewards) ProcessBuiltinFunction(
acntSnd, acntDst state.UserAccountHandler,
vmInput *vmcommon.ContractCallInput,
) (*big.Int, uint64, error) {
if vmInput == nil {
return nil, 0, process.ErrNilVmInput
}
if check.IfNil(acntDst) {
return nil, vmInput.GasProvided, process.ErrNilSCDestAccount
}
if !bytes.Equal(vmInput.CallerAddr, acntDst.GetOwnerAddress()) {
return nil, vmInput.GasProvided, process.ErrOperationNotPermitted
}
if vmInput.GasProvided < c.gasCost {
return nil, vmInput.GasProvided, process.ErrNotEnoughGas
}
value, err := acntDst.ClaimDeveloperRewards(vmInput.CallerAddr)
if err != nil {
return nil, vmInput.GasProvided, err
}
if check.IfNil(acntSnd) {
return value, vmInput.GasProvided, nil
}
err = acntSnd.AddToBalance(value)
if err != nil {
return nil, vmInput.GasProvided, err
}
return value, c.gasCost, nil
}
// IsInterfaceNil returns true if underlying object is nil
func (c *claimDeveloperRewards) IsInterfaceNil() bool {
return c == nil
}