btc

package
v0.0.0-...-872243e Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2019 License: GPL-3.0, LGPL-3.0 Imports: 28 Imported by: 0

Documentation

Overview

Package helpers provides convenience functions to simplify wallet code. This package is intended for internal wallet use only.

Index

Constants

View Source
const (
	// RedeemP2PKHSigScriptSize is the worst case (largest) serialize size
	// of a transaction input script that redeems a compressed P2PKH output.
	// It is calculated as:
	//
	//   - OP_DATA_73
	//   - 72 bytes DER signature + 1 byte sighash
	//   - OP_DATA_33
	//   - 33 bytes serialized compressed pubkey
	RedeemP2PKHSigScriptSize = 1 + 73 + 1 + 33

	// P2PKHPkScriptSize is the size of a transaction output script that
	// pays to a compressed pubkey hash.  It is calculated as:
	//
	//   - OP_DUP
	//   - OP_HASH160
	//   - OP_DATA_20
	//   - 20 bytes pubkey hash
	//   - OP_EQUALVERIFY
	//   - OP_CHECKSIG
	P2PKHPkScriptSize = 1 + 1 + 1 + 20 + 1 + 1

	// RedeemP2PKHInputSize is the worst case (largest) serialize size of a
	// transaction input redeeming a compressed P2PKH output.  It is
	// calculated as:
	//
	//   - 32 bytes previous tx
	//   - 4 bytes output index
	//   - 1 byte compact int encoding value 107
	//   - 107 bytes signature script
	//   - 4 bytes sequence
	RedeemP2PKHInputSize = 32 + 4 + 1 + RedeemP2PKHSigScriptSize + 4

	// P2PKHOutputSize is the serialize size of a transaction output with a
	// P2PKH output script.  It is calculated as:
	//
	//   - 8 bytes output value
	//   - 1 byte compact int encoding value 25
	//   - 25 bytes P2PKH output script
	P2PKHOutputSize = 8 + 1 + P2PKHPkScriptSize

	// P2WPKHPkScriptSize is the size of a transaction output script that
	// pays to a witness pubkey hash. It is calculated as:
	//
	//   - OP_0
	//   - OP_DATA_20
	//   - 20 bytes pubkey hash
	P2WPKHPkScriptSize = 1 + 1 + 20

	// P2WPKHOutputSize is the serialize size of a transaction output with a
	// P2WPKH output script. It is calculated as:
	//
	//   - 8 bytes output value
	//   - 1 byte compact int encoding value 22
	//   - 22 bytes P2PKH output script
	P2WPKHOutputSize = 8 + 1 + P2WPKHPkScriptSize

	// RedeemP2WPKHScriptSize is the size of a transaction input script
	// that spends a pay-to-witness-public-key hash (P2WPKH). The redeem
	// script for P2WPKH spends MUST be empty.
	RedeemP2WPKHScriptSize = 0

	// RedeemP2WPKHInputSize is the worst case size of a transaction
	// input redeeming a P2WPKH output. It is calculated as:
	//
	//   - 32 bytes previous tx
	//   - 4 bytes output index
	//   - 1 byte encoding empty redeem script
	//   - 0 bytes redeem script
	//   - 4 bytes sequence
	RedeemP2WPKHInputSize = 32 + 4 + 1 + RedeemP2WPKHScriptSize + 4

	// RedeemNestedP2WPKHScriptSize is the worst case size of a transaction
	// input script that redeems a pay-to-witness-key hash nested in P2SH
	// (P2SH-P2WPKH). It is calculated as:
	//
	//   - 1 byte compact int encoding value 22
	//   - OP_0
	//   - 1 byte compact int encoding value 20
	//   - 20 byte key hash
	RedeemNestedP2WPKHScriptSize = 1 + 1 + 1 + 20

	// RedeemNestedP2WPKHInputSize is the worst case size of a
	// transaction input redeeming a P2SH-P2WPKH output. It is
	// calculated as:
	//
	//   - 32 bytes previous tx
	//   - 4 bytes output index
	//   - 1 byte compact int encoding value 23
	//   - 23 bytes redeem script (scriptSig)
	//   - 4 bytes sequence
	RedeemNestedP2WPKHInputSize = 32 + 4 + 1 +
		RedeemNestedP2WPKHScriptSize + 4

	// RedeemP2WPKHInputWitnessWeight is the worst case weight of
	// a witness for spending P2WPKH and nested P2WPKH outputs. It
	// is calculated as:
	//
	//   - 1 wu compact int encoding value 2 (number of items)
	//   - 1 wu compact int encoding value 73
	//   - 72 wu DER signature + 1 wu sighash
	//   - 1 wu compact int encoding value 33
	//   - 33 wu serialized compressed pubkey
	RedeemP2WPKHInputWitnessWeight = 1 + 1 + 73 + 1 + 33
)

Worst case script and input/output size estimates.

Variables

View Source
var BTC_DEFAULT_FEE, _ = new(big.Int).SetString("50000", 10)
View Source
var ChainConfig = chaincfg.TestNet3Params
View Source
var RequiredConfirmations int64

Functions

func BTCInit

func BTCInit()

func EstimateSerializeSize

func EstimateSerializeSize(inputCount int, txOuts []*wire.TxOut, addChangeOutput bool) int

EstimateSerializeSize returns a worst case serialize size estimate for a signed transaction that spends inputCount number of compressed P2PKH outputs and contains each transaction output from txOuts. The estimated size is incremented for an additional P2PKH change output if addChangeOutput is true.

func EstimateVirtualSize

func EstimateVirtualSize(numP2PKHIns, numP2WPKHIns, numNestedP2WPKHIns int,
	txOuts []*wire.TxOut, addChangeOutput bool) int

EstimateVirtualSize returns a worst case virtual size estimate for a signed transaction that spends the given number of P2PKH, P2WPKH and (nested) P2SH-P2WPKH outputs, and contains each transaction output from txOuts. The estimate is incremented for an additional P2PKH change output if addChangeOutput is true.

func GetTransaction_electrs

func GetTransaction_electrs(hash string) (*electrsTx, error)

func ListUnspent_electrs

func ListUnspent_electrs(addr string) (list []btcjson.ListUnspentResult, balance *big.Int, err error)

func MakeInputSource

func MakeInputSource(outputs []btcjson.ListUnspentResult) txauthor.InputSource

func SendRawTransaction

func SendRawTransaction(c *rpcutils.RpcClient, tx *wire.MsgTx, allowHighFees bool) (ret string, err error)

发送交易

func SumOutputSerializeSizes

func SumOutputSerializeSizes(outputs []*wire.TxOut) (serializeSize int)

SumOutputSerializeSizes sums up the serialized size of the supplied outputs.

func SumOutputValues

func SumOutputValues(outputs []*wire.TxOut) (totalOutput btcutil.Amount)

SumOutputValues sums up the list of TxOuts and returns an Amount.

Types

type AddrApiResult

type AddrApiResult struct {
	Address             string
	Total_received      float64
	Balance             float64
	Unconfirmed_balance uint64
	Final_balance       float64
	N_tx                int64
	Unconfirmed_n_tx    int64
	Final_n_tx          int64
	Txrefs              []Txref
	Tx_url              string
}

type AuthoredTx

type AuthoredTx struct {
	Tx              *wire.MsgTx
	PrevScripts     [][]byte
	PrevInputValues []btcutil.Amount
	TotalInput      btcutil.Amount
	ChangeIndex     int // negative if no change
	Digests         []string
	PubKeyData      []byte
}

func NewUnsignedTransaction

func NewUnsignedTransaction(outputs []*wire.TxOut, relayFeePerKb btcutil.Amount, fetchInputs txauthor.InputSource, fetchChange txauthor.ChangeSource) (*AuthoredTx, error)

type BTCHandler

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

func NewBTCHandler

func NewBTCHandler() *BTCHandler

func NewBTCHandlerWithConfig

func NewBTCHandlerWithConfig(userServerHost string, suserServerPort int, userRpcuser, userPasswd string, userUsessl bool) *BTCHandler

func (*BTCHandler) BuildUnsignedTransaction

func (h *BTCHandler) BuildUnsignedTransaction(fromAddress, fromPublicKey, toAddress string, amount *big.Int, jsonstring string) (transaction interface{}, digests []string, err error)

jsonstring: '{"feeRate":0.0001,"changAddress":"mtjq9RmBBDVne7YB4AFHYCZFn3P2AXv9D5"}'

func (*BTCHandler) GetAddressBalance

func (h *BTCHandler) GetAddressBalance(address string, jsonstring string) (balance types.Balance, err error)

func (*BTCHandler) GetDefaultFee

func (h *BTCHandler) GetDefaultFee() types.Value

func (*BTCHandler) GetTransactionInfo

func (h *BTCHandler) GetTransactionInfo(txhash string) (fromAddress string, txOutputs []types.TxOutput, jsonstring string, confirmed bool, fee types.Value, err error)

func (*BTCHandler) IsToken

func (h *BTCHandler) IsToken() bool

func (*BTCHandler) MakeSignedTransaction

func (h *BTCHandler) MakeSignedTransaction(rsv []string, transaction interface{}) (signedTransaction interface{}, err error)

func (*BTCHandler) PublicKeyToAddress

func (h *BTCHandler) PublicKeyToAddress(pubKeyHex string) (address string, err error)

func (*BTCHandler) SignTransaction

func (h *BTCHandler) SignTransaction(hash []string, wif interface{}) (rsv []string, err error)

func (*BTCHandler) SubmitTransaction

func (h *BTCHandler) SubmitTransaction(signedTransaction interface{}) (ret string, err error)

type Output

type Output struct {
	Script    string
	Addresses []string
}

type TxApiResult

type TxApiResult struct {
	TxHash  string
	Outputs []Output
}

type Txref

type Txref struct {
	Tx_hash       string
	Block_height  int64
	Tx_input_n    int32
	Tx_output_n   int32
	Value         float64
	Ref_balance   float64
	Spent         bool
	Confirmations int64
	Confirmed     string
	Double_spend  bool
}

Txref 表示一次交易中的第 Tx_input_n 个输入, 或第 Tx_output_n 个输出 如果是一个输入, Tx_input_n = -1 如果是一个输出, Tx_output_n = -1 如果表示交易输出,spent表示是否花出

type UtxoLsRes

type UtxoLsRes struct {
	Unspent_outputs []UtxoRes
}

type UtxoRes

type UtxoRes struct {
	Tx_hash_big_endian string
	Script             string
	Tx_output_n        uint32
	Value              float64
	Confirmations      int64
}

Jump to

Keyboard shortcuts

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