forked from thetatoken/theta-protocol-ledger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
slash_intent.go
98 lines (83 loc) · 2.3 KB
/
slash_intent.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package types
import (
"encoding/hex"
"encoding/json"
"fmt"
"github.com/thetatoken/theta/common"
)
// SlashIntent contains the address, reserve sequence of the account to
// be slashed, and the proof why the account should be slashed
type SlashIntent struct {
Address common.Address
ReserveSequence uint64
Proof common.Bytes
}
type SlashIntentJSON struct {
Address common.Address
ReserveSequence common.JSONUint64
Proof common.Bytes
}
func NewSlashIntentJSON(s SlashIntent) SlashIntentJSON {
return SlashIntentJSON{
Address: s.Address,
ReserveSequence: common.JSONUint64(s.ReserveSequence),
Proof: s.Proof,
}
}
func (s SlashIntentJSON) SlashIntent() SlashIntent {
return SlashIntent{
Address: s.Address,
ReserveSequence: uint64(s.ReserveSequence),
Proof: s.Proof,
}
}
func (s SlashIntent) MarshalJSON() ([]byte, error) {
return json.Marshal(NewSlashIntentJSON(s))
}
func (s *SlashIntent) UnmarshalJSON(data []byte) error {
var a SlashIntentJSON
if err := json.Unmarshal(data, &a); err != nil {
return err
}
*s = a.SlashIntent()
return nil
}
func (si *SlashIntent) String() string {
if si == nil {
return "nil-SlashIntent"
}
return fmt.Sprintf("SlashIntent{%v %v %v}",
si.Address, si.ReserveSequence, hex.EncodeToString(si.Proof))
}
// OverspendingProof contains the proof that the ReservedFund has been overly spent
type OverspendingProof struct {
ReserveSequence uint64
ServicePayments []ServicePaymentTx
}
type OverspendingProofJSON struct {
ReserveSequence common.JSONUint64
ServicePayments []ServicePaymentTx
}
func NewOverspendingProofJSON(a OverspendingProof) OverspendingProofJSON {
return OverspendingProofJSON{
ReserveSequence: common.JSONUint64(a.ReserveSequence),
ServicePayments: a.ServicePayments,
}
}
func (a OverspendingProofJSON) OverspendingProof() OverspendingProof {
return OverspendingProof{
ReserveSequence: uint64(a.ReserveSequence),
ServicePayments: a.ServicePayments,
}
}
func (a OverspendingProof) MarshalJSON() ([]byte, error) {
return json.Marshal(NewOverspendingProofJSON(a))
}
func (a *OverspendingProof) UnmarshalJSON(data []byte) error {
var b OverspendingProofJSON
if err := json.Unmarshal(data, &b); err != nil {
return err
}
*a = b.OverspendingProof()
return nil
}