Skip to content

Commit

Permalink
make admin flag optional
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianElvis committed Jan 13, 2025
1 parent 7f95e0a commit 354a94b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
2 changes: 1 addition & 1 deletion demo/app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ func TestInstantiateBabylonContracts(t *testing.T) {
fmt.Sprintf(`{"admin":"%s"}`, babylonKeeper.GetAuthority()),
"test-consumer",
"test-consumer-description",
babylonKeeper.GetAuthority(),
},
babylonKeeper.GetAuthority(),
babylonKeeper.GetAuthority(),
)
require.NoError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/types/test_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ func (p *TestConsumerClient) BootstrapContracts() (*ConsumerContract, error) {
fmt.Sprintf(`{"admin":"%s"}`, p.GetSender().String()),
"test-consumer",
"test-consumer-description",
p.GetSender().String(),
},
p.GetSender().String(),
p.GetSender().String(),
)
if err != nil {
return nil, err
Expand Down
26 changes: 18 additions & 8 deletions x/babylon/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import (
"github.com/babylonlabs-io/babylon-sdk/x/babylon/types"
)

const flagAuthority = "authority"
const (
flagAdmin = "admin"
)

// GetTxCmd returns the transaction commands for this module
func GetTxCmd() *cobra.Command {
Expand All @@ -31,8 +33,8 @@ func GetTxCmd() *cobra.Command {
return txCmd
}

// [babylon-contract-code-id] [btc-staking-contract-code-id] [btc-finality-contract-code-id] [btc-network] [babylon-tag] [btc-confirmation-depth] [checkpoint-finalization-timeout] [notify-cosmos-zone] [btc-staking-init-msg-json] [btc-finality-init-msg-json] [consumer-name] [consumer-description] [admin]
func ParseInstantiateArgs(args []string, sender string) (*types.MsgInstantiateBabylonContracts, error) {
// [babylon-contract-code-id] [btc-staking-contract-code-id] [btc-finality-contract-code-id] [btc-network] [babylon-tag] [btc-confirmation-depth] [checkpoint-finalization-timeout] [notify-cosmos-zone] [btc-staking-init-msg-json] [btc-finality-init-msg-json] [consumer-name] [consumer-description]
func ParseInstantiateArgs(args []string, sender string, admin string) (*types.MsgInstantiateBabylonContracts, error) {
// get the id of the code to instantiate
babylonContractCodeID, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
Expand Down Expand Up @@ -71,7 +73,6 @@ func ParseInstantiateArgs(args []string, sender string) (*types.MsgInstantiateBa
}
consumerName := args[10]
consumerDescription := args[11]
adminStr := args[12]

// build and sign the transaction, then broadcast to Tendermint
msg := types.MsgInstantiateBabylonContracts{
Expand All @@ -88,24 +89,32 @@ func ParseInstantiateArgs(args []string, sender string) (*types.MsgInstantiateBa
BtcFinalityMsg: btcFinalityInitMsg,
ConsumerName: consumerName,
ConsumerDescription: consumerDescription,
Admin: adminStr,
}
if len(admin) > 0 {
msg.Admin = admin
}
return &msg, nil
}

func NewInstantiateBabylonContractsCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "instantiate-babylon-contracts [babylon-contract-code-id] [btc-staking-contract-code-id] [btc-finality-contract-code-id] [btc-network] [babylon-tag] [btc-confirmation-depth] [checkpoint-finalization-timeout] [notify-cosmos-zone] [btc-staking-init-msg-json] [btc-finality-init-msg-json] [consumer-name] [consumer-description] [admin]",
Use: "instantiate-babylon-contracts [babylon-contract-code-id] [btc-staking-contract-code-id] [btc-finality-contract-code-id] [btc-network] [babylon-tag] [btc-confirmation-depth] [checkpoint-finalization-timeout] [notify-cosmos-zone] [btc-staking-init-msg-json] [btc-finality-init-msg-json] [consumer-name] [consumer-description]",
Short: "Instantiate Babylon contracts",
Long: "Instantiate Babylon contracts",
Aliases: []string{"i"},
Args: cobra.ExactArgs(13),
Args: cobra.ExactArgs(12),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
msg, err := ParseInstantiateArgs(args, clientCtx.GetFromAddress().String())

admin, err := cmd.Flags().GetString(flagAdmin)
if err != nil {
return err
}

msg, err := ParseInstantiateArgs(args, clientCtx.GetFromAddress().String(), admin)
if err != nil {
return err
}
Expand All @@ -114,6 +123,7 @@ func NewInstantiateBabylonContractsCmd() *cobra.Command {
SilenceUsage: true,
}

cmd.Flags().String(flagAdmin, "", "Admin address for the contracts")
flags.AddTxFlagsToCmd(cmd)
return cmd
}
4 changes: 3 additions & 1 deletion x/babylon/types/babylon.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ func NewInitMsg(
"consumer_description": consumerDescription,
"btc_finality_code_id": btcFinalityCodeId,
"btc_finality_msg": btcFinalityInitMsgBytes,
"admin": admin,
}
if len(admin) > 0 {
initMsg["admin"] = admin
}
initMsgBytes, err := json.Marshal(initMsg)
if err != nil {
Expand Down

0 comments on commit 354a94b

Please sign in to comment.