-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathtips.go
74 lines (61 loc) · 1.82 KB
/
tips.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
package types
import (
"github.com/synapsecns/sanguine/core"
"math/big"
)
const (
// TipsSize is the size of the tips in bytes.
TipsSize = 8 * 4
// ShiftSummitTip is the shift for the summit tip.
ShiftSummitTip = 24 * 8
// ShiftAttestationTip is the shift for the attestation tip.
ShiftAttestationTip = 16 * 8
// ShiftExecutionTip is the shift for the execution tip.
ShiftExecutionTip = 8 * 8
)
// Tips contain tips used for scientizing different agents.
type Tips interface {
// SummitTip gets the tips for the agent work on summit
SummitTip() *big.Int
// AttestationTip gets the tips for the doing the attestation
AttestationTip() *big.Int
// ExecutionTip gets the tips for executing the message
ExecutionTip() *big.Int
// DeliveryTip gets the tips for delivering the message receipt to summit
DeliveryTip() *big.Int
}
// NewTips creates a new tips type.
func NewTips(summitTip, attestationTip, executionTip, deliveryTip *big.Int) Tips {
return tips{
summitTip: summitTip,
attestationTip: attestationTip,
executionTip: executionTip,
deliveryTip: deliveryTip,
}
}
// tips implements Tips.
type tips struct {
summitTip, attestationTip, executionTip, deliveryTip *big.Int
}
func (t tips) SummitTip() *big.Int {
return core.CopyBigInt(t.summitTip)
}
func (t tips) AttestationTip() *big.Int {
return core.CopyBigInt(t.attestationTip)
}
func (t tips) ExecutionTip() *big.Int {
return core.CopyBigInt(t.executionTip)
}
func (t tips) DeliveryTip() *big.Int {
return core.CopyBigInt(t.deliveryTip)
}
var _ Tips = tips{}
// TotalTips gets the combined value of the tips.
func TotalTips(tips Tips) *big.Int {
vals := []*big.Int{tips.SummitTip(), tips.AttestationTip(), tips.ExecutionTip(), tips.DeliveryTip()}
total := new(big.Int)
for _, val := range vals {
total = new(big.Int).Add(total, val)
}
return total
}