From 00b820aece2b2d899837286305a836c725b5adc6 Mon Sep 17 00:00:00 2001 From: zengyuexing <1736782823@qq.com> Date: Wed, 21 Feb 2024 18:12:31 +0800 Subject: [PATCH] feat: save rollup_tx on chain --- x/bridge/keeper/msg_server_withdraw.go | 32 ++++++++++++++++++++++++++ x/bridge/types/errors.go | 1 + 2 files changed, 33 insertions(+) diff --git a/x/bridge/keeper/msg_server_withdraw.go b/x/bridge/keeper/msg_server_withdraw.go index 2e4fa97cb7..8ac0f2d9ab 100644 --- a/x/bridge/keeper/msg_server_withdraw.go +++ b/x/bridge/keeper/msg_server_withdraw.go @@ -23,6 +23,19 @@ func (k msgServer) CreateWithdraw(goCtx context.Context, msg *types.MsgCreateWit if isFound { return nil, types.ErrIndexExist } + for _, txHash := range msg.TxHashList { + _, isTxHashFound := k.GetRollupTx(ctx, txHash) + if isTxHashFound { + return nil, types.ErrRollupTxHashExist + } + } + for _, txHash := range msg.TxHashList { + k.SetRollupTx(ctx, types.RollupTx{ + TxHash: txHash, + TxId: msg.TxId, + Status: types.WithdrawStatus_WITHDRAW_STATUS_PENDING, + }) + } withdraw := types.Withdraw{ Creator: msg.Creator, @@ -68,6 +81,14 @@ func (k msgServer) UpdateWithdraw(goCtx context.Context, msg *types.MsgUpdateWit return nil, types.ErrNotCallerGroupMembers } + for _, txHash := range valFound.TxHashList { + k.SetRollupTx(ctx, types.RollupTx{ + TxHash: txHash, + TxId: valFound.TxId, + Status: msg.Status, + }) + } + withdraw := types.Withdraw{ Creator: valFound.Creator, TxId: valFound.TxId, @@ -146,6 +167,13 @@ func (k msgServer) SignWithdraw(goCtx context.Context, msg *types.MsgSignWithdra if err := ctx.EventManager().EmitTypedEvent(&types.EventSignWithdraw{TxId: msg.TxId}); err != nil { return nil, err } + for _, txHash := range valFound.TxHashList { + k.SetRollupTx(ctx, types.RollupTx{ + TxHash: txHash, + TxId: valFound.TxId, + Status: status, + }) + } k.RemoveStatusIndex(ctx, valFound.GetStatus().String(), valFound.TxId) k.SetStatusIndex(ctx, withdraw.Status.String(), withdraw.TxId) } @@ -169,6 +197,10 @@ func (k msgServer) DeleteWithdraw(goCtx context.Context, msg *types.MsgDeleteWit return nil, types.ErrNotOwner } + for _, txHash := range valFound.TxHashList { + k.RemoveRollupTx(ctx, txHash) + } + k.RemoveWithdraw( ctx, msg.TxId, diff --git a/x/bridge/types/errors.go b/x/bridge/types/errors.go index 83ad43a656..a536cf0102 100644 --- a/x/bridge/types/errors.go +++ b/x/bridge/types/errors.go @@ -17,4 +17,5 @@ var ( ErrNotSignerGroupMembers = errorsmod.Register(ModuleName, 1106, "only signer group members can do this") ErrAlreadySigned = errorsmod.Register(ModuleName, 1107, "this sender already signed") ErrThresholdNotSet = errorsmod.Register(ModuleName, 1108, "threshold is not set") + ErrRollupTxHashExist = errorsmod.Register(ModuleName, 1109, "rollup tx hash already exist") )