plugin

package
v0.0.0-...-a71e659 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2020 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package plugin contains utilities for building a VendoPunkto plugin in Go A plugin is basically a binary which runs an HTTP server that VendoPunkto consumes. This package aims to help doing so.

Index

Constants

View Source
const (
	ExchangeRatesMainEndpoint        = "/vp/exchange-rates"
	ExchangeRatesSupportedCurrencies = "/supported-currencies"
)
View Source
const (
	// WalletMainEndpoint is root wallet plugin path
	WalletMainEndpoint = "/vp/wallet"
	// GenerateAddressWalletEndpoint the suffix for address generation
	GenerateAddressWalletEndpoint = "/address"
	// GetIncomingTransfersWalletEndpoint returns incoming transfers
	GetIncomingTransfersWalletEndpoint = "/incoming-transfers"
	// WalletInfoEndpoint the suffix for info
	WalletInfoEndpoint = "/info"
)
View Source
const ActivatePluginEndpoint = "/activate"
View Source
const (
	CurrencyMetadataMainEndpoint = "/vp/currency-metadata"
)

Variables

This section is empty.

Functions

func NewCurrencyMetadataHandler

func NewCurrencyMetadataHandler(plugin CurrencyMetadataPlugin, serverPlugin ServerPlugin) *chi.Mux

func NewExchangeRatesHandler

func NewExchangeRatesHandler(plugin ExchangeRatesPlugin, serverPlugin ServerPlugin) *chi.Mux

func NewWalletHandler

func NewWalletHandler(plugin WalletPlugin, serverPlugin ServerPlugin) *chi.Mux

Types

type CoinWalletAddressParams

type CoinWalletAddressParams struct {
	InvoiceID string `json:"invoiceId"`
}

type CoinWalletAddressResponse

type CoinWalletAddressResponse struct {
	Address string `json:"address"`
}

type CurrencyMetadata

type CurrencyMetadata struct {
	Name         string `json:"name"`
	Symbol       string `json:"symbol"`
	LogoImageURL string `json:"logoImageUrl"`
}

type CurrencyMetadataHandler

type CurrencyMetadataHandler struct {
	// contains filtered or unexported fields
}

CurrencyMetadataHandler exposes the plugin interface through HTTP

type CurrencyMetadataPlugin

type CurrencyMetadataPlugin interface {
	VendoPunktoPlugin
	GetCurrencies(currencies []string) ([]CurrencyMetadata, error)
}

CurrencyMetadataPlugin providers currency information

type ExchangeRatesHandler

type ExchangeRatesHandler struct {
	// contains filtered or unexported fields
}

ExchangeRatesHandler exposes the plugin through HTTP

type ExchangeRatesPlugin

type ExchangeRatesPlugin interface {
	VendoPunktoPlugin
	SearchSupportedCurrencies(term string) ([]dtos.BasicCurrencyDto, error)
	GetExchangeRates(base string, currencies []string) (ExchangeRatesResult, error)
}

ExchangeRatesPlugin must be implemented in order to provide coin exchange rates

type ExchangeRatesResult

type ExchangeRatesResult map[string]decimal.Decimal

type GetCurrencyParams

type GetCurrencyParams struct {
	Currencies []string `json:"currencies"`
}

type GetExchangeRatesParams

type GetExchangeRatesParams struct {
	Currency   string   `json:"currency"`
	Currencies []string `json:"currencies"`
}

type PluginInfo

type PluginInfo struct {
	Name string     `json:"name"`
	ID   string     `json:"id"`
	Type PluginType `json:"pluginType"`
}

func (PluginInfo) GetAddress

func (info PluginInfo) GetAddress() string

type PluginType

type PluginType string
const (
	PluginTypeWallet           PluginType = "wallet"
	PluginTypeExchangeRate     PluginType = "exchange-rate"
	PluginTypeCurrencyMetadata PluginType = "currency-metadata"
)

type Server

