junglebus

package module
v0.2.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2023 License: MIT Imports: 12 Imported by: 20

README

JungleBus: Go Client

Get started using JungleBus in five minutes

Release Build Status Report codecov Mergify Status Go
Gitpod Ready-to-Code standard-readme compliant Makefile Included Sponsor Donate


package main

import (
    "context"
    "log"
    "time"

    "github.com/GorillaPool/go-junglebus"
    "github.com/GorillaPool/go-junglebus/models"
)

func main() {
    junglebusClient, err := junglebus.New(
        junglebus.WithHTTP("https://junglebus.gorillapool.io"),
    )
    if err != nil {
        log.Fatalln(err.Error())
    }

    subscriptionID := "..." // fill in the ID for the subscription
    fromBlock := uint64(750000)

    eventHandler := junglebus.EventHandler{
        // do not set this function to leave out mined transactions
        OnTransaction: func(tx *models.TransactionResponse) {
            log.Printf("[TX]: %d: %v", tx.BlockHeight, tx.Id)
        },
        // do not set this function to leave out mempool transactions
        OnMempool: func(tx *models.TransactionResponse) {
            log.Printf("[MEMPOOL TX]: %v", tx.Id)
        },
        OnStatus: func(status *models.ControlResponse) {
            log.Printf("[STATUS]: %v", status)
        },
        OnError: func(err error) {
            log.Printf("[ERROR]: %v", err)
        },
    }

    var subscription *junglebus.Subscription
    if subscription, err = junglebusClient.Subscribe(context.Background(), subscriptionID, fromBlock, eventHandler); err != nil {
        log.Printf("ERROR: failed getting subscription %s", err.Error())
    } else {
        time.Sleep(10 * time.Second) // stop after 10 seconds
        if err = subscription.Unsubscribe(); err != nil {
            log.Printf("ERROR: failed unsubscribing %s", err.Error())
        }
    }
}

Table of Contents


What is JungleBus?

Read more about JungleBus


Installation

go-junglebusclient requires a supported release of Go.

go get -u github.com/GorillaPool/go-junglebus

Documentation

View the generated documentation

GoDoc


Repository Features

This repository was created using MrZ's go-template

Built-in Features
Package Dependencies
Library Deployment

Releases are automatically created when you create a new git tag!

If you want to manually make releases, please install GoReleaser:

goreleaser for easy binary or library deployment to Github and can be installed:

  • using make: make install-releaser
  • using brew: brew install goreleaser

The .goreleaser.yml file is used to configure goreleaser.


Automatic releases via Github Actions from creating a new tag:

make tag version=1.2.3

Manual Releases (optional)

Use make release-snap to create a snapshot version of the release, and finally make release to ship to production (manually).


Makefile Commands

View all makefile commands

make help

List of all current commands:

all                           Runs multiple commands
clean                         Remove previous builds and any cached data
clean-mods                    Remove all the Go mod cache
coverage                      Shows the test coverage
diff                          Show the git diff
generate                      Runs the go generate command in the base of the repo
godocs                        Sync the latest tag with GoDocs
help                          Show this help message
install                       Install the application
install-all-contributors      Installs all contributors locally
install-go                    Install the application (Using Native Go)
install-releaser              Install the GoReleaser application
lint                          Run the golangci-lint application (install if not found)
release                       Full production release (creates release in Github)
release                       Runs common.release then runs godocs
release-snap                  Test the full release (build binaries)
release-test                  Full production test release (everything except deploy)
replace-version               Replaces the version in HTML/JS (pre-deploy)
tag                           Generate a new tag and push (tag version=0.0.0)
tag-remove                    Remove a tag if found (tag-remove version=0.0.0)
tag-update                    Update an existing tag to current commit (tag-update version=0.0.0)
test                          Runs lint and ALL tests
test-ci                       Runs all tests via CI (exports coverage)
test-ci-no-race               Runs all tests via CI (no race) (exports coverage)
test-ci-short                 Runs unit tests via CI (exports coverage)
test-no-lint                  Runs just tests
test-short                    Runs vet, lint and tests (excludes integration tests)
test-unit                     Runs tests and outputs coverage
uninstall                     Uninstall the application (and remove files)
update-contributors           Regenerates the contributors html/list
update-linter                 Update the golangci-lint package (macOS only)
vet                           Run the Go vet application

Examples & Tests

All unit tests and examples run via Github Actions and uses Go version 1.18.x. View the configuration file.


Run all tests (including integration tests)

make test

Run tests (excluding integration tests)

make test-short

Benchmarks

Run the Go benchmarks:

make bench

Code Standards

Read more about this Go project's code standards.


Usage

Checkout all the examples!


Contributing

View the contributing guidelines and follow the code of conduct.


How can I help?

All kinds of contributions are welcome 🙌! The most basic way to show your support is to star 🌟 the project, or to raise issues 💬. You can also support this project by becoming a sponsor on GitHub 👏 or by making a bitcoin donation to ensure this journey continues indefinitely! 🚀

Stars


Contributors ✨

Thank you to these wonderful people (emoji key):


Siggi

🚇 💻 🛡️

This project follows the all-contributors specification.


