From 8ce7d09898f885e7ca33dce3c4d3c9196ea97c6b Mon Sep 17 00:00:00 2001 From: Dat Luong Date: Tue, 24 Dec 2024 14:33:54 +0700 Subject: [PATCH] feat: strimp result --- pkg/mev/bundle_sender.go | 12 ++++++++ pkg/mev/bundle_sender_test.go | 3 +- pkg/mev/pkg.go | 10 +++++++ pkg/mev/pkg_test.go | 53 +++++++++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+), 1 deletion(-) diff --git a/pkg/mev/bundle_sender.go b/pkg/mev/bundle_sender.go index 06b8da7..41bb266 100644 --- a/pkg/mev/bundle_sender.go +++ b/pkg/mev/bundle_sender.go @@ -233,6 +233,18 @@ func (s *Client) sendBundle( resp.Error.Code, resp.Error.Messange) } + // for some case, blink builder resp contains "" wrap around the bundle hash like + /* + 2024-12-24T03:58:38Z info operator/broadcaster.go:465 send bundle (multiple) + success {"RequestID": "ctl32rfdqqbc73cb4m80", "id": "builder-blink", + "tx": ["0xd629cbb2b4b741f6e71f8daafdbe1d484c5b53020b9cca9a407e0a7cb65f394c"], + "uuid": null, "block": 21469801, "response": + {"jsonrpc":"2.0","id":1,"result":{"bundleHash":"\"0xf72e9e8afd22af2904857e03575eb6f125cabc0d18fe7fb89ee1f8c6861687ae\""},"error":{}}, + "time": "661.127521ms", "start": "2024-12-24 03:58:37.475914455 +0000 UTC"} + + so we need to strip before save to db + */ + resp.Result.BundleHash = CleanBundleHash(resp.Result.BundleHash) return resp, nil } diff --git a/pkg/mev/bundle_sender_test.go b/pkg/mev/bundle_sender_test.go index 0a9269e..7bd8e00 100644 --- a/pkg/mev/bundle_sender_test.go +++ b/pkg/mev/bundle_sender_test.go @@ -25,7 +25,8 @@ import ( ) func TestSendBundle(t *testing.T) { - t.Skip() + //t.Skip() + // Generate a new private key privateKey, err := ecdsa.GenerateKey(crypto.S256(), rand.Reader) if err != nil { diff --git a/pkg/mev/pkg.go b/pkg/mev/pkg.go index 1d80dc4..9cdf299 100644 --- a/pkg/mev/pkg.go +++ b/pkg/mev/pkg.go @@ -312,3 +312,13 @@ func ToCallArg(msg ethereum.CallMsg) interface{} { } return arg } + +func CleanBundleHash(hash string) string { + // First remove escaped quotes if they exist + hash = strings.ReplaceAll(hash, "\\\"", "") + + // Then remove any remaining regular quotes + hash = strings.Trim(hash, "\"") + + return hash +} diff --git a/pkg/mev/pkg_test.go b/pkg/mev/pkg_test.go index 96492d1..51fc84e 100644 --- a/pkg/mev/pkg_test.go +++ b/pkg/mev/pkg_test.go @@ -22,3 +22,56 @@ func TestUnmarshalSendBundleResponse1(t *testing.T) { t.Logf("%+v\n", resp) } } + +func TestCleanBundleHash(t *testing.T) { + tests := []struct { + name string + input string + expected string + }{ + { + name: "hash with escaped quotes", + input: "\"0xf72e9e8afd22af2904857e03575eb6f125cabc0d18fe7fb89ee1f8c6861687ae\"", + expected: "0xf72e9e8afd22af2904857e03575eb6f125cabc0d18fe7fb89ee1f8c6861687ae", + }, + { + name: "hash with regular quotes", + input: "\"0xabc123\"", + expected: "0xabc123", + }, + { + name: "hash without quotes", + input: "0xdef456", + expected: "0xdef456", + }, + { + name: "empty string", + input: "", + expected: "", + }, + { + name: "only quotes", + input: "\"\"", + expected: "", + }, + { + name: "multiple escaped quotes", + input: "\"\\\"0xabc123\\\"\"", + expected: "0xabc123", + }, + { + name: "mixed quotes", + input: "\\\"0xabc123\"", + expected: "0xabc123", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := mev.CleanBundleHash(tt.input) + if got != tt.expected { + t.Errorf("cleanBundleHash() = %v, want %v", got, tt.expected) + } + }) + } +}