Documentation

Index

Constants

View Source
const (
	EventFieldTypeInt     = "int"
	EventFieldTypeUInt    = "uint"
	EventFieldTypeAddress = "address"
	EventFieldTypeBytes   = "bytes"
	EventFieldTypeBool    = "bool"
	EventFieldTypeString  = "string"
)

    Defined event input types - these are currently align with EVM types but they technically define a pair/mapping of EVM type -> SQL type

    View Source
    const (
    	PostgresDB = "postgres"
    	SQLiteDB   = "sqlite"
    )

      supported databases

      View Source
      const (
      	// event related
      	EventNameLabel  = "eventName"
      	EventTypeLabel  = "eventType"
      	EventIndexLabel = "eventIndex"
      
      	// block related
      	ChainIDLabel     = "chainID"
      	BlockHeightLabel = "height"
      	TxIndexLabel     = "txIndex"
      
      	// transaction related
      	TxTxHashLabel = "txHash"
      )

        labels for column mapping

        Variables

        View Source
        var DefaultSQLColumnNames = SQLColumnNames{
        
        	Id:          "_id",
        	TimeStamp:   "_timestamp",
        	TableName:   "_tablename",
        	EventName:   "_eventname",
        	EventFilter: "_eventfilter",
        	Height:      "_height",
        	TxHash:      "_txhash",
        	Action:      "_action",
        	DataRow:     "_datarow",
        	SqlStmt:     "_sqlstmt",
        	SqlValues:   "_sqlvalues",
        
        	ColumnName:   "_columnname",
        	ColumnType:   "_columntype",
        	ColumnLength: "_columnlength",
        	PrimaryKey:   "_primarykey",
        	ColumnOrder:  "_columnorder",
        
        	BurrowVersion: "_burrowversion",
        	ChainID:       "_chainid",
        
        	TxIndex:     "_txindex",
        	EventIndex:  "_eventindex",
        	EventType:   "_eventtype",
        	BlockHeader: "_blockheader",
        	TxType:      "_txtype",
        	Envelope:    "_envelope",
        	Events:      "_events",
        	Result:      "_result",
        	Receipt:     "_receipt",
        	Origin:      "_origin",
        	Exception:   "_exception",
        }
        View Source
        var DefaultSQLNames = SQLNames{
        	Tables:  DefaultSQLTableNames,
        	Columns: DefaultSQLColumnNames,
        }
        View Source
        var DefaultSQLTableNames = SQLTableNames{
        	Log:        "_vent_log",
        	Dictionary: "_vent_dictionary",
        	Block:      "_vent_block",
        	Tx:         "_vent_tx",
        	ChainInfo:  "_vent_chain",
        }

        Functions

        func ProjectionSpecSchema

        func ProjectionSpecSchema() *jsonschema.Schema

        Types

        type DBAction

        type DBAction string

          DBAction generic type

          const (
          	ActionDelete      DBAction = "DELETE"
          	ActionUpsert      DBAction = "UPSERT"
          	ActionRead        DBAction = "READ"
          	ActionCreateTable DBAction = "CREATE"
          	ActionAlterTable  DBAction = "ALTER"
          )

          type EventClass

          type EventClass struct {
          	// Destination table in DB
          	TableName string
          	// Burrow event filter query in query peg grammar
          	Filter string
          	// The name of a solidity event field that when present indicates that the rest of the event should be interpreted
          	// as requesting a row deletion (rather than upsert) in the projection table.
          	DeleteMarkerField string `json:",omitempty"`
          	// EventFieldMapping from solidity event field name to EventFieldMapping descriptor
          	FieldMappings []*EventFieldMapping
          	// contains filtered or unexported fields
          }

            EventClass struct (table name where to persist filtered events and it structure)

            func (*EventClass) GetFieldMapping

            func (ec *EventClass) GetFieldMapping(fieldName string) *EventFieldMapping

            func (*EventClass) GetFilter

            func (ec *EventClass) GetFilter() string

            func (*EventClass) Query

            func (ec *EventClass) Query() (query.Query, error)

              Get a (memoised) Query from the EventClass Filter string

              func (*EventClass) Validate

              func (ec *EventClass) Validate() error

                Validate checks the structure of an EventClass

                type EventData

                type EventData struct {
                	BlockHeight uint64
                	Tables      map[string]EventDataTable
                }

                  EventData contains data for each block of events already mapped to SQL columns & tables Tables map key is the table name

                  type EventDataRow

                  type EventDataRow struct {
                  	Action  DBAction
                  	RowData map[string]interface{}
                  	// The EventClass that caused this row to be emitted (if it was caused by an specific event)
                  	EventClass *EventClass `json:"-"`
                  }

                    EventDataRow contains each SQL column name and a corresponding value to upsert map key is the column name and map value is the given column value if Action == 'delete' then the row has to be deleted

                    type EventDataTable

                    type EventDataTable []EventDataRow

                      EventDataTable is an array of rows

                      type EventFieldMapping

                      type EventFieldMapping struct {
                      	// EVM event field name to process
                      	Field string
                      	// EVM type of this field - used to derive SQL type
                      	Type string
                      	// Destination SQL column name to which to map this event field
                      	ColumnName string
                      	// Whether this event field should map to a primary key
                      	Primary bool `json:",omitempty"`
                      	// Whether to convert this event field from bytes32 to string
                      	BytesToString bool `json:",omitempty"`
                      	// Whether to convert this event field from bytes32 to hex-encoded string
                      	BytesToHex bool `json:",omitempty"`
                      	// Notification channels on which submit (via a trigger) a payload that contains this column's new value (upsert) or
                      	// old value (delete). The payload will contain all other values with the same channel set as a JSON object.
                      	Notify []string `json:",omitempty"`
                      }

                        EventFieldMapping struct (table column definition)

                        func (EventFieldMapping) Validate

                        func (evColumn EventFieldMapping) Validate() error

                          Validate checks the structure of an EventFieldMapping

                          type EventTables

                          type EventTables map[string]*SQLTable

                            EventTables contains SQL tables definition Map from TableName to SQLTable

                            type ProjectionSpec

                            type ProjectionSpec []*EventClass

                              ProjectionSpec contains all event class specifications

                              type SQLCleanDBQuery

                              type SQLCleanDBQuery struct {
                              	SelectChainIDQry    string
                              	DeleteChainIDQry    string
                              	InsertChainIDQry    string
                              	SelectDictionaryQry string
                              	DeleteDictionaryQry string
                              	DeleteLogQry        string
                              }

                                SQLCleanDBQuery stores queries needed to clean the database

                                type SQLColumnNames

                                type SQLColumnNames struct {
                                	// log
                                	Id          string
                                	TimeStamp   string
                                	TableName   string
                                	EventName   string
                                	EventFilter string
                                	Height      string
                                	TxHash      string
                                	Action      string
                                	DataRow     string
                                	SqlStmt     string
                                	SqlValues   string
                                	// dictionary
                                	ColumnName   string
                                	ColumnType   string
                                	ColumnLength string
                                	PrimaryKey   string
                                	ColumnOrder  string
                                	// chain info
                                	BurrowVersion string
                                	ChainID       string
                                	// context
                                	TxIndex     string
                                	EventIndex  string
                                	EventType   string
                                	BlockHeader string
                                	TxType      string
                                	Envelope    string
                                	Events      string
                                	Result      string
                                	Receipt     string
                                	Origin      string
                                	Exception   string
                                }

                                type SQLColumnType

                                type SQLColumnType int

                                  SQLColumnType to store generic SQL column types

                                  const (
                                  	SQLColumnTypeBool SQLColumnType = iota
                                  	SQLColumnTypeByteA
                                  	SQLColumnTypeInt
                                  	SQLColumnTypeSerial
                                  	SQLColumnTypeText
                                  	SQLColumnTypeVarchar
                                  	SQLColumnTypeTimeStamp
                                  	SQLColumnTypeNumeric
                                  	SQLColumnTypeJSON
                                  	SQLColumnTypeBigInt
                                  )

                                    generic SQL column types

                                    func (SQLColumnType) IsNumeric

                                    func (ct SQLColumnType) IsNumeric() bool

                                      IsNumeric determines if an sqlColumnType is numeric

                                      func (SQLColumnType) String

                                      func (ct SQLColumnType) String() string

                                      type SQLConnection

                                      type SQLConnection struct {
                                      	DBAdapter string
                                      	DBURL     string
                                      	DBSchema  string
                                      	Log       *logging.Logger
                                      }

                                        SQLConnection stores parameters to build a new db connection & initialize the database

                                        type SQLErrorType

                                        type SQLErrorType int

                                          SQLErrorType stores generic SQL error types

                                          const (
                                          	SQLErrorTypeDuplicatedSchema SQLErrorType = iota
                                          	SQLErrorTypeDuplicatedColumn
                                          	SQLErrorTypeDuplicatedTable
                                          	SQLErrorTypeInvalidType
                                          	SQLErrorTypeUndefinedTable
                                          	SQLErrorTypeUndefinedColumn
                                          	SQLErrorTypeGeneric
                                          )

                                            generic SQL error types

                                            type SQLNames

                                            type SQLNames struct {
                                            	Tables  SQLTableNames
                                            	Columns SQLColumnNames
                                            }

                                            type SQLTable

                                            type SQLTable struct {
                                            	Name    string
                                            	Columns []*SQLTableColumn
                                            	// Map of channel name -> columns to be sent as payload on that channel
                                            	NotifyChannels map[string][]string
                                            	// contains filtered or unexported fields
                                            }

                                              SQLTable contains the structure of a SQL table,

                                              func (*SQLTable) GetColumn

                                              func (table *SQLTable) GetColumn(columnName string) *SQLTableColumn

                                              type SQLTableColumn

                                              type SQLTableColumn struct {
                                              	Name    string
                                              	Type    SQLColumnType
                                              	Primary bool
                                              	// Length of variable column type where applicable 0 indicates variable/unbounded length
                                              	Length int
                                              }

                                                SQLTableColumn contains the definition of a SQL table column, the Order is given to be able to sort the columns to be created

                                                func (*SQLTableColumn) Equals

                                                func (col *SQLTableColumn) Equals(otherCol *SQLTableColumn) bool

                                                func (*SQLTableColumn) String

                                                func (col *SQLTableColumn) String() string

                                                type SQLTableNames

                                                type SQLTableNames struct {
                                                	Log        string
                                                	Dictionary string
                                                	Block      string
                                                	Tx         string
                                                	ChainInfo  string
                                                }

                                                type UpsertDeleteQuery

                                                type UpsertDeleteQuery struct {
                                                	Query    string
                                                	Values   string
                                                	Pointers []interface{}
                                                }

                                                  UpsertDeleteQuery contains query and values to upsert or delete row data