Skip to content

Commit

Permalink
Add Missing Fields to InitBridgeAccountAction (#109)
Browse files Browse the repository at this point in the history
* add missing fields to init bridge account action

* update comments
  • Loading branch information
sambukowski committed Jun 14, 2024
1 parent f727a42 commit d2ae5f0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
20 changes: 14 additions & 6 deletions cmd/sequencer/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,25 @@ func bridgeInitCmdHandler(c *cobra.Command, args []string) {
sequencerChainID := flagHandler.GetValue("sequencer-chain-id")
assetID := flagHandler.GetValue("asset-id")
feeAssetID := flagHandler.GetValue("fee-asset-id")
sudoAddress := flagHandler.GetValue("sudo-address")
withdrawerAddress := flagHandler.GetValue("withdrawer-address")

rollupName := args[0]

priv, err := GetPrivateKeyFromFlags(c)
if err != nil {
log.WithError(err).Error("Could not get private key from flags")
panic(err)
}
opts := sequencer.InitBridgeOpts{
SequencerURL: url,
FromKey: priv,
RollupName: rollupName,
SequencerChainID: sequencerChainID,
AssetID: assetID,
FeeAssetID: feeAssetID,
SequencerURL: url,
FromKey: priv,
RollupName: rollupName,
SequencerChainID: sequencerChainID,
AssetID: assetID,
FeeAssetID: feeAssetID,
SudoAddress: sudoAddress,
WithdrawerAddress: withdrawerAddress,
}
bridgeAccount, err := sequencer.InitBridgeAccount(opts)
if err != nil {
Expand Down Expand Up @@ -118,6 +124,8 @@ func init() {
bifh.BindStringPFlag("sequencer-chain-id", "c", DefaultSequencerChainID, "The chain ID of the sequencer.")
bifh.BindStringFlag("asset-id", DefaultBridgeAssetID, "The asset id of the asset we want to bridge.")
bifh.BindStringFlag("fee-asset-id", DefaultBridgeFeeAssetID, "The fee asset id of the asset used for fees.")
bifh.BindStringFlag("sudo-address", "", "Set the sudo address to use for the bridge account. The address of the sender is used if this is not set.")
bifh.BindStringFlag("withdrawer-address", "", "Set the withdrawer address to use for the bridge account. The address of the sender is used if this is not set.")

bifh.BindBoolFlag("json", false, "Output bridge account as JSON.")
bifh.BindStringPFlag("sequencer-url", "u", DefaultSequencerURL, "The URL of the sequencer to init bridge account on.")
Expand Down
18 changes: 15 additions & 3 deletions internal/sequencer/sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,16 @@ func InitBridgeAccount(opts InitBridgeOpts) (*InitBridgeResponse, error) {
return &InitBridgeResponse{}, err
}

sudoAddress, err := addressFromText(opts.SudoAddress)
if err != nil {
log.WithError(err).Errorf("Error decoding 'sudo' address %v to proto", opts.SudoAddress)
}

withdrawerAddress, err := addressFromText(opts.WithdrawerAddress)
if err != nil {
log.WithError(err).Errorf("Error decoding 'withdrawer' address %v to proto", opts.WithdrawerAddress)
}

// build transaction
tx := &txproto.UnsignedTransaction{
Params: &txproto.TransactionParams{
Expand All @@ -309,9 +319,11 @@ func InitBridgeAccount(opts InitBridgeOpts) (*InitBridgeResponse, error) {
{
Value: &txproto.Action_InitBridgeAccountAction{
InitBridgeAccountAction: &txproto.InitBridgeAccountAction{
RollupId: rollupID,
AssetId: assetIdFromDenom(opts.AssetID),
FeeAssetId: assetIdFromDenom(opts.FeeAssetID),
RollupId: rollupID,
AssetId: assetIdFromDenom(opts.AssetID),
FeeAssetId: assetIdFromDenom(opts.FeeAssetID),
SudoAddress: sudoAddress,
WithdrawerAddress: withdrawerAddress,
},
},
},
Expand Down
7 changes: 7 additions & 0 deletions internal/sequencer/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,13 @@ type InitBridgeOpts struct {
AssetID string
// FeeAssetID is the name of the fee asset to use for the transaction fee
FeeAssetID string
// SudoAddress specifies the address to use for the bridge account which has
// sudo capabilities; ie. it can change the sudo and withdrawer addresses for
// this bridge account. If this is empty, the sender of the transaction is used.
SudoAddress string
// WithdrawerAddress specifies the address that can withdraw funds from this
// bridge account. If this is empty, the sender of the transaction is used.
WithdrawerAddress string
}
type InitBridgeResponse struct {
RollupID string `json:"rollupID"`
Expand Down

0 comments on commit d2ae5f0

Please sign in to comment.