Skip to content

Commit 66884b8

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

File tree

9 files changed

+263
-140
lines changed

9 files changed

+263
-140
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/account/unlink_key/unlink_key.go

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@ import (
1919
"github.com/spf13/cobra"
2020
"github.com/spf13/viper"
2121

22+
"github.com/smartcontractkit/chainlink/deployment/cre/workflow_registry/v2/changeset"
23+
2224
"github.com/smartcontractkit/cre-cli/cmd/client"
2325
"github.com/smartcontractkit/cre-cli/internal/client/graphqlclient"
2426
"github.com/smartcontractkit/cre-cli/internal/credentials"
2527
"github.com/smartcontractkit/cre-cli/internal/environments"
2628
"github.com/smartcontractkit/cre-cli/internal/prompt"
2729
"github.com/smartcontractkit/cre-cli/internal/runtime"
2830
"github.com/smartcontractkit/cre-cli/internal/settings"
31+
"github.com/smartcontractkit/cre-cli/internal/types"
2932
"github.com/smartcontractkit/cre-cli/internal/validation"
3033
)
3134

@@ -289,8 +292,35 @@ func (h *handler) unlinkOwner(owner string, resp initiateUnlinkingResponse) erro
289292
fmt.Println("")
290293

291294
case client.Changeset:
292-
// TODO: implement changeset handling
293-
fmt.Println("Changeset output type is not yet implemented")
295+
chainSelector, err := settings.GetChainSelectorByChainName(h.environmentSet.WorkflowRegistryChainName)
296+
if err != nil {
297+
return fmt.Errorf("failed to get chain selector for chain %q: %w", h.environmentSet.WorkflowRegistryChainName, err)
298+
}
299+
mcmsConfig, err := types.MCMSConfig(h.settings, chainSelector)
300+
if err != nil {
301+
return fmt.Errorf("failed to get MCMS config: %w", err)
302+
}
303+
csFile := types.ChangesetFile{
304+
Environment: h.settings.Workflow.CLDSettings.Environment,
305+
Domain: h.settings.Workflow.CLDSettings.Domain,
306+
Changesets: []types.Changeset{
307+
{
308+
UnlinkOwner: &types.UnlinkOwner{
309+
Payload: changeset.UserUnlinkOwnerInput{
310+
ValidityTimestamp: ts,
311+
Signature: common.Bytes2Hex(sigBytes),
312+
ChainSelector: chainSelector,
313+
MCMSConfig: mcmsConfig,
314+
WorkflowRegistryQualifier: h.settings.Workflow.CLDSettings.WorkflowRegistryQualifier,
315+
},
316+
},
317+
},
318+
},
319+
}
320+
321+
fileName := fmt.Sprintf("UnlinkOwner_%s_%s.yaml", h.settings.Workflow.UserWorkflowSettings.WorkflowOwnerAddress, time.Now().Format("20060102_150405"))
322+
323+
return types.WriteChangesetFile(fileName, &csFile, h.settings)
294324

295325
default:
296326
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)

0 commit comments

Comments
 (0)