Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion cmd/account/link_key/link_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ import (
"github.com/spf13/viper"

"github.com/smartcontractkit/cre-cli/cmd/client"
cmdCommon "github.com/smartcontractkit/cre-cli/cmd/common"
"github.com/smartcontractkit/cre-cli/internal/client/graphqlclient"
"github.com/smartcontractkit/cre-cli/internal/constants"
"github.com/smartcontractkit/cre-cli/internal/credentials"
"github.com/smartcontractkit/cre-cli/internal/environments"
"github.com/smartcontractkit/cre-cli/internal/prompt"
"github.com/smartcontractkit/cre-cli/internal/runtime"
"github.com/smartcontractkit/cre-cli/internal/settings"
"github.com/smartcontractkit/cre-cli/internal/types"
"github.com/smartcontractkit/cre-cli/internal/validation"
)

Expand Down Expand Up @@ -84,7 +86,7 @@ func New(runtimeContext *runtime.Context) *cobra.Command {
return h.Execute(inputs)
},
}
settings.AddRawTxFlag(cmd)
settings.AddTxnTypeFlags(cmd)
settings.AddSkipConfirmation(cmd)
cmd.Flags().StringP("owner-label", "l", "", "Label for the workflow owner")

Expand Down Expand Up @@ -328,6 +330,42 @@ func (h *handler) linkOwner(resp initiateLinkingResponse) error {
fmt.Println("")
fmt.Printf(" %x\n", txOut.RawTx.Data)
fmt.Println("")

case client.Changeset:
chainSelector, err := settings.GetChainSelectorByChainName(h.environmentSet.WorkflowRegistryChainName)
if err != nil {
return fmt.Errorf("failed to get chain selector for chain %q: %w", h.environmentSet.WorkflowRegistryChainName, err)
}
mcmsConfig, err := settings.GetMCMSConfig(h.settings, chainSelector)
if err != nil {
fmt.Println("\nMCMS config not found or is incorrect, skipping MCMS config in changeset")
}
cldSettings := h.settings.CLDSettings
changesets := []types.Changeset{
{
LinkOwner: &types.LinkOwner{
Payload: types.UserLinkOwnerInput{
ValidityTimestamp: ts,
Proof: common.Bytes2Hex(proofBytes[:]),
Signature: common.Bytes2Hex(sigBytes),
ChainSelector: chainSelector,
MCMSConfig: mcmsConfig,
WorkflowRegistryQualifier: cldSettings.WorkflowRegistryQualifier,
},
},
},
}
csFile := types.NewChangesetFile(cldSettings.Environment, cldSettings.Domain, cldSettings.MergeProposals, changesets)

var fileName string
if cldSettings.ChangesetFile != "" {
fileName = cldSettings.ChangesetFile
} else {
fileName = fmt.Sprintf("LinkOwner_%s_%s.yaml", h.settings.Workflow.UserWorkflowSettings.WorkflowOwnerAddress, time.Now().Format("20060102_150405"))
}

return cmdCommon.WriteChangesetFile(fileName, csFile, h.settings)

default:
h.log.Warn().Msgf("Unsupported transaction type: %s", txOut.Type)
}
Expand Down
39 changes: 38 additions & 1 deletion cmd/account/unlink_key/unlink_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ import (
"github.com/spf13/viper"

"github.com/smartcontractkit/cre-cli/cmd/client"
cmdCommon "github.com/smartcontractkit/cre-cli/cmd/common"
"github.com/smartcontractkit/cre-cli/internal/client/graphqlclient"
"github.com/smartcontractkit/cre-cli/internal/credentials"
"github.com/smartcontractkit/cre-cli/internal/environments"
"github.com/smartcontractkit/cre-cli/internal/prompt"
"github.com/smartcontractkit/cre-cli/internal/runtime"
"github.com/smartcontractkit/cre-cli/internal/settings"
"github.com/smartcontractkit/cre-cli/internal/types"
"github.com/smartcontractkit/cre-cli/internal/validation"
)

