Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: parse ledger single and multi assets #507

Merged
merged 1 commit into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmd/metrics/bigmapdiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ func initHandlers() {
bigMapDiffHandlers = append(bigMapDiffHandlers,
contractHandlers.NewTokenMetadata(ctx.BigMapDiffs, ctx.Blocks, ctx.Protocols, ctx.Schema, ctx.Storage, ctx.RPC, ctx.SharePath, ctx.Config.IPFSGateways),
)
bigMapDiffHandlers = append(bigMapDiffHandlers,
contractHandlers.NewLedger(ctx.Storage, ctx.Schema, ctx.RPC),
)
}

type result struct {
Expand Down
6 changes: 0 additions & 6 deletions internal/events/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ package events

import "errors"

// Names
const (
SingleAssetBalanceUpdates = "singleassetbalanceupdates"
MultiAssetBalanceUpdates = "multiassetbalanceupdates"
)

// errors
var (
ErrNodeReturn = errors.New(`Node return error`)
Expand Down
21 changes: 7 additions & 14 deletions internal/events/general.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package events

import (
"encoding/json"
stdJSON "encoding/json"
"fmt"
"math/big"
"strings"

"github.com/baking-bad/bcdhub/internal/noderpc"
"github.com/baking-bad/bcdhub/internal/parsers/tokenbalance"
"github.com/pkg/errors"
"github.com/tidwall/gjson"
)

// Event -
type Event interface {
GetCode() (gjson.Result, error)
Parse(response gjson.Result) []TokenBalance
Parse(response gjson.Result) []tokenbalance.TokenBalance
Normalize(parameter string) gjson.Result
}

Expand All @@ -33,16 +33,9 @@ type Context struct {

// Sections -
type Sections struct {
Parameter json.RawMessage
ReturnType json.RawMessage
Code json.RawMessage
}

// TokenBalance -
type TokenBalance struct {
Address string
TokenID int64
Value *big.Int
Parameter stdJSON.RawMessage
ReturnType stdJSON.RawMessage
Code stdJSON.RawMessage
}

// GetCode -
Expand All @@ -60,7 +53,7 @@ func (sections Sections) GetCode() (gjson.Result, error) {
}

// Execute -
func Execute(rpc noderpc.INode, event Event, ctx Context) ([]TokenBalance, error) {
func Execute(rpc noderpc.INode, event Event, ctx Context) ([]tokenbalance.TokenBalance, error) {
parameter := event.Normalize(ctx.Parameters)
storage := gjson.Parse(`[]`)
code, err := event.GetCode()
Expand Down
17 changes: 13 additions & 4 deletions internal/events/michelson_extended_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/baking-bad/bcdhub/internal/models/bigmapdiff"
"github.com/baking-bad/bcdhub/internal/models/schema"
"github.com/baking-bad/bcdhub/internal/models/tzip"
"github.com/baking-bad/bcdhub/internal/parsers/tokenbalance"
"github.com/tidwall/gjson"
)

Expand All @@ -17,7 +18,7 @@ type MichelsonExtendedStorage struct {
Sections

name string
parser Parser
parser tokenbalance.Parser

protocol string
operationID string
Expand All @@ -28,7 +29,7 @@ type MichelsonExtendedStorage struct {

// NewMichelsonExtendedStorage -
func NewMichelsonExtendedStorage(impl tzip.EventImplementation, name, protocol, operationID, contract string, repo schema.Repository, bmd []bigmapdiff.BigMapDiff) (*MichelsonExtendedStorage, error) {
parser, err := GetParser(name, impl.MichelsonExtendedStorageEvent.ReturnType)
parser, err := tokenbalance.GetParser(name, impl.MichelsonExtendedStorageEvent.ReturnType)
if err != nil {
return nil, err
}
Expand All @@ -50,8 +51,16 @@ func NewMichelsonExtendedStorage(impl tzip.EventImplementation, name, protocol,
}

// Parse -
func (mes *MichelsonExtendedStorage) Parse(response gjson.Result) []TokenBalance {
return mes.parser.Parse(response)
func (mes *MichelsonExtendedStorage) Parse(response gjson.Result) []tokenbalance.TokenBalance {
balances := make([]tokenbalance.TokenBalance, 0)
for _, item := range response.Get("storage").Array() {
balance, err := mes.parser.Parse(item)
if err != nil {
continue
}
balances = append(balances, balance)
}
return balances
}

// Normalize - `value` is `Operation.DeffatedStorage`
Expand Down
17 changes: 13 additions & 4 deletions internal/events/michelson_initial_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package events

import (
"github.com/baking-bad/bcdhub/internal/models/tzip"
"github.com/baking-bad/bcdhub/internal/parsers/tokenbalance"
"github.com/tidwall/gjson"
)

Expand All @@ -10,12 +11,12 @@ type MichelsonInitialStorage struct {
Sections

name string
parser Parser
parser tokenbalance.Parser
}

// NewMichelsonInitialStorage -
func NewMichelsonInitialStorage(impl tzip.EventImplementation, name string) (*MichelsonInitialStorage, error) {
parser, err := GetParser(name, impl.MichelsonInitialStorageEvent.ReturnType)
parser, err := tokenbalance.GetParser(name, impl.MichelsonInitialStorageEvent.ReturnType)
if err != nil {
return nil, err
}
Expand All @@ -32,8 +33,16 @@ func NewMichelsonInitialStorage(impl tzip.EventImplementation, name string) (*Mi
}

// Parse -
func (event *MichelsonInitialStorage) Parse(response gjson.Result) []TokenBalance {
return event.parser.Parse(response)
func (event *MichelsonInitialStorage) Parse(response gjson.Result) []tokenbalance.TokenBalance {
balances := make([]tokenbalance.TokenBalance, 0)
for _, item := range response.Get("storage").Array() {
balance, err := event.parser.Parse(item)
if err != nil {
continue
}
balances = append(balances, balance)
}
return balances
}

// Normalize - `value` is `Operation.DeffatedStorage`
Expand Down
17 changes: 13 additions & 4 deletions internal/events/michelson_parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package events

import (
"github.com/baking-bad/bcdhub/internal/models/tzip"
"github.com/baking-bad/bcdhub/internal/parsers/tokenbalance"
"github.com/tidwall/gjson"
)

Expand All @@ -10,12 +11,12 @@ type MichelsonParameter struct {
Sections

name string
parser Parser
parser tokenbalance.Parser
}

// NewMichelsonParameter -
func NewMichelsonParameter(impl tzip.EventImplementation, name string) (*MichelsonParameter, error) {
parser, err := GetParser(name, impl.MichelsonParameterEvent.ReturnType)
parser, err := tokenbalance.GetParser(name, impl.MichelsonParameterEvent.ReturnType)
if err != nil {
return nil, err
}
Expand All @@ -32,8 +33,16 @@ func NewMichelsonParameter(impl tzip.EventImplementation, name string) (*Michels
}

// Parse -
func (event *MichelsonParameter) Parse(response gjson.Result) []TokenBalance {
return event.parser.Parse(response)
func (event *MichelsonParameter) Parse(response gjson.Result) []tokenbalance.TokenBalance {
balances := make([]tokenbalance.TokenBalance, 0)
for _, item := range response.Get("storage").Array() {
balance, err := event.parser.Parse(item)
if err != nil {
continue
}
balances = append(balances, balance)
}
return balances
}

// Normalize - `value` is `Operation.Parameters`
Expand Down
144 changes: 0 additions & 144 deletions internal/events/parsers.go

This file was deleted.

Loading