Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 44 additions & 37 deletions tx-submitter/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (
"time"

"morph-l2/bindings/bindings"
ntype "morph-l2/node/types"

"github.com/morph-l2/go-ethereum/accounts/abi"
"github.com/morph-l2/go-ethereum/common"
"github.com/morph-l2/go-ethereum/common/hexutil"
"github.com/morph-l2/go-ethereum/core/types"
"github.com/morph-l2/go-ethereum/log"
"github.com/morph-l2/go-ethereum/rpc"
)

// Loop Run the f func periodically.
Expand Down Expand Up @@ -146,45 +146,52 @@ func SetFBatchIndex(calldata []byte, batchIndex uint64) error {
return nil
}

func ParseBusinessInfo(tx *types.Transaction, a *abi.ABI) []interface{} {
// var method string
// var batchIndex uint64
// var finalizedIndex uint64
var res []interface{}
if len(tx.Data()) > 0 {
id := tx.Data()[:4]
if bytes.Equal(id, a.Methods["commitBatch"].ID) {
method := "commitBatch"
batchIndex := ParseParentBatchIndex(tx.Data()) + 1
res = append(res,
"method", method,
"batchIndex", batchIndex,
)
} else if bytes.Equal(id, a.Methods["commitState"].ID) {
method := "commitState"
batchIndex := ParseParentBatchIndex(tx.Data()) + 1
res = append(res,
"method", method,
"batchIndex", batchIndex,
)
} else if bytes.Equal(id, a.Methods["finalizeBatch"].ID) {
method := "finalizeBatch"
parms, err := a.Methods["finalizeBatch"].Inputs.Unpack(tx.Data()[4:])
if err != nil {
log.Error("unpack finalizeBatch error", "err", err)
}
batchIndex, _ := ntype.BatchHeaderBytes(parms[0].([]byte)).BatchIndex()
res = append(res,
"method", method,
"finalizedIndex", batchIndex,
)
// ParseL1Mempool parses the L1 mempool and returns the transactions.
func ParseL1Mempool(rpc *rpc.Client, addr common.Address) ([]*types.Transaction, error) {

var result map[string]map[string]*types.Transaction
err := rpc.Call(&result, "txpool_contentFrom", addr)
if err != nil {
return nil, fmt.Errorf("failed to get txpool content: %v", err)
}

var txs []*types.Transaction

// get pending txs
if pendingTxs, ok := result["pending"]; ok {
for _, tx := range pendingTxs {
txs = append(txs, tx)
}
}

} else {
return []interface{}{}
// get queued txs
if pendingTxs, ok := result["queued"]; ok {
for _, tx := range pendingTxs {
txs = append(txs, tx)
}
}
return res

return txs, nil

}

func ParseMempoolLatestBatchIndex(id []byte, txs []*types.Transaction) uint64 {

var res uint64
for _, tx := range txs {
if len(tx.Data()) < 4 {
continue
}
if bytes.Equal(tx.Data()[:4], id) {
pindex := ParseParentBatchIndex(tx.Data())
Comment thread
coderabbitai[bot] marked this conversation as resolved.
if pindex > res {
res = pindex
}
}
}

return res + 1

}

func ParseMethod(tx *types.Transaction, a *abi.ABI) string {
Expand Down