From 4dd7ac228f68d7917469eecffc8fb320bedbdbdd Mon Sep 17 00:00:00 2001 From: tiennam Date: Thu, 3 Aug 2023 14:11:21 +0700 Subject: [PATCH] feat: validate callBundle params --- flashbotsrpc.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/flashbotsrpc.go b/flashbotsrpc.go index c47091e..d4e36cc 100644 --- a/flashbotsrpc.go +++ b/flashbotsrpc.go @@ -11,6 +11,8 @@ import ( "math/big" "net/http" "os" + "strconv" + "strings" "sync" "time" @@ -617,8 +619,30 @@ func (rpc *FlashbotsRPC) FlashbotsGetUserStats(privKey *ecdsa.PrivateKey, blockN return res, err } +// FlashbotsCallBundle simulate a bundle against a specific block number // https://docs.flashbots.net/flashbots-auction/searchers/advanced/rpc-endpoint#eth_callbundle func (rpc *FlashbotsRPC) FlashbotsCallBundle(privKey *ecdsa.PrivateKey, param FlashbotsCallBundleParam) (res FlashbotsCallBundleResponse, err error) { + // validate the input + if len(param.Txs) == 0 { + return FlashbotsCallBundleResponse{}, fmt.Errorf("txs are empty") + } + + if param.BlockNumber == "" { + return FlashbotsCallBundleResponse{}, fmt.Errorf("blockNumber is empty") + } + + blockNumber, err := strconv.ParseInt(strings.ReplaceAll(param.BlockNumber, "0x", ""), 16, 64) + if err != nil { + return FlashbotsCallBundleResponse{}, fmt.Errorf("blockNumber is invalid") + } + if blockNumber <= 0 { + return FlashbotsCallBundleResponse{}, fmt.Errorf("blockNumber is smaller than zero") + } + + if param.StateBlockNumber == "" { + return FlashbotsCallBundleResponse{}, fmt.Errorf("stateBlockNumber is empty") + } + rawMsg, err := rpc.CallWithFlashbotsSignature("eth_callBundle", privKey, param) if err != nil { return res, err