/
contract_template_content.go
115 lines (98 loc) · 3.28 KB
/
contract_template_content.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package main
// contractTemplateContent contains the template string from contract.go.tmpl
var contractTemplateContent = `// Code generated - DO NOT EDIT.
// This file is a generated binding and any manual changes will be lost.
package contract
import (
"strings"
"sync"
hostchainabi "{{.HostChainModule}}/accounts/abi"
"{{.HostChainModule}}/accounts/abi/bind"
"{{.HostChainModule}}/accounts/keystore"
"{{.HostChainModule}}/common"
"{{.HostChainModule}}/core/types"
"{{.HostChainModule}}/crypto"
"{{.HostChainModule}}/event"
"github.com/ipfs/go-log"
chainutil "{{.ChainUtilPackage}}"
"github.com/keep-network/keep-common/pkg/chain/ethlike"
"github.com/keep-network/keep-common/pkg/subscription"
)
// Create a package-level logger for this contract. The logger exists at
// package level so that the logger is registered at startup and can be
// included or excluded from logging at startup by name.
var {{.ShortVar}}Logger = log.Logger("keep-contract-{{.Class}}")
type {{.Class}} struct {
contract *abi.{{.AbiClass}}
contractAddress common.Address
contractABI *hostchainabi.ABI
caller bind.ContractCaller
transactor bind.ContractTransactor
callerOptions *bind.CallOpts
transactorOptions *bind.TransactOpts
errorResolver *chainutil.ErrorResolver
nonceManager *ethlike.NonceManager
miningWaiter *ethlike.MiningWaiter
blockCounter *ethlike.BlockCounter
transactionMutex *sync.Mutex
}
func New{{.Class}}(
contractAddress common.Address,
chainId *big.Int,
accountKey *keystore.Key,
backend bind.ContractBackend,
nonceManager *ethlike.NonceManager,
miningWaiter *ethlike.MiningWaiter,
blockCounter *ethlike.BlockCounter,
transactionMutex *sync.Mutex,
) (*{{.Class}}, error) {
callerOptions := &bind.CallOpts{
From: accountKey.Address,
}
// FIXME Switch to bind.NewKeyedTransactorWithChainID when
// FIXME celo-org/celo-blockchain merges in changes from upstream
// FIXME ethereum/go-ethereum beyond v1.9.25.
transactorOptions, err := chainutil.NewKeyedTransactorWithChainID(
accountKey.PrivateKey,
chainId,
)
if err != nil {
return nil, fmt.Errorf("failed to instantiate transactor: [%v]", err)
}
contract, err := abi.New{{.AbiClass}}(
contractAddress,
backend,
)
if err != nil {
return nil, fmt.Errorf(
"failed to instantiate contract at address: %s [%v]",
contractAddress.String(),
err,
)
}
contractABI, err := hostchainabi.JSON(strings.NewReader(abi.{{.AbiClass}}ABI))
if err != nil {
return nil, fmt.Errorf("failed to instantiate ABI: [%v]", err)
}
return &{{.Class}}{
contract: contract,
contractAddress: contractAddress,
contractABI: &contractABI,
caller: backend,
transactor: backend,
callerOptions: callerOptions,
transactorOptions: transactorOptions,
errorResolver: chainutil.NewErrorResolver(backend, &contractABI, &contractAddress),
nonceManager: nonceManager,
miningWaiter: miningWaiter,
blockCounter: blockCounter,
transactionMutex: transactionMutex,
}, nil
}
// ----- Non-const Methods ------
{{template "contract_non_const_methods.go.tmpl" .}}
// ----- Const Methods ------
{{template "contract_const_methods.go.tmpl" .}}
// ------ Events -------
{{template "contract_events.go.tmpl" . -}}
`