blockchain

package module
v0.0.0-...-647ebea Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2022 License: MIT Imports: 8 Imported by: 1

README

blockchain

Build Status

Go Client for the Blockchain Data API https://blockchain.info/api/blockchain_api

Documentation: https://godoc.org/github.com/alfg/blockchain

Installation

go get github.com/alfg/blockchain

Example

package main

import (
  "github.com/alfg/blockchain"
  "fmt"
)

func main() {

	c, e := blockchain.New()
	resp, e := c.GetAddress("162FjqU7RYdojnejCDe6zrPDUpaLcv9Hhq")
	if e != nil {
		fmt.Print(e)
	}

	fmt.Println(resp.Hash160)
	fmt.Println(resp.Address)
	fmt.Println(resp.NTx)
	fmt.Println(resp.TotalReceived)
	fmt.Println(resp.TotalSent)
	fmt.Println(resp.FinalBalance)

	for i := range resp.Txs {
		fmt.Println(resp.Txs[i].Result)

		for j := range resp.Txs[i].Inputs {
			fmt.Println(resp.Txs[i].Inputs[j].Sequence)
			fmt.Println(resp.Txs[i].Inputs[j].PrevOut.Spent)
		}
	}

}

License

MIT

Documentation

Index

Constants

View Source
const (
	API_ROOT = "https://blockchain.info"
	ETH_ROOT = "https://api.blockchain.info"
)

Variables

This section is empty.

Functions

func GetHtmlTitle

func GetHtmlTitle(r io.Reader) (string, bool)

Types

type Address

type Address struct {
	Hash160       string `json:"hash160"`
	Address       string `json:"address"`
	NTx           int    `json:"n_tx"`
	TotalReceived int    `json:"total_received"`
	TotalSent     int    `json:"total_sent"`
	FinalBalance  int    `json:"final_balance"`
	Txs           []*Tx  `json:"txs"`
}

type Block

type Block struct {
	Hash         string `json:"hash"`
	Ver          int    `json:"ver"`
	PrevBlock    string `json:"prev_block"`
	MrklRoot     string `json:"mrkl_root"`
	Time         int    `json:"time"`
	Bits         int    `json:"bits"`
	Nonce        int    `json:"nonce"`
	NTx          int    `json:"n_tx"`
	Size         int    `json:"size"`
	BlockIndex   int    `json:"block_index"`
	MainChain    bool   `json:"main_chain"`
	Height       int    `json:"height"`
	ReceivedTime int    `json:"received_time"`
	RelayedBy    string `json:"relayed_by"`
	Tx           []*Tx  `json:"tx"`
	TxIndexes    []int  `json:"txIndexes"`
}

type BlockHeight

type BlockHeight struct {
	Blocks []*Block `json:"blocks"`
}

type Chart

type Chart struct {
	Values []*Value `json:"values"`
}

type Client

type Client struct {
	*http.Client
}

func New

func New() (*Client, error)

func (*Client) CheckAddress

func (c *Client) CheckAddress(address string) (string, error)

func (*Client) GetAddress

func (c *Client) GetAddress(address string) (*Address, error)

func (*Client) GetAddresses

func (c *Client) GetAddresses(addresses []string) (*MultiAddr, error)

func (*Client) GetBlock

func (c *Client) GetBlock(block string) (*Block, error)

func (*Client) GetBlockHeight

func (c *Client) GetBlockHeight(blockHeight string) (*BlockHeight, error)

func (*Client) GetChart

func (c *Client) GetChart(chartType string) (*Chart, error)

func (*Client) GetETHAddress

func (c *Client) GetETHAddress(address string) (*ETHResponse, error)

func (*Client) GetETHAddressSummary

func (c *Client) GetETHAddressSummary(address string, getSummary bool) (*ETHAddress, error)

func (*Client) GetLatestBlock

func (c *Client) GetLatestBlock() (*Block, error)

func (*Client) GetTransaction

func (c *Client) GetTransaction(transaction string) (*Transaction, error)

func (*Client) GetUnconfirmedTransactions

func (c *Client) GetUnconfirmedTransactions() (*Transactions, error)

type ETHAddress

type ETHAddress struct {
	Hash                     string `json:"hash"`
	Nonce                    string `json:"nonce"`
	Balance                  string `json:"balance"`
	TransactionCount         string `json:"transactionCount"`
	InternalTransactionCount string `json:"internalTransactionCount"`
	TotalSent                string `json:"totalSent"`
	TotalReceived            string `json:"totalReceived"`
	TotalFees                string `json:"totalFees"`
	LastUpdatedAtNumber      string `json:"lastUpdatedAtNumber"`
	TokenTransferCount       string `json:"tokenTransferCount"`
}

type ETHResponse

type ETHResponse struct {
	Transactions []struct {
		Hash                 string        `json:"hash"`
		BlockHash            string        `json:"blockHash"`
		BlockNumber          string        `json:"blockNumber"`
		To                   string        `json:"to"`
		From                 string        `json:"from"`
		Value                string        `json:"value"`
		Nonce                string        `json:"nonce"`
		GasPrice             string        `json:"gasPrice"`
		GasLimit             string        `json:"gasLimit"`
		GasUsed              string        `json:"gasUsed"`
		TransactionIndex     string        `json:"transactionIndex"`
		Success              bool          `json:"success"`
		State                string        `json:"state"`
		Timestamp            string        `json:"timestamp"`
		InternalTransactions []interface{} `json:"internalTransactions"`
		Data                 string        `json:"data,omitempty"`
	} `json:"transactions"`
	Page string `json:"page"`
	Size int    `json:"size"`
}

type Inputs

type Inputs struct {
	Sequence int      `json:"sequence"`
	Script   string   `json:"script"`
	PrevOut  *PrevOut `json:"prev_out"`
}

type MultiAddr

type MultiAddr struct {
	Addresses []*Address `json:"addresses"`
	Txs       []*Tx      `json:"txs"`
}

type Out

type Out struct {
	Spent   bool   `json:"spent"`
	TxIndex int    `json:"tx_index"`
	Type    int    `json:"type"`
	Addr    string `json:"addr"`
	Value   int    `json:"value"`
	N       int    `json:"n"`
	Script  string `json:"script"`
}

type PrevOut

type PrevOut struct {
	Spent   bool   `json:"spent"`
	TxIndex int    `json:"tx_index"`
	Type    int    `json:"type"`
	Addr    string `json:"addr"`
	Value   int    `json:"value"`
	N       int    `json:"n"`
	Script  string `json:"script"`
}

type Transaction

type Transaction struct {
	Hash        string    `json:"hash"`
	Ver         int       `json:"ver"`
	VinSz       int       `json:"vin_sz"`
	VoutSz      int       `json:"vout_sz"`
	LockTime    int       `json:"lock_time"`
	Size        int       `json:"size"`
	RelayedBy   string    `json:"relayed_by"`
	BlockHeight int       `json:"block_height"`
	TxIndex     int       `json:"tx_index"`
	Inputs      []*Inputs `json:"inputs"`
	Out         []*Out    `json:"out"`
}

type Transactions

type Transactions struct {
	Transactions []*Transaction `json:"txs"`
}

type Tx

type Tx struct {
	Result      int       `json:"result"`
	Ver         int       `json:"ver"`
	Size        int       `json:"size"`
	Inputs      []*Inputs `json:"inputs"`
	Time        int       `json:"time"`
	BlockHeight int       `json:"block_height"`
	TxIndex     int       `json:"tx_index"`
	VinSz       int       `json:"vin_sz"`
	Hash        string    `json:"hash"`
	VoutSz      int       `json:"vout_sz"`
	RelayedBy   string    `json:"relayed_by"`
	Out         []*Out    `json:"out"`
}

type Value

type Value struct {
	X int `json:"x"`
	Y int `json:"y"`
}

Jump to

Keyboard shortcuts

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