-
Notifications
You must be signed in to change notification settings - Fork 2
/
copy.go
58 lines (51 loc) · 1.36 KB
/
copy.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
package slashtest
import (
"math/big"
"github.com/PositionExchange/posichain/staking/slash"
)
// CopyRecord makes a deep copy the slash Record
func CopyRecord(r slash.Record) slash.Record {
return slash.Record{
Evidence: CopyEvidence(r.Evidence),
Reporter: r.Reporter,
}
}
// CopyEvidence makes a deep copy the slash evidence
func CopyEvidence(e slash.Evidence) slash.Evidence {
return slash.Evidence{
Moment: CopyMoment(e.Moment),
ConflictingVotes: CopyConflictingVotes(e.ConflictingVotes),
Offender: e.Offender,
}
}
// CopyMoment makes a deep copy of the Moment structure
func CopyMoment(m slash.Moment) slash.Moment {
cp := slash.Moment{
ShardID: m.ShardID,
Height: m.Height,
ViewID: m.ViewID,
}
if m.Epoch != nil {
cp.Epoch = new(big.Int).Set(m.Epoch)
}
return cp
}
// CopyConflictingVotes makes a deep copy of slash.ConflictingVotes
func CopyConflictingVotes(cv slash.ConflictingVotes) slash.ConflictingVotes {
return slash.ConflictingVotes{
FirstVote: CopyVote(cv.FirstVote),
SecondVote: CopyVote(cv.SecondVote),
}
}
// CopyVote makes a deep copy of slash.Vote
func CopyVote(v slash.Vote) slash.Vote {
cp := slash.Vote{
SignerPubKeys: v.SignerPubKeys,
BlockHeaderHash: v.BlockHeaderHash,
}
if v.Signature != nil {
cp.Signature = make([]byte, len(v.Signature))
copy(cp.Signature, v.Signature)
}
return cp
}