From 15a754a6add246c01d27dab66f7aa4428fabddaf Mon Sep 17 00:00:00 2001 From: Abdulkadir DILSIZ Date: Mon, 13 May 2024 15:27:18 +0300 Subject: [PATCH 1/2] Fix: search request --- client.go | 17 +++++++++++++---- search.go | 23 ++++++++++++++++++++--- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/client.go b/client.go index 387b4d3..c7c0185 100644 --- a/client.go +++ b/client.go @@ -672,12 +672,21 @@ func (c *client) TxSearch(search *Search) (txs []*Transaction, totalCount uint64 _ = resp.Body.Close() }() + var b []byte + if resp.StatusCode != 200 { - err = errors.New("transaction can not be broadcast") - return nil, 0, err - } + b, err = io.ReadAll(resp.Body) + if err != nil { + return nil, 0, err + } - var b []byte + var errorResponse Response + if err = json.Unmarshal(b, &errorResponse); err != nil { + return nil, 0, err + } + + return nil, 0, errors.New(errorResponse.Detail) + } b, err = io.ReadAll(resp.Body) if err != nil { diff --git a/search.go b/search.go index d95a96e..d6bfbe4 100644 --- a/search.go +++ b/search.go @@ -55,7 +55,7 @@ const ( type Search struct { HeightOperator HeightOperator `json:"-"` Height uint64 `json:"-"` - height string `json:"height,omitempty"` + PHeight string `json:"height,omitempty"` RecipientAddresses []string `json:"recipient_addrs,omitempty"` SenderAddresses []string `json:"sender_addrs,omitempty"` Hashes []string `json:"hashes,omitempty"` @@ -107,9 +107,18 @@ func (s *Search) IsValid() bool { } func (s *Search) ToJSON() ([]byte, error) { - s.height = fmt.Sprintf("%s %d", s.HeightOperator, s.Height) + s.PHeight = fmt.Sprintf("%s %d", s.HeightOperator, s.Height) - return json.Marshal(s) + buf := bytes.NewBuffer([]byte{}) + enc := json.NewEncoder(buf) + + enc.SetEscapeHTML(false) + + if err := enc.Encode(s); err != nil { + return nil, err + } + + return buf.Bytes(), nil } func (s *Search) ToRequest() (*http.Request, error) { @@ -125,3 +134,11 @@ type SearchResponse struct { TXS []*Transaction `json:"data"` TotalCount uint64 `json:"total_count"` } + +type Response struct { + Data interface{} `json:"data"` + TotalCount uint64 `json:"total_count"` + Error bool `json:"error"` + Errors map[string]string `json:"errors"` + Detail string `json:"detail"` +} From 7f468d0d31bb17fde1810815020288a17c7bf756 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abdulkadir=20D=C4=B0LS=C4=B0Z?= Date: Mon, 13 May 2024 15:30:20 +0300 Subject: [PATCH 2/2] Version bumps --- client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client.go b/client.go index c7c0185..512dad0 100644 --- a/client.go +++ b/client.go @@ -104,7 +104,7 @@ type sendMsg struct { // NewClient make ws client func NewClient(address string, wsAddress string) (Client, error) { c := new(client) - c.version = "v1.2.6" + c.version = "v1.2.7" c.address = address c.wsAddress = wsAddress