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"
|
2020-01-13 19:17:30 +00:00
|
|
|
"github.com/status-im/status-go/waku"
|
2019-12-09 10:36:14 +00:00
|
|
|
"github.com/status-im/status-go/whisper/v6"
|
2019-10-09 14:22:53 +00:00
|
|
|
)
|
|
|
|
|
2020-01-13 19:17:30 +00:00
|
|
|
// NewWhisperEnvelopeEventWrapper returns a types.EnvelopeEvent object that mimics Geth's EnvelopeEvent
|
|
|
|
func NewWhisperEnvelopeEventWrapper(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 {
|
2020-01-13 19:17:30 +00:00
|
|
|
wrappedData[index] = *NewWhisperEnvelopeErrorWrapper(&envError)
|
2019-10-09 14:22:53 +00:00
|
|
|
}
|
|
|
|
case *whisper.MailServerResponse:
|
2020-01-13 19:17:30 +00:00
|
|
|
wrappedData = NewWhisperMailServerResponseWrapper(data)
|
2019-10-09 14:22:53 +00:00
|
|
|
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,
|
|
|
|
}
|
|
|
|
}
|
2020-01-13 19:17:30 +00:00
|
|
|
|
|
|
|
// NewWakuEnvelopeEventWrapper returns a types.EnvelopeEvent object that mimics Geth's EnvelopeEvent
|
|
|
|
func NewWakuEnvelopeEventWrapper(envelopeEvent *waku.EnvelopeEvent) *types.EnvelopeEvent {
|
|
|
|
if envelopeEvent == nil {
|
|
|
|
panic("envelopeEvent should not be nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
wrappedData := envelopeEvent.Data
|
|
|
|
switch data := envelopeEvent.Data.(type) {
|
|
|
|
case []waku.EnvelopeError:
|
|
|
|
wrappedData := make([]types.EnvelopeError, len(data))
|
|
|
|
for index, envError := range data {
|
|
|
|
wrappedData[index] = *NewWakuEnvelopeErrorWrapper(&envError)
|
|
|
|
}
|
|
|
|
case *waku.MailServerResponse:
|
|
|
|
wrappedData = NewWakuMailServerResponseWrapper(data)
|
|
|
|
}
|
|
|
|
return &types.EnvelopeEvent{
|
|
|
|
Event: types.EventType(envelopeEvent.Event),
|
|
|
|
Hash: types.Hash(envelopeEvent.Hash),
|
|
|
|
Batch: types.Hash(envelopeEvent.Batch),
|
|
|
|
Peer: types.EnodeID(envelopeEvent.Peer),
|
|
|
|
Data: wrappedData,
|
|
|
|
}
|
|
|
|
}
|