@@ -12,8 +12,6 @@ import (
12
12
"os"
13
13
"time"
14
14
15
- "github.com/pkg/errors"
16
-
17
15
"github.com/ethereum/go-ethereum/accounts"
18
16
"github.com/ethereum/go-ethereum/common/hexutil"
19
17
"github.com/ethereum/go-ethereum/core/types"
@@ -187,7 +185,7 @@ func (rpc *FlashbotsRPC) CallWithFlashbotsSignature(method string, privKey *ecds
187
185
errorResp := new (RelayErrorResponse )
188
186
if err := json .Unmarshal (data , errorResp ); err == nil && errorResp .Error != "" {
189
187
// relay returned an error
190
- return nil , errors . New ( errorResp .Error )
188
+ return nil , fmt . Errorf ( "%w: %s" , ErrRelayErrorResponse , errorResp .Error )
191
189
}
192
190
193
191
resp := new (rpcResponse )
@@ -621,7 +619,7 @@ func (rpc *FlashbotsRPC) FlashbotsSendBundle(privKey *ecdsa.PrivateKey, param Fl
621
619
return res , err
622
620
}
623
621
624
- // numTx is the maximum number of tx to include ( used for troubleshooting). default 0 ( all transactions)
622
+ // Simulate a full Ethereum block. numTx is the maximum number of tx to include, used for troubleshooting ( default: 0 - all transactions)
625
623
func (rpc * FlashbotsRPC ) FlashbotsSimulateBlock (privKey * ecdsa.PrivateKey , block * types.Block , maxTx int ) (res FlashbotsCallBundleResponse , err error ) {
626
624
if rpc .Debug {
627
625
fmt .Printf ("Simulating block %s 0x%x %s \t %d tx \t timestamp: %d\n " , block .Number (), block .Number (), block .Header ().Hash (), len (block .Transactions ()), block .Header ().Time )
@@ -682,3 +680,28 @@ func (rpc *FlashbotsRPC) FlashbotsSimulateBlock(privKey *ecdsa.PrivateKey, block
682
680
res , err = rpc .FlashbotsCallBundle (privKey , params )
683
681
return res , err
684
682
}
683
+
684
+ // Sends a rawTx to the Flashbots relay. It will be sent to miners as bundle for 25 blocks, after which the transaction is failed.
685
+ func (rpc * FlashbotsRPC ) FlashbotsSendPrivateTransaction (privKey * ecdsa.PrivateKey , param FlashbotsSendPrivateTransactionRequest ) (txHash string , err error ) {
686
+ rawMsg , err := rpc .CallWithFlashbotsSignature ("eth_sendPrivateTransaction" , privKey , param )
687
+ if err != nil {
688
+ return "" , err
689
+ }
690
+ err = json .Unmarshal (rawMsg , & txHash )
691
+ return txHash , err
692
+ }
693
+
694
+ // Try to cancel a private transaction at the Flashbots relay. If this call returns true this means the cancel was initiated, but it's not guaranteed
695
+ // that the transaction is actually cancelled, only that it won't be sent to miners anymore. A transaction that was already sent to miners might still
696
+ // be included in the next block.
697
+ //
698
+ // Possible errors: 'tx not found', 'tx was already cancelled', 'tx has already expired'
699
+ func (rpc * FlashbotsRPC ) FlashbotsCancelPrivateTransaction (privKey * ecdsa.PrivateKey , param FlashbotsCancelPrivateTransactionRequest ) (cancelled bool , err error ) {
700
+ rawMsg , err := rpc .CallWithFlashbotsSignature ("eth_cancelPrivateTransaction" , privKey , param )
701
+ if err != nil {
702
+ // possible todo: return specific errors for the 3 possible relay-internal error cases
703
+ return false , err
704
+ }
705
+ err = json .Unmarshal (rawMsg , & cancelled )
706
+ return cancelled , err
707
+ }
0 commit comments