btcplex

package
v0.0.0-...-c6748dd Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2014 License: MIT Imports: 16 Imported by: 2

Documentation

Index

Constants

View Source
const GenesisTx = "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"

Variables

This section is empty.

Functions

func AddressBalance

func AddressBalance(rpool *redis.Pool, address string) (balance uint64, err error)

func AddressFirstSeen

func AddressFirstSeen(rpool *redis.Pool, address string) (firstseen uint64, err error)

Return the block time at which the address first appeared

func CallBitcoinRPC

func CallBitcoinRPC(address string, method string, id interface{}, params []interface{}) (map[string]interface{}, error)

Helper to make call to bitcoind RPC API

func CatchUpLatestBlock

func CatchUpLatestBlock(conf *Config, rpool *redis.Pool, spool *redis.Pool) (done bool)

func FloatToUint

func FloatToUint(x float64) uint64

Float rounding to precision 8

func GetBlockCountRPC

func GetBlockCountRPC(conf *Config) uint

func GetBlockHash

func GetBlockHash(rpool *redis.Pool, height uint) (hash string, err error)

Return block hash for the given height

func GetBlockHashRPC

func GetBlockHashRPC(conf *Config, height uint) string

func GetBlockReward

func GetBlockReward(height uint) uint

Return block reward at the given height

func GetLastBitcoinPrice

func GetLastBitcoinPrice() (price float64, err error)

Return last USD price from BitcoinAverage API

func GetRawMemPoolRPC

func GetRawMemPoolRPC(conf *Config) (unconfirmedtxs []string, err error)

func GetRawMemPoolVerboseRPC

func GetRawMemPoolVerboseRPC(conf *Config) (unconfirmedtxs map[string]interface{}, err error)

func GetReceivedByAddress

func GetReceivedByAddress(rpool *redis.Pool, address string) (total uint64, err error)

func GetRedis

func GetRedis(conf *Config) (pool *redis.Pool, err error)

func GetSSDB

func GetSSDB(conf *Config) (pool *redis.Pool, err error)

func GetSentByAddress

func GetSentByAddress(rpool *redis.Pool, address string) (total uint64, err error)

func IsAddress

func IsAddress(q string) (s bool, res string)

Check if the string is a valid Bitcoin address

func IsBlockHash

func IsBlockHash(rpool *redis.Pool, q string) (s bool, res string)

func IsBlockHeight

func IsBlockHeight(rpool *redis.Pool, q string) (s bool, res string)

Use SSDB

func IsTxHash

func IsTxHash(rpool *redis.Pool, q string) (s bool, res string)

func IsUnconfirmedTx

func IsUnconfirmedTx(pool *redis.Pool, hash string) (status bool, res string)

Check if the Tx is in Redis (not SSDB, Redis!) (in rawmempool)

func ProcessNewBlock

func ProcessNewBlock(conf *Config, rpool *redis.Pool, spool *redis.Pool)

func ProcessUnconfirmedTxs

func ProcessUnconfirmedTxs(conf *Config, pool *redis.Pool, running *bool)

Get unconfirmed transactions from memory pool, along with first seem time/block height, requires a recent bitcoind version

func TxBlockTime

func TxBlockTime(tx1, tx2 *Tx) bool

func TxFirstSeenAsc

func TxFirstSeenAsc(tx1, tx2 *Tx) bool

func TxFirstSeenDesc

func TxFirstSeenDesc(tx1, tx2 *Tx) bool

func TxIndex

func TxIndex(tx1, tx2 *Tx) bool

func ValidA58

func ValidA58(a58 []byte) (ok bool, err error)

ValidA58 validates a base58 encoded bitcoin address. An address is valid if it can be decoded into a 25 byte address, the version number is 0, and the checksum validates. Return value ok will be true for valid addresses. If ok is false, the address is invalid and the error value may indicate why.

Types

type A25

type A25 [25]byte

A25 is a type for a 25 byte (not base58 encoded) bitcoin address.

func (*A25) ComputeChecksum

func (a *A25) ComputeChecksum() (c [4]byte)

ComputeChecksum returns a four byte checksum computed from the first 21 bytes of the address. The embedded checksum is not updated.

func (*A25) EmbeddedChecksum

func (a *A25) EmbeddedChecksum() (c [4]byte)

func (*A25) Set58

func (a *A25) Set58(s []byte) error

Set58 takes a base58 encoded address and decodes it into the receiver. Errors are returned if the argument is not valid base58 or if the decoded value does not fit in the 25 byte address. The address is not otherwise checked for validity.

func (*A25) Version

func (a *A25) Version() byte

type AddressData

type AddressData struct {
	Address       string                       `json:"address"`
	TxCnt         uint64                       `json:"n_tx"`
	ReceivedCnt   uint64                       `json:"-"`
	SentCnt       uint64                       `json:"-"`
	TotalReceived uint64                       `json:"total_received"`
	TotalSent     uint64                       `json:"total_sent"`
	FinalBalance  uint64                       `json:"final_balance"`
	Txs           []*Tx                        `json:"txs"`
	Links         map[string]map[string]string `json:"_links,omitempty"`
}

func GetAddress

func GetAddress(rpool *redis.Pool, address string) (addressdata *AddressData, err error)

func (*AddressData) FetchTxs

func (addrData *AddressData) FetchTxs(rpool *redis.Pool, start, stop int) (err error)

type AddressHash

type AddressHash struct {
	TotalSent     int `redis:"ts"`
	TotalReceived int `redis:"tr"`
}

type BitcoindInfo

type BitcoindInfo struct {
	Version         int64   `json:"version"`
	ProtocolVersion int64   `json:"protocolversion"`
	Blocks          int64   `json:"blocks"`
	TimeOffset      int64   `json:"timeoffset"`
	Connections     int64   `json:"connections"`
	Proxy           string  `json:"proxy"`
	Difficulty      float64 `json:"difficulty"`
	Testnet         bool    `json:"testnet"`
	Errors          string  `json:"errors"`
}

func GetInfoRPC

func GetInfoRPC(conf *Config) (bitcoindinfo *BitcoindInfo, err error)

type Block

type Block struct {
	Hash       string `json:"hash"`
	Height     uint   `json:"height"`
	Txs        []*Tx  `json:"tx,omitempty"`
	Version    uint32 `json:"ver"`
	MerkleRoot string `json:"mrkl_root"`
	BlockTime  uint32 `json:"time"`
	Bits       uint32 `json:"bits"`
	Nonce      uint32 `json:"nonce"`
	Size       uint32 `json:"size"`
	TxCnt      uint32 `json:"n_tx"`
	TotalBTC   uint64 `json:"total_out"`
	//    BlockReward float64 `json:"-"`
	Parent string                       `json:"prev_block"`
	Next   string                       `json:"next_block"`
	Links  map[string]map[string]string `json:"_links,omitempty"`
	Meta   *BlockMeta                   `json:"-"`
	Main   bool                         `json:"-"`
}

func GetBlockByHash

func GetBlockByHash(rpool *redis.Pool, hash string) (block *Block, err error)

Get a block by its hash

func GetBlockCachedByHash

func GetBlockCachedByHash(rpool *redis.Pool, hash string) (block *Block, err error)

Get a block by its hash along with its full transactions

func GetLastXBlocks

func GetLastXBlocks(rpool *redis.Pool, start uint, stop uint) (blocks []*Block, err error)

Return last X blocks from stop to start (both included)

func SaveBlockFromRPC

func SaveBlockFromRPC(conf *Config, pool *redis.Pool, hash string) (block *Block, err error)

func (*Block) FetchMeta

func (block *Block) FetchMeta(rpool *redis.Pool) (err error)

func (*Block) FetchTxs

func (block *Block) FetchTxs(rpool *redis.Pool) (err error)

type BlockMeta

type BlockMeta struct {
	Main   bool   `redis:"main"`
	Next   string `redis:"next"`
	Parent string `redis:"parent"`
	Height int    `redis:"height"`
}

func NewBlockMeta

func NewBlockMeta(rpool *redis.Pool, block_hash string) (blockmeta *BlockMeta, err error)

type By

type By func(tx1, tx2 *Tx) bool

func (By) Sort

func (by By) Sort(txs []*Tx)

type Config

type Config struct {
	BitcoindBlocksPath string `json:"bitcoind_blocks_path"`
	BitcoindRpcUrl     string `json:"bitcoind_rpc_url"`
	SsdbHost           string `json:"ssdb_host"`
	RedisHost          string `json:"redis_host"`
	LevelDbPath        string `json:"leveldb_path"`
	AppUrl             string `json:"app_url"`
	AppPort            uint   `json:"app_port"`
	AppApiRateLimited  bool   `json:"app_api_rate_limited"`
	AppTemplatesPath   string `json:"app_templates_path"`
	AppGoogleAnalytics string `json:"app_google_analytics"`
}

