blockchain

package
v0.0.0-...-de2bd08 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2023 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const API_BASE_URL = "https://chain.api.btc.com/v3"

Variables

This section is empty.

Functions

func InitMetrics

func InitMetrics()

func Plugin

func Plugin(ctx context.Context) *plugin.Plugin

func ShouldRetryBlockchainError

func ShouldRetryBlockchainError(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData, err error) bool

Types

type ApiWrapper

type ApiWrapper[T any] struct {
	Data      T      `json:"data"`
	Status    string `json:"status"` // Can be "success" or "fail"
	Message   string `json:"msg"`
	ErrorCode int    `json:"err_code"` // 0 if request was successful
}

type BlockchainClient

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

func (BlockchainClient) GetTransaction

func (c BlockchainClient) GetTransaction(hash string) (TransactionInfo, error)

Returns data about a single transaction, identified by its hash

func (BlockchainClient) GetTransactionsForWallet

func (c BlockchainClient) GetTransactionsForWallet(address string, page int) ([]TransactionInfo, error)

Returns a page of results for transactions that involve a certain wallet, identified by its Base58 address

func (BlockchainClient) GetWalletInfo

func (c BlockchainClient) GetWalletInfo(address string) (WalletInfo, error)

Returns information about a single wallet, identified by its Base58 address

type PaginatedWrapper

type PaginatedWrapper[T any] struct {
	Items    []T `json:"list"`
	Page     int `json:"page"`
	PageSize int `json:"pagesize"`
	NumPages int `json:"page_total"`
	NumItems int `json:"total_count"`
}

type RateLimitError

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

func (RateLimitError) Error

func (e RateLimitError) Error() string

type TransactionInfo

type TransactionInfo struct {
	Hash         string    `json:"hash"`
	Fee          int       `json:"fee"`
	RelayedBy    string    `json:"-"` // This does not work :(
	OriginalTime int       `json:"block_time"`
	Time         time.Time `json:"-"` // This will be filled manually from .OriginalTime
	InputsCount  int       `json:"inputs_count"`
	InputsValue  int       `json:"inputs_value"`
	OutputsCount int       `json:"outputs_count"`
	OutputsValue int       `json:"outputs_value"`
	Balance      int       `json:"balance_diff"`

	Inputs  []map[string]any `json:"inputs"`
	Outputs []map[string]any `json:"outputs"`
}

func (*TransactionInfo) FillTime

func (ti *TransactionInfo) FillTime()

Fills the .Time field by interpreting the .OriginalTime field as the number of seconds since the Unix epoch

func (TransactionInfo) String

func (i TransactionInfo) String() string

type WalletInfo

type WalletInfo struct {
	Hash160            string `json:"-"` // This will be manually extracted from .Address
	Address            string `json:"address"`
	NumberTransactions int    `json:"tx_count"`
	NumberUnredeemed   int    `json:"unspent_tx_count"`
	TotalReceived      int    `json:"received"`
	TotalSent          int    `json:"sent"`
	FinalBalance       int    `json:"balance"`
}

func (*WalletInfo) FillHash160

func (wi *WalletInfo) FillHash160()

Fills the .Hash160 field from the .Address field, by reversing the Base58Check encoding used See the process in "Creating a Base58Check string" here: https://en.bitcoin.it/wiki/Base58Check_encoding

func (WalletInfo) String

func (i WalletInfo) String() string

Jump to

Keyboard shortcuts

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