Skip to content

Commit

Permalink
feat: save rollup_tx on chain
Browse files Browse the repository at this point in the history
  • Loading branch information
YuexingZeng committed Feb 21, 2024
1 parent 47257b7 commit 00b820a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
32 changes: 32 additions & 0 deletions x/bridge/keeper/msg_server_withdraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions x/bridge/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)

0 comments on commit 00b820a

Please sign in to comment.