-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* find tx using txsearch with tx hash * change sequence * add oracle executor account to avoid executor sequence mismatch * query block header instead of block * handle tx failed * remove redunt sequence err * update readme * return sender when creating msgs & split msg queue every sender * set bridge info first * update authz grant checker * add sender * add broadcaster account checker * sender not set bug fix * delete debug print * add sender to pendingtx * add sender when unmarshalling processed msgs * remove redundant msg queue allocation * format * delete processed msgs from db when simulation failed and error is handled * change oracle tx sender * change proof query error (#46) * enable to query withdrawals that their tree is not finalized yet (#47) * introduce authz tx msg command (#48) * introduce authz tx msg command * update readme * format * update evm version * can disable to relay oracle data by emptying oracle-bridge-executor
- Loading branch information
Showing
49 changed files
with
1,208 additions
and
624 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
|
||
"cosmossdk.io/errors" | ||
"github.com/spf13/cobra" | ||
"golang.org/x/sync/errgroup" | ||
|
||
"github.com/cosmos/cosmos-sdk/x/authz" | ||
|
||
"github.com/initia-labs/opinit-bots/bot" | ||
bottypes "github.com/initia-labs/opinit-bots/bot/types" | ||
executortypes "github.com/initia-labs/opinit-bots/executor/types" | ||
"github.com/initia-labs/opinit-bots/keys" | ||
"github.com/initia-labs/opinit-bots/node/broadcaster" | ||
broadcastertypes "github.com/initia-labs/opinit-bots/node/broadcaster/types" | ||
"github.com/initia-labs/opinit-bots/node/rpcclient" | ||
"github.com/initia-labs/opinit-bots/provider/child" | ||
"github.com/initia-labs/opinit-bots/types" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// txCmd represents the tx command | ||
func txCmd(ctx *cmdContext) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "tx", | ||
Short: "send a transaction", | ||
} | ||
|
||
cmd.AddCommand( | ||
txGrantOracleCmd(ctx), | ||
) | ||
return cmd | ||
} | ||
|
||
func txGrantOracleCmd(baseCtx *cmdContext) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "grant-oracle [oracle-account-address]", | ||
Args: cobra.ExactArgs(1), | ||
Short: "Grant oracle permission to the given account", | ||
Long: `Grant oracle permission to the given account on L2 chain`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
cmdCtx, botDone := context.WithCancel(cmd.Context()) | ||
gracefulShutdown(botDone) | ||
|
||
errGrp, ctx := errgroup.WithContext(cmdCtx) | ||
ctx = types.WithErrGrp(ctx, errGrp) | ||
|
||
account, err := l2BroadcasterAccount(baseCtx, cmd) | ||
if err != nil { | ||
return err | ||
} | ||
err = account.Load(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
oracleAddress, err := keys.DecodeBech32AccAddr(args[0], account.Bech32Prefix()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
grantMsg, err := authz.NewMsgGrant(account.GetAddress(), oracleAddress, authz.NewGenericAuthorization(types.MsgUpdateOracleTypeUrl), nil) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
txBytes, _, err := account.BuildTxWithMessages(ctx, []sdk.Msg{grantMsg}) | ||
if err != nil { | ||
return errors.Wrapf(err, "simulation failed") | ||
} | ||
|
||
res, err := account.BroadcastTxSync(ctx, txBytes) | ||
if err != nil { | ||
// TODO: handle error, may repeat sending tx | ||
return fmt.Errorf("broadcast txs: %w", err) | ||
} | ||
bz, err := json.Marshal(res) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Println(string(bz)) | ||
return nil | ||
}, | ||
} | ||
|
||
cmd = configFlag(baseCtx.v, cmd) | ||
return cmd | ||
} | ||
|
||
func l2BroadcasterAccount(ctx *cmdContext, cmd *cobra.Command) (*broadcaster.BroadcasterAccount, error) { | ||
configPath, err := getConfigPath(cmd, ctx.homePath, string(bottypes.BotTypeExecutor)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
cfg := &executortypes.Config{} | ||
err = bot.LoadJsonConfig(configPath, cfg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
l2Config := cfg.L2NodeConfig(ctx.homePath) | ||
broadcasterConfig := l2Config.BroadcasterConfig | ||
cdc, txConfig, err := child.GetCodec(broadcasterConfig.Bech32Prefix) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
rpcClient, err := rpcclient.NewRPCClient(cdc, l2Config.RPC) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
keyringConfig := broadcastertypes.KeyringConfig{ | ||
Name: cfg.BridgeExecutor, | ||
} | ||
|
||
return broadcaster.NewBroadcasterAccount(*broadcasterConfig, cdc, txConfig, rpcClient, keyringConfig) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.