dcr

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: May 24, 2021 License: AGPL-3.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MainnetMagic is mainnet network constant
	MainnetMagic wire.BitcoinNet = 0xd9b400f9
	// TestnetMagic is testnet network constant
	TestnetMagic wire.BitcoinNet = 0xb194aa75
)

Variables

View Source
var (
	// MainNetParams are parser parameters for mainnet
	MainNetParams chaincfg.Params
	// TestNet3Params are parser parameters for testnet
	TestNet3Params chaincfg.Params
)

Functions

func GetChainParams

func GetChainParams(chain string) *chaincfg.Params

GetChainParams contains network parameters for the main Decred network, and the test Decred network.

func NewDecredRPC

func NewDecredRPC(config json.RawMessage, pushHandler func(bchain.NotificationType)) (bchain.BlockChain, error)

NewDecredRPC returns new DecredRPC instance.

Types

type DecodeRawTransactionResult

type DecodeRawTransactionResult struct {
	Error  Error `json:"error"`
	Result struct {
		Txid     string `json:"txid"`
		Version  int32  `json:"version"`
		Locktime uint32 `json:"locktime"`
		Expiry   uint32 `json:"expiry"`
		Vin      []Vin  `json:"vin"`
		Vout     []Vout `json:"vout"`
		TxExtraInfo
	} `json:"result"`
}

type DecredParser

type DecredParser struct {
	*btc.BitcoinParser
	// contains filtered or unexported fields
}

DecredParser handle

func NewDecredParser

func NewDecredParser(params *chaincfg.Params, c *btc.Configuration) *DecredParser

NewDecredParser returns new DecredParser instance

func (*DecredParser) DerivationBasePath

func (p *DecredParser) DerivationBasePath(xpub string) (string, error)

DerivationBasePath returns base path of xpub which whose full format is m/44'/<coin type>'/<account>'/<branch>/<address index>. This function only returns a path up to m/44'/<coin type>'/<account>'/ whereby the rest of the other details (<branch>/<address index>) are populated automatically.

func (*DecredParser) DeriveAddressDescriptors

func (p *DecredParser) DeriveAddressDescriptors(xpub string, change uint32,
	indexes []uint32) ([]bchain.AddressDescriptor, error)

DeriveAddressDescriptors derives address descriptors from given xpub for listed indexes

func (*DecredParser) DeriveAddressDescriptorsFromTo

func (p *DecredParser) DeriveAddressDescriptorsFromTo(xpub string, change uint32,
	fromIndex uint32, toIndex uint32) ([]bchain.AddressDescriptor, error)

DeriveAddressDescriptorsFromTo derives address descriptors from given xpub for addresses in index range

func (*DecredParser) GetAddrDescForUnknownInput

func (p *DecredParser) GetAddrDescForUnknownInput(tx *bchain.Tx, input int) bchain.AddressDescriptor

GetAddrDescForUnknownInput returns nil AddressDescriptor.

func (*DecredParser) GetAddrDescFromAddress

func (p *DecredParser) GetAddrDescFromAddress(address string) (bchain.AddressDescriptor, error)

GetAddrDescFromAddress returns internal address representation of a given address.

func (*DecredParser) GetAddrDescFromVout

func (p *DecredParser) GetAddrDescFromVout(output *bchain.Vout) (bchain.AddressDescriptor, error)

GetAddrDescFromVout returns internal address representation of a given transaction output.

func (*DecredParser) GetAddressesFromAddrDesc

func (p *DecredParser) GetAddressesFromAddrDesc(addrDesc bchain.AddressDescriptor) ([]string, bool, error)

GetAddressesFromAddrDesc returns addresses obtained from the internal address representation

func (*DecredParser) PackTx

func (p *DecredParser) PackTx(tx *bchain.Tx, height uint32, blockTime int64) ([]byte, error)

PackTx packs transaction to byte array using protobuf

func (*DecredParser) ParseBlock

func (p *DecredParser) ParseBlock(b []byte) (*bchain.Block, error)

ParseBlock parses raw block to our Block struct.

func (*DecredParser) ParseTxFromJson

func (p *DecredParser) ParseTxFromJson(jsonTx json.RawMessage) (*bchain.Tx, error)

ParseTxFromJson parses JSON message containing transaction and returns Tx struct

func (*DecredParser) UnpackTx

func (p *DecredParser) UnpackTx(buf []byte) (*bchain.Tx, uint32, error)

UnpackTx unpacks transaction from protobuf byte array

type DecredRPC

type DecredRPC struct {
	*btc.BitcoinRPC
	// contains filtered or unexported fields
}

func (*DecredRPC) Call

func (d *DecredRPC) Call(req interface{}, res interface{}) error

Call calls Backend RPC interface, using RPCMarshaler interface to marshall the request

func (*DecredRPC) EstimateFee

func (d *DecredRPC) EstimateFee(blocks int) (big.Int, error)

EstimateFee returns fee estimation.

func (*DecredRPC) EstimateSmartFee

func (d *DecredRPC) EstimateSmartFee(blocks int, conservative bool) (big.Int, error)

EstimateSmartFee returns fee estimation

func (*DecredRPC) GetBestBlockHash

func (d *DecredRPC) GetBestBlockHash() (string, error)

GetBestBlockHash returns the block hash of the most recent block to be mined and has a minimum of 1 confirming block.

func (*DecredRPC) GetBestBlockHeight

func (d *DecredRPC) GetBestBlockHeight() (uint32, error)

GetBestBlockHeight returns the block height of the most recent block to be mined and has a minimum of 1 confirming block.

func (*DecredRPC) GetBlock

func (d *DecredRPC) GetBlock(hash string, height uint32) (*bchain.Block, error)

GetBlock returns the block retrieved using the provided block hash by default or using the block height if an empty hash string was provided. If the requested block has less than 2 confirmation bchain.ErrBlockNotFound error is returned. This rule is in places to guarrantee that only validated block details (txs) are saved to the db. Access to the bestBlock height is threadsafe.

func (*DecredRPC) GetBlockHash

func (d *DecredRPC) GetBlockHash(height uint32) (string, error)

GetBlockHash returns the block hash of the block at the provided height.

func (*DecredRPC) GetBlockHeader

func (d *DecredRPC) GetBlockHeader(hash string) (*bchain.BlockHeader, error)

GetBlockHeader returns the block header of the block the provided block hash.

func (*DecredRPC) GetBlockInfo

func (d *DecredRPC) GetBlockInfo(hash string) (*bchain.BlockInfo, error)

func (*DecredRPC) GetChainInfo

func (d *DecredRPC) GetChainInfo() (*bchain.ChainInfo, error)

func (*DecredRPC) GetMempoolTransactions

func (d *DecredRPC) GetMempoolTransactions() ([]string, error)

GetMempoolTransactions returns a slice of regular transactions currently in the mempool. The block whose validation is still undecided will have its txs, listed like they are still in the mempool till the block is confirmed.

func (*DecredRPC) GetTransaction

func (d *DecredRPC) GetTransaction(txid string) (*bchain.Tx, error)

GetTransaction returns a transaction by the transaction ID

func (*DecredRPC) GetTransactionForMempool

func (d *DecredRPC) GetTransactionForMempool(txid string) (*bchain.Tx, error)

GetTransactionForMempool returns the full tx information identified by the provided txid.

func (*DecredRPC) GetTransactionSpecific

func (d *DecredRPC) GetTransactionSpecific(tx *bchain.Tx) (json.RawMessage, error)

GetTransactionSpecific returns the json raw message for the tx identified by the provided txid.

func (*DecredRPC) Initialize

func (d *DecredRPC) Initialize() error

Initialize initializes DecredRPC instance.

func (*DecredRPC) SendRawTransaction

func (d *DecredRPC) SendRawTransaction(tx string) (string, error)

type Error

type Error struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

type EstimateFeeResult

type EstimateFeeResult struct {
	Error  Error             `json:"error"`
	Result common.JSONNumber `json:"result"`
}

type EstimateSmartFeeResult

type EstimateSmartFeeResult struct {
	Error  Error `json:"error"`
	Result struct {
		FeeRate float64  `json:"feerate"`
		Errors  []string `json:"errors"`
		Blocks  int64    `json:"blocks"`
	} `json:"result"`
}

type GenericCmd

type GenericCmd struct {
	ID     int           `json:"id"`
	Method string        `json:"method"`
	Params []interface{} `json:"params,omitempty"`
}

type GetBestBlockResult

type GetBestBlockResult struct {
	Error  Error `json:"error"`
	Result struct {
		Hash   string `json:"hash"`
		Height uint32 `json:"height"`
	} `json:"result"`
}

type GetBlockChainInfoResult

type GetBlockChainInfoResult struct {
	Error  Error `json:"error"`
	Result struct {
		Chain                string  `json:"chain"`
		Blocks               int64   `json:"blocks"`
		Headers              int64   `json:"headers"`
		SyncHeight           int64   `json:"syncheight"`
		BestBlockHash        string  `json:"bestblockhash"`
		Difficulty           uint32  `json:"difficulty"`
		VerificationProgress float64 `json:"verificationprogress"`
		ChainWork            string  `json:"chainwork"`
		InitialBlockDownload bool    `json:"initialblockdownload"`
		MaxBlockSize         int64   `json:"maxblocksize"`
	} `json:"result"`
}

type GetBlockHashResult

type GetBlockHashResult struct {
	Error  Error  `json:"error"`
	Result string `json:"result"`
}

type GetBlockHeaderResult

type GetBlockHeaderResult struct {
	Error  Error `json:"error"`
	Result struct {
		Hash          string            `json:"hash"`
		Confirmations int64             `json:"confirmations"`
		Version       common.JSONNumber `json:"version"`
		MerkleRoot    string            `json:"merkleroot"`
		StakeRoot     string            `json:"stakeroot"`
		VoteBits      uint16            `json:"votebits"`
		FinalState    string            `json:"finalstate"`
		Voters        uint16            `json:"voters"`
		FreshStake    uint8             `json:"freshstake"`
		Revocations   uint8             `json:"revocations"`
		PoolSize      uint32            `json:"poolsize"`
		Bits          string            `json:"bits"`
		SBits         float64           `json:"sbits"`
		Height        uint32            `json:"height"`
		Size          uint32            `json:"size"`
		Time          int64             `json:"time"`
		Nonce         uint32            `json:"nonce"`
		ExtraData     string            `json:"extradata"`
		StakeVersion  uint32            `json:"stakeversion"`
		Difficulty    float64           `json:"difficulty"`
		ChainWork     string            `json:"chainwork"`
		PreviousHash  string            `json:"previousblockhash,omitempty"`
		NextHash      string            `json:"nextblockhash,omitempty"`
	} `json:"result"`
}

type GetBlockResult

type GetBlockResult struct {
	Error  Error `json:"error"`
	Result struct {
		Hash          string            `json:"hash"`
		Confirmations int64             `json:"confirmations"`
		Size          int32             `json:"size"`
		Height        uint32            `json:"height"`
		Version       common.JSONNumber `json:"version"`
		MerkleRoot    string            `json:"merkleroot"`
		StakeRoot     string            `json:"stakeroot"`
		RawTx         []RawTx           `json:"rawtx"`
		Tx            []string          `json:"tx,omitempty"`
		STx           []string          `json:"stx,omitempty"`
		Time          int64             `json:"time"`
		Nonce         common.JSONNumber `json:"nonce"`
		VoteBits      uint16            `json:"votebits"`
		FinalState    string            `json:"finalstate"`
		Voters        uint16            `json:"voters"`
		FreshStake    uint8             `json:"freshstake"`
		Revocations   uint8             `json:"revocations"`
		PoolSize      uint32            `json:"poolsize"`
		Bits          string            `json:"bits"`
		SBits         float64           `json:"sbits"`
		ExtraData     string            `json:"extradata"`
		StakeVersion  uint32            `json:"stakeversion"`
		Difficulty    float64           `json:"difficulty"`
		ChainWork     string            `json:"chainwork"`
		PreviousHash  string            `json:"previousblockhash"`
		NextHash      string            `json:"nextblockhash,omitempty"`
	} `json:"result"`
}

type GetInfoChainResult

type GetInfoChainResult struct {
	Error  Error `json:"error"`
	Result struct {
		Version         int32   `json:"version"`
		ProtocolVersion int32   `json:"protocolversion"`
		Blocks          int64   `json:"blocks"`
		TimeOffset      int64   `json:"timeoffset"`
		Connections     int32   `json:"connections"`
		Proxy           string  `json:"proxy"`
		Difficulty      float64 `json:"difficulty"`
		TestNet         bool    `json:"testnet"`
		RelayFee        float64 `json:"relayfee"`
		Errors          string  `json:"errors"`
	}
}

type GetNetworkInfoResult

type GetNetworkInfoResult struct {
	Error  Error `json:"error"`
	Result struct {
		Version         int32   `json:"version"`
		ProtocolVersion int32   `json:"protocolversion"`
		TimeOffset      int64   `json:"timeoffset"`
		Connections     int32   `json:"connections"`
		RelayFee        float64 `json:"relayfee"`
	} `json:"result"`
}

type GetTransactionResult

type GetTransactionResult struct {
	Error  Error `json:"error"`
	Result struct {
		RawTx
	} `json:"result"`
}

type MempoolTxsResult

type MempoolTxsResult struct {
	Error  Error    `json:"error"`
	Result []string `json:"result"`
}

type RawTx

type RawTx struct {
	Hex           string `json:"hex"`
	Txid          string `json:"txid"`
	Version       int32  `json:"version"`
	LockTime      uint32 `json:"locktime"`
	Vin           []Vin  `json:"vin"`
	Vout          []Vout `json:"vout"`
	Expiry        uint32 `json:"expiry"`
	BlockIndex    uint32 `json:"blockindex,omitempty"`
	Confirmations int64  `json:"confirmations,omitempty"`
	Time          int64  `json:"time,omitempty"`
	Blocktime     int64  `json:"blocktime,omitempty"`
	TxExtraInfo
}

type ScriptPubKeyResult

type ScriptPubKeyResult struct {
	Asm       string   `json:"asm"`
	Hex       string   `json:"hex,omitempty"`
	ReqSigs   int32    `json:"reqSigs,omitempty"`
	Type      string   `json:"type"`
	Addresses []string `json:"addresses,omitempty"`
	CommitAmt *float64 `json:"commitamt,omitempty"`
}

type ScriptSig

type ScriptSig struct {
	Asm string `json:"asm"`
	Hex string `json:"hex"`
}

type SendRawTransactionResult

type SendRawTransactionResult struct {
	Error  Error  `json:"error"`
	Result string `json:"result"`
}

type TxExtraInfo

type TxExtraInfo struct {
	BlockHeight uint32 `json:"blockheight,omitempty"`
	BlockHash   string `json:"blockhash,omitempty"`
}

type Vin

type Vin struct {
	Coinbase    string     `json:"coinbase"`
	Stakebase   string     `json:"stakebase"`
	Txid        string     `json:"txid"`
	Vout        uint32     `json:"vout"`
	Tree        int8       `json:"tree"`
	Sequence    uint32     `json:"sequence"`
	AmountIn    float64    `json:"amountin"`
	BlockHeight uint32     `json:"blockheight"`
	BlockIndex  uint32     `json:"blockindex"`
	ScriptSig   *ScriptSig `json:"scriptsig"`
}

type Vout

type Vout struct {
	Value        float64            `json:"value"`
	N            uint32             `json:"n"`
	Version      uint16             `json:"version"`
	ScriptPubKey ScriptPubKeyResult `json:"scriptPubKey"`
}

Jump to

Keyboard shortcuts

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