-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
transmitter_pipeline.go
97 lines (85 loc) · 3.16 KB
/
transmitter_pipeline.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
package ocrcommon
import (
"context"
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/pkg/errors"
"github.com/smartcontractkit/chainlink/v2/common/txmgr/types"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/txmgr"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/job"
"github.com/smartcontractkit/chainlink/v2/core/services/pipeline"
)
const txObservationSource = `
transmit_tx [type=ethtx
minConfirmations=0
to="$(jobSpec.contractAddress)"
from="[$(jobSpec.fromAddress)]"
evmChainID="$(jobSpec.evmChainID)"
data="$(jobSpec.data)"
gasLimit="$(jobSpec.gasLimit)"
forwardingAllowed="$(jobSpec.forwardingAllowed)"
transmitChecker="$(jobSpec.transmitChecker)"]
transmit_tx
`
type pipelineTransmitter struct {
lgr logger.Logger
fromAddress common.Address
gasLimit uint32
effectiveTransmitterAddress common.Address
strategy types.TxStrategy
checker txmgr.TransmitCheckerSpec
pr pipeline.Runner
spec job.Job
chainID string
}
// NewPipelineTransmitter creates a new eth transmitter using the job pipeline mechanism
func NewPipelineTransmitter(
lgr logger.Logger,
fromAddress common.Address,
gasLimit uint32,
effectiveTransmitterAddress common.Address,
strategy types.TxStrategy,
checker txmgr.TransmitCheckerSpec,
pr pipeline.Runner,
spec job.Job,
chainID string,
) Transmitter {
return &pipelineTransmitter{
lgr: lgr,
fromAddress: fromAddress,
gasLimit: gasLimit,
effectiveTransmitterAddress: effectiveTransmitterAddress,
strategy: strategy,
checker: checker,
pr: pr,
spec: spec,
chainID: chainID,
}
}
func (t *pipelineTransmitter) CreateEthTransaction(ctx context.Context, toAddress common.Address, payload []byte, _ *txmgr.TxMeta) error {
// t.strategy is ignored currently as pipeline does not support passing this (sc-55115)
vars := pipeline.NewVarsFrom(map[string]interface{}{
"jobSpec": map[string]interface{}{
"contractAddress": toAddress.String(),
"fromAddress": t.fromAddress.String(),
"gasLimit": t.gasLimit,
"evmChainID": t.chainID,
"forwardingAllowed": t.spec.ForwardingAllowed,
"data": payload,
"transmitChecker": t.checker,
},
})
t.spec.PipelineSpec.DotDagSource = txObservationSource
run := pipeline.NewRun(*t.spec.PipelineSpec, vars)
if _, err := t.pr.Run(ctx, &run, t.lgr, true, nil); err != nil {
return errors.Wrap(err, "Skipped OCR transmission")
}
if run.State != pipeline.RunStatusCompleted {
return fmt.Errorf("unexpected pipeline run state: %s with fatal errors %w", run.State, run.FatalErrors.ToError())
}
return nil
}
func (t *pipelineTransmitter) FromAddress() common.Address {
return t.effectiveTransmitterAddress
}