urchain

package module
v0.0.0-...-64fa486 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2024 License: MIT Imports: 5 Imported by: 0

README

go-urchain

A Go client for integrating with the btc.urchain.com API.

Usage

To use the package, import it in your code:


import "github.com/xianb/go-urchain"

Example:

package main

import "github.com/xianb/go-urchain"

func main() {
    var opt = urchain.Options{
        ApiKey: "1234567890",
    }
    var cli = urchain.NewClient(opt)
    
    _, err := cli.CheckUrchainHealth()
    if err != nil {
        panic(err)
    }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatStruct

func FormatStruct(v any) string

Types

type Balance

type Balance struct {
	Confirmed   string `json:"confirmed"`
	Unconfirmed string `json:"unconfirmed"`
}

type Block

type Block struct {
	Hash              string `json:"hash"`
	Height            int64  `json:"height"`
	Version           int    `json:"version"`
	VersionHex        string `json:"versionHex"`
	Time              int64  `json:"time"`
	Mediantime        int64  `json:"mediantime"`
	Nonce             string `json:"nonce"`
	Bits              string `json:"bits"`
	Difficulty        string `json:"difficulty"`
	Chainwork         string `json:"chainwork"`
	NumTx             int    `json:"num_tx"`
	PreviousBlockHash string `json:"previousblockhash"`
	NextBlockHash     string `json:"nextblockhash"`
	BlockSize         int    `json:"blockSize"`
	Coinbase          string `json:"coinbase"`
	BlockSubsidy      string `json:"blockSubsidy"`
	Merkleroot        string `json:"merkleroot"`
	TotalFee          string `json:"totalFee"`
	Miner             string `json:"miner"`
	Reorg             any    `json:"reorg"`
	Blockchain        string `json:"blockchain"`
	NoteMerkelRoot    string `json:"noteMerkelRoot"`
}

type BlockHeader

type BlockHeader struct {
	Hash   string `json:"hash"`
	Height int64  `json:"height"`
}

type BroadcastResult

type BroadcastResult struct {
	Success bool   `json:"success"`
	TxId    string `json:"txId,omitempty"`
	Error   any    `json:"error,omitempty"`
}

type Client

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

func NewClient

func NewClient(opt Options) *Client

func (*Client) BroadcastTx

func (c *Client) BroadcastTx(rawHex string) (*BroadcastResult, error)

BroadcastTx broadcast a raw bitcoin transaction

func (*Client) CheckUrchainHealth

func (c *Client) CheckUrchainHealth() (*Health, error)

CheckUrchainHealth check urchain health

func (*Client) DecodePSBT

func (c *Client) DecodePSBT(psbtHex, blockchain string) (string, error)

DecodePSBT decode a PSBT

func (*Client) GetAllN20Tokens

func (c *Client) GetAllN20Tokens() ([]*N20TokenInfo, error)

GetAllN20Tokens get all N20 tokens

func (*Client) GetBalance

func (c *Client) GetBalance(scriptHash string) (*Balance, error)

GetBalance get bitcoin balance of a script hash

func (*Client) GetBalances

func (c *Client) GetBalances(scriptHashs []string) (*Balance, error)

GetBalances get bitcoin balances of multiple script hashes

func (*Client) GetBlockHeader

func (c *Client) GetBlockHeader() (*BlockHeader, error)

GetBlockHeader get the best bitcoin block header

func (*Client) GetNoteBlock

func (c *Client) GetNoteBlock(blockHash string) (*NoteBlock, error)

GetNoteBlock get note block by block hash

func (*Client) GetNoteContract

func (c *Client) GetNoteContract(contractHash string) (*NoteContract, error)

GetNoteContract get note contract by contract hash

func (*Client) GetNoteTxHistory

func (c *Client) GetNoteTxHistory(scriptHash string) ([]*NoteTxHistory, error)

GetNoteTxHistory get note transaction history of a script hash

func (*Client) GetNoteTxInfo

func (c *Client) GetNoteTxInfo(txId string) (*NoteTxInfo, error)

GetNoteTxInfo parse note transaction by tx id

func (*Client) GetTokenBalanceByAddress

func (c *Client) GetTokenBalanceByAddress(address, tick string) (*TokenBalance, error)

GetTokenBalanceByAddress get token balance of an address

func (*Client) GetTokenBalanceByScriptHas

func (c *Client) GetTokenBalanceByScriptHas(scriptHash, tick string) (*TokenBalance, error)

GetTokenBalanceByScriptHas get token balance of a script hash

func (*Client) GetTokenInfo

func (c *Client) GetTokenInfo(tick string) (*N20TokenInfo, error)

GetTokenInfo get N20 token info by tick

func (*Client) GetTokenUtxos

func (c *Client) GetTokenUtxos(scriptHashs []string, tick string) ([]*TokenUtxo, error)

GetTokenUtxos get token utxos

func (*Client) GetTokensByAddress

func (c *Client) GetTokensByAddress(address string) ([]*Token, error)

GetTokensByAddress get tokens of an address

func (*Client) GetTokensByScriptHash

func (c *Client) GetTokensByScriptHash(scriptHash string) ([]*Token, error)

GetTokensByScriptHash get tokens of a script hash

func (*Client) GetTxHistory

func (c *Client) GetTxHistory(scriptHash string) ([]*TxHistory, error)

GetTxHistory get bitcoin transaction history of a script hash

func (*Client) GetUnspentUtxos

func (c *Client) GetUnspentUtxos(scriptHashs []string) ([]*Utxo, error)

GetUnspentUtxos get unspent bitcoin utxos of multiple script hashes

func (*Client) RefreshUtxos

func (c *Client) RefreshUtxos(scriptHash string) error

RefreshUtxos refresh bitcoin utxos of a script hash

type Health

type Health struct {
	Status              string `json:"status"`
	LastHealthChecktime int64  `json:"lastHealthChecktime"`
	Height              int64  `json:"height"`
	Merkleroot          string `json:"merkleroot"`
}

type N20TokenInfo

type N20TokenInfo struct {
	Inpoint       string `json:"inpoint"`
	Blockchain    string `json:"blockchain"`
	TxId          string `json:"txId"`
	InputIndex    int    `json:"inputIndex"`
	Height        int64  `json:"height"`
	BlockHash     string `json:"blockHash"`
	BlockTime     int64  `json:"blockTime"`
	IndexInBlock  int    `json:"indexInBlock"`
	IndexInChain  int    `json:"indexInChain"`
	AccountId     string `json:"accountId"`
	Address       string `json:"address"`
	P             string `json:"p"`
	Tick          string `json:"tick"`
	Max           string `json:"max"`
	Lim           string `json:"lim"`
	Dec           int32  `json:"dec"`
	Uri           string `json:"uri"`
	Idx           string `json:"idx"`
	Code          string `json:"code"`
	Sch           string `json:"sch"`
	Time          int64  `json:"time"`
	DeployOptions string `json:"deployOptions"`
	Total         string `json:"total"`
}

type N20TokenInfoResp

type N20TokenInfoResp struct {
	Total int             `json:"total"`
	Data  []*N20TokenInfo `json:"data"`
}

type NoteBlock

type NoteBlock struct {
	Block   *Block    `json:"block"`
	Txs     []*NoteTx `json:"txs"`
	TxCount int       `json:"txCount"`
}

type NoteContract

type NoteContract struct {
	Hash         string `json:"hash"`
	Inpoint      string `json:"inpoint"`
	Blockchain   string `json:"blockchain"`
	TxId         string `json:"txId"`
	InputIndex   int    `json:"inputIndex"`
	Height       int64  `json:"height"`
	BlockHash    string `json:"blockHash"`
	BlockTime    int64  `json:"blockTime"`
	IndexInBlock int    `json:"indexInBlock"`
	IndexInChain int    `json:"indexInChain"`
	Name         string `json:"name"`
	Code         string `json:"code"`
	AccountId    string `json:"accountId"`
	Time         int64  `json:"time"`
	Status       string `json:"status"`
	AbiJson      any    `json:"abiJson"`
	Creater      string `json:"creater"`
}

type NotePayload

type NotePayload struct {
	P    string `json:"p"`
	Op   string `json:"op"`
	Amt  any    `json:"amt"` // string or []string
	Tick string `json:"tick"`
}

type NoteTx

type NoteTx struct {
	TxId         string `json:"txId"`
	Blockchain   string `json:"blockchain"`
	Time         int64  `json:"time"`
	NumInputs    int    `json:"num_inputs"`
	NumOutputs   int    `json:"num_outputs"`
	Height       int64  `json:"height"`
	BlockHash    string `json:"blockHash"`
	BlockTime    int64  `json:"blockTime"`
	IndexInBlock int    `json:"indexInBlock"`
	IndexInChain int    `json:"indexInChain"`
	Status       string `json:"status"`
	Type         string `json:"type"`
	Payload      string `json:"payload"`
}

type NoteTxHistory

type NoteTxHistory struct {
	TxId        string `json:"txId"`
	Amount      string `json:"amount"`
	Income      bool   `json:"income"`
	Tick        string `json:"tick"`
	Op          string `json:"op"`
	Dec         int32  `json:"dec"`
	Height      int64  `json:"height"`
	Time        int64  `json:"time"`
	FromAddress string `json:"fromAddress"`
	ToAddress   string `json:"toAddress"`
}

type NoteTxHistoryResp

type NoteTxHistoryResp struct {
	Total int              `json:"total"`
	Data  []*NoteTxHistory `json:"data"`
}

type NoteTxInfo

type NoteTxInfo struct {
	TxId           string `json:"txId"`
	Blockchain     string `json:"blockchain"`
	Time           int64  `json:"time"`
	NumInputs      int    `json:"num_inputs"`
	NumOutputs     int    `json:"num_outputs"`
	Height         int64  `json:"height"`
	BlockHash      string `json:"blockHash"`
	BlockTime      int64  `json:"blockTime"`
	IndexInBlock   int    `json:"indexInBlock"`
	IndexInChain   int    `json:"indexInChain"`
	Status         string `json:"status"`
	Type           string `json:"type"`
	Payload        string `json:"payload"`
	Version        int    `json:"version"`
	NLockTime      int64  `json:"nLockTime"`
	TxSize         int    `json:"txSize"`
	Fee            any    `json:"fee"`
	OutputSatoshis string `json:"outputSatoshis"`
	TxHex          string `json:"txHex"`
	MempoolTime    int64  `json:"mempoolTime"`
	Rbf            bool   `json:"rbf"`
	Replaced       any    `json:"replaced"`

	Inputs []*struct {
		Unlock *TxUnlock `json:"Unlock"`
		TXO    *Txo      `json:"TXO"`
	} `json:"inputs"`

	Outputs []*struct {
		TXO    *Txo      `json:"TXO"`
		Unlock *TxUnlock `json:"Unlock"`

		Satoshis string `json:"satoshis,omitempty"`
		Holder   string `json:"holder,omitempty"`
		Amount   string `json:"amount,omitempty"`
		// contains filtered or unexported fields
	}
}

type Options

type Options struct {

	// testnet4 or mainnet
	Testnet bool

	// urchain api key
	ApiKey string

	// http debug
	Debug bool
}

func (*Options) GetHost

func (o *Options) GetHost() string

type Token

type Token struct {
	*TokenBalance
	ScriptHash string `json:"tokenAddressScriptHash"`
	Dec        int32  `json:"dec"`
	P          string `json:"p"`
}

type TokenBalance

type TokenBalance struct {
	Tick        string `json:"tick"`
	Confirmed   string `json:"confirmed"`
	Unconfirmed string `json:"unconfirmed"`
}

type TokenUtxo

type TokenUtxo struct {
	TxId        string `json:"txId"`
	Outpoint    string `json:"outpoint"`
	OutputIndex uint32 `json:"outputIndex"`
	Script      string `json:"script"`
	Satoshis    int64  `json:"satoshis"`
	Holder      string `json:"holder"`
	Amount      string `json:"amount"`
	Height      int64  `json:"height"`
	Tick        string `json:"tick"`
	Dec         int32  `json:"dec"`
	P           string `json:"p"`
	Time        int64  `json:"time"`
}

type TxHistory

type TxHistory struct {
	TxId     string `json:"txId"`
	Satoshis int64  `json:"satoshis"`
	Income   bool   `json:"income"`
	Height   int64  `json:"height"`
	Time     int64  `json:"time"`
}

type TxUnlock

type TxUnlock struct {
	Inpoint        string   `json:"inpoint"`
	InputIndex     int      `json:"inputIndex"`
	PrevTxId       string   `json:"prevTxId"`
	SequenceNumber int      `json:"sequenceNumber"`
	Witnesses      []string `json:"witnesses"`
	Type           string   `json:"type"`
	FullScript     string   `json:"fullScript"`
	Amounts        []string `json:"amounts"`
	// contains filtered or unexported fields
}

type Txo

type Txo struct {
	Satoshis   string `json:"satoshis"`
	Holder     string `json:"holder,omitempty"`
	Size       int    `json:"size"`
	ScriptHash string `json:"tokenAddressScriptHash"`
	Type       string `json:"type"`
	Pubkey     string `json:"pubkey"`
	Address    string `json:"address"`
	Amount     string `json:"amount,omitempty"`
	// contains filtered or unexported fields
}

type Utxo

type Utxo struct {
	Address     string `json:"address"`
	TxId        string `json:"txId"`
	OutputIndex uint32 `json:"outputIndex"`
	Height      int64  `json:"height"`
	ScriptHash  string `json:"tokenAddressScriptHash"`
	Script      string `json:"script"`
	Satoshis    int64  `json:"satoshis"`
	Type        string `json:"type"`
	Time        int64  `json:"time"`
}

func (*Utxo) GetTxidHash

func (o *Utxo) GetTxidHash() *chainhash.Hash

Jump to

Keyboard shortcuts

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