Skip to content

Commit bf17e12

Browse files
feat: add changeset for workflows ops
1 parent f874cfa commit bf17e12

File tree

7 files changed

+131
-138
lines changed

7 files changed

+131
-138
lines changed

cmd/account/link_key/link_key.go

Lines changed: 15 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,20 @@ import (
88
"io"
99
"math/big"
1010
"os"
11-
"path/filepath"
1211
"strconv"
1312
"strings"
1413
"sync"
1514
"time"
1615

17-
commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config"
18-
crecontracts "github.com/smartcontractkit/chainlink/deployment/cre/contracts"
19-
"github.com/smartcontractkit/chainlink/deployment/cre/workflow_registry/v2/changeset"
20-
"github.com/smartcontractkit/mcms/types"
21-
"sigs.k8s.io/yaml"
22-
2316
"github.com/ethereum/go-ethereum/common"
2417
"github.com/google/uuid"
2518
"github.com/machinebox/graphql"
2619
"github.com/rs/zerolog"
2720
"github.com/spf13/cobra"
2821
"github.com/spf13/viper"
2922

23+
"github.com/smartcontractkit/chainlink/deployment/cre/workflow_registry/v2/changeset"
24+
3025
"github.com/smartcontractkit/cre-cli/cmd/client"
3126
"github.com/smartcontractkit/cre-cli/internal/client/graphqlclient"
3227
"github.com/smartcontractkit/cre-cli/internal/constants"
@@ -35,6 +30,7 @@ import (
3530
"github.com/smartcontractkit/cre-cli/internal/prompt"
3631
"github.com/smartcontractkit/cre-cli/internal/runtime"
3732
"github.com/smartcontractkit/cre-cli/internal/settings"
33+
"github.com/smartcontractkit/cre-cli/internal/types"
3834
"github.com/smartcontractkit/cre-cli/internal/validation"
3935
)
4036

@@ -63,20 +59,6 @@ type initiateLinkingResponse struct {
6359
FunctionArgs []string `json:"functionArgs"`
6460
}
6561

66-
type ChangesetFile struct {
67-
Environment string `json:"environment"`
68-
Domain string `json:"domain"`
69-
Changesets []Changeset `json:"changesets"`
70-
}
71-
72-
type Changeset struct {
73-
LinkOwner LinkOwner `json:"LinkOwner"`
74-
}
75-
76-
type LinkOwner struct {
77-
Payload changeset.UserLinkOwnerInput `json:"payload"`
78-
}
79-
8062
func Exec(ctx *runtime.Context, in Inputs) error {
8163
h := newHandler(ctx, os.Stdin)
8264

@@ -355,64 +337,32 @@ func (h *handler) linkOwner(resp initiateLinkingResponse) error {
355337
if err != nil {
356338
return fmt.Errorf("failed to get chain selector for chain %q: %w", h.environmentSet.WorkflowRegistryChainName, err)
357339
}
358-
minDelay, err := time.ParseDuration(h.settings.Workflow.CLDSettings.MCMSSettings.MinDelay)
359-
if err != nil {
360-
return fmt.Errorf("failed to parse min delay duration: %w", err)
361-
}
362-
validDuration, err := time.ParseDuration(h.settings.Workflow.CLDSettings.MCMSSettings.ValidDuration)
340+
mcmsConfig, err := types.MCMSConfig(h.settings, chainSelector)
363341
if err != nil {
364-
return fmt.Errorf("failed to parse valid duration: %w", err)
342+
return fmt.Errorf("failed to get MCMS config: %w", err)
365343
}
366-
csFile := ChangesetFile{
344+
csFile := types.ChangesetFile{
367345
Environment: h.settings.Workflow.CLDSettings.Environment,
368346
Domain: h.settings.Workflow.CLDSettings.Domain,
369-
Changesets: []Changeset{
347+
Changesets: []types.Changeset{
370348
{
371-
LinkOwner: LinkOwner{
349+
LinkOwner: &types.LinkOwner{
372350
Payload: changeset.UserLinkOwnerInput{
373-
ValidityTimestamp: ts,
374-
Proof: common.Bytes2Hex(proofBytes[:]),
375-
Signature: common.Bytes2Hex(sigBytes),
376-
ChainSelector: chainSelector,
377-
MCMSConfig: &crecontracts.MCMSConfig{
378-
MinDelay: minDelay,
379-
MCMSAction: types.TimelockActionSchedule,
380-
OverrideRoot: h.settings.Workflow.CLDSettings.MCMSSettings.OverrideRoot == "true",
381-
TimelockQualifierPerChain: map[uint64]string{
382-
chainSelector: h.settings.Workflow.CLDSettings.MCMSSettings.TimelockQualifier,
383-
},
384-
ValidDuration: commonconfig.MustNewDuration(validDuration),
385-
},
351+
ValidityTimestamp: ts,
352+
Proof: common.Bytes2Hex(proofBytes[:]),
353+
Signature: common.Bytes2Hex(sigBytes),
354+
ChainSelector: chainSelector,
355+
MCMSConfig: mcmsConfig,
386356
WorkflowRegistryQualifier: h.settings.Workflow.CLDSettings.WorkflowRegistryQualifier,
387357
},
388358
},
389359
},
390360
},
391361
}
392362

393-
yamlData, err := yaml.Marshal(&csFile)
394-
if err != nil {
395-
return fmt.Errorf("failed to marshal changeset to yaml: %w", err)
396-
}
363+
fileName := fmt.Sprintf("LinkOwner_%s_%s.yaml", h.settings.Workflow.UserWorkflowSettings.WorkflowOwnerAddress, time.Now().Format("20060102_150405"))
397364

398-
fileName := fmt.Sprintf("LinkOwner_%s_%d.yaml", h.settings.Workflow.UserWorkflowSettings.WorkflowOwnerAddress, time.Now().Unix())
399-
fullFilePath := filepath.Join(
400-
filepath.Clean(h.settings.Workflow.CLDSettings.CLDPath),
401-
"domains",
402-
h.settings.Workflow.CLDSettings.Domain,
403-
h.settings.Workflow.CLDSettings.Environment,
404-
"durable_pipelines",
405-
"inputs",
406-
fileName,
407-
)
408-
if err := os.WriteFile(fullFilePath, yamlData, 0600); err != nil {
409-
return fmt.Errorf("failed to write changeset yaml file: %w", err)
410-
}
411-
412-
fmt.Println("")
413-
fmt.Println("Changeset YAML file generated!")
414-
fmt.Printf("File: %s\n", fullFilePath)
415-
fmt.Println("")
365+
return types.WriteChangesetFile(fileName, &csFile, h.settings)
416366

417367
default:
418368
h.log.Warn().Msgf("Unsupported transaction type: %s", txOut.Type)

cmd/workflow/activate/activate.go

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,20 @@ import (
66
"math/big"
77
"sort"
88
"sync"
9+
"time"
910

1011
"github.com/ethereum/go-ethereum/common"
1112
"github.com/rs/zerolog"
1213
"github.com/spf13/cobra"
1314
"github.com/spf13/viper"
1415

16+
"github.com/smartcontractkit/chainlink/deployment/cre/workflow_registry/v2/changeset"
17+
1518
"github.com/smartcontractkit/cre-cli/cmd/client"
1619
"github.com/smartcontractkit/cre-cli/internal/environments"
1720
"github.com/smartcontractkit/cre-cli/internal/runtime"
1821
"github.com/smartcontractkit/cre-cli/internal/settings"
22+
"github.com/smartcontractkit/cre-cli/internal/types"
1923
"github.com/smartcontractkit/cre-cli/internal/validation"
2024
)
2125

@@ -198,8 +202,36 @@ func (h *handler) Execute() error {
198202
fmt.Println("")
199203

200204
case client.Changeset:
201-
// TODO: implement changeset handling
202-
fmt.Println("Changeset output type is not yet implemented")
205+
chainSelector, err := settings.GetChainSelectorByChainName(h.environmentSet.WorkflowRegistryChainName)
206+
if err != nil {
207+
return fmt.Errorf("failed to get chain selector for chain %q: %w", h.environmentSet.WorkflowRegistryChainName, err)
208+
}
209+
mcmsConfig, err := types.MCMSConfig(h.settings, chainSelector)
210+
if err != nil {
211+
return fmt.Errorf("failed to get MCMS config: %w", err)
212+
}
213+
csFile := types.ChangesetFile{
214+
Environment: h.settings.Workflow.CLDSettings.Environment,
215+
Domain: h.settings.Workflow.CLDSettings.Domain,
216+
Changesets: []types.Changeset{
217+
{
218+
ActivateWorkflow: &types.ActivateWorkflow{
219+
Payload: changeset.UserWorkflowActivateInput{
220+
WorkflowID: h.runtimeContext.Workflow.ID,
221+
DonFamily: h.inputs.DonFamily,
222+
223+
ChainSelector: chainSelector,
224+
MCMSConfig: mcmsConfig,
225+
WorkflowRegistryQualifier: h.settings.Workflow.CLDSettings.WorkflowRegistryQualifier,
226+
},
227+
},
228+
},
229+
},
230+
}
231+
232+
fileName := fmt.Sprintf("ActivateWorkflow_%s_%s.yaml", workflowName, time.Now().Format("20060102_150405"))
233+
234+
return types.WriteChangesetFile(fileName, &csFile, h.settings)
203235

204236
default:
205237
h.log.Warn().Msgf("Unsupported transaction type: %s", txOut.Type)

cmd/workflow/delete/delete.go

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,23 @@ import (
77
"io"
88
"math/big"
99
"sync"
10+
"time"
1011

1112
"github.com/ethereum/go-ethereum/common"
1213
"github.com/jedib0t/go-pretty/v6/text"
1314
"github.com/rs/zerolog"
1415
"github.com/spf13/cobra"
1516
"github.com/spf13/viper"
1617

18+
"github.com/smartcontractkit/chainlink/deployment/cre/workflow_registry/v2/changeset"
19+
1720
"github.com/smartcontractkit/cre-cli/cmd/client"
1821
"github.com/smartcontractkit/cre-cli/internal/credentials"
1922
"github.com/smartcontractkit/cre-cli/internal/environments"
2023
"github.com/smartcontractkit/cre-cli/internal/prompt"
2124
"github.com/smartcontractkit/cre-cli/internal/runtime"
2225
"github.com/smartcontractkit/cre-cli/internal/settings"
26+
"github.com/smartcontractkit/cre-cli/internal/types"
2327
"github.com/smartcontractkit/cre-cli/internal/validation"
2428
)
2529

@@ -210,8 +214,35 @@ func (h *handler) Execute() error {
210214
fmt.Println("")
211215

212216
case client.Changeset:
213-
// TODO: implement changeset handling
214-
fmt.Println("Changeset output type is not yet implemented")
217+
chainSelector, err := settings.GetChainSelectorByChainName(h.environmentSet.WorkflowRegistryChainName)
218+
if err != nil {
219+
return fmt.Errorf("failed to get chain selector for chain %q: %w", h.environmentSet.WorkflowRegistryChainName, err)
220+
}
221+
mcmsConfig, err := types.MCMSConfig(h.settings, chainSelector)
222+
if err != nil {
223+
return fmt.Errorf("failed to get MCMS config: %w", err)
224+
}
225+
csFile := types.ChangesetFile{
226+
Environment: h.settings.Workflow.CLDSettings.Environment,
227+
Domain: h.settings.Workflow.CLDSettings.Domain,
228+
Changesets: []types.Changeset{
229+
{
230+
DeleteWorkflow: &types.DeleteWorkflow{
231+
Payload: changeset.UserWorkflowDeleteInput{
232+
WorkflowID: h.runtimeContext.Workflow.ID,
233+
234+
ChainSelector: chainSelector,
235+
MCMSConfig: mcmsConfig,
236+
WorkflowRegistryQualifier: h.settings.Workflow.CLDSettings.WorkflowRegistryQualifier,
237+
},
238+
},
239+
},
240+
},
241+
}
242+
243+
fileName := fmt.Sprintf("DeleteWorkflow_%s_%s.yaml", workflowName, time.Now().Format("20060102_150405"))
244+
245+
return types.WriteChangesetFile(fileName, &csFile, h.settings)
215246

216247
default:
217248
h.log.Warn().Msgf("Unsupported transaction type: %s", txOut.Type)

cmd/workflow/deploy/register.go

Lines changed: 13 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,17 @@ package deploy
33
import (
44
"encoding/hex"
55
"fmt"
6-
"os"
7-
"path/filepath"
86
"time"
97

10-
"github.com/smartcontractkit/cre-cli/internal/settings"
11-
"github.com/smartcontractkit/mcms/types"
12-
138
"github.com/ethereum/go-ethereum/common"
14-
"sigs.k8s.io/yaml"
159

16-
commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config"
17-
crecontracts "github.com/smartcontractkit/chainlink/deployment/cre/contracts"
1810
"github.com/smartcontractkit/chainlink/deployment/cre/workflow_registry/v2/changeset"
11+
1912
"github.com/smartcontractkit/cre-cli/cmd/client"
13+
"github.com/smartcontractkit/cre-cli/internal/settings"
14+
"github.com/smartcontractkit/cre-cli/internal/types"
2015
)
2116

22-
type ChangesetFile struct {
23-
Environment string `json:"environment"`
24-
Domain string `json:"domain"`
25-
Changesets []Changeset `json:"changesets"`
26-
}
27-
28-
type Changeset struct {
29-
UpsertWorkflow UpsertWorkflow `json:"UpsertWorkflow"`
30-
}
31-
32-
type UpsertWorkflow struct {
33-
Payload changeset.UserWorkflowUpsertInput `json:"payload"`
34-
}
35-
3617
func (h *handler) upsert() error {
3718
if !h.validated {
3819
return fmt.Errorf("handler inputs not validated")
@@ -114,22 +95,18 @@ func (h *handler) handleUpsert(params client.RegisterWorkflowV2Parameters) error
11495
if err != nil {
11596
return fmt.Errorf("failed to get chain selector for chain %q: %w", h.environmentSet.WorkflowRegistryChainName, err)
11697
}
117-
minDelay, err := time.ParseDuration(h.settings.Workflow.CLDSettings.MCMSSettings.MinDelay)
118-
if err != nil {
119-
return fmt.Errorf("failed to parse min delay duration: %w", err)
120-
}
121-
validDuration, err := time.ParseDuration(h.settings.Workflow.CLDSettings.MCMSSettings.ValidDuration)
98+
mcmsConfig, err := types.MCMSConfig(h.settings, chainSelector)
12299
if err != nil {
123-
return fmt.Errorf("failed to parse valid duration: %w", err)
100+
return fmt.Errorf("failed to get MCMS config: %w", err)
124101
}
125-
csFile := ChangesetFile{
102+
csFile := types.ChangesetFile{
126103
Environment: h.settings.Workflow.CLDSettings.Environment,
127104
Domain: h.settings.Workflow.CLDSettings.Domain,
128-
Changesets: []Changeset{
105+
Changesets: []types.Changeset{
129106
{
130-
UpsertWorkflow: UpsertWorkflow{
107+
UpsertWorkflow: &types.UpsertWorkflow{
131108
Payload: changeset.UserWorkflowUpsertInput{
132-
WorkflowID: hex.EncodeToString(params.WorkflowID[:]),
109+
WorkflowID: h.runtimeContext.Workflow.ID,
133110
WorkflowName: params.WorkflowName,
134111
WorkflowTag: params.Tag,
135112
WorkflowStatus: params.Status,
@@ -139,46 +116,18 @@ func (h *handler) handleUpsert(params client.RegisterWorkflowV2Parameters) error
139116
Attributes: common.Bytes2Hex(params.Attributes),
140117
KeepAlive: params.KeepAlive,
141118

142-
ChainSelector: chainSelector,
143-
MCMSConfig: &crecontracts.MCMSConfig{
144-
MinDelay: minDelay,
145-
MCMSAction: types.TimelockActionSchedule,
146-
OverrideRoot: h.settings.Workflow.CLDSettings.MCMSSettings.OverrideRoot == "true",
147-
TimelockQualifierPerChain: map[uint64]string{
148-
chainSelector: h.settings.Workflow.CLDSettings.MCMSSettings.TimelockQualifier,
149-
},
150-
ValidDuration: commonconfig.MustNewDuration(validDuration),
151-
},
119+
ChainSelector: chainSelector,
120+
MCMSConfig: mcmsConfig,
152121
WorkflowRegistryQualifier: h.settings.Workflow.CLDSettings.WorkflowRegistryQualifier,
153122
},
154123
},
155124
},
156125
},
157126
}
158127

159-
yamlData, err := yaml.Marshal(&csFile)
160-
if err != nil {
161-
return fmt.Errorf("failed to marshal changeset to yaml: %w", err)
162-
}
128+
fileName := fmt.Sprintf("UpsertWorkflow_%s_%s.yaml", workflowName, time.Now().Format("20060102_150405"))
163129

164-
fileName := fmt.Sprintf("UpsertWorkflow_%s_%d.yaml", workflowName, time.Now().Unix())
165-
fullFilePath := filepath.Join(
166-
filepath.Clean(h.settings.Workflow.CLDSettings.CLDPath),
167-
"domains",
168-
h.settings.Workflow.CLDSettings.Domain,
169-
h.settings.Workflow.CLDSettings.Environment,
170-
"durable_pipelines",
171-
"inputs",
172-
fileName,
173-
)
174-
if err := os.WriteFile(fullFilePath, yamlData, 0600); err != nil {
175-
return fmt.Errorf("failed to write changeset yaml file: %w", err)
176-
}
177-
178-
fmt.Println("")
179-
fmt.Println("Changeset YAML file generated!")
180-
fmt.Printf("File: %s\n", fullFilePath)
181-
fmt.Println("")
130+
return types.WriteChangesetFile(fileName, &csFile, h.settings)
182131

183132
default:
184133
h.log.Warn().Msgf("Unsupported transaction type: %s", txOut.Type)

0 commit comments

Comments
 (0)