@@ -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-
8062func 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 )
0 commit comments