github.com/Tri-stone/burrow@v0.25.0/vent/sqlsol/block_data.go (about)

     1  package sqlsol
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/hyperledger/burrow/vent/types"
     7  )
     8  
     9  // BlockData contains EventData definition
    10  type BlockData struct {
    11  	Data types.EventData
    12  }
    13  
    14  // NewBlockData returns a pointer to an empty BlockData structure
    15  func NewBlockData(height uint64) *BlockData {
    16  	data := types.EventData{
    17  		Tables:      make(map[string]types.EventDataTable),
    18  		BlockHeight: height,
    19  	}
    20  
    21  	return &BlockData{
    22  		Data: data,
    23  	}
    24  }
    25  
    26  // AddRow appends a row to a specific table name in structure
    27  func (b *BlockData) AddRow(tableName string, row types.EventDataRow) {
    28  	if _, ok := b.Data.Tables[tableName]; !ok {
    29  		b.Data.Tables[tableName] = types.EventDataTable{}
    30  	}
    31  	b.Data.Tables[tableName] = append(b.Data.Tables[tableName], row)
    32  }
    33  
    34  // GetRows gets data rows for a given table name from structure
    35  func (b *BlockData) GetRows(tableName string) (types.EventDataTable, error) {
    36  	if table, ok := b.Data.Tables[tableName]; ok {
    37  		return table, nil
    38  	}
    39  	return nil, fmt.Errorf("GetRows: tableName does not exists as a table in data structure: %s ", tableName)
    40  }
    41  
    42  // PendingRows returns true if the given block has at least one pending row to upsert
    43  func (b *BlockData) PendingRows(height uint64) bool {
    44  	hasRows := false
    45  	// TODO: understand why the guard on height is needed - what does it prevent?
    46  	if b.Data.BlockHeight == height && len(b.Data.Tables) > 0 {
    47  		hasRows = true
    48  	}
    49  	return hasRows
    50  }