diff --git a/go.mod b/go.mod index c71f27c..6384d85 100644 --- a/go.mod +++ b/go.mod @@ -12,6 +12,7 @@ require ( github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416 github.com/prometheus/client_golang v1.18.0 github.com/stretchr/testify v1.8.4 + github.com/tredeske/u v0.0.0-20240301202545-cc23fee03f7c go.uber.org/multierr v1.11.0 go.uber.org/zap v1.26.0 ) diff --git a/go.sum b/go.sum index 3dae5cf..ef7a605 100644 --- a/go.sum +++ b/go.sum @@ -2315,8 +2315,9 @@ github.com/lib/pq v1.8.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/lib/pq v1.9.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/lib/pq v1.10.4/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/lib/pq v1.10.6/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= -github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw= github.com/lib/pq v1.10.7/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= +github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= +github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/libp2p/go-addr-util v0.0.2/go.mod h1:Ecd6Fb3yIuLzq4bD7VcywcVSBtefcAwnUISBM3WG15E= github.com/libp2p/go-addr-util v0.1.0/go.mod h1:6I3ZYuFr2O/9D+SoyM0zEw0EF3YkldtTX406BpdQMqw= github.com/libp2p/go-buffer-pool v0.0.1/go.mod h1:xtyIz9PMobb13WaxR6Zo1Pd1zXJKYg0a8KiIvDp3TzQ= @@ -3462,6 +3463,8 @@ github.com/tonistiigi/units v0.0.0-20180711220420-6950e57a87ea/go.mod h1:WPnis/6 github.com/tonistiigi/vt100 v0.0.0-20210615222946-8066bb97264f/go.mod h1:ulncasL3N9uLrVann0m+CDlJKWsIAP34MPcOJF6VRvc= github.com/trailofbits/go-mutexasserts v0.0.0-20200708152505-19999e7d3cef/go.mod h1:+SV/613m53DNAmlXPTWGZhIyt4E/qDvn9g/lOPRiy0A= github.com/trailofbits/go-mutexasserts v0.0.0-20230328101604-8cdbc5f3d279/go.mod h1:GA3+Mq3kt3tYAfM0WZCu7ofy+GW9PuGysHfhr+6JX7s= +github.com/tredeske/u v0.0.0-20240301202545-cc23fee03f7c h1:x7NJo4wXqdtCdfEXLd42HunCXHy2b9/TeW7vM4W5G7Q= +github.com/tredeske/u v0.0.0-20240301202545-cc23fee03f7c/go.mod h1:/9Soq9m+Gmq7qhvNzdO/CjOFGol1MuZFvWY2iMHzsgw= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= github.com/tv42/httpunix v0.0.0-20191220191345-2ba4b9c3382c/go.mod h1:hzIxponao9Kjc7aWznkXaL4U4TWaDSs8zcsY4Ka08nM= github.com/twitchtv/twirp v7.1.0+incompatible/go.mod h1:RRJoFSAmTEh2weEqWtpPE3vFK5YBhA6bqp2l1kfCC5A= diff --git a/service/sentry.go b/service/sentry.go index b926bda..863d3ce 100644 --- a/service/sentry.go +++ b/service/sentry.go @@ -12,11 +12,11 @@ import ( "github.com/ethereum/go-ethereum/rpc" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" + "github.com/tredeske/u/ustrings" "github.com/bnb-chain/bsc-mev-sentry/account" "github.com/bnb-chain/bsc-mev-sentry/log" "github.com/bnb-chain/bsc-mev-sentry/node" - "github.com/bnb-chain/bsc-mev-sentry/utils" ) var ( @@ -198,11 +198,11 @@ func timeoutCancel(ctx *context.Context, timeout Duration) func() { type Duration time.Duration func (d Duration) MarshalText() ([]byte, error) { - return utils.UnsafeStringToBytes(time.Duration(d).String()), nil + return ustrings.UnsafeStringToBytes(time.Duration(d).String()), nil } func (d *Duration) UnmarshalText(text []byte) error { - dd, err := time.ParseDuration(utils.UnsafeBytesToString(text)) + dd, err := time.ParseDuration(ustrings.UnsafeBytesToString(text)) *d = Duration(dd) return err } diff --git a/utils/string.go b/utils/string.go deleted file mode 100644 index 2f4eb4f..0000000 --- a/utils/string.go +++ /dev/null @@ -1,23 +0,0 @@ -package utils - -import ( - "reflect" - "unsafe" -) - -// UnsafeStringToBytes converts string to []byte without memory copy. -// The return []byte is readonly since it ref to the string's content, -// and golang strings are immutable. -func UnsafeStringToBytes(str string) []byte { - var buf []byte - *(*string)(unsafe.Pointer(&buf)) = str - (*reflect.SliceHeader)(unsafe.Pointer(&buf)).Cap = len(str) - return buf -} - -// UnsafeBytesToString converts []bytes to string without memory copy. -// The return string is not immutable since it ref to the []byte's content, -// and []byte is writable. -func UnsafeBytesToString(raw []byte) string { - return *(*string)(unsafe.Pointer(&raw)) -}