btc

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2021 License: GPL-3.0 Imports: 24 Imported by: 0

Documentation

Overview

description: keybox

@author: xwc1125 @date: 2020/8/21 0021

description: keybox

@author: xwc1125 @date: 2020/8/24 0024

description: keybox

@author: xwc1125 @date: 2020/8/21 0021

description: keybox

@author: xwc1125 @date: 2020/8/21 0021

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateMultiSig

func CreateMultiSig(cmd *btcjson.CreateMultisigCmd, chainParam *chaincfg.Params) (*btcjson.CreateMultiSigResult, error)

CreateMultiSig handles an createmultisig request by returning a multisig address for the given inputs. This method is originally copied and modified from https://github.com/btcsuite/btcwallet/blob/master/rpc/legacyrpc/methods.go

func DecodeScript

func DecodeScript(c *btcjson.DecodeScriptCmd, chainCfg *chaincfg.Params) (reply btcjson.DecodeScriptResult, err error)

DecodeScript handles decodescript commands.

func ParseNetworkToConf

func ParseNetworkToConf(network string) (*chaincfg.Params, error)

func SignRawTransaction

func SignRawTransaction(cmd *SignRawTransactionCmd, chainCfg *chaincfg.Params) (*btcjson.SignRawTransactionResult, error)

SignRawTransaction handles the signrawtransaction command.

Types

type BTCAddress

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

func NewBTCAddressFromString

func NewBTCAddressFromString(addr string, network string) (address *BTCAddress, err error)

将地址字符串转为BTC地址

type BTCAmount

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

BTCAmount 对float64 的封装

func NewBTCAmount

func NewBTCAmount(amount float64) (amt *BTCAmount, err error)

NewBTCAmount 数量in BTC (not in satoshi)

type BTCOutput

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

BTCOutputAmount 交易输出

func (*BTCOutput) Add

func (baa *BTCOutput) Add(address *BTCAddress, amount *BTCAmount)

Add 添加一个交易输出 address 地址 amount 金额

type BTCTransaction

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

func InternalNewBTCTransaction

func InternalNewBTCTransaction(unSpent *BTCUnspent, amounts *BTCOutput, change *BTCAddress, feeRate int64, network string, manualTxOuts []*wire.TxOut) (tr *BTCTransaction, err error)

InternalNewBTCTransaction 内部用,构造btc transaction

func NewBTCTransaction

func NewBTCTransaction(unSpent *BTCUnspent, amounts *BTCOutput, change *BTCAddress, feeRate int64, network string) (tr *BTCTransaction, err error)

NewBTCTransaction creates a new bitcoin transaction with the given properties. unSpent : listUnspent amounts: toAddress + amount change: 找零地址 feeRate: 单位手续费/byte network: 网络类型(mainnet,testnet,testnet3)

func (BTCTransaction) Encode

func (tx BTCTransaction) Encode() (string, error)

Encode encode to raw transaction

func (BTCTransaction) EncodeToSignCmd

func (tx BTCTransaction) EncodeToSignCmd() (string, error)

EncodeToSignCmd 结果可以用于签名接口

func (BTCTransaction) EncodeToSignCmdForNextSigner

func (tx BTCTransaction) EncodeToSignCmdForNextSigner(signedRawTX string) (string, error)

EncodeToSignCmdForNextSigner 构造给下个签名者签名的命令, signedRawTX: 当前签名者已签名好的交易数据

func (BTCTransaction) GetFee

func (tx BTCTransaction) GetFee() (float64, error)

GetFee 获取目前的费率(in BTC, not satoshi) Returns the miner's fee for the current transaction

type BTCUnspent

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

未使用的花费

func (*BTCUnspent) Add

func (us *BTCUnspent) Add(txId string, vOut int64, amount float64, scriptPubKey, redeemScript string)

添加未消费的花费

type Chain

type Chain struct {
	s256.Algorithm
	// contains filtered or unexported fields
}

func NewChain

func NewChain(networkType chain.NetworkType) *Chain

func (*Chain) ChainInfo

func (a *Chain) ChainInfo() *keybox.ChainInfo

获取链信息

func (*Chain) ExportPrivateKey

func (a *Chain) ExportPrivateKey(priKey []byte, isCompressPubKey bool) (string, error)

