Skip to content

Commit

Permalink
whisper: move ShhClient to its own package
Browse files Browse the repository at this point in the history
  • Loading branch information
bas-vk committed Jun 21, 2017
1 parent b58a501 commit 36e7963
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions whisper/whisperv5/client.go → whisper/shhclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.

package whisperv5
package shhclient

import (
"context"

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/rpc"
whisper "github.com/ethereum/go-ethereum/whisper/whisperv5"
)

// Client defines typed wrappers for the Whisper RPC API.
// Client defines typed wrappers for the Whisper v5 RPC API.
type Client struct {
c *rpc.Client
}
Expand All @@ -51,8 +52,8 @@ func (sc *Client) Version(ctx context.Context) (uint, error) {
}

// Info returns diagnostic information about the whisper node.
func (sc *Client) Info(ctx context.Context) (Info, error) {
var info Info
func (sc *Client) Info(ctx context.Context) (whisper.Info, error) {
var info whisper.Info
err := sc.c.CallContext(ctx, &info, "shh_info")
return info, err
}
Expand Down Expand Up @@ -159,22 +160,22 @@ func (sc *Client) DeleteSymmetricKey(ctx context.Context, id string) error {
}

// Post a message onto the network.
func (sc *Client) Post(ctx context.Context, message NewMessage) error {
func (sc *Client) Post(ctx context.Context, message whisper.NewMessage) error {
var ignored bool
return sc.c.CallContext(ctx, &ignored, "shh_post", message)
}

// SubscribeMessages subscribes to messages that match the given criteria. This method
// is only supported on bi-directional connections such as websockets and IPC.
// NewMessageFilter uses polling and is supported over HTTP.
func (ec *Client) SubscribeMessages(ctx context.Context, criteria Criteria, ch chan<- *Message) (ethereum.Subscription, error) {
func (ec *Client) SubscribeMessages(ctx context.Context, criteria whisper.Criteria, ch chan<- *whisper.Message) (ethereum.Subscription, error) {
return ec.c.ShhSubscribe(ctx, ch, "messages", criteria)
}

// NewMessageFilter creates a filter within the node. This filter can be used to poll
// for new messages (see FilterMessages) that satisfy the given criteria. A filter can
// timeout when it was polled for in whisper.filterTimeout.
func (ec *Client) NewMessageFilter(ctx context.Context, criteria Criteria) (string, error) {
func (ec *Client) NewMessageFilter(ctx context.Context, criteria whisper.Criteria) (string, error) {
var id string
return id, ec.c.CallContext(ctx, &id, "shh_newMessageFilter", criteria)
}
Expand All @@ -187,7 +188,7 @@ func (ec *Client) DeleteMessageFilter(ctx context.Context, id string) error {

// FilterMessages retrieves all messages that are received between the last call to
// this function and match the criteria that where given when the filter was created.
func (ec *Client) FilterMessages(ctx context.Context, id string) ([]*Message, error) {
var messages []*Message
func (ec *Client) FilterMessages(ctx context.Context, id string) ([]*whisper.Message, error) {
var messages []*whisper.Message
return messages, ec.c.CallContext(ctx, &messages, "shh_getFilterMessages", id)
}

0 comments on commit 36e7963

Please sign in to comment.