Skip to content

Commit

Permalink
Fix: bigmap elastic parse
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky authored and m-kus committed Dec 14, 2020
1 parent b7103e4 commit 8251448
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 27 deletions.
9 changes: 7 additions & 2 deletions cmd/api/handlers/bigmap.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package handlers

import (
"encoding/json"
"net/http"

"github.com/baking-bad/bcdhub/internal/contractparser/docstring"
Expand Down Expand Up @@ -330,8 +331,12 @@ func prepareItem(item elastic.BigMapDiff, contractMetadata *meta.ContractMetadat
}
var key interface{}
var keyString string
if item.Key != "" {
val := gjson.Parse(item.Key)
if item.Key != nil {
bKey, err := json.Marshal(item.Key)
if err != nil {
return nil, nil, "", err
}
val := gjson.ParseBytes(bKey)
key, err = newmiguel.BigMapToMiguel(val, binPath+"/k", metadata)
if err != nil {
return nil, nil, "", err
Expand Down
8 changes: 2 additions & 6 deletions internal/elastic/big_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,7 @@ func (e *Elastic) GetBigMapKeys(ctx GetBigMapKeysContext) ([]BigMapDiff, error)
return nil, err
}
b.ID = arr[i].TopKey.Hits.Hits[0].ID
if err := result[i].FromModel(&b); err != nil {
return nil, err
}
result[i].FromModel(&b)
result[i].Count = arr[i].DocCount
}
return result, nil
Expand Down Expand Up @@ -286,9 +284,7 @@ func (e *Elastic) GetBigMapDiffsByPtrAndKeyHash(ptr int64, network, keyHash stri
return nil, 0, err
}
b.ID = response.Hits.Hits[i].ID
if err := result[i].FromModel(&b); err != nil {
return nil, 0, err
}
result[i].FromModel(&b)
}

return result, response.Hits.Total.Value, nil
Expand Down
32 changes: 13 additions & 19 deletions internal/elastic/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,23 @@ type SimilarContract struct {

// BigMapDiff -
type BigMapDiff struct {
Ptr int64 `json:"ptr,omitempty"`
BinPath string `json:"bin_path"`
Key string `json:"key"`
KeyHash string `json:"key_hash"`
Value string `json:"value"`
OperationID string `json:"operation_id"`
Level int64 `json:"level"`
Address string `json:"address"`
Network string `json:"network"`
Timestamp time.Time `json:"timestamp"`
Protocol string `json:"protocol"`
Ptr int64 `json:"ptr,omitempty"`
BinPath string `json:"bin_path"`
Key interface{} `json:"key"`
KeyHash string `json:"key_hash"`
Value string `json:"value"`
OperationID string `json:"operation_id"`
Level int64 `json:"level"`
Address string `json:"address"`
Network string `json:"network"`
Timestamp time.Time `json:"timestamp"`
Protocol string `json:"protocol"`

Count int64 `json:"count"`
}

// FromModel -
func (b *BigMapDiff) FromModel(bmd *models.BigMapDiff) error {
func (b *BigMapDiff) FromModel(bmd *models.BigMapDiff) {
b.Ptr = bmd.Ptr
b.BinPath = bmd.BinPath
b.KeyHash = bmd.KeyHash
Expand All @@ -61,13 +61,7 @@ func (b *BigMapDiff) FromModel(bmd *models.BigMapDiff) error {
b.Network = bmd.Network
b.Timestamp = bmd.Timestamp
b.Protocol = bmd.Protocol

bytes, err := json.Marshal(bmd.Key)
if err != nil {
return err
}
b.Key = string(bytes)
return nil
b.Key = bmd.Key
}

// ContractStats -
Expand Down

0 comments on commit 8251448

Please sign in to comment.