Expand Down Expand Up @@ -83,7 +85,7 @@ func New(runtimeContext *runtime.Context) *cobra.Command {
return h.Execute(in)
},
}
settings.AddRawTxFlag(cmd)
settings.AddTxnTypeFlags(cmd)
settings.AddSkipConfirmation(cmd)
return cmd
}
Expand Down Expand Up @@ -287,6 +289,41 @@ func (h *handler) unlinkOwner(owner string, resp initiateUnlinkingResponse) erro
fmt.Println("")
fmt.Printf(" %s\n", resp.TransactionData)
fmt.Println("")

case client.Changeset:
chainSelector, err := settings.GetChainSelectorByChainName(h.environmentSet.WorkflowRegistryChainName)
if err != nil {
return fmt.Errorf("failed to get chain selector for chain %q: %w", h.environmentSet.WorkflowRegistryChainName, err)
}
mcmsConfig, err := settings.GetMCMSConfig(h.settings, chainSelector)
if err != nil {
fmt.Println("\nMCMS config not found or is incorrect, skipping MCMS config in changeset")
}
cldSettings := h.settings.CLDSettings
changesets := []types.Changeset{
{
UnlinkOwner: &types.UnlinkOwner{
Payload: types.UserUnlinkOwnerInput{
ValidityTimestamp: ts,
Signature: common.Bytes2Hex(sigBytes),
ChainSelector: chainSelector,
MCMSConfig: mcmsConfig,
WorkflowRegistryQualifier: cldSettings.WorkflowRegistryQualifier,
},
},
},
}
csFile := types.NewChangesetFile(cldSettings.Environment, cldSettings.Domain, cldSettings.MergeProposals, changesets)

var fileName string
if cldSettings.ChangesetFile != "" {
fileName = cldSettings.ChangesetFile
} else {
fileName = fmt.Sprintf("UnlinkOwner_%s_%s.yaml", h.settings.Workflow.UserWorkflowSettings.WorkflowOwnerAddress, time.Now().Format("20060102_150405"))
}

return cmdCommon.WriteChangesetFile(fileName, csFile, h.settings)

default:
h.log.Warn().Msgf("Unsupported transaction type: %s", txOut.Type)
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/client/client_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ func (f *factoryImpl) GetTxType() TxType {
return Raw
} else if f.viper.GetBool(settings.Flags.Ledger.Name) {
return Ledger
} else if f.viper.GetBool(settings.Flags.Changeset.Name) {
return Changeset
}
return Regular
}
Expand Down
15 changes: 15 additions & 0 deletions cmd/client/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const (
Regular TxType = iota
Raw
Ledger
Changeset
)

type TxClientConfig struct {
Expand Down Expand Up @@ -223,6 +224,20 @@ func (c *TxClient) executeTransactionByTxType(txFn func(opts *bind.TransactOpts)
Args: cmdCommon.ToStringSlice(args),
},
}, nil
case Changeset:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: When you run both flags - e.g.cre workflow deploy tf-wf-3 --changeset --unsigned results in --unsigned behaviour only and no --changeset or feedback message. This is not a blocker but could create confusion.

tx, err := txFn(cmdCommon.SimTransactOpts())
if err != nil {
return TxOutput{Type: Changeset}, err
}
return TxOutput{
Type: Changeset,
RawTx: RawTx{
To: tx.To().Hex(),
Data: []byte{},
Function: funName,
Args: cmdCommon.ToStringSlice(args),
},
}, nil
//case Ledger:
// txOpts, err := c.ledgerOpts(c.ledgerConfig)
// if err != nil {
Expand Down
28 changes: 12 additions & 16 deletions cmd/client/workflow_registry_v2_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -678,42 +678,38 @@ func (wrc *WorkflowRegistryV2Client) IsRequestAllowlisted(owner common.Address,

// AllowlistRequest sends the request digest to the WorkflowRegistry allowlist with a default expiry of now + 10 minutes.
// `requestDigestHex` should be the hex string produced by utils.CalculateRequestDigest(...), with or without "0x".
func (wrc *WorkflowRegistryV2Client) AllowlistRequest(requestDigest [32]byte, duration time.Duration) error {
func (wrc *WorkflowRegistryV2Client) AllowlistRequest(requestDigest [32]byte, duration time.Duration) (*TxOutput, error) {
var contract workflowRegistryV2Contract
if wrc.Wr != nil {
contract = wrc.Wr
} else {
c, err := workflow_registry_v2_wrapper.NewWorkflowRegistry(wrc.ContractAddress, wrc.EthClient.Client)
if err != nil {
wrc.Logger.Error().Err(err).Msg("Failed to connect for AllowlistRequest")
return err
return nil, err
}
contract = c
}

// #nosec G115 -- int64 to uint32 conversion; Unix() returns seconds since epoch, which fits in uint32 until 2106
deadline := uint32(time.Now().Add(duration).Unix())

// Send tx; keep the same "callContractMethodV2" pattern you used for read-only calls.
// Here we return the tx hash string to the helper (it may log/track it).
_, err := callContractMethodV2(wrc, func() (string, error) {
tx, txErr := contract.AllowlistRequest(wrc.EthClient.NewTXOpts(), requestDigest, deadline)
if txErr != nil {
return "", txErr
}
// Return the tx hash string for visibility through the helper
return tx.Hash().Hex(), nil
})
txFn := func(opts *bind.TransactOpts) (*types.Transaction, error) {
return contract.AllowlistRequest(opts, requestDigest, deadline)
}
txOut, err := wrc.executeTransactionByTxType(txFn, "AllowlistRequest", "RequestAllowlisted", requestDigest, duration)
if err != nil {
wrc.Logger.Error().Err(err).Msg("AllowlistRequest tx failed")
return err
wrc.Logger.Error().
Str("contract", wrc.ContractAddress.Hex()).
Err(err).
Msg("Failed to call AllowlistRequest")
return nil, err
}

wrc.Logger.Debug().
Str("digest", hex.EncodeToString(requestDigest[:])).
Str("deadline", time.Unix(int64(deadline), 0).UTC().Format(time.RFC3339)).
Msg("AllowlistRequest submitted")
return nil
return &txOut, nil
}

func callContractMethodV2[T any](wrc *WorkflowRegistryV2Client, contractMethod func() (T, error)) (T, error) {
Expand Down
47 changes: 47 additions & 0 deletions cmd/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/rs/zerolog"
"sigs.k8s.io/yaml"

"github.com/smartcontractkit/chainlink-testing-framework/seth"

"github.com/smartcontractkit/cre-cli/internal/constants"
"github.com/smartcontractkit/cre-cli/internal/logger"
"github.com/smartcontractkit/cre-cli/internal/settings"
inttypes "github.com/smartcontractkit/cre-cli/internal/types"
)

func ValidateEventSignature(l *zerolog.Logger, tx *seth.DecodedTransaction, e abi.Event) (bool, int) {
Expand Down Expand Up @@ -214,3 +217,47 @@ func GetBuildCmd(inputFile string, outputFile string, rootFolder string) *exec.C

return buildCmd
}

func WriteChangesetFile(fileName string, changesetFile *inttypes.ChangesetFile, settings *settings.Settings) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you choose the same changeset filename twice it duplicates the contents instead of replace. Is this intended?

fullFilePath := filepath.Join(
filepath.Clean(settings.CLDSettings.CLDPath),
"domains",
settings.CLDSettings.Domain,
settings.CLDSettings.Environment,
"durable_pipelines",
"inputs",
fileName,
)

// if file exists, read it and append the new changesets
if _, err := os.Stat(fullFilePath); err == nil {
existingYamlData, err := os.ReadFile(fullFilePath)
if err != nil {
return fmt.Errorf("failed to read existing changeset yaml file: %w", err)
}

var existingChangesetFile inttypes.ChangesetFile
if err := yaml.Unmarshal(existingYamlData, &existingChangesetFile); err != nil {
return fmt.Errorf("failed to unmarshal existing changeset yaml: %w", err)
}

// Append new changesets to the existing ones
existingChangesetFile.Changesets = append(existingChangesetFile.Changesets, changesetFile.Changesets...)
changesetFile = &existingChangesetFile
}

yamlData, err := yaml.Marshal(&changesetFile)
if err != nil {
return fmt.Errorf("failed to marshal changeset to yaml: %w", err)
}

if err := os.WriteFile(fullFilePath, yamlData, 0600); err != nil {
return fmt.Errorf("failed to write changeset yaml file: %w", err)
}

fmt.Println("")
fmt.Println("Changeset YAML file generated!")
fmt.Printf("File: %s\n", fullFilePath)
fmt.Println("")
return nil
}
Loading
Loading