blockio_webhook_receiver

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2020 License: MIT Imports: 5 Imported by: 1

README

blockio_webhook_receiver

High-performance webhook endpoint for block.io, to process your transactions rapidly. See https://block.io/docs/notifications for instructions how to set up the notifications.

Usage

Getting started is easy. Just import the receiver, create a callback function, set a port to listen to, and start the server.

package main

import (
  "fmt"
  "log"
  recv "github.com/pawcommerce/blockio_webhook_receiver"
)

func PrintNotification(n *recv.Notification) bool {
  fmt.Println("=========================")
  fmt.Printf("Id:        %s\n", n.Id)
  fmt.Printf("Timestamp: %d\n", n.CreatedAt)
  fmt.Printf("Attempt:   %d\n", n.DeliveryAttempt)
  addr, _ :=  n.AddressData()
  fmt.Printf("%+v\n", addr)

  return true
}

func main() {
  log.Fatal(recv.New(":8083", "/", PrintNotification).Start())
}
Deployment

The server expects calls to be routed through a front-end load balancer, such as HAProxy or Nginx, or a hosted solution like CloudFlare or CloudFront.

The allow list operates on the X-Forwarded-For header, so make sure that this is properly set-up on the front-end server.

API
func New (port, path, callback)
func New(listen string, path string, handler NotificationHandler) *server {}

Returns a server object that will listen on port and path, parse messages and forward them to handler

func server.SetFilter(type)
func (s *server) SetFilter(noteType string) *server {}

Set a filter to only process specific notification types. Non-matching types will be voided. Supported values:

  • "address"
func server.DisableAllowlist()
func (s *server) DisableAllowlist() *server {}

Disable matching to allow lists (enabled by default) for development environments.

NOTE: DO NOT USE THIS IN PRODUCTION!

func server.EnableAllowlist()
func (s *server) EnableAllowlist() *server {}

Enable matching to allow lists.

func server.Start()
func (s *server) Start() error {}

Starts the server or returns an error if this is not possible.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ServerAllowlist = map[string]bool{
	"45.56.79.5":                     true,
	"45.56.123.170":                  true,
	"45.33.20.161":                   true,
	"45.33.4.167":                    true,
	"2600:3c00::f03c:91ff:fe33:2e14": true,
	"2600:3c00::f03c:91ff:fe89:bb9b": true,
	"2600:3c00::f03c:91ff:fe33:d082": true,
	"2600:3c00::f03c:92ff:fe5e:4219": true,
}

Functions

func IsAllowlisted added in v1.0.0

func IsAllowlisted(addr string) bool

func New

func New(listen string, path string, handler NotificationHandler) *server

Types

type AddressData

type AddressData struct {
	Network        string          `json:"network"`
	Address        string          `json:"address"`
	BalanceChange  decimal.Decimal `json:"balance_change"`
	AmountSent     decimal.Decimal `json:"amount_sent"`
	AmountReceived decimal.Decimal `json:"amount_received"`
	TxId           string          `json:"txid"`
	Confirmations  int             `json:"confirmations"`
	IsGreen        bool            `json:"is_green"`
}

type Notification

type Notification struct {
	Id              string          `json:"notification_id"`
	DeliveryAttempt int             `json:"delivery_attempt"`
	CreatedAt       int             `json:"created_at"`
	Type            string          `json:"type"`
	RawData         json.RawMessage `json:"data"`
}

func ParseNotification

func ParseNotification(jsonstr []byte) (*Notification, error)

func (*Notification) AddressData

func (n *Notification) AddressData() (*AddressData, error)

type NotificationHandler

type NotificationHandler func(*Notification) bool

Directories

Path Synopsis
example module

Jump to

Keyboard shortcuts

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