shared

package
Version: v0.2.15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2019 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrLogMissingTopics = func(expectedNumTopics, actualNumTopics int) error {
		return fmt.Errorf("log missing topics: has %d, want %d", actualNumTopics, expectedNumTopics)
	}
	ErrLogMissingData   = errors.New("log missing data")
	ErrCouldNotCreateFK = func(err error) error {
		return fmt.Errorf("converter could not create FK: %v", err)
	}
)
View Source
var ErrInvalidIndex = func(index int) error {
	return errors.New(fmt.Sprintf("unsupported log data index: %d", index))
}
View Source
var ModelToQuery = map[string]string{}

Stores memoised insertion queries to minimise computation

Functions

func BigIntToInt64

func BigIntToInt64(value *big.Int) int64

func BigIntToString

func BigIntToString(value *big.Int) string

func ConvertInt256HexToBigInt added in v0.2.3

func ConvertInt256HexToBigInt(hex string) *big.Int

func ConvertIntStringToHex added in v0.2.2

func ConvertIntStringToHex(n string) (string, error)

func ConvertUint256HexToBigInt added in v0.2.3

func ConvertUint256HexToBigInt(hex string) *big.Int

func Create added in v0.2.8

func Create(models []InsertionModel, db *postgres.DB) error
Given an instance of InsertionModel, example below, generates an insertion query and fills in

foreign keys automatically after getting from the DB. These "special fields" are populated in the columnToValue mapping, and are treated like any other in the insertion.

testModel = shared.InsertionModel{

	SchemaName:     "maker"
	TableName:      "testEvent",
	OrderedColumns: []string{"header_id", "log_id", constants.IlkFK, constants.UrnFK, "variable1"},
	ColumnValues: ColumnValues{
		"log_id":   "1",
		"variable1": "value1",
	},
	ForeignKeyValues: shared.ForeignKeyValues{
		constants.IlkFK: test_helpers.FakeIlk.Hex,
		constants.UrnFK: "0x12345",
	},
}

func DecodeHexToText added in v0.2.4

func DecodeHexToText(payload string) string

func FormatRollbackError added in v0.2.12

func FormatRollbackError(field, err string) error

func GenerateInsertionQuery added in v0.2.12

func GenerateInsertionQuery(model InsertionModel) string

Creates an insertion query from an insertion model. This is called through GetMemoizedQuery, so the query is not generated on each call to Create. Note: With extraction of event metadata, one would not have to supply header_id, tx_idx, etc in InsertionModel.OrderedColumns? Note: I have a feeling we can actually do away with the OrderedColumns field, but the tricky part is that some fields

needed aren't present in the map in the beginning

func GetEventTransformerConfig added in v0.2.10

func GetEventTransformerConfig(transformerLabel, signature string) transformer.EventTransformerConfig

Creates a transformer config by pulling values from configuration environment

func GetLogNoteArgumentAtIndex added in v0.2.6

func GetLogNoteArgumentAtIndex(index int, logData []byte) ([]byte, error)

func GetMemoizedQuery added in v0.2.12

func GetMemoizedQuery(model InsertionModel) string

func GetOrCreateAddress added in v0.2.12

func GetOrCreateAddress(address string, db *postgres.DB) (int64, error)

func GetOrCreateAddressInTransaction added in v0.2.12

func GetOrCreateAddressInTransaction(address string, tx *sqlx.Tx) (int64, error)

func GetOrCreateIlk

func GetOrCreateIlk(ilk string, db *postgres.DB) (int64, error)

func GetOrCreateIlkInTransaction

func GetOrCreateIlkInTransaction(ilk string, tx *sqlx.Tx) (int64, error)

func GetOrCreateUrn added in v0.2.2

func GetOrCreateUrn(guy string, hexIlk string, db *postgres.DB) (urnID int64, err error)

func GetOrCreateUrnInTransaction added in v0.2.2

func GetOrCreateUrnInTransaction(guy string, hexIlk string, tx *sqlx.Tx) (urnID int64, err error)

func MinInt64

func MinInt64(ints []int64) (min int64)

func PopulateForeignKeyIDs added in v0.2.12

func PopulateForeignKeyIDs(fkToValue ForeignKeyValues, columnToValue ColumnValues, tx *sqlx.Tx) error

Gets or creates the FK for the key/values supplied, and inserts the resulting ID into the columnToValue mapping

func VerifyLog added in v0.2.12

func VerifyLog(log types.Log, expectedNumTopics int, isDataRequired bool) error

Types

type ColumnValues added in v0.2.8

type ColumnValues map[string]interface{}

type Converter added in v0.2.13

type Converter interface {
	ToModels(contractAbi string, ethLog []core.HeaderSyncLog) ([]InsertionModel, error)
}

TODO purge when everything moved to vDB interface

type EventTransformer added in v0.2.13

type EventTransformer struct {
	Config     transformer.EventTransformerConfig
	Converter  Converter
	Repository SharedRepository
}

func (EventTransformer) Execute added in v0.2.13

func (tr EventTransformer) Execute(logs []core.HeaderSyncLog) error

func (EventTransformer) GetConfig added in v0.2.13

func (EventTransformer) GetName added in v0.2.13

func (tr EventTransformer) GetName() string

func (EventTransformer) NewEventTransformer added in v0.2.13

func (tr EventTransformer) NewEventTransformer(db *postgres.DB) transformer.EventTransformer

type ForeignKeyValues added in v0.2.8

type ForeignKeyValues map[constants.ForeignKeyField]string

type InsertionModel added in v0.2.8

type InsertionModel struct {
	SchemaName     string
	TableName      string   // For MarkHeaderChecked, insert query
	OrderedColumns []string // Defines the fields to insert, and in which order the table expects them
	// ColumnValues needs to be typed interface{}, since `raw_log` is a slice of bytes and not a string
	ColumnValues     ColumnValues     // Associated values for columns, headerID, FKs and event metadata populated automatically
	ForeignKeyValues ForeignKeyValues // FK name and value to get/create ID for
}

type SharedRepository added in v0.2.8

type SharedRepository interface {
	Create(models []InsertionModel) error
	SetDB(db *postgres.DB)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL