status-go/protocol/bridge/geth/envelope_error.go

31 lines
947 B
Go
Raw Normal View History

package gethbridge
import (
whispertypes "github.com/status-im/status-go/protocol/transport/whisper/types"
protocol "github.com/status-im/status-go/protocol/types"
whisper "github.com/status-im/whisper/whisperv6"
)
// NewGethEnvelopeErrorWrapper returns a whispertypes.EnvelopeError object that mimics Geth's EnvelopeError
func NewGethEnvelopeErrorWrapper(envelopeError *whisper.EnvelopeError) *whispertypes.EnvelopeError {
if envelopeError == nil {
panic("envelopeError should not be nil")
}
return &whispertypes.EnvelopeError{
Hash: protocol.Hash(envelopeError.Hash),
Code: mapGethErrorCode(envelopeError.Code),
Description: envelopeError.Description,
}
}
func mapGethErrorCode(code uint) uint {
switch code {
case whisper.EnvelopeTimeNotSynced:
return whispertypes.EnvelopeTimeNotSynced
case whisper.EnvelopeOtherError:
return whispertypes.EnvelopeOtherError
}
return whispertypes.EnvelopeOtherError
}