github.com/koko1123/flow-go-1@v0.29.6/engine/access/rest/models/event.go (about)

     1  package models
     2  
     3  import (
     4  	"github.com/koko1123/flow-go-1/engine/access/rest/util"
     5  	"github.com/koko1123/flow-go-1/model/flow"
     6  )
     7  
     8  func (e *Event) Build(event flow.Event) {
     9  	e.Type_ = string(event.Type)
    10  	e.TransactionId = event.TransactionID.String()
    11  	e.TransactionIndex = util.FromUint64(uint64(event.TransactionIndex))
    12  	e.EventIndex = util.FromUint64(uint64(event.EventIndex))
    13  	e.Payload = util.ToBase64(event.Payload)
    14  }
    15  
    16  type Events []Event
    17  
    18  func (e *Events) Build(events []flow.Event) {
    19  	evs := make([]Event, len(events))
    20  	for i, ev := range events {
    21  		var event Event
    22  		event.Build(ev)
    23  		evs[i] = event
    24  	}
    25  
    26  	*e = evs
    27  }
    28  
    29  func (b *BlockEvents) Build(blockEvents flow.BlockEvents) {
    30  	b.BlockHeight = util.FromUint64(blockEvents.BlockHeight)
    31  	b.BlockId = blockEvents.BlockID.String()
    32  	b.BlockTimestamp = blockEvents.BlockTimestamp
    33  
    34  	var events Events
    35  	events.Build(blockEvents.Events)
    36  	b.Events = events
    37  }
    38  
    39  type BlocksEvents []BlockEvents
    40  
    41  func (b *BlocksEvents) Build(blocksEvents []flow.BlockEvents) {
    42  	evs := make([]BlockEvents, 0)
    43  	for _, ev := range blocksEvents {
    44  		// don't include blocks without events
    45  		if len(ev.Events) == 0 {
    46  			continue
    47  		}
    48  
    49  		var blockEvent BlockEvents
    50  		blockEvent.Build(ev)
    51  		evs = append(evs, blockEvent)
    52  	}
    53  
    54  	*b = evs
    55  }