code: func (stack *TxStack) Consume(ev *StreamEvent) *TxExecution {
  	switch {
  	case ev.BeginTx != nil:
  		stack.Push(initTx(ev.BeginTx))
  	case ev.Envelope != nil:
  		txe := stack.Peek()
  		txe.Envelope = ev.Envelope
  		txe.Receipt = txe.Envelope.Tx.GenerateReceipt()
  	case ev.Event != nil:
  		txe := stack.Peek()
  		txe.Events = append(txe.Events, ev.Event)
  	case ev.EndTx != nil:
  		txe := stack.Pop()
  		if len(*stack) == 0 {
  			// This terminates the outermost transaction
  			return txe
  		}
  		// If there is a parent tx on the stack add this tx as child
  		parent := stack.Peek()
  		parent.TxExecutions = append(parent.TxExecutions, txe)
  	}
  	return nil
  }
docs: // Consume will add the StreamEvent to the transaction stack and if that completes a single outermost transaction
  // returns the TxExecution otherwise will return nil