Skip to content

Commit

Permalink
chore_: remove waku api wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
osmaczko committed Jan 21, 2025
1 parent b2bb680 commit f56eb37
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 147 deletions.
25 changes: 12 additions & 13 deletions protocol/messenger_waku_wrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@ import (
type testWakuWrapper struct {
*bridge.GethWakuWrapper

publicWakuAPIWrapper *testPublicWakuAPIWrapper
api *testPublicWakuAPI
}

func newTestWaku(w *wakuv1.Waku) wakutypes.Waku {
wrapper := bridge.NewGethWakuWrapper(w)
return &testWakuWrapper{
GethWakuWrapper: wrapper.(*bridge.GethWakuWrapper),
publicWakuAPIWrapper: newTestPublicWakuAPI(wakuv1.NewPublicWakuAPI(w)).(*testPublicWakuAPIWrapper),
GethWakuWrapper: wrapper.(*bridge.GethWakuWrapper),
api: newTestPublicWakuAPI(wakuv1.NewPublicWakuAPI(w)),
}
}

func (tw *testWakuWrapper) PublicWakuAPI() wakutypes.PublicWakuAPI {
return tw.publicWakuAPIWrapper
return tw.api
}

func (tw *testWakuWrapper) SubscribePostEvents() chan *PostMessageSubscription {
subscription := make(chan *PostMessageSubscription, 100)
tw.publicWakuAPIWrapper.postSubscriptions = append(tw.publicWakuAPIWrapper.postSubscriptions, subscription)
tw.api.postSubscriptions = append(tw.api.postSubscriptions, subscription)
return subscription
}

Expand All @@ -39,21 +39,20 @@ type PostMessageSubscription struct {
msg *wakutypes.NewMessage
}

type testPublicWakuAPIWrapper struct {
*bridge.GethPublicWakuAPIWrapper
type testPublicWakuAPI struct {
*wakuv1.PublicWakuAPI

postSubscriptions []chan *PostMessageSubscription
}

func newTestPublicWakuAPI(api *wakuv1.PublicWakuAPI) wakutypes.PublicWakuAPI {
wrapper := bridge.NewGethPublicWakuAPIWrapper(api)
return &testPublicWakuAPIWrapper{
GethPublicWakuAPIWrapper: wrapper.(*bridge.GethPublicWakuAPIWrapper),
func newTestPublicWakuAPI(api *wakuv1.PublicWakuAPI) *testPublicWakuAPI {
return &testPublicWakuAPI{
PublicWakuAPI: api,
}
}

func (tp *testPublicWakuAPIWrapper) Post(ctx context.Context, req wakutypes.NewMessage) ([]byte, error) {
id, err := tp.GethPublicWakuAPIWrapper.Post(ctx, req)
func (tp *testPublicWakuAPI) Post(ctx context.Context, req wakutypes.NewMessage) ([]byte, error) {
id, err := tp.PublicWakuAPI.Post(ctx, req)
if err != nil {
return nil, err
}
Expand Down
64 changes: 0 additions & 64 deletions waku/bridge/public_waku_api.go

This file was deleted.

64 changes: 0 additions & 64 deletions waku/bridge/public_wakuv2_api.go

This file was deleted.

2 changes: 1 addition & 1 deletion waku/bridge/waku.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func GetGethWakuFrom(m wakutypes.Waku) *wakuv1.Waku {
}

func (w *GethWakuWrapper) PublicWakuAPI() wakutypes.PublicWakuAPI {
return NewGethPublicWakuAPIWrapper(wakuv1.NewPublicWakuAPI(w.waku))
return wakuv1.NewPublicWakuAPI(w.waku)
}

func (w *GethWakuWrapper) Version() uint {
Expand Down
2 changes: 1 addition & 1 deletion waku/bridge/wakuv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func GetGethWakuV2From(m wakutypes.Waku) *wakuv2.Waku {
}

func (w *gethWakuV2Wrapper) PublicWakuAPI() wakutypes.PublicWakuAPI {
return NewGethPublicWakuV2APIWrapper(wakuv2.NewPublicWakuAPI(w.waku))
return wakuv2.NewPublicWakuAPI(w.waku)
}

func (w *gethWakuV2Wrapper) Version() uint {
Expand Down
8 changes: 6 additions & 2 deletions wakuv1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import (
"go.uber.org/zap"

"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/wakuv1/common"

Expand Down Expand Up @@ -58,6 +60,8 @@ type PublicWakuAPI struct {
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.
func NewPublicWakuAPI(w *Waku) *PublicWakuAPI {
api := &PublicWakuAPI{
Expand Down Expand Up @@ -122,7 +126,7 @@ func (api *PublicWakuAPI) NewKeyPair(ctx context.Context) (string, error) {
}

// 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)
if err != nil {
return "", err
Expand Down Expand Up @@ -212,7 +216,7 @@ func (api *PublicWakuAPI) CancelLightClient(ctx context.Context) bool {

// 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 types.NewMessage) (hexutil.Bytes, error) {
func (api *PublicWakuAPI) Post(ctx context.Context, req types.NewMessage) ([]byte, error) {
var (
symKeyGiven = len(req.SymKeyID) > 0
pubKeyGiven = len(req.PublicKey) > 0
Expand Down
7 changes: 5 additions & 2 deletions wakuv2/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/waku-org/go-waku/waku/v2/payload"
"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/waku/types"
"github.com/status-im/status-go/wakuv2/common"
Expand Down Expand Up @@ -63,6 +64,8 @@ type PublicWakuAPI struct {
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.
func NewPublicWakuAPI(w *Waku) *PublicWakuAPI {
api := &PublicWakuAPI{
Expand Down Expand Up @@ -95,7 +98,7 @@ func (api *PublicWakuAPI) NewKeyPair(ctx context.Context) (string, error) {
}

// 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)
if err != nil {
return "", err
Expand Down Expand Up @@ -176,7 +179,7 @@ func (api *PublicWakuAPI) BloomFilter() []byte {

// 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 types.NewMessage) (hexutil.Bytes, error) {
func (api *PublicWakuAPI) Post(ctx context.Context, req types.NewMessage) ([]byte, error) {
var (
symKeyGiven = len(req.SymKeyID) > 0
pubKeyGiven = len(req.PublicKey) > 0
Expand Down

0 comments on commit f56eb37

Please sign in to comment.