2019-10-09 14:22:53 +00:00
|
|
|
package gethbridge
|
|
|
|
|
|
|
|
import (
|
2019-11-23 17:57:05 +00:00
|
|
|
"github.com/status-im/status-go/eth-node/types"
|
2019-12-09 10:36:14 +00:00
|
|
|
"github.com/status-im/status-go/whisper/v6"
|
2019-10-09 14:22:53 +00:00
|
|
|
)
|
|
|
|
|
2019-11-23 17:57:05 +00:00
|
|
|
// NewGethEnvelopeEventWrapper returns a types.EnvelopeEvent object that mimics Geth's EnvelopeEvent
|
|
|
|
func NewGethEnvelopeEventWrapper(envelopeEvent *whisper.EnvelopeEvent) *types.EnvelopeEvent {
|
2019-10-09 14:22:53 +00:00
|
|
|
if envelopeEvent == nil {
|
|
|
|
panic("envelopeEvent should not be nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
wrappedData := envelopeEvent.Data
|
|
|
|
switch data := envelopeEvent.Data.(type) {
|
|
|
|
case []whisper.EnvelopeError:
|
2019-11-23 17:57:05 +00:00
|
|
|
wrappedData := make([]types.EnvelopeError, len(data))
|
2019-10-09 14:22:53 +00:00
|
|
|
for index, envError := range data {
|
|
|
|
wrappedData[index] = *NewGethEnvelopeErrorWrapper(&envError)
|
|
|
|
}
|
|
|
|
case *whisper.MailServerResponse:
|
|
|
|
wrappedData = NewGethMailServerResponseWrapper(data)
|
|
|
|
case whisper.SyncEventResponse:
|
|
|
|
wrappedData = NewGethSyncEventResponseWrapper(data)
|
|
|
|
}
|
2019-11-23 17:57:05 +00:00
|
|
|
return &types.EnvelopeEvent{
|
|
|
|
Event: types.EventType(envelopeEvent.Event),
|
|
|
|
Hash: types.Hash(envelopeEvent.Hash),
|
|
|
|
Batch: types.Hash(envelopeEvent.Batch),
|
|
|
|
Peer: types.EnodeID(envelopeEvent.Peer),
|
2019-10-09 14:22:53 +00:00
|
|
|
Data: wrappedData,
|
|
|
|
}
|
|
|
|
}
|