-
Notifications
You must be signed in to change notification settings - Fork 5
/
soloValidator.go
39 lines (33 loc) · 1 KB
/
soloValidator.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
package solo
import (
"github.com/drep-project/DREP-Chain/chain/block"
"github.com/drep-project/DREP-Chain/crypto/secp256k1"
"github.com/drep-project/DREP-Chain/crypto/sha3"
"github.com/drep-project/DREP-Chain/types"
)
type SoloValidator struct {
pubkey *secp256k1.PublicKey
}
func NewSoloValidator(pubkey *secp256k1.PublicKey) *SoloValidator {
return &SoloValidator{
pubkey: pubkey,
}
}
func (soloValidator *SoloValidator) VerifyHeader(header, parent *types.BlockHeader) error {
return nil
}
func (soloValidator *SoloValidator) VerifyBody(block *types.Block) error {
hash := sha3.Keccak256(block.AsSignMessage())
sig, err := secp256k1.ParseSignature(block.Proof.Evidence)
if err != nil {
return err
}
if sig.Verify(hash, soloValidator.pubkey) {
return nil
} else {
return ErrCheckSigFail
}
}
func (soloValidator *SoloValidator) ExecuteBlock(context *block.BlockExecuteContext) error {
return AccumulateRewards(soloValidator.pubkey, context.TrieStore, context.GasFee, context.Block.Header.Height)
}