-
Notifications
You must be signed in to change notification settings - Fork 0
/
offchain_config_digester.go
51 lines (44 loc) · 1.44 KB
/
offchain_config_digester.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
package evmutil
import (
"fmt"
"strings"
"github.com/ethereum/go-ethereum/common"
"github.com/GoPlugin/libocr/offchainreporting2plus/types"
)
var _ types.OffchainConfigDigester = EVMOffchainConfigDigester{}
type EVMOffchainConfigDigester struct {
ChainID uint64
ContractAddress common.Address
}
func (d EVMOffchainConfigDigester) ConfigDigest(cc types.ContractConfig) (types.ConfigDigest, error) {
signers := []common.Address{}
for i, signer := range cc.Signers {
if len(signer) != 20 {
return types.ConfigDigest{}, fmt.Errorf("%v-th evm signer should be a 20 byte address, but got %x", i, signer)
}
a := common.BytesToAddress(signer)
signers = append(signers, a)
}
transmitters := []common.Address{}
for i, transmitter := range cc.Transmitters {
if !strings.HasPrefix(string(transmitter), "0x") || len(transmitter) != 42 || !common.IsHexAddress(string(transmitter)) {
return types.ConfigDigest{}, fmt.Errorf("%v-th evm transmitter should be a 42 character Ethereum address string, but got '%v'", i, transmitter)
}
a := common.HexToAddress(string(transmitter))
transmitters = append(transmitters, a)
}
return configDigest(
d.ChainID,
d.ContractAddress,
cc.ConfigCount,
signers,
transmitters,
cc.F,
cc.OnchainConfig,
cc.OffchainConfigVersion,
cc.OffchainConfig,
), nil
}
func (d EVMOffchainConfigDigester) ConfigDigestPrefix() (types.ConfigDigestPrefix, error) {
return types.ConfigDigestPrefixEVM, nil
}