License

License

Documentation

Overview

Package junglebus is a Go client for interacting with GorillaPool's JungleBus

If you have any suggestions or comments, please feel free to open an issue on this GitHub repository!

By GorillaPool (https://githujb.com/GorillaPool)

Index

Constants

This section is empty.

Variables

View Source
var DefaultServer = "junglebus.gorillapool.io"

Functions

This section is empty.

Types

type Client

type Client struct {
	transports.TransportService
	// contains filtered or unexported fields
}

Client is the go-junglebus client

func New

func New(opts ...ClientOps) (*Client, error)

New create a new jungle bus client

func (*Client) GetAddressTransactionDetails

func (jb *Client) GetAddressTransactionDetails(ctx context.Context, address string) ([]*models.Transaction, error)

GetAddressTransactionDetails get full transaction data for the given address

func (*Client) GetAddressTransactions

func (jb *Client) GetAddressTransactions(ctx context.Context, address string) ([]*models.Address, error)

GetAddressTransactions get transaction meta data for the given address

func (*Client) GetBlockHeader

func (jb *Client) GetBlockHeader(ctx context.Context, block string) (*models.BlockHeader, error)

GetBlockHeader get a block header from JungleBus

func (*Client) GetBlockHeaders

func (jb *Client) GetBlockHeaders(ctx context.Context, block string, limit uint) ([]*models.BlockHeader, error)

GetBlockHeaders get a list of block headers from JungleBus

func (*Client) GetTransaction

func (jb *Client) GetTransaction(ctx context.Context, txID string) (*models.Transaction, error)

func (*Client) GetTransport

func (jb *Client) GetTransport() *transports.TransportService

GetTransport returns the current transport service

func (*Client) IsDebug

func (jb *Client) IsDebug() bool

IsDebug return the debugging status

func (*Client) SetDebug

func (jb *Client) SetDebug(debug bool)

SetDebug turn the debugging on or off

func (*Client) Subscribe

func (jb *Client) Subscribe(ctx context.Context, subscriptionID string, fromBlock uint64, eventHandler EventHandler) (*Subscription, error)

func (*Client) Unsubscribe

func (jb *Client) Unsubscribe() (err error)

type ClientOps

type ClientOps func(c *Client)

ClientOps are used for client options

func WithDebugging

func WithDebugging(debug bool) ClientOps

WithDebugging will set whether to turn debugging on

func WithHTTP

func WithHTTP(serverURL string) ClientOps

WithHTTP will overwrite the default server url (junglebus.gorillapool.io)

func WithHTTPClient

func WithHTTPClient(serverURL string, httpClient *http.Client) ClientOps

WithHTTPClient will overwrite the default client with a custom client

func WithSSL

func WithSSL(useSSL bool) ClientOps

WithSSL will set whether to use SSL in all communications or not

func WithToken

func WithToken(token string) ClientOps

WithToken will set the token to use in all requests

func WithVersion

func WithVersion(version string) ClientOps

WithVersion will set the API version to use (v1 is default)

type EventHandler

type EventHandler struct {
	OnTransaction func(tx *models.TransactionResponse)
	OnMempool     func(tx *models.TransactionResponse)
	OnStatus      func(response *models.ControlResponse)
	OnError       func(err error)
	// contains filtered or unexported fields
}

func (*EventHandler) OnPublish

func (e *EventHandler) OnPublish(event centrifuge.PublicationEvent)

type StatusCode

type StatusCode uint

StatusCode defines the codes that can be returned from the control channel of a subscription

var (
	// StatusConnecting is when connecting to a server
	StatusConnecting StatusCode = 1
	// StatusConnected is when connected to a server
	StatusConnected StatusCode = 2
	// StatusJoin is when joining to a server
	StatusJoin StatusCode = 3
	// StatusLeave is when leaving to a server
	StatusLeave StatusCode = 4
	// StatusDisconnecting is when disconnecting from a server
	StatusDisconnecting StatusCode = 10
	// StatusDisconnected is when disconnected from a server
	StatusDisconnected StatusCode = 11
	// StatusSubscribing is when subscribing to a server
	StatusSubscribing StatusCode = 20
	// StatusSubscribed is when subscribed on a server
	StatusSubscribed StatusCode = 21
	// StatusUnsubscribed is when unsubscribed on a server
	StatusUnsubscribed StatusCode = 29
	// SubscriptionWait is sent when the server is waiting for a new block to be ready to send transactions
	SubscriptionWait StatusCode = 100
	// SubscriptionError is sent when an error was encountered
	SubscriptionError StatusCode = 101
	// SubscriptionBlockDone is sent when a block is done processing
	SubscriptionBlockDone StatusCode = 200
	// SubscriptionReorg is sent when a reorg is initialized
	SubscriptionReorg StatusCode = 300
	// StatusError is sent when an error is found
	StatusError StatusCode = 999
)

type Subscription

type Subscription struct {
	SubscriptionID string
	FromBlock      uint64
	EventHandler   EventHandler
	// contains filtered or unexported fields
}

func (*Subscription) Unsubscribe

func (s *Subscription) Unsubscribe() (err error)

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL