Skip to content

Commit

Permalink
feat: strimp result
Browse files Browse the repository at this point in the history
  • Loading branch information
datluongductuan committed Dec 24, 2024
1 parent 65a0eff commit 8ce7d09
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 1 deletion.
12 changes: 12 additions & 0 deletions pkg/mev/bundle_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":{}},

Check failure on line 242 in pkg/mev/bundle_sender.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

line is 135 characters (lll)
"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
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/mev/bundle_sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import (
)

func TestSendBundle(t *testing.T) {
t.Skip()
//t.Skip()

Check failure on line 28 in pkg/mev/bundle_sender_test.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

commentFormatting: put a space between `//` and comment text (gocritic)

// Generate a new private key
privateKey, err := ecdsa.GenerateKey(crypto.S256(), rand.Reader)
if err != nil {
Expand Down
10 changes: 10 additions & 0 deletions pkg/mev/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
53 changes: 53 additions & 0 deletions pkg/mev/pkg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}
}

0 comments on commit 8ce7d09

Please sign in to comment.