/
handler.go
642 lines (558 loc) · 19.4 KB
/
handler.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
package handler
import (
"context"
"crypto/ecdsa"
"encoding/json"
"errors"
"fmt"
"io"
"log"
"math/big"
"net/http"
"net/url"
"os"
"regexp"
"time"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/mount"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/client"
"github.com/docker/docker/pkg/stdcopy"
"github.com/docker/go-connections/nat"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/rpc"
"github.com/manyminds/api2go/jsonapi"
"github.com/smartcontractkit/chainlink/core/scripts/chaincli/config"
helpers "github.com/smartcontractkit/chainlink/core/scripts/common"
"github.com/smartcontractkit/chainlink/v2/core/cmd"
link "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/link_token_interface"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/chaintype"
"github.com/smartcontractkit/chainlink/v2/core/sessions"
bigmath "github.com/smartcontractkit/chainlink/v2/core/utils/big_math"
)
const (
defaultChainlinkNodeLogin = "notreal@fakeemail.ch"
defaultChainlinkNodePassword = "fj293fbBnlQ!f9vNs~#"
ethKeysEndpoint = "/v2/keys/eth"
ocr2KeysEndpoint = "/v2/keys/ocr2"
p2pKeysEndpoint = "/v2/keys/p2p"
csaKeysEndpoint = "/v2/keys/csa"
)
const (
nodeTOML = `[Log]
JSONConsole = true
Level = 'debug'
[WebServer]
AllowOrigins = '*'
SecureCookies = false
SessionTimeout = '999h0m0s'
[WebServer.TLS]
HTTPSPort = 0
[Feature]
LogPoller = true
[OCR2]
Enabled = true
[Keeper]
TurnLookBack = 0
[[EVM]]
ChainID = '%d'
[[EVM.Nodes]]
Name = 'node-0'
WSURL = '%s'
HTTPURL = '%s'
`
secretTOML = `
[Mercury.Credentials.cred1]
URL = '%s'
Username = '%s'
Password = '%s'
`
)
// baseHandler is the common handler with a common logic
type baseHandler struct {
cfg *config.Config
rpcClient *rpc.Client
client *ethclient.Client
privateKey *ecdsa.PrivateKey
linkToken *link.LinkToken
fromAddr common.Address
approveAmount *big.Int
}
// NewBaseHandler is the constructor of baseHandler
func NewBaseHandler(cfg *config.Config) *baseHandler {
// Created a client by the given node address
rpcClient, err := rpc.Dial(cfg.NodeURL)
if err != nil {
log.Fatal("failed to deal with ETH node: ", err)
}
nodeClient := ethclient.NewClient(rpcClient)
// Parse private key
var fromAddr common.Address
var privateKey *ecdsa.PrivateKey
if cfg.PrivateKey != "" {
d := new(big.Int).SetBytes(common.FromHex(cfg.PrivateKey))
pkX, pkY := crypto.S256().ScalarBaseMult(d.Bytes())
privateKey = &ecdsa.PrivateKey{
PublicKey: ecdsa.PublicKey{
Curve: crypto.S256(),
X: pkX,
Y: pkY,
},
D: d,
}
// Init from address
publicKey := privateKey.Public()
publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey)
if !ok {
log.Fatal("error casting public key to ECDSA")
}
fromAddr = crypto.PubkeyToAddress(*publicKeyECDSA)
} else {
log.Println("WARNING: no PRIVATE_KEY set: cannot use commands that deploy contracts or send transactions")
}
// Create link token wrapper
linkToken, err := link.NewLinkToken(common.HexToAddress(cfg.LinkTokenAddr), nodeClient)
if err != nil {
log.Fatal(err)
}
approveAmount := big.NewInt(0)
approveAmount.SetString(cfg.ApproveAmount, 10)
return &baseHandler{
cfg: cfg,
client: nodeClient,
rpcClient: rpcClient,
privateKey: privateKey,
linkToken: linkToken,
fromAddr: fromAddr,
approveAmount: approveAmount,
}
}
func (h *baseHandler) buildTxOpts(ctx context.Context) *bind.TransactOpts {
nonce, err := h.client.PendingNonceAt(ctx, h.fromAddr)
if err != nil {
log.Fatal("PendingNonceAt failed: ", err)
}
gasPrice, err := h.client.SuggestGasPrice(ctx)
if err != nil {
log.Fatal("SuggestGasPrice failed: ", err)
}
gasPrice = bigmath.Add(gasPrice, bigmath.Div(gasPrice, big.NewInt(5))) // add 20%
auth, err := bind.NewKeyedTransactorWithChainID(h.privateKey, big.NewInt(h.cfg.ChainID))
if err != nil {
log.Fatal("NewKeyedTransactorWithChainID failed: ", err)
}
auth.Nonce = big.NewInt(int64(nonce))
auth.Value = big.NewInt(0) // in wei
auth.GasLimit = h.cfg.GasLimit // in units
auth.GasPrice = gasPrice
return auth
}
// Send eth from prefunded account.
// Amount is number of wei.
func (k *Keeper) sendEth(ctx context.Context, to common.Address, amount *big.Int) error {
txOpts := k.buildTxOpts(ctx)
tx := ethtypes.NewTx(ðtypes.LegacyTx{
Nonce: txOpts.Nonce.Uint64(),
To: &to,
Value: amount,
Gas: txOpts.GasLimit,
GasPrice: txOpts.GasPrice,
Data: nil,
})
signedTx, err := ethtypes.SignTx(tx, ethtypes.NewEIP155Signer(big.NewInt(k.cfg.ChainID)), k.privateKey)
if err != nil {
return fmt.Errorf("failed to sign tx: %w", err)
}
if err = k.client.SendTransaction(ctx, signedTx); err != nil {
return fmt.Errorf("failed to send tx: %w", err)
}
if err := k.waitTx(ctx, signedTx); err != nil {
log.Fatalf("Send ETH failed, error is %s", err.Error())
}
log.Println("Send ETH successfully")
return nil
}
func (h *baseHandler) waitDeployment(ctx context.Context, tx *ethtypes.Transaction) {
if _, err := bind.WaitDeployed(ctx, h.client, tx); err != nil {
log.Fatal("WaitDeployed failed: ", err, " ", helpers.ExplorerLink(h.cfg.ChainID, tx.Hash()))
}
}
func (h *baseHandler) waitTx(ctx context.Context, tx *ethtypes.Transaction) error {
receipt, err := bind.WaitMined(ctx, h.client, tx)
if err != nil {
log.Println("WaitTx failed: ", err)
return err
}
if receipt.Status == ethtypes.ReceiptStatusFailed {
log.Println("Transaction failed: ", helpers.ExplorerLink(h.cfg.ChainID, tx.Hash()))
return errors.New("Transaction failed")
}
return nil
}
func (h *baseHandler) launchChainlinkNode(ctx context.Context, port int, containerName string, extraTOML string, force bool) (string, func(bool), error) {
// Create docker client to launch nodes
dockerClient, err := client.NewClientWithOpts(client.WithAPIVersionNegotiation())
if err != nil {
return "", nil, fmt.Errorf("failed to create docker client from env: %w", err)
}
// Make sure everything works well
if _, err = dockerClient.Ping(ctx); err != nil {
return "", nil, fmt.Errorf("failed to ping docker server: %w", err)
}
// Pull DB image if needed
var out io.ReadCloser
if _, _, err = dockerClient.ImageInspectWithRaw(ctx, h.cfg.PostgresDockerImage); err != nil {
log.Println("Pulling Postgres docker image...")
if out, err = dockerClient.ImagePull(ctx, h.cfg.PostgresDockerImage, types.ImagePullOptions{}); err != nil {
return "", nil, fmt.Errorf("failed to pull Postgres image: %w", err)
}
out.Close()
log.Println("Postgres docker image successfully pulled!")
}
// Create network config
const networkName = "chaincli-local"
existingNetworks, err := dockerClient.NetworkList(ctx, types.NetworkListOptions{})
if err != nil {
return "", nil, fmt.Errorf("failed to list networks: %w", err)
}
var found bool
for _, ntwrk := range existingNetworks {
if ntwrk.Name == networkName {
found = true
break
}
}
if !found {
if _, err = dockerClient.NetworkCreate(ctx, networkName, types.NetworkCreate{}); err != nil {
return "", nil, fmt.Errorf("failed to create network: %w", err)
}
}
postgresContainerName := fmt.Sprintf("%s-postgres", containerName)
// If force flag is on, we check and remove containers with the same name before creating new ones
if force {
if err = checkAndRemoveContainer(ctx, dockerClient, postgresContainerName); err != nil {
return "", nil, fmt.Errorf("failed to remove container: %w", err)
}
}
// Create DB container
dbContainerResp, err := dockerClient.ContainerCreate(ctx, &container.Config{
Image: h.cfg.PostgresDockerImage,
Cmd: []string{"postgres", "-c", `max_connections=1000`},
Env: []string{
"POSTGRES_USER=postgres",
"POSTGRES_PASSWORD=verylongdatabasepassword",
},
ExposedPorts: nat.PortSet{"5432": struct{}{}},
}, nil, &network.NetworkingConfig{
EndpointsConfig: map[string]*network.EndpointSettings{
networkName: {Aliases: []string{postgresContainerName}},
},
}, nil, postgresContainerName)
if err != nil {
return "", nil, fmt.Errorf("failed to create Postgres container, use --force=true to force removing existing containers: %w", err)
}
// Start container
if err = dockerClient.ContainerStart(ctx, dbContainerResp.ID, types.ContainerStartOptions{}); err != nil {
return "", nil, fmt.Errorf("failed to start DB container: %w", err)
}
log.Println("Postgres docker container successfully created and started: ", dbContainerResp.ID)
time.Sleep(time.Second * 10)
// If force flag is on, we check and remove containers with the same name before creating new ones
if force {
if err = checkAndRemoveContainer(ctx, dockerClient, containerName); err != nil {
return "", nil, fmt.Errorf("failed to remove container: %w", err)
}
}
// Pull node image if needed
if _, _, err = dockerClient.ImageInspectWithRaw(ctx, h.cfg.ChainlinkDockerImage); err != nil {
log.Println("Pulling node docker image...")
if out, err = dockerClient.ImagePull(ctx, h.cfg.ChainlinkDockerImage, types.ImagePullOptions{}); err != nil {
return "", nil, fmt.Errorf("failed to pull node image: %w", err)
}
out.Close()
log.Println("Node docker image successfully pulled!")
}
// Create temporary file with chainlink node login creds
apiFile, passwordFile, fileCleanup, err := createCredsFiles()
if err != nil {
return "", nil, fmt.Errorf("failed to create creds files: %w", err)
}
var baseTOML = fmt.Sprintf(nodeTOML, h.cfg.ChainID, h.cfg.NodeURL, h.cfg.NodeHttpURL)
tomlFile, tomlFileCleanup, err := createTomlFile(baseTOML)
if err != nil {
return "", nil, fmt.Errorf("failed to create toml file: %w", err)
}
var secretTOMLStr = fmt.Sprintf(secretTOML, h.cfg.DataStreamsURL, h.cfg.DataStreamsID, h.cfg.DataStreamsKey)
secretFile, secretTOMLFileCleanup, err := createTomlFile(secretTOMLStr)
if err != nil {
return "", nil, fmt.Errorf("failed to create secret toml file: %w", err)
}
// Create container with mounted files
portStr := fmt.Sprintf("%d", port)
nodeContainerResp, err := dockerClient.ContainerCreate(ctx, &container.Config{
Image: h.cfg.ChainlinkDockerImage,
Cmd: []string{"-s", "/run/secrets/01-secret.toml", "-c", "/run/secrets/01-config.toml", "local", "n", "-a", "/run/secrets/chainlink-node-api"},
Env: []string{
"CL_CONFIG=" + extraTOML,
"CL_PASSWORD_KEYSTORE=" + defaultChainlinkNodePassword,
"CL_DATABASE_URL=postgresql://postgres:verylongdatabasepassword@" + postgresContainerName + ":5432/postgres?sslmode=disable",
},
ExposedPorts: map[nat.Port]struct{}{
nat.Port(portStr): {},
},
}, &container.HostConfig{
Mounts: []mount.Mount{
{
Type: mount.TypeBind,
Source: apiFile,
Target: "/run/secrets/chainlink-node-api",
},
{
Type: mount.TypeBind,
Source: passwordFile,
Target: "/run/secrets/chainlink-node-password",
},
{
Type: mount.TypeBind,
Source: tomlFile,
Target: "/run/secrets/01-config.toml",
},
{
Type: mount.TypeBind,
Source: secretFile,
Target: "/run/secrets/01-secret.toml",
},
},
PortBindings: nat.PortMap{
"6688/tcp": []nat.PortBinding{
{
HostIP: "0.0.0.0",
HostPort: portStr,
},
},
},
}, &network.NetworkingConfig{
EndpointsConfig: map[string]*network.EndpointSettings{
networkName: {Aliases: []string{containerName}},
},
}, nil, containerName)
if err != nil {
return "", nil, fmt.Errorf("failed to create node container, use --force=true to force removing existing containers: %w", err)
}
// Start container
if err = dockerClient.ContainerStart(ctx, nodeContainerResp.ID, types.ContainerStartOptions{}); err != nil {
return "", nil, fmt.Errorf("failed to start node container: %w", err)
}
addr := fmt.Sprintf("http://localhost:%s", portStr)
log.Println("Node docker container successfully created and started: ", nodeContainerResp.ID, addr)
if err = waitForNodeReady(ctx, addr); err != nil {
log.Fatal(err, nodeContainerResp.ID)
}
log.Println("Node ready: ", nodeContainerResp.ID)
return addr, func(writeLogs bool) {
fileCleanup()
tomlFileCleanup()
secretTOMLFileCleanup()
if writeLogs {
var rdr io.ReadCloser
rdr, err2 := dockerClient.ContainerLogs(ctx, nodeContainerResp.ID, types.ContainerLogsOptions{
ShowStderr: true,
Timestamps: true,
})
if err2 != nil {
rdr.Close()
log.Fatal("Failed to collect logs from container: ", err2)
}
stdErr, err2 := os.OpenFile(fmt.Sprintf("./%s-stderr.log", nodeContainerResp.ID), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755)
if err2 != nil {
rdr.Close()
stdErr.Close()
log.Fatal("Failed to open file: ", err2)
}
if _, err2 := stdcopy.StdCopy(io.Discard, stdErr, rdr); err2 != nil {
rdr.Close()
stdErr.Close()
log.Fatal("Failed to write logs to file: ", err2)
}
rdr.Close()
stdErr.Close()
}
if err2 := dockerClient.ContainerStop(ctx, nodeContainerResp.ID, container.StopOptions{}); err2 != nil {
log.Fatal("Failed to stop node container: ", err2)
}
if err2 := dockerClient.ContainerRemove(ctx, nodeContainerResp.ID, types.ContainerRemoveOptions{}); err2 != nil {
log.Fatal("Failed to remove node container: ", err2)
}
if err2 := dockerClient.ContainerStop(ctx, dbContainerResp.ID, container.StopOptions{}); err2 != nil {
log.Fatal("Failed to stop DB container: ", err2)
}
if err2 := dockerClient.ContainerRemove(ctx, dbContainerResp.ID, types.ContainerRemoveOptions{}); err2 != nil {
log.Fatal("Failed to remove DB container: ", err2)
}
}, nil
}
func checkAndRemoveContainer(ctx context.Context, dockerClient *client.Client, containerName string) error {
opts := types.ContainerListOptions{
Filters: filters.NewArgs(filters.Arg("name", "^/"+regexp.QuoteMeta(containerName)+"$")),
}
containers, err := dockerClient.ContainerList(ctx, opts)
if err != nil {
return fmt.Errorf("failed to list containers: %w", err)
}
if len(containers) > 1 {
log.Fatal("more than two containers with the same name should not happen")
} else if len(containers) > 0 {
if err := dockerClient.ContainerRemove(ctx, containers[0].ID, types.ContainerRemoveOptions{
Force: true,
}); err != nil {
return fmt.Errorf("failed to remove existing container: %w", err)
}
log.Println("successfully removed an existing container with name: ", containerName)
}
return nil
}
func waitForNodeReady(ctx context.Context, addr string) error {
client := &http.Client{}
defer client.CloseIdleConnections()
const timeout = 120
startTime := time.Now().Unix()
for {
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("%s/health", addr), nil)
if err != nil {
return err
}
req.Close = true
resp, err := client.Do(req)
if err == nil {
resp.Body.Close()
if resp.StatusCode == http.StatusOK {
return nil
}
}
if time.Now().Unix()-startTime > int64(timeout*time.Second) {
return fmt.Errorf("timed out waiting for node to start, waited %d seconds", timeout)
}
time.Sleep(time.Second * 5)
}
}
// authenticate creates a http client with URL, email and password
func authenticate(ctx context.Context, urlStr, email, password string, lggr logger.Logger) (cmd.HTTPClient, error) {
remoteNodeURL, err := url.Parse(urlStr)
if err != nil {
return nil, err
}
c := cmd.ClientOpts{RemoteNodeURL: *remoteNodeURL}
sr := sessions.SessionRequest{Email: email, Password: password}
store := &cmd.MemoryCookieStore{}
tca := cmd.NewSessionCookieAuthenticator(c, store, lggr)
if _, err = tca.Authenticate(ctx, sr); err != nil {
log.Println("failed to authenticate: ", err)
return nil, err
}
return cmd.NewAuthenticatedHTTPClient(lggr, c, tca, sr), nil
}
func nodeRequest(ctx context.Context, client cmd.HTTPClient, path string) ([]byte, error) {
resp, err := client.Get(ctx, path)
if err != nil {
return []byte{}, fmt.Errorf("GET error from client: %w", err)
}
defer resp.Body.Close()
raw, err := io.ReadAll(resp.Body)
if err != nil {
return []byte{}, fmt.Errorf("failed to read response body: %w", err)
}
type errorDetail struct {
Detail string `json:"detail"`
}
type errorResp struct {
Errors []errorDetail `json:"errors"`
}
var errs errorResp
if err := json.Unmarshal(raw, &errs); err == nil && len(errs.Errors) > 0 {
return []byte{}, fmt.Errorf("error returned from api: %s", errs.Errors[0].Detail)
}
return raw, nil
}
// getNodeAddress returns chainlink node's wallet address
func getNodeAddress(ctx context.Context, client cmd.HTTPClient) (string, error) {
resp, err := nodeRequest(ctx, client, ethKeysEndpoint)
if err != nil {
return "", fmt.Errorf("failed to get ETH keys: %w", err)
}
var keys cmd.EthKeyPresenters
if err = jsonapi.Unmarshal(resp, &keys); err != nil {
return "", fmt.Errorf("failed to unmarshal response body: %w", err)
}
return keys[0].Address, nil
}
// getNodeOCR2Config returns chainlink node's OCR2 bundle key ID
func getNodeOCR2Config(ctx context.Context, client cmd.HTTPClient) (*cmd.OCR2KeyBundlePresenter, error) {
resp, err := nodeRequest(ctx, client, ocr2KeysEndpoint)
if err != nil {
return nil, fmt.Errorf("failed to get OCR2 keys: %w", err)
}
var keys cmd.OCR2KeyBundlePresenters
if err = jsonapi.Unmarshal(resp, &keys); err != nil {
return nil, fmt.Errorf("failed to unmarshal response body: %w", err)
}
var evmKey cmd.OCR2KeyBundlePresenter
for _, key := range keys {
if key.ChainType == string(chaintype.EVM) {
evmKey = key
break
}
}
return &evmKey, nil
}
// getP2PKeyID returns chainlink node's P2P key ID
func getP2PKeyID(ctx context.Context, client cmd.HTTPClient) (string, error) {
resp, err := nodeRequest(ctx, client, p2pKeysEndpoint)
if err != nil {
return "", fmt.Errorf("failed to get P2P keys: %w", err)
}
var keys cmd.P2PKeyPresenters
if err = jsonapi.Unmarshal(resp, &keys); err != nil {
return "", fmt.Errorf("failed to unmarshal response body: %w", err)
}
return keys[0].ID, nil
}
// createCredsFiles creates two temporary files with node creds: api and password.
func createCredsFiles() (string, string, func(), error) {
// Create temporary file with chainlink node login creds
apiFile, err := os.CreateTemp("", "chainlink-node-api")
if err != nil {
return "", "", nil, fmt.Errorf("failed to create api file: %w", err)
}
_, _ = apiFile.WriteString(defaultChainlinkNodeLogin)
_, _ = apiFile.WriteString("\n")
_, _ = apiFile.WriteString(defaultChainlinkNodePassword)
// Create temporary file with chainlink node password
passwordFile, err := os.CreateTemp("", "chainlink-node-password")
if err != nil {
return "", "", nil, fmt.Errorf("failed to create password file: %w", err)
}
_, _ = passwordFile.WriteString(defaultChainlinkNodePassword)
return apiFile.Name(), passwordFile.Name(), func() {
os.RemoveAll(apiFile.Name())
os.RemoveAll(passwordFile.Name())
}, nil
}
// createTomlFile creates temporary file with TOML config
func createTomlFile(tomlString string) (string, func(), error) {
// Create temporary file with chainlink node TOML config
tomlFile, err := os.CreateTemp("", "chainlink-toml-config")
if err != nil {
return "", nil, fmt.Errorf("failed to create toml file: %w", err)
}
_, _ = tomlFile.WriteString(tomlString)
return tomlFile.Name(), func() {
os.RemoveAll(tomlFile.Name())
}, nil
}