Skip to content

Commit

Permalink
Fix: storage by protocol (#957)
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky authored Jan 10, 2023
1 parent fa7e36f commit 377849e
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions cmd/api/handlers/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package handlers
import (
"net/http"

"github.com/baking-bad/bcdhub/internal/bcd"
"github.com/baking-bad/bcdhub/internal/bcd/ast"
"github.com/baking-bad/bcdhub/internal/bcd/formatter"
"github.com/baking-bad/bcdhub/internal/config"
Expand Down Expand Up @@ -289,14 +290,28 @@ func getDeffattedStorage(c *gin.Context, ctx *config.Context, address string, le
filters["level"] = level
}
operation, err := ctx.Operations.Last(filters, 0)
if err != nil && !ctx.Storage.IsRecordNotFound(err) {
switch {
case err != nil && !ctx.Storage.IsRecordNotFound(err):
return nil, err
}
if len(operation.DeffatedStorage) == 0 || ctx.Storage.IsRecordNotFound(err) {
case len(operation.DeffatedStorage) == 0 || ctx.Storage.IsRecordNotFound(err):
return ctx.RPC.GetScriptStorageRaw(c, address, level)
}
return operation.DeffatedStorage, nil
default:
protocol, err := ctx.Cache.ProtocolByID(operation.ProtocolID)
if err != nil {
return nil, err
}
currentSymLink, err := bcd.GetProtoSymLink(bcd.GetCurrentProtocol())
if err != nil {
return nil, err
}

// check for sym link because last operation may have storage type before migration
if currentSymLink == protocol.SymLink {
return operation.DeffatedStorage, nil
} else {
return ctx.RPC.GetScriptStorageRaw(c, address, level)
}
}
}

func getInitialOperation(c *gin.Context, ctx *config.Context, address string) (operation.Operation, error) {
Expand Down

0 comments on commit 377849e

Please sign in to comment.