/
vrf_coordinator_abi_values.go
87 lines (74 loc) · 2.69 KB
/
vrf_coordinator_abi_values.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
package models
import (
"fmt"
"strings"
"sync"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/smartcontractkit/chainlink/core/internal/gethwrappers/generated/solidity_vrf_coordinator_interface"
)
// VRFCoordinatorABI returns the ABI for the VRFCoordinator contract
func VRFCoordinatorABI() abi.ABI {
return coordinatorABIValues().coordinatorABI
}
// VRFFulfillMethod returns the golang abstraction of the fulfillRandomnessRequest method
func VRFFulfillMethod() abi.Method {
return coordinatorABIValues().fulfillMethod
}
// VRFFulfillSelector returns the signature of the fulfillRandomnessRequest method
// on the VRFCoordinator contract
func VRFFulfillSelector() string {
return coordinatorABIValues().fulfillSelector
}
// VRFRandomnessRequestLogTopic returns the signature of the RandomnessRequest log
// emitted by the VRFCoordinator contract
func VRFRandomnessRequestLogTopic() common.Hash {
return coordinatorABIValues().randomnessRequestLogTopic
}
// randomnessRequestRawDataArgs returns a list of the arguments to the
// RandomnessRequest log emitted by the VRFCoordinator contract
func randomnessRequestRawDataArgs() abi.Arguments {
return coordinatorABIValues().randomnessRequestRawDataArgs
}
var fulfillMethodName = "fulfillRandomnessRequest"
// abiValues is a singleton carrying information parsed once from the
// VRFCoordinator abi string
type abiValues struct {
// CoordinatorABI is the ABI of the VRFCoordinator
coordinatorABI abi.ABI
fulfillSelector string
fulfillMethod abi.Method
// RandomnessRequestLogTopic is the signature of the RandomnessRequest log
randomnessRequestLogTopic common.Hash
randomnessRequestRawDataArgs abi.Arguments
}
var dontUseThisUseGetterFunctionsAbove abiValues
var parseABIOnce sync.Once
func coordinatorABIValues() *abiValues {
parseABIOnce.Do(readCoordinatorABI)
return &dontUseThisUseGetterFunctionsAbove
}
func readCoordinatorABI() {
v := &dontUseThisUseGetterFunctionsAbove
var err error
v.coordinatorABI, err = abi.JSON(strings.NewReader(
solidity_vrf_coordinator_interface.VRFCoordinatorABI))
if err != nil {
panic(err)
}
var found bool
v.fulfillMethod, found = v.coordinatorABI.Methods[fulfillMethodName]
if !found {
panic(fmt.Errorf("could not find method %s in VRFCoordinator ABI",
fulfillMethodName))
}
v.fulfillSelector = hexutil.Encode(v.fulfillMethod.ID)
randomnessRequestABI := v.coordinatorABI.Events["RandomnessRequest"]
v.randomnessRequestLogTopic = randomnessRequestABI.ID
for _, arg := range randomnessRequestABI.Inputs {
if !arg.Indexed {
v.randomnessRequestRawDataArgs = append(v.randomnessRequestRawDataArgs, arg)
}
}
}