Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouop0 committed Jun 16, 2024
1 parent e69d4f7 commit 3b23cf2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 127 deletions.
97 changes: 44 additions & 53 deletions internal/handler/disputeGame.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
package handler

import (
"context"
"encoding/hex"
"fmt"
"strings"

"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/optimism-java/dispute-explorer/internal/blockchain"
"github.com/optimism-java/dispute-explorer/internal/schema"
"github.com/optimism-java/dispute-explorer/internal/svc"
"github.com/optimism-java/dispute-explorer/pkg/contract"
"github.com/optimism-java/dispute-explorer/pkg/event"
"github.com/optimism-java/dispute-explorer/pkg/log"
"github.com/pkg/errors"
)

func FilterAddAndRemove(ctx *svc.ServiceContext, evt *schema.SyncEvent) error {
func FilterAddAndRemove(evt *schema.SyncEvent) error {
dispute := event.DisputeGameCreated{}
if evt.EventName == dispute.Name() && evt.EventHash == dispute.EventHash().String() {
err := dispute.ToObj(evt.Data)
Expand All @@ -39,9 +30,9 @@ func FilterAddAndRemove(ctx *svc.ServiceContext, evt *schema.SyncEvent) error {
return nil
}

func BatchFilterAddAndRemove(ctx *svc.ServiceContext, events []*schema.SyncEvent) error {
func BatchFilterAddAndRemove(events []*schema.SyncEvent) error {
for _, evt := range events {
err := FilterAddAndRemove(ctx, evt)
err := FilterAddAndRemove(evt)
if err != nil {
log.Errorf("[BatchFilterAddAndRemove] FilterAddAndRemove: %s\n", err)
return err
Expand All @@ -50,44 +41,44 @@ func BatchFilterAddAndRemove(ctx *svc.ServiceContext, events []*schema.SyncEvent
return nil
}

func getGameInput(ctx *svc.ServiceContext, txHash string) (map[uint64]map[string]interface{}, error) {
abiObject, err := abi.JSON(strings.NewReader(contract.DisputeGameProxyMetaData.ABI))
if err != nil {
return nil, fmt.Errorf("[getGameInput] parse abi error: %s", errors.WithStack(err))
}
tx, _, err := ctx.L1RPC.TransactionByHash(context.Background(), common.HexToHash(txHash))
if err != nil {
return nil, fmt.Errorf("[getGameInput] get tx error: %s", errors.WithStack(err))
}
inputsMap, methodName := decodeTransactionInputData(abiObject, tx.Data())

if methodName != "create" {
return nil, fmt.Errorf("[getGameInput] methodName is : %s parse method error: %s", methodName, errors.WithStack(err))
}

e := inputsMap["_gameType"].(uint32)
f := inputsMap["_rootClaim"].([32]byte)
g := inputsMap["_extraData"].([]byte)

fmt.Println("_gameType", e)
fmt.Println("_rootClaim:", hex.EncodeToString(f[:]))
fmt.Println("_extraData: ", hex.EncodeToString(g))
return nil, nil
}

func decodeTransactionInputData(contractABI abi.ABI, data []byte) (map[string]interface{}, string) {
methodSigData := data[:4]
inputsSigData := data[4:]

method, err := contractABI.MethodById(methodSigData)
if err != nil {
log.Errorf("[DecodeTransactionInputData] parse abi error: %s\n", errors.WithStack(err))
}

inputsMap := make(map[string]interface{})

if err := method.Inputs.UnpackIntoMap(inputsMap, inputsSigData); err != nil {
log.Errorf("[DecodeTransactionInputData] parse abi error: %s\n", errors.WithStack(err))
}
return inputsMap, method.Name
}
// func getGameInput(ctx *svc.ServiceContext, txHash string) (map[uint64]map[string]interface{}, error) {
// abiObject, err := abi.JSON(strings.NewReader(contract.DisputeGameProxyMetaData.ABI))
// if err != nil {
// return nil, fmt.Errorf("[getGameInput] parse abi error: %s", errors.WithStack(err))
// }
// tx, _, err := ctx.L1RPC.TransactionByHash(context.Background(), common.HexToHash(txHash))
// if err != nil {
// return nil, fmt.Errorf("[getGameInput] get tx error: %s", errors.WithStack(err))
// }
// inputsMap, methodName := decodeTransactionInputData(abiObject, tx.Data())
//
// if methodName != "create" {
// return nil, fmt.Errorf("[getGameInput] methodName is : %s parse method error: %s", methodName, errors.WithStack(err))
// }
//
// e := inputsMap["_gameType"].(uint32)
// f := inputsMap["_rootClaim"].([32]byte)
// g := inputsMap["_extraData"].([]byte)
//
// fmt.Println("_gameType", e)
// fmt.Println("_rootClaim:", hex.EncodeToString(f[:]))
// fmt.Println("_extraData: ", hex.EncodeToString(g))
// return nil, nil
//}
//
//func decodeTransactionInputData(contractABI abi.ABI, data []byte) (map[string]interface{}, string) {

Check failure on line 69 in internal/handler/disputeGame.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

commentFormatting: put a space between `//` and comment text (gocritic)
// methodSigData := data[:4]
// inputsSigData := data[4:]
//
// method, err := contractABI.MethodById(methodSigData)
// if err != nil {
// log.Errorf("[DecodeTransactionInputData] parse abi error: %s\n", errors.WithStack(err))
// }
//
// inputsMap := make(map[string]interface{})
//
// if err := method.Inputs.UnpackIntoMap(inputsMap, inputsSigData); err != nil {
// log.Errorf("[DecodeTransactionInputData] parse abi error: %s\n", errors.WithStack(err))
// }
// return inputsMap, method.Name
//}
2 changes: 1 addition & 1 deletion internal/handler/syncEvent.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func HandlePendingBlock(ctx *svc.ServiceContext, block schema.SyncBlock) error {
log.Errorf("[Handler.SyncEvent.PendingBlock]Batch Events Update SyncBlock Status err: %s\n ", err)
return errors.WithStack(err)
}
err = BatchFilterAddAndRemove(ctx, BatchEvents)
err = BatchFilterAddAndRemove(BatchEvents)
if err != nil {
log.Errorf("[Handler.SyncEvent.PendingBlock] BatchFilterAddAndRemove err: %s\n ", err)
return errors.WithStack(err)
Expand Down
73 changes: 0 additions & 73 deletions internal/websocket/server.go

This file was deleted.

0 comments on commit 3b23cf2

Please sign in to comment.