-
Notifications
You must be signed in to change notification settings - Fork 199
/
backwardsCompatibility.go
82 lines (67 loc) · 1.94 KB
/
backwardsCompatibility.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package smartContract
import (
"bytes"
"math/big"
"github.com/ElrondNetwork/elrond-go-core/core"
"github.com/ElrondNetwork/elrond-go-core/core/check"
"github.com/ElrondNetwork/elrond-go-core/data"
vmcommon "github.com/ElrondNetwork/elrond-vm-common"
)
func (sc *scProcessor) updateDeveloperRewardsV1(
tx data.TransactionHandler,
vmOutput *vmcommon.VMOutput,
builtInFuncGasUsed uint64,
) error {
usedGasByMainSC := tx.GetGasLimit() - vmOutput.GasRemaining
if !sc.isSelfShard(tx.GetSndAddr()) {
usedGasByMainSC -= sc.economicsFee.ComputeGasLimit(tx)
}
usedGasByMainSC -= builtInFuncGasUsed
for _, outAcc := range vmOutput.OutputAccounts {
if bytes.Equal(tx.GetRcvAddr(), outAcc.Address) {
continue
}
sentGas := uint64(0)
for _, outTransfer := range outAcc.OutputTransfers {
sentGas += outTransfer.GasLimit
}
usedGasByMainSC -= sentGas
usedGasByMainSC -= outAcc.GasUsed
if outAcc.GasUsed > 0 && sc.isSelfShard(outAcc.Address) {
err := sc.addToDevRewardsV1(outAcc.Address, outAcc.GasUsed, tx.GetGasPrice())
if err != nil {
return err
}
}
}
err := sc.addToDevRewardsV1(tx.GetRcvAddr(), usedGasByMainSC, tx.GetGasPrice())
if err != nil {
return err
}
return nil
}
func (sc *scProcessor) addToDevRewardsV1(address []byte, gasUsed uint64, gasPrice uint64) error {
if core.IsEmptyAddress(address) || !core.IsSmartContractAddress(address) {
return nil
}
consumedFee := core.SafeMul(gasPrice, gasUsed)
var devRwd *big.Int
if sc.flagStakingV2.IsSet() {
devRwd = core.GetIntTrimmedPercentageOfValue(consumedFee, sc.economicsFee.DeveloperPercentage())
} else {
devRwd = core.GetApproximatePercentageOfValue(consumedFee, sc.economicsFee.DeveloperPercentage())
}
userAcc, err := sc.getAccountFromAddress(address)
if err != nil {
return err
}
if check.IfNil(userAcc) {
return nil
}
userAcc.AddToDeveloperReward(devRwd)
err = sc.accounts.SaveAccount(userAcc)
if err != nil {
return err
}
return nil
}