mirror of
https://github.com/status-im/status-go.git
synced 2025-02-06 11:56:01 +00:00
chore_: remove waku's NewMessage
duplication
This commit is contained in:
parent
495ecb3f05
commit
c3c9d0f454
@ -94,18 +94,5 @@ func (w *GethPublicWakuAPIWrapper) GetFilterMessages(id string) ([]*wakutypes.Me
|
||||
// Post posts a message on the network.
|
||||
// returns the hash of the message in case of success.
|
||||
func (w *GethPublicWakuAPIWrapper) Post(ctx context.Context, req wakutypes.NewMessage) ([]byte, error) {
|
||||
msg := wakuv1.NewMessage{
|
||||
SymKeyID: req.SymKeyID,
|
||||
PublicKey: req.PublicKey,
|
||||
Sig: req.SigID, // Sig is really a SigID
|
||||
TTL: req.TTL,
|
||||
Topic: wakuv1common.TopicType(req.Topic),
|
||||
Payload: req.Payload,
|
||||
Padding: req.Padding,
|
||||
PowTime: req.PowTime,
|
||||
PowTarget: req.PowTarget,
|
||||
TargetPeer: req.TargetPeer,
|
||||
Ephemeral: req.Ephemeral,
|
||||
}
|
||||
return w.api.Post(ctx, msg)
|
||||
return w.api.Post(ctx, req)
|
||||
}
|
||||
|
@ -91,17 +91,5 @@ func (w *gethPublicWakuV2APIWrapper) GetFilterMessages(id string) ([]*wakutypes.
|
||||
// Post posts a message on the network.
|
||||
// returns the hash of the message in case of success.
|
||||
func (w *gethPublicWakuV2APIWrapper) Post(ctx context.Context, req wakutypes.NewMessage) ([]byte, error) {
|
||||
msg := wakuv2.NewMessage{
|
||||
SymKeyID: req.SymKeyID,
|
||||
PublicKey: req.PublicKey,
|
||||
Sig: req.SigID, // Sig is really a SigID
|
||||
PubsubTopic: req.PubsubTopic,
|
||||
ContentTopic: wakucommon.TopicType(req.Topic),
|
||||
Payload: req.Payload,
|
||||
Padding: req.Padding,
|
||||
TargetPeer: req.TargetPeer,
|
||||
Ephemeral: req.Ephemeral,
|
||||
Priority: req.Priority,
|
||||
}
|
||||
return w.api.Post(ctx, msg)
|
||||
return w.api.Post(ctx, req)
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ import (
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/status-im/status-go/logutils"
|
||||
"github.com/status-im/status-go/waku/types"
|
||||
"github.com/status-im/status-go/wakuv1/common"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
@ -209,24 +210,9 @@ func (api *PublicWakuAPI) CancelLightClient(ctx context.Context) bool {
|
||||
return !api.w.LightClientMode()
|
||||
}
|
||||
|
||||
// NewMessage represents a new waku message that is posted through the RPC.
|
||||
type NewMessage struct {
|
||||
SymKeyID string `json:"symKeyID"`
|
||||
PublicKey []byte `json:"pubKey"`
|
||||
Sig string `json:"sig"`
|
||||
TTL uint32 `json:"ttl"`
|
||||
Topic common.TopicType `json:"topic"`
|
||||
Payload []byte `json:"payload"`
|
||||
Padding []byte `json:"padding"`
|
||||
PowTime uint32 `json:"powTime"`
|
||||
PowTarget float64 `json:"powTarget"`
|
||||
TargetPeer string `json:"targetPeer"`
|
||||
Ephemeral bool `json:"ephemeral"`
|
||||
}
|
||||
|
||||
// Post posts a message on the Waku network.
|
||||
// returns the hash of the message in case of success.
|
||||
func (api *PublicWakuAPI) Post(ctx context.Context, req NewMessage) (hexutil.Bytes, error) {
|
||||
func (api *PublicWakuAPI) Post(ctx context.Context, req types.NewMessage) (hexutil.Bytes, error) {
|
||||
var (
|
||||
symKeyGiven = len(req.SymKeyID) > 0
|
||||
pubKeyGiven = len(req.PublicKey) > 0
|
||||
@ -244,12 +230,12 @@ func (api *PublicWakuAPI) Post(ctx context.Context, req NewMessage) (hexutil.Byt
|
||||
Padding: req.Padding,
|
||||
WorkTime: req.PowTime,
|
||||
PoW: req.PowTarget,
|
||||
Topic: req.Topic,
|
||||
Topic: common.TopicType(req.Topic),
|
||||
}
|
||||
|
||||
// Set key that is used to sign the message
|
||||
if len(req.Sig) > 0 {
|
||||
if params.Src, err = api.w.GetPrivateKey(req.Sig); err != nil {
|
||||
if len(req.SigID) > 0 {
|
||||
if params.Src, err = api.w.GetPrivateKey(req.SigID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ import (
|
||||
"github.com/waku-org/go-waku/waku/v2/protocol/pb"
|
||||
|
||||
"github.com/status-im/status-go/logutils"
|
||||
"github.com/status-im/status-go/waku/types"
|
||||
"github.com/status-im/status-go/wakuv2/common"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
@ -173,23 +174,9 @@ func (api *PublicWakuAPI) BloomFilter() []byte {
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewMessage represents a new waku message that is posted through the RPC.
|
||||
type NewMessage struct {
|
||||
SymKeyID string `json:"symKeyID"`
|
||||
PublicKey []byte `json:"pubKey"`
|
||||
Sig string `json:"sig"`
|
||||
PubsubTopic string `json:"pubsubTopic"`
|
||||
ContentTopic common.TopicType `json:"topic"`
|
||||
Payload []byte `json:"payload"`
|
||||
Padding []byte `json:"padding"`
|
||||
TargetPeer string `json:"targetPeer"`
|
||||
Ephemeral bool `json:"ephemeral"`
|
||||
Priority *int `json:"priority"`
|
||||
}
|
||||
|
||||
// Post posts a message on the Waku network.
|
||||
// returns the hash of the message in case of success.
|
||||
func (api *PublicWakuAPI) Post(ctx context.Context, req NewMessage) (hexutil.Bytes, error) {
|
||||
func (api *PublicWakuAPI) Post(ctx context.Context, req types.NewMessage) (hexutil.Bytes, error) {
|
||||
var (
|
||||
symKeyGiven = len(req.SymKeyID) > 0
|
||||
pubKeyGiven = len(req.PublicKey) > 0
|
||||
@ -204,19 +191,21 @@ func (api *PublicWakuAPI) Post(ctx context.Context, req NewMessage) (hexutil.Byt
|
||||
var keyInfo *payload.KeyInfo = new(payload.KeyInfo)
|
||||
|
||||
// Set key that is used to sign the message
|
||||
if len(req.Sig) > 0 {
|
||||
privKey, err := api.w.GetPrivateKey(req.Sig)
|
||||
if len(req.SigID) > 0 {
|
||||
privKey, err := api.w.GetPrivateKey(req.SigID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
keyInfo.PrivKey = privKey
|
||||
}
|
||||
|
||||
contentTopic := common.TopicType(req.Topic)
|
||||
|
||||
// Set symmetric key that is used to encrypt the message
|
||||
if symKeyGiven {
|
||||
keyInfo.Kind = payload.Symmetric
|
||||
|
||||
if req.ContentTopic == (common.TopicType{}) { // topics are mandatory with symmetric encryption
|
||||
if contentTopic == (common.TopicType{}) { // topics are mandatory with symmetric encryption
|
||||
return nil, ErrNoTopics
|
||||
}
|
||||
if keyInfo.SymKey, err = api.w.GetSymKey(req.SymKeyID); err != nil {
|
||||
@ -252,7 +241,7 @@ func (api *PublicWakuAPI) Post(ctx context.Context, req NewMessage) (hexutil.Byt
|
||||
wakuMsg := &pb.WakuMessage{
|
||||
Payload: payload,
|
||||
Version: &version,
|
||||
ContentTopic: req.ContentTopic.ContentTopic(),
|
||||
ContentTopic: contentTopic.ContentTopic(),
|
||||
Timestamp: proto.Int64(api.w.timestamp()),
|
||||
Meta: []byte{}, // TODO: empty for now. Once we use Waku Archive v2, we should deprecate the timestamp and use an ULID here
|
||||
Ephemeral: &req.Ephemeral,
|
||||
|
Loading…
x
Reference in New Issue
Block a user