client

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

type Block struct {
	ID          string   `json:"id"`
	Height      int64    `json:"height"`
	Version     int32    `json:"version"`
	Timestamp   int64    `json:"timestamp"`
	TxCount     int      `json:"tx_count"`
	Size        int      `json:"size"`
	Weight      int      `json:"weight"`
	MerkleRoot  string   `json:"merkle_root"`
	PrevBlockID string   `json:"previousblockhash"`
	Nonce       uint64   `json:"nonce"`
	Bits        int32    `json:"bits"`
	Txids       []string `json:"tx"` // Changed from "txids" to "tx"
}

Bitcoin block

type BlockHeader

type BlockHeader struct {
	Raw          string `json:"raw"` // Raw header in hex format
	Version      int32  `json:"version"`
	PreviousHash string `json:"previousblockhash"`
	MerkleRoot   string `json:"merkle_root"`
	Timestamp    int64  `json:"time"`
	Bits         string `json:"bits"`
	Nonce        uint64 `json:"nonce"`
}

Block Header

type BroadcastResponse

type BroadcastResponse struct {
	Txid string `json:"txid"`
}

BroadcastResponse represents the response from broadcasting a transaction

type Client

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

Client represents a Bitcoin REST API client

func NewClient

func NewClient(opts ...ClientOption) *Client

NewClient creates a new Bitcoin REST API client

func (*Client) BroadcastTransaction

func (c *Client) BroadcastTransaction(ctx context.Context, rawTx string) (*BroadcastResponse, error)

BroadcastTransaction broadcasts a raw transaction to the network

func (*Client) GetBlockByHash

func (c *Client) GetBlockByHash(ctx context.Context, hash string) (*Block, error)

GetBlockByHash retrieves a block by its hash

func (*Client) GetBlockByHeight

func (c *Client) GetBlockByHeight(ctx context.Context, height int64) (*Block, error)

GetBlockByHeight retrieves a block by its height

func (*Client) GetBlockHeader

func (c *Client) GetBlockHeader(ctx context.Context, hash string) (*BlockHeader, error)

GetBlockHeader retrieves block headers

func (*Client) GetBlockTransactions

func (c *Client) GetBlockTransactions(ctx context.Context, blockHash string) ([]string, error)

GetBlockTransactions retrieves transaction IDs for a given block hash

func (*Client) GetTransaction

func (c *Client) GetTransaction(ctx context.Context, txid string) (*Transaction, error)

GetTransaction retrieves transaction details by txid

func (*Client) GetTransactionConfirmation

func (c *Client) GetTransactionConfirmation(ctx context.Context, txid string) (*TransactionConfirmation, error)

GetTransactionConfirmation retrieves the confirmation status of a transaction

type ClientOption

type ClientOption func(*Client)

ClientOption is a function that configures the Client

func WithBaseURL

func WithBaseURL(url string) ClientOption

WithBaseURL sets a custom base URL for the client

func WithTimeout

func WithTimeout(timeout time.Duration) ClientOption

WithTimeout sets a custom timeout for the HTTP client

type Transaction

type Transaction struct {
	Txid    string   `json:"txid"`
	Version int32    `json:"version"`
	Size    int      `json:"size"`
	Weight  int      `json:"weight"`
	Fee     int64    `json:"fee"`
	Status  TxStatus `json:"status"`
}

Transaction represents a Bitcoin transaction

type TransactionConfirmation

type TransactionConfirmation struct {
	Txid          string `json:"txid"`
	Confirmed     bool   `json:"confirmed"`
	BlockHeight   int64  `json:"block_height,omitempty"`
	Confirmations int64  `json:"confirmations"`
	BlockHash     string `json:"block_hash,omitempty"`
	BlockTime     int64  `json:"block_time,omitempty"`
}

TransactionConfirmation contains confirmation details for a transaction

type TxStatus

type TxStatus struct {
	Confirmed   bool   `json:"confirmed"`
	BlockHeight int64  `json:"block_height,omitempty"`
	BlockHash   string `json:"block_hash,omitempty"`
	BlockTime   int64  `json:"block_time,omitempty"`
}

TxStatus represents the status of a transaction

Jump to

Keyboard shortcuts

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