比特币中的netId就是PrivateKeyID[wifPrvkey]

func (*Chain) ExportPrivateKey2

func (a *Chain) ExportPrivateKey2(priKey []byte, isCompressPubKey bool) (string, error)

比特币中的netId就是PrivateKeyID[wifPrvkey]

func (*Chain) GetAddressFromPubKey

func (a *Chain) GetAddressFromPubKey(pubKey []byte) (string, error)

从公钥获取地址

func (*Chain) SignRawTx

func (c *Chain) SignRawTx(rawTx, privateKeyWif string) (signedRawTx string, err error)

func (*Chain) SignToStr

func (a *Chain) SignToStr(priKey []byte, rawTxBytes []byte) (string, error)

签名直接返回签名的string

type CustomHexMsg

type CustomHexMsg struct {
	SignRawTransactionCmd
	DecodeTransaction func(cmd *btcjson.DecodeRawTransactionCmd, params *chaincfg.Params) (
		btcjson.TxRawDecodeResult, error) `json:"-,omitempty"`
	SignTransaction func() `json:"-,omitempty"`
	// contains filtered or unexported fields
}

服务端发送的消息 "{hex:"",rawTxInput:[{scriptPubKey:"xxx",redeemScript:"xxx",amount:0}]}"

func (*CustomHexMsg) MarshalJSON

func (c *CustomHexMsg) MarshalJSON() ([]byte, error)

func (*CustomHexMsg) MarshalToWalletTxJSON

func (c *CustomHexMsg) MarshalToWalletTxJSON(chainCfg *chaincfg.Params) (tx string, err error)

func (*CustomHexMsg) UnmarshalJSON

func (c *CustomHexMsg) UnmarshalJSON(msg string) (err error)

type RawTxInput

type RawTxInput struct {
	Txid         string  `json:"txid"`
	Vout         uint32  `json:"vout"`
	ScriptPubKey string  `json:"scriptPubKey"`
	RedeemScript string  `json:"redeemScript"`
	Amount       float64 `json:"amount,omitempty"` // only for bch
}

RawTxInput models the data needed for raw transaction input that is used in the SignRawTransactionCmd struct.

type SignRawTransactionCmd

type SignRawTransactionCmd struct {
	RawTx    string
	Inputs   *[]RawTxInput
	PrivKeys *[]string
	Flags    *string `default:"\"ALL\""`
}

SignRawTransactionCmd defines the signrawtransaction JSON-RPC command.

func NewSignRawTransactionCmd

func NewSignRawTransactionCmd(hexEncodedTx string, inputs *[]RawTxInput, privKeys *[]string, flags *string) *SignRawTransactionCmd

NewSignRawTransactionCmd returns a new instance which can be used to issue a signrawtransaction JSON-RPC command.

The parameters which are pointers indicate they are optional. Passing nil for optional parameters will use the default value.

type SignatureError

type SignatureError struct {
	InputIndex uint32
	Error      error
}

SignatureError records the underlying error when validating a transaction input signature.

type WalletTx

type WalletTx struct {
	Version  int32  `json:"version"`
	Locktime uint32 `json:"locktime"`
	Vin      []vin  `json:"vin"`
	Vout     []vout `json:"vout"`
}

WalletTx 钱包可读数据

* version : 2 * locktime : 0 * vin : [{"txid":"07d25a5793dd24cd6d1a810d8bb2958c271ed1971d7e1fb823217a1947170fed","output":0,"sequence":4294967295,"address":"38pfGw2jtkRvwJqXYqLtcFbPS7gHmkWfsN"}] * vout : [{"address":"38pfGw2jtkRvwJqXYqLtcFbPS7gHmkWfsN","amount":0.084},{"address":"1QLGpxXUfJUVfVNDUJsuQ4dxBppgeuGX5R","amount":0.1}]

Directories

Path Synopsis
Package helpers provides convenience functions to simplify wallet code.
Package helpers provides convenience functions to simplify wallet code.
Package txauthor provides transaction creation code for wallets.
Package txauthor provides transaction creation code for wallets.
Package txrules provides transaction rules that should be followed by transaction authors for wide mempool acceptance and quick mining.
Package txrules provides transaction rules that should be followed by transaction authors for wide mempool acceptance and quick mining.

Jump to

Keyboard shortcuts

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