Skip to content

Commit

Permalink
Minor formatting, version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
mrz1836 committed Mar 26, 2022
1 parent fd5cebb commit c3c3a93
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 22 deletions.
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
const (

// version is the current version
version = "v0.9.5"
version = "v0.10.0"

// defaultUserAgent is the default user agent for all requests
defaultUserAgent string = "go-whatsonchain: " + version
Expand Down
2 changes: 1 addition & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestNewClient_CustomHTTPClient(t *testing.T) {
func ExampleNewClient() {
client := NewClient(NetworkTest, nil, nil)
fmt.Println(client.UserAgent())
// Output:go-whatsonchain: v0.9.5
// Output:go-whatsonchain: v0.10.0
}

// BenchmarkNewClient benchmarks the NewClient method
Expand Down
4 changes: 2 additions & 2 deletions interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type ScriptService interface {
type TransactionService interface {
BroadcastTx(ctx context.Context, txHex string) (txID string, err error)
BulkBroadcastTx(ctx context.Context, rawTxs []string, feedback bool) (response *BulkBroadcastResponse, err error)
BulkRawTransactionDataProcessor(ctx context.Context, hashes *TxHashes) (txList TxList, err error)
BulkTransactionDetails(ctx context.Context, hashes *TxHashes) (txList TxList, err error)
BulkTransactionDetailsProcessor(ctx context.Context, hashes *TxHashes) (txList TxList, err error)
BulkUnspentTransactions(ctx context.Context, list *AddressList) (response BulkUnspentResponse, err error)
Expand All @@ -69,7 +70,6 @@ type TransactionService interface {
GetMerkleProof(ctx context.Context, hash string) (merkleResults MerkleResults, err error)
GetMerkleProofTSC(ctx context.Context, hash string) (merkleResults MerkleTSCResults, err error)
GetRawTransactionData(ctx context.Context, hash string) (string, error)
BulkRawTransactionDataProcessor(ctx context.Context, hashes *TxHashes) (txList TxList, err error)
GetRawTransactionOutputData(ctx context.Context, hash string, vOutIndex int) (string, error)
GetTxByHash(ctx context.Context, hash string) (txInfo *TxInfo, err error)
}
Expand All @@ -93,6 +93,6 @@ type ClientInterface interface {
HTTPClient() HTTPInterface
LastRequest() *LastRequest
Network() NetworkType
UserAgent() string
RateLimit() int
UserAgent() string
}
40 changes: 22 additions & 18 deletions websocket.go
Original file line number Diff line number Diff line change
@@ -1,36 +1,40 @@
package whatsonchain

import (
"fmt"

"github.com/centrifugal/centrifuge-go"
)

const (
socketEndpointMempool = "mempool"
)

// socketHandler describe the interface
type socketHandler interface {
OnConnect(_ *centrifuge.Client, _ centrifuge.ConnectEvent)
OnError(_ *centrifuge.Client, e centrifuge.ErrorEvent)
OnDisconnect(_ *centrifuge.Client, e centrifuge.DisconnectEvent)
OnMessage(_ *centrifuge.Client, e centrifuge.MessageEvent)
OnServerPublish(_ *centrifuge.Client, e centrifuge.ServerPublishEvent)
OnConnect(*centrifuge.Client, centrifuge.ConnectEvent)
OnError(*centrifuge.Client, centrifuge.ErrorEvent)
OnDisconnect(*centrifuge.Client, centrifuge.DisconnectEvent)
OnMessage(*centrifuge.Client, centrifuge.MessageEvent)
OnServerPublish(*centrifuge.Client, centrifuge.ServerPublishEvent)
}

// NewMempoolWebsocket instantiates a new websocket client to stream mempool transactions
func (c *Client) NewMempoolWebsocket(handler socketHandler) *centrifuge.Client {
return newWebsocketClient(fmt.Sprintf("%s%s", socketEndpoint, "mempool"), handler)
return newWebsocketClient(socketEndpoint+socketEndpointMempool, handler)
}

func newWebsocketClient(url string, handler socketHandler) *centrifuge.Client {
// newWebsocketClient will create a new websocket client
func newWebsocketClient(url string, handler socketHandler) (client *centrifuge.Client) {
if url == "" || handler == nil {
return nil
return
}
c := centrifuge.NewJsonClient(url, centrifuge.DefaultConfig())
if c == nil {
return nil
if client = centrifuge.NewJsonClient(
url, centrifuge.DefaultConfig(),
); client == nil {
return
}
c.OnDisconnect(handler)
c.OnConnect(handler)
c.OnServerPublish(handler)
c.OnError(handler)
return c
client.OnDisconnect(handler)
client.OnConnect(handler)
client.OnServerPublish(handler)
client.OnError(handler)
return
}

0 comments on commit c3c3a93

Please sign in to comment.