diff --git a/internal/cache/cache.go b/internal/cache/cache.go index f39176a45..c4ec7b62c 100644 --- a/internal/cache/cache.go +++ b/internal/cache/cache.go @@ -116,3 +116,19 @@ func (cache *Cache) Script(ctx context.Context, address, symLink string) (contra } return item.Value().(contract.Script), nil } + +func (cache *Cache) ScriptBytes(ctx context.Context, address, symLink string) ([]byte, error) { + key := fmt.Sprintf("script_bytes:%s:%s", address, symLink) + item, err := cache.Fetch(key, time.Hour, func() (interface{}, error) { + script, err := cache.contracts.Script(ctx, address, symLink) + if err != nil { + return script, err + } + return script.Full() + }) + if err != nil { + cache.Delete(key) + return nil, err + } + return item.Value().([]byte), nil +} diff --git a/internal/parsers/operations/transaction.go b/internal/parsers/operations/transaction.go index 435297bc6..d451b5879 100644 --- a/internal/parsers/operations/transaction.go +++ b/internal/parsers/operations/transaction.go @@ -112,7 +112,7 @@ func (p Transaction) parseContractParams(ctx context.Context, data noderpc.Opera } } - scriptEntity, err := p.ctx.Cache.Script(ctx, tx.Destination.Address, p.protocol.SymLink) + scriptBytes, err := p.ctx.Cache.ScriptBytes(ctx, tx.Destination.Address, p.protocol.SymLink) if err != nil { if !tx.Internal { return nil @@ -146,10 +146,7 @@ func (p Transaction) parseContractParams(ctx context.Context, data noderpc.Opera return err } } else { - tx.Script, err = scriptEntity.Full() - if err != nil { - return err - } + tx.Script = scriptBytes } tx.AST, err = ast.NewScriptWithoutCode(tx.Script) diff --git a/internal/postgres/contract/storage.go b/internal/postgres/contract/storage.go index 33ca93d28..d8eb415f1 100644 --- a/internal/postgres/contract/storage.go +++ b/internal/postgres/contract/storage.go @@ -106,7 +106,7 @@ func (storage *Storage) Storage(ctx context.Context, id int64) ([]byte, error) { return data, err } -// Storage - +// Views - func (storage *Storage) Views(ctx context.Context, id int64) ([]byte, error) { var data []byte err := storage.DB.NewSelect().