type Server struct {
	Logger hclog.Logger
	// contains filtered or unexported fields
}

Server is the plugin server running on every plugin

func NewServer

func NewServer(logger hclog.Logger) *Server

NewServer creates the plugin server which must be run by every plugin

func (*Server) AddPlugin

func (s *Server) AddPlugin(plugin ServerPlugin) error

AddPlugin adds a plugin to the server This must be called before the server is started

func (*Server) Start

func (s *Server) Start(addr string) error

Start initializes the router and starts serving on the provided net address

type ServerPlugin

type ServerPlugin interface {
	GetPluginImpl() (VendoPunktoPlugin, error)
	// contains filtered or unexported methods
}

ServerPlugin wraps the plugin implementation. It configures the router and orchestrates the underlying calls to the actual implementation

func BuildCurrencyMetadataPlugin

func BuildCurrencyMetadataPlugin(impl CurrencyMetadataPlugin) ServerPlugin

func BuildExchangeRatesPlugin

func BuildExchangeRatesPlugin(impl ExchangeRatesPlugin) ServerPlugin

func BuildWalletPlugin

func BuildWalletPlugin(impl WalletPlugin) ServerPlugin

BuildWalletPlugin needs to be called by implementors with their WalletPlugin implementation. Afterwards, you need to call server.AddPlugin with the resulting ServerPlugin

type VendoPunktoPlugin

type VendoPunktoPlugin interface {
	GetPluginInfo() (PluginInfo, error)
}

type WalletPlugin

type WalletPlugin interface {
	VendoPunktoPlugin
	// GetWalletInfo returns information about the currency of this wallet
	GetWalletInfo() (WalletPluginInfo, error)
	// GenerateNewAddress will be called everytime a new payment for this
	// currency is requested. It must generate a new addres everytime. This is
	// by design, given that received payments will be matched by address.
	GenerateNewAddress(invoiceID string) (string, error)
	// GetIncomingTransfers returns the list of input transfers, confirmed and
	// on the mempool. Filters should be applied
	GetIncomingTransfers(params WalletPluginIncomingTransferParams) ([]WalletPluginIncomingTransferResult, error)
}

WalletPlugin must be implemented for a currency to be supported by VendoPunkto

type WalletPluginCurrency

type WalletPluginCurrency struct {
	Name           string `json:"name"`
	Symbol         string `json:"symbol"`
	QRCodeTemplate string `json:"qrCodeTemplate"`
}

WalletPluginCurrency provides metadata for WalletPlugin currencies

type WalletPluginHandler

type WalletPluginHandler struct {
	// contains filtered or unexported fields
}

WalletPluginHandler is the Wallet Plugin HTTP API implementation which runs on the plugin server and will be called by vendopunkto It exposes the wallet interface provided by the plugin developer into HTTP endpoints

type WalletPluginIncomingTransferParams

type WalletPluginIncomingTransferParams struct {
	MinBlockHeight uint64 `json:"minBlockHeight"`
}

WalletPluginIncomingTransferParams are the filters for returning transfers

type WalletPluginIncomingTransferResult

type WalletPluginIncomingTransferResult struct {
	TxHash        string          `json:"txHash"`
	Address       string          `json:"address"`
	BlockHeight   uint64          `json:"blockHeight"`
	Confirmations uint64          `json:"confirmations"`
	Amount        decimal.Decimal `json:"amount"`
}

WalletPluginIncomingTransferResult is a transfer representation

type WalletPluginInfo

type WalletPluginInfo struct {
	Currency WalletPluginCurrency `json:"currency"`
}

WalletPluginInfo provides metadata for the WalletPlugin

func (WalletPluginInfo) BuildQRCode

func (info WalletPluginInfo) BuildQRCode(
	address string,
	amount decimal.Decimal) (string, error)

BuildQRCode generates the string for a QR code based on the template. If the WalletPluginInfo has no template, BIP21 will be used

Jump to

Keyboard shortcuts

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