Struct holding our configuration

func LoadConfig

func LoadConfig(path string) (conf *Config, err error)

Load configuration from json file

type PrevOut

type PrevOut struct {
	Hash    string `json:"hash"`
	Vout    uint32 `json:"n"`
	Address string `json:"address"`
	Value   uint64 `json:"value"`
}

type Tx

type Tx struct {
	Hash            string                       `json:"hash"`
	Index           uint32                       `json:"-"`
	Size            uint32                       `json:"size"`
	LockTime        uint32                       `json:"lock_time"`
	Version         uint32                       `json:"ver"`
	TxInCnt         uint32                       `json:"vin_sz"`
	TxOutCnt        uint32                       `json:"vout_sz"`
	TxIns           []*TxIn                      `json:"in"`
	TxOuts          []*TxOut                     `json:"out"`
	TotalOut        uint64                       `json:"vout_total"`
	TotalIn         uint64                       `json:"vin_total"`
	BlockHash       string                       `json:"block_hash"`
	BlockHeight     uint                         `json:"block_height"`
	BlockTime       uint32                       `json:"block_time"`
	FirstSeenTime   uint32                       `json:"first_seen_time"`
	FirstSeenHeight uint                         `json:"first_seen_height"`
	TxAddressInfo   *TxAddressInfo               `json:"-"`
	Links           map[string]map[string]string `json:"_links,omitempty"`
}

func GetTx

func GetTx(rpool *redis.Pool, hash string) (tx *Tx, err error)

Fetch a transaction by hash

func GetTxRPC

func GetTxRPC(conf *Config, tx_id string, block *Block) (tx *Tx, err error)

Fetch a transaction via bticoind RPC API

func GetUnconfirmedTx

func GetUnconfirmedTx(pool *redis.Pool, hash string) (tx *Tx, err error)

Fetch unconfirmed tx from Redis

func GetUnconfirmedTxs

func GetUnconfirmedTxs(pool *redis.Pool) (utxs []*Tx, err error)

Return all unconfirmed transactions from Redis

func SaveTxFromRPC

func SaveTxFromRPC(conf *Config, pool *redis.Pool, tx_id string, block *Block, tx_index int) (tx *Tx, err error)

Fetch a transaction via bticoind RPC API

func (*Tx) Addresses

func (tx *Tx) Addresses() (addresses []string)

Return a set containing every addresses listed in txis/txos

func (*Tx) AddressesChannels

func (tx *Tx) AddressesChannels() (addresses []string)

Return a set containing every addresses listed in txis/txos

func (*Tx) Build

func (tx *Tx) Build(rpool *redis.Pool) (err error)

Fetch Txos and Txins

func (*Tx) Revert

func (tx *Tx) Revert(spool *redis.Pool) (err error)

type TxAddressInfo

type TxAddressInfo struct {
	InTxIn  bool
	InTxOut bool
	Value   int64
}

type TxIn

type TxIn struct {
	TxHash    string   `json:"-"`
	BlockHash string   `json:"-"`
	BlockTime uint32   `json:"-"`
	PrevOut   *PrevOut `json:"prev_out"`
	Index     uint32   `json:"n"`
}

type TxOut

type TxOut struct {
	TxHash    string    `json:"-"`
	BlockHash string    `json:"-"`
	BlockTime uint32    `json:"-"`
	Addr      string    `json:"hash"`
	Value     uint64    `json:"value"`
	Index     uint32    `json:"n"`
	Spent     *TxoSpent `json:"spent,omitempty"`
}

func GetTxOutRPC

func GetTxOutRPC(conf *Config, tx_id string, txo_vout uint32) (txo *TxOut, err error)

Fetch a transaction without additional info, used to fetch previous txouts when parsing txins

type TxoSpent

type TxoSpent struct {
	Spent       bool   `json:"spent"`
	BlockHeight uint32 `json:"block_height,omitempty"`
	InputHash   string `json:"tx_hash,omitempty"`
	InputIndex  uint32 `json:"in_index,omitempty"`
}

Jump to

Keyboard shortcuts

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