mirror of
https://github.com/status-im/status-go.git
synced 2025-02-11 14:26:53 +00:00
chore_: remove waku api wrappers
This commit is contained in:
parent
b2bb680ccc
commit
69855f2e36
@ -13,24 +13,24 @@ import (
|
|||||||
type testWakuWrapper struct {
|
type testWakuWrapper struct {
|
||||||
*bridge.GethWakuWrapper
|
*bridge.GethWakuWrapper
|
||||||
|
|
||||||
publicWakuAPIWrapper *testPublicWakuAPIWrapper
|
api *testPublicWakuAPI
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTestWaku(w *wakuv1.Waku) wakutypes.Waku {
|
func newTestWaku(w *wakuv1.Waku) wakutypes.Waku {
|
||||||
wrapper := bridge.NewGethWakuWrapper(w)
|
wrapper := bridge.NewGethWakuWrapper(w)
|
||||||
return &testWakuWrapper{
|
return &testWakuWrapper{
|
||||||
GethWakuWrapper: wrapper.(*bridge.GethWakuWrapper),
|
GethWakuWrapper: wrapper.(*bridge.GethWakuWrapper),
|
||||||
publicWakuAPIWrapper: newTestPublicWakuAPI(wakuv1.NewPublicWakuAPI(w)).(*testPublicWakuAPIWrapper),
|
api: newTestPublicWakuAPI(wakuv1.NewPublicWakuAPI(w)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tw *testWakuWrapper) PublicWakuAPI() wakutypes.PublicWakuAPI {
|
func (tw *testWakuWrapper) PublicWakuAPI() wakutypes.PublicWakuAPI {
|
||||||
return tw.publicWakuAPIWrapper
|
return tw.api
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tw *testWakuWrapper) SubscribePostEvents() chan *PostMessageSubscription {
|
func (tw *testWakuWrapper) SubscribePostEvents() chan *PostMessageSubscription {
|
||||||
subscription := make(chan *PostMessageSubscription, 100)
|
subscription := make(chan *PostMessageSubscription, 100)
|
||||||
tw.publicWakuAPIWrapper.postSubscriptions = append(tw.publicWakuAPIWrapper.postSubscriptions, subscription)
|
tw.api.postSubscriptions = append(tw.api.postSubscriptions, subscription)
|
||||||
return subscription
|
return subscription
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,21 +39,20 @@ type PostMessageSubscription struct {
|
|||||||
msg *wakutypes.NewMessage
|
msg *wakutypes.NewMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
type testPublicWakuAPIWrapper struct {
|
type testPublicWakuAPI struct {
|
||||||
*bridge.GethPublicWakuAPIWrapper
|
*wakuv1.PublicWakuAPI
|
||||||
|
|
||||||
postSubscriptions []chan *PostMessageSubscription
|
postSubscriptions []chan *PostMessageSubscription
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTestPublicWakuAPI(api *wakuv1.PublicWakuAPI) wakutypes.PublicWakuAPI {
|
func newTestPublicWakuAPI(api *wakuv1.PublicWakuAPI) *testPublicWakuAPI {
|
||||||
wrapper := bridge.NewGethPublicWakuAPIWrapper(api)
|
return &testPublicWakuAPI{
|
||||||
return &testPublicWakuAPIWrapper{
|
PublicWakuAPI: api,
|
||||||
GethPublicWakuAPIWrapper: wrapper.(*bridge.GethPublicWakuAPIWrapper),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tp *testPublicWakuAPIWrapper) Post(ctx context.Context, req wakutypes.NewMessage) ([]byte, error) {
|
func (tp *testPublicWakuAPI) Post(ctx context.Context, req wakutypes.NewMessage) ([]byte, error) {
|
||||||
id, err := tp.GethPublicWakuAPIWrapper.Post(ctx, req)
|
id, err := tp.PublicWakuAPI.Post(ctx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -1,64 +0,0 @@
|
|||||||
package bridge
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
|
||||||
|
|
||||||
"github.com/status-im/status-go/eth-node/types"
|
|
||||||
"github.com/status-im/status-go/wakuv1"
|
|
||||||
|
|
||||||
wakutypes "github.com/status-im/status-go/waku/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
type GethPublicWakuAPIWrapper struct {
|
|
||||||
api *wakuv1.PublicWakuAPI
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewGethPublicWakuAPIWrapper returns an object that wraps Geth's PublicWakuAPI in a types interface
|
|
||||||
func NewGethPublicWakuAPIWrapper(api *wakuv1.PublicWakuAPI) wakutypes.PublicWakuAPI {
|
|
||||||
if api == nil {
|
|
||||||
panic("PublicWakuAPI cannot be nil")
|
|
||||||
}
|
|
||||||
|
|
||||||
return &GethPublicWakuAPIWrapper{
|
|
||||||
api: api,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddPrivateKey imports the given private key.
|
|
||||||
func (w *GethPublicWakuAPIWrapper) AddPrivateKey(ctx context.Context, privateKey types.HexBytes) (string, error) {
|
|
||||||
return w.api.AddPrivateKey(ctx, hexutil.Bytes(privateKey))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GenerateSymKeyFromPassword derives a key from the given password, stores it, and returns its ID.
|
|
||||||
func (w *GethPublicWakuAPIWrapper) GenerateSymKeyFromPassword(ctx context.Context, passwd string) (string, error) {
|
|
||||||
return w.api.GenerateSymKeyFromPassword(ctx, passwd)
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeleteKeyPair removes the key with the given key if it exists.
|
|
||||||
func (w *GethPublicWakuAPIWrapper) DeleteKeyPair(ctx context.Context, key string) (bool, error) {
|
|
||||||
return w.api.DeleteKeyPair(ctx, key)
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewMessageFilter creates a new filter that can be used to poll for
|
|
||||||
// (new) messages that satisfy the given criteria.
|
|
||||||
func (w *GethPublicWakuAPIWrapper) NewMessageFilter(req wakutypes.Criteria) (string, error) {
|
|
||||||
return w.api.NewMessageFilter(req)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *GethPublicWakuAPIWrapper) BloomFilter() []byte {
|
|
||||||
return w.api.BloomFilter()
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetFilterMessages returns the messages that match the filter criteria and
|
|
||||||
// are received between the last poll and now.
|
|
||||||
func (w *GethPublicWakuAPIWrapper) GetFilterMessages(id string) ([]*wakutypes.Message, error) {
|
|
||||||
return w.api.GetFilterMessages(id)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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) {
|
|
||||||
return w.api.Post(ctx, req)
|
|
||||||
}
|
|
@ -1,64 +0,0 @@
|
|||||||
package bridge
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
|
||||||
|
|
||||||
"github.com/status-im/status-go/eth-node/types"
|
|
||||||
"github.com/status-im/status-go/wakuv2"
|
|
||||||
|
|
||||||
wakutypes "github.com/status-im/status-go/waku/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
type gethPublicWakuV2APIWrapper struct {
|
|
||||||
api *wakuv2.PublicWakuAPI
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewGethPublicWakuAPIWrapper returns an object that wraps Geth's PublicWakuAPI in a types interface
|
|
||||||
func NewGethPublicWakuV2APIWrapper(api *wakuv2.PublicWakuAPI) wakutypes.PublicWakuAPI {
|
|
||||||
if api == nil {
|
|
||||||
panic("PublicWakuV2API cannot be nil")
|
|
||||||
}
|
|
||||||
|
|
||||||
return &gethPublicWakuV2APIWrapper{
|
|
||||||
api: api,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddPrivateKey imports the given private key.
|
|
||||||
func (w *gethPublicWakuV2APIWrapper) AddPrivateKey(ctx context.Context, privateKey types.HexBytes) (string, error) {
|
|
||||||
return w.api.AddPrivateKey(ctx, hexutil.Bytes(privateKey))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GenerateSymKeyFromPassword derives a key from the given password, stores it, and returns its ID.
|
|
||||||
func (w *gethPublicWakuV2APIWrapper) GenerateSymKeyFromPassword(ctx context.Context, passwd string) (string, error) {
|
|
||||||
return w.api.GenerateSymKeyFromPassword(ctx, passwd)
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeleteKeyPair removes the key with the given key if it exists.
|
|
||||||
func (w *gethPublicWakuV2APIWrapper) DeleteKeyPair(ctx context.Context, key string) (bool, error) {
|
|
||||||
return w.api.DeleteKeyPair(ctx, key)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *gethPublicWakuV2APIWrapper) BloomFilter() []byte {
|
|
||||||
return w.api.BloomFilter()
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewMessageFilter creates a new filter that can be used to poll for
|
|
||||||
// (new) messages that satisfy the given criteria.
|
|
||||||
func (w *gethPublicWakuV2APIWrapper) NewMessageFilter(req wakutypes.Criteria) (string, error) {
|
|
||||||
return w.api.NewMessageFilter(req)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetFilterMessages returns the messages that match the filter criteria and
|
|
||||||
// are received between the last poll and now.
|
|
||||||
func (w *gethPublicWakuV2APIWrapper) GetFilterMessages(id string) ([]*wakutypes.Message, error) {
|
|
||||||
return w.api.GetFilterMessages(id)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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) {
|
|
||||||
return w.api.Post(ctx, req)
|
|
||||||
}
|
|
@ -43,7 +43,7 @@ func GetGethWakuFrom(m wakutypes.Waku) *wakuv1.Waku {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *GethWakuWrapper) PublicWakuAPI() wakutypes.PublicWakuAPI {
|
func (w *GethWakuWrapper) PublicWakuAPI() wakutypes.PublicWakuAPI {
|
||||||
return NewGethPublicWakuAPIWrapper(wakuv1.NewPublicWakuAPI(w.waku))
|
return wakuv1.NewPublicWakuAPI(w.waku)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *GethWakuWrapper) Version() uint {
|
func (w *GethWakuWrapper) Version() uint {
|
||||||
|
@ -44,7 +44,7 @@ func GetGethWakuV2From(m wakutypes.Waku) *wakuv2.Waku {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *gethWakuV2Wrapper) PublicWakuAPI() wakutypes.PublicWakuAPI {
|
func (w *gethWakuV2Wrapper) PublicWakuAPI() wakutypes.PublicWakuAPI {
|
||||||
return NewGethPublicWakuV2APIWrapper(wakuv2.NewPublicWakuAPI(w.waku))
|
return wakuv2.NewPublicWakuAPI(w.waku)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *gethWakuV2Wrapper) Version() uint {
|
func (w *gethWakuV2Wrapper) Version() uint {
|
||||||
|
@ -29,6 +29,8 @@ import (
|
|||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
|
||||||
"github.com/status-im/status-go/logutils"
|
"github.com/status-im/status-go/logutils"
|
||||||
|
|
||||||
|
ethtypes "github.com/status-im/status-go/eth-node/types"
|
||||||
"github.com/status-im/status-go/waku/types"
|
"github.com/status-im/status-go/waku/types"
|
||||||
"github.com/status-im/status-go/wakuv1/common"
|
"github.com/status-im/status-go/wakuv1/common"
|
||||||
|
|
||||||
@ -58,6 +60,8 @@ type PublicWakuAPI struct {
|
|||||||
lastUsed map[string]time.Time // keeps track when a filter was polled for the last time.
|
lastUsed map[string]time.Time // keeps track when a filter was polled for the last time.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var _ types.PublicWakuAPI = (*PublicWakuAPI)(nil)
|
||||||
|
|
||||||
// NewPublicWakuAPI create a new RPC waku service.
|
// NewPublicWakuAPI create a new RPC waku service.
|
||||||
func NewPublicWakuAPI(w *Waku) *PublicWakuAPI {
|
func NewPublicWakuAPI(w *Waku) *PublicWakuAPI {
|
||||||
api := &PublicWakuAPI{
|
api := &PublicWakuAPI{
|
||||||
@ -122,7 +126,7 @@ func (api *PublicWakuAPI) NewKeyPair(ctx context.Context) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddPrivateKey imports the given private key.
|
// AddPrivateKey imports the given private key.
|
||||||
func (api *PublicWakuAPI) AddPrivateKey(ctx context.Context, privateKey hexutil.Bytes) (string, error) {
|
func (api *PublicWakuAPI) AddPrivateKey(ctx context.Context, privateKey ethtypes.HexBytes) (string, error) {
|
||||||
key, err := crypto.ToECDSA(privateKey)
|
key, err := crypto.ToECDSA(privateKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@ -212,7 +216,7 @@ func (api *PublicWakuAPI) CancelLightClient(ctx context.Context) bool {
|
|||||||
|
|
||||||
// Post posts a message on the Waku network.
|
// Post posts a message on the Waku network.
|
||||||
// returns the hash of the message in case of success.
|
// returns the hash of the message in case of success.
|
||||||
func (api *PublicWakuAPI) Post(ctx context.Context, req types.NewMessage) (hexutil.Bytes, error) {
|
func (api *PublicWakuAPI) Post(ctx context.Context, req types.NewMessage) ([]byte, error) {
|
||||||
var (
|
var (
|
||||||
symKeyGiven = len(req.SymKeyID) > 0
|
symKeyGiven = len(req.SymKeyID) > 0
|
||||||
pubKeyGiven = len(req.PublicKey) > 0
|
pubKeyGiven = len(req.PublicKey) > 0
|
||||||
|
@ -31,6 +31,7 @@ import (
|
|||||||
"github.com/waku-org/go-waku/waku/v2/payload"
|
"github.com/waku-org/go-waku/waku/v2/payload"
|
||||||
"github.com/waku-org/go-waku/waku/v2/protocol/pb"
|
"github.com/waku-org/go-waku/waku/v2/protocol/pb"
|
||||||
|
|
||||||
|
ethtypes "github.com/status-im/status-go/eth-node/types"
|
||||||
"github.com/status-im/status-go/logutils"
|
"github.com/status-im/status-go/logutils"
|
||||||
"github.com/status-im/status-go/waku/types"
|
"github.com/status-im/status-go/waku/types"
|
||||||
"github.com/status-im/status-go/wakuv2/common"
|
"github.com/status-im/status-go/wakuv2/common"
|
||||||
@ -63,6 +64,8 @@ type PublicWakuAPI struct {
|
|||||||
lastUsed map[string]time.Time // keeps track when a filter was polled for the last time.
|
lastUsed map[string]time.Time // keeps track when a filter was polled for the last time.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var _ types.PublicWakuAPI = (*PublicWakuAPI)(nil)
|
||||||
|
|
||||||
// NewPublicWakuAPI create a new RPC waku service.
|
// NewPublicWakuAPI create a new RPC waku service.
|
||||||
func NewPublicWakuAPI(w *Waku) *PublicWakuAPI {
|
func NewPublicWakuAPI(w *Waku) *PublicWakuAPI {
|
||||||
api := &PublicWakuAPI{
|
api := &PublicWakuAPI{
|
||||||
@ -95,7 +98,7 @@ func (api *PublicWakuAPI) NewKeyPair(ctx context.Context) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddPrivateKey imports the given private key.
|
// AddPrivateKey imports the given private key.
|
||||||
func (api *PublicWakuAPI) AddPrivateKey(ctx context.Context, privateKey hexutil.Bytes) (string, error) {
|
func (api *PublicWakuAPI) AddPrivateKey(ctx context.Context, privateKey ethtypes.HexBytes) (string, error) {
|
||||||
key, err := crypto.ToECDSA(privateKey)
|
key, err := crypto.ToECDSA(privateKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@ -176,7 +179,7 @@ func (api *PublicWakuAPI) BloomFilter() []byte {
|
|||||||
|
|
||||||
// Post posts a message on the Waku network.
|
// Post posts a message on the Waku network.
|
||||||
// returns the hash of the message in case of success.
|
// returns the hash of the message in case of success.
|
||||||
func (api *PublicWakuAPI) Post(ctx context.Context, req types.NewMessage) (hexutil.Bytes, error) {
|
func (api *PublicWakuAPI) Post(ctx context.Context, req types.NewMessage) ([]byte, error) {
|
||||||
var (
|
var (
|
||||||
symKeyGiven = len(req.SymKeyID) > 0
|
symKeyGiven = len(req.SymKeyID) > 0
|
||||||
pubKeyGiven = len(req.PublicKey) > 0
|
pubKeyGiven = len(req.PublicKey) > 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user