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