Documentation ¶
Index ¶
- Constants
- Variables
- func CoinIdentifier(hash string, vout int64) string
- func Int64Pointer(v int64) *int64
- func LocalhostURL(rpcPort int) string
- func MustMarshalMap(v interface{}) map[string]interface{}
- func ParseCoinIdentifier(coinIdentifier *types.CoinIdentifier) (*chainhash.Hash, uint32, error)
- func ParseSingleAddress(chainParams *chaincfg.Params, script []byte) (txscript.ScriptClass, zenutil.Address, error)
- func StartZEND(ctx context.Context, configPath string, g *errgroup.Group) error
- func TransactionHash(identifier string) string
- type Block
- type BlockMetadata
- type BlockchainInfo
- type Cert
- type Certificate
- type Client
- func (b *Client) GetBestBlock(ctx context.Context) (int64, error)
- func (b *Client) GetHashFromIndex(ctx context.Context, index int64) (string, error)
- func (b *Client) GetPeers(ctx context.Context) ([]*types.Peer, error)
- func (b *Client) GetRawBlock(ctx context.Context, identifier *types.PartialBlockIdentifier) (*Block, []string, error)
- func (b *Client) NetworkStatus(ctx context.Context) (*types.NetworkStatusResponse, error)
- func (b *Client) ParseBlock(ctx context.Context, block *Block, coins map[string]*storage.AccountCoin) (*types.Block, error)
- func (b *Client) PruneBlockchain(ctx context.Context, height int64) (int64, error)
- func (b *Client) RawMempool(ctx context.Context) ([]string, error)
- func (b *Client) SendRawTransaction(ctx context.Context, serializedTx string) (string, error)
- func (b *Client) SuggestedFeeRate(ctx context.Context, confTarget int64) (float64, error)
- type Input
- type Joinsplit
- type OperationMetadata
- type Output
- type PeerInfo
- type ScriptPubKey
- type ScriptSig
- type Transaction
- type TransactionMetadata
Constants ¶
const ( // Blockchain is Bitcoin. Blockchain string = "Zen" // MainnetNetwork is the value of the network // in MainnetNetworkIdentifier. MainnetNetwork string = "main" // TestnetNetwork is the value of the network // in TestnetNetworkIdentifier. TestnetNetwork string = "test" // Decimals is the decimals value // used in Currency. Decimals = 8 // SatoshisInBitcoin is the number of // Satoshis in 1 BTC (10^8). SatoshisInBitcoin = 100000000 // InputOpType is used to describe // INPUT. InputOpType = "INPUT" // OutputOpType is used to describe // OUTPUT. OutputOpType = "OUTPUT" // CoinbaseOpType is used to describe // Coinbase. CoinbaseOpType = "COINBASE" // SuccessStatus is the status of all // Bitcoin operations because anything // on-chain is considered successful. SuccessStatus = "SUCCESS" // SkippedStatus is the status of all // operations that are skipped because // of BIP-30. You can read more about these // types of operations in BIP-30. SkippedStatus = "SKIPPED" // TransactionHashLength is the length // of any transaction hash in Bitcoin. TransactionHashLength = 64 // NullData is returned by bitcoind // as the ScriptPubKey.Type for OP_RETURN // locking scripts. NullData = "nulldata" )
const ( MinFeeRate = float64(0.00001) // nolint:gomnd TransactionOverhead = 10 // 4 version, 1 vin, 1 vout, 4 lock time InputSize = 147 // 4 prev index, 32 prev hash, 4 sequence, 1 script size, 106 script sig OutputOverhead = 9 // 8 value, 1 script size P2PKHReplayScriptPubkeySize = 63 // P2PKH size with replay protection )
Fee estimate constants Source: https://bitcoinops.org/en/tools/calc-size/
Variables ¶
var ( // ErrBlockNotFound is returned by when the requested block // cannot be found by the node ErrBlockNotFound = errors.New("unable to find block") // ErrJSONRPCError is returned when receiving an error from a JSON-RPC response ErrJSONRPCError = errors.New("JSON-RPC error") )
var ( // MainnetGenesisBlockIdentifier is the genesis block for mainnet. MainnetGenesisBlockIdentifier = &types.BlockIdentifier{ Hash: "0007104ccda289427919efc39dc9e4d499804b7bebc22df55f8b834301260602", } // MainnetParams are the params for mainnet. MainnetParams = &chaincfg.MainNetParams // MainnetCurrency is the *types.Currency for mainnet. MainnetCurrency = &types.Currency{ Symbol: "ZEN", Decimals: Decimals, } // TestnetGenesisBlockIdentifier is the genesis block for testnet. TestnetGenesisBlockIdentifier = &types.BlockIdentifier{ Hash: "03e1c4bb705c871bf9bfda3e74b7f8f86bff267993c215a89d5795e3708e5e1f", } // TestnetParams are the params for testnet. TestnetParams = &chaincfg.RegressionNetParams // TestnetCurrency is the *types.Currency for testnet. TestnetCurrency = &types.Currency{ Symbol: "ZEN", Decimals: Decimals, } // RegtestGenesisBlockIdentifier is the genesis block for regtest. RegtestGenesisBlockIdentifier = &types.BlockIdentifier{ Hash: "0da5ee723b7923feb580518541c6f098206330dbc711a6678922c11f2ccf1abb", } // RegtestParams are the params for regtest. RegtestParams = &chaincfg.RegtestParams // OperationTypes are all supported operation.Types. OperationTypes = []string{ InputOpType, OutputOpType, CoinbaseOpType, } // OperationStatuses are all supported operation.Status. OperationStatuses = []*types.OperationStatus{ { Status: SuccessStatus, Successful: true, }, { Status: SkippedStatus, Successful: false, }, } )
Functions ¶
func CoinIdentifier ¶
CoinIdentifier converts a tx hash and vout into the canonical CoinIdentifier.Identifier used in rosetta-bitcoin.
func Int64Pointer ¶ added in v0.0.8
func LocalhostURL ¶
LocalhostURL returns the URL to use for a client that is running at localhost.
func MustMarshalMap ¶ added in v0.0.8
func MustMarshalMap(v interface{}) map[string]interface{}
func ParseCoinIdentifier ¶
ParseCoinIdentifier returns the corresponding hash and index associated with a *types.CoinIdentifier.
func ParseSingleAddress ¶
func ParseSingleAddress( chainParams *chaincfg.Params, script []byte, ) (txscript.ScriptClass, zenutil.Address, error)
ParseSingleAddress extracts a single address from a pkscript or throws an error.
func StartZEND ¶
StartZEND starts a zend daemon in another goroutine and logs the results to the console.
func TransactionHash ¶
TransactionHash extracts the transaction hash from a CoinIdentifier.Identifier.
Types ¶
type Block ¶
type Block struct { Hash string `json:"hash"` Height int64 `json:"height"` PreviousBlockHash string `json:"previousblockhash"` Time int64 `json:"time"` Nonce string `json:"nonce"` MerkleRoot string `json:"merkleroot"` Version int32 `json:"version"` Size int64 `json:"size"` Bits string `json:"bits"` Difficulty float64 `json:"difficulty"` Txs []*Transaction `json:"tx"` Certs []*Certificate `json:"cert"` MaturedCerts []*Certificate `json:"matureCertificate"` }
Block is a raw Horizen block (with verbosity == 2).
type BlockMetadata ¶
type BlockMetadata struct { Nonce string `json:"nonce,omitempty"` MerkleRoot string `json:"merkleroot,omitempty"` Version int32 `json:"version,omitempty"` Size int64 `json:"size,omitempty"` Bits string `json:"bits,omitempty"` Difficulty float64 `json:"difficulty,omitempty"` }
BlockMetadata is a collection of useful metadata in a block.
type BlockchainInfo ¶
type BlockchainInfo struct { Chain string `json:"chain"` Blocks int64 `json:"blocks"` BestBlockHash string `json:"bestblockhash"` }
BlockchainInfo is information about the Bitcoin network. This struct only contains the information necessary for this implementation.
type Cert ¶ added in v0.0.6
type Cert struct { Scid string `json:"scid"` EpochNumber int64 `json:"epochNumber"` Quality int64 `json:"quality"` EndEpochCumScTxCommTreeRoot string `json:"endEpochCumScTxCommTreeRoot"` ScProof string `json:"scProof"` VFieldElementCertificateField []string `json:"vFieldElementCertificateField"` VBitVectorCertificateField []string `json:"vBitVectorCertificateField"` FtScFee float64 `json:"ftScFee"` MbtrScFee float64 `json:"mbtrScFee"` TotalAmount float64 `json:"totalAmount"` }
type Certificate ¶ added in v0.0.6
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is used to fetch blocks from bitcoind and to parse Bitcoin block data into Rosetta types.
We opted not to use existing Bitcoin RPC libraries because they don't allow providing context in each request.
func NewClient ¶
func NewClient( baseURL string, genesisBlockIdentifier *types.BlockIdentifier, currency *types.Currency, ) *Client
NewClient creates a new Bitcoin client.
func (*Client) GetBestBlock ¶
GetBestBlock performs the `getbestblock` JSON-RPC request
func (*Client) GetHashFromIndex ¶
GetHashFromIndex performs the `getblockhash` JSON-RPC request for the specified block index, and returns the hash. https://bitcoin.org/en/developer-reference#getblockhash
func (*Client) GetRawBlock ¶
func (b *Client) GetRawBlock( ctx context.Context, identifier *types.PartialBlockIdentifier, ) (*Block, []string, error)
GetRawBlock fetches a block (block) by *types.PartialBlockIdentifier.
func (*Client) NetworkStatus ¶
NetworkStatus returns the *types.NetworkStatusResponse for bitcoind.
func (*Client) ParseBlock ¶
func (b *Client) ParseBlock( ctx context.Context, block *Block, coins map[string]*storage.AccountCoin, ) (*types.Block, error)
ParseBlock returns a parsed bitcoin block given a raw bitcoin block and a map of transactions containing inputs.
func (*Client) PruneBlockchain ¶
PruneBlockchain prunes up to the provided height. https://bitcoincore.org/en/doc/0.20.0/rpc/blockchain/pruneblockchain
func (*Client) RawMempool ¶
RawMempool returns an array of all transaction hashes currently in the mempool.
func (*Client) SendRawTransaction ¶
SendRawTransaction submits a serialized transaction to bitcoind.
type Input ¶
type Input struct { TxHash string `json:"txid"` Vout int64 `json:"vout"` ScriptSig *ScriptSig `json:"scriptSig"` Sequence int64 `json:"sequence"` // Relevant when the input is the coinbase input Coinbase string `json:"coinbase"` }
Input is a raw input in a Bitcoin transaction.
type Joinsplit ¶
type Joinsplit struct { VPubOld float64 `json:"vpub_old"` VPubNew float64 `json:"vpub_new"` Anchor string `json:"anchor"` Nullifiers []string `json:"nullifiers"` Commitments []string `json:"commitments"` OneTimePubKey string `json:"onetimePubkey"` RandomSeed string `json:"randomSeed"` Macs []string `json:"macs"` Proof string `json:"proof"` Ciphertexts []string `json:"ciphertexts"` }
Joinsplit is a raw Joinsplit transaction representation.
type OperationMetadata ¶
type OperationMetadata struct { // Coinbase Metadata Coinbase string `json:"coinbase,omitempty"` // Input Metadata ScriptSig *ScriptSig `json:"scriptsig,omitempty"` Sequence int64 `json:"sequence,omitempty"` // Output Metadata ScriptPubKey *ScriptPubKey `json:"scriptPubKey,omitempty"` }
OperationMetadata is a collection of useful metadata from Bitcoin inputs and outputs.
type Output ¶
type Output struct { Value float64 `json:"value"` Index int64 `json:"n"` ScriptPubKey *ScriptPubKey `json:"scriptPubKey"` BackwardTransfer bool `json:"backwardTransfer,omitempty"` }
Output is a raw output in a Bitcoin transaction.
type PeerInfo ¶
type PeerInfo struct { Addr string `json:"addr"` Version int64 `json:"version"` SubVer string `json:"subver"` StartingHeight int64 `json:"startingheight"` RelayTxes bool `json:"relaytxes"` LastSend int64 `json:"lastsend"` LastRecv int64 `json:"lastrecv"` BanScore int64 `json:"banscore"` SyncedBlocks int64 `json:"synced_blocks"` SyncedHeaders int64 `json:"synced_headers"` }
PeerInfo is a collection of relevant info about a particular peer.
type ScriptPubKey ¶
type ScriptPubKey struct { ASM string `json:"asm"` Hex string `json:"hex"` RequiredSigs int64 `json:"reqSigs,omitempty"` Type string `json:"type"` Addresses []string `json:"addresses,omitempty"` }
ScriptPubKey is a script placed on the output operations of a Bitcoin transaction that must be satisfied to spend the output.
type ScriptSig ¶
ScriptSig is a script on the input operations of a Bitcoin transaction that satisfies the ScriptPubKey on an output being spent.
type Transaction ¶
type Transaction struct { Hex string `json:"hex"` Hash string `json:"txid"` Size int64 `json:"size"` Vsize int64 `json:"vsize"` Version int32 `json:"version"` Locktime int64 `json:"locktime"` Inputs []*Input `json:"vin"` Outputs []*Output `json:"vout"` Joinsplits []*Joinsplit `json:"vjoinsplit"` }
Transaction is a raw Horizen transaction.
func (Transaction) Metadata ¶
func (t Transaction) Metadata() (map[string]interface{}, error)
Metadata returns the metadata for a transaction.
type TransactionMetadata ¶
type TransactionMetadata struct { Size int64 `json:"size,omitempty"` Version int32 `json:"version,omitempty"` Locktime int64 `json:"locktime,omitempty"` Joinsplit []*Joinsplit `json:"vjoinsplit,omitempty"` }
TransactionMetadata is a collection of useful metadata in a transaction.