btc

package
v1.10.0-beta.20201225 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2020 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const ChainMainNet = internal.ChainMainNet

ChainMainNet 链:MainNet

View Source
const ChainRegtest = internal.ChainRegtest

ChainRegtest 链:Regression

View Source
const ChainTestNet3 = internal.ChainTestNet3

ChainTestNet3 链:TestNet3

View Source
const FlagUseSegWitFormat = internal.FlagUseSegWitFormat

FlagUseSegWitFormat BTC使用隔离见证地址

Variables

Functions

func Hello

func Hello() string

Hello 返回简单的hello 字符串,可用于验证api调用

func NewBip44Deriver

func NewBip44Deriver(bip44Path string, isSegWit bool, seed []byte, chainID int) (bip44.Deriver, error)

NewBip44Deriver btc bip44 实现

func NewCoin

func NewCoin(bip44Path string, isSegWit bool, seed []byte, chainID int) (core.Coin, error)

NewCoin btc impl of core.Coin

func NewFromMetadata

func NewFromMetadata(metadata core.MetadataProvider) (c core.Coin, err error)

NewFromMetadata .

func NewMultiSigAddress

func NewMultiSigAddress(mRequired, chainID int, keys string) (string, error)

NewMultiSigAddress 工具函数,生成BTC多签地址 Params:

chainID: 0主链,1测试链,2Regression链
cmd.NRequired 需要签名的人数
cmd.Keys hex编码的公钥

限制:len(cmd.Keys) >= cmd.NRequired Return:

多签地址,redeemScript

Types

type BTCAddress

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

BTCAddress .

func NewBTCAddressFromString

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

NewBTCAddressFromString converts a string to a address value.

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 BTCOutputAmount

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

BTCOutputAmount 交易输出

func (*BTCOutputAmount) Add

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

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

type BTCTransaction

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

BTCTransaction represents a single bitcoin transaction.

func InternalNewBTCTransaction

func InternalNewBTCTransaction(unSpent *BTCUnspent, amounts *BTCOutputAmount, change *BTCAddress, feeRate int64, chainID int, manualTxOuts []*wire.TxOut) (tr *BTCTransaction, err error)

InternalNewBTCTransaction 内部用,构造btc transaction

func NewBTCTransaction

func NewBTCTransaction(unSpent *BTCUnspent, amounts *BTCOutputAmount, change *BTCAddress, feeRate int64, chainID int) (tr *BTCTransaction, err error)

NewBTCTransaction creates a new bitcoin transaction with the given properties. unSpent : listUnspent amounts: toAddress + amount change: 找零地址 feeRate: 单位手续费/byte testNet: 测试网络传true

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
}

BTCUnspent represents a single bitcoin transaction.

func (*BTCUnspent) Add

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

Add add one utxo

type Btc

type Btc struct {
	internal.BTC
}

Btc (全部大写在导出到java那边有点问题)

type SignRawTransactionResult

type SignRawTransactionResult struct {
	Hex      string
	Changed  bool //is raw tx changed
	Complete bool //multi input,multisig require meetted
	Errors   string
}

SignRawTransactionResult 签名结果

func SignRawTransactionWithKey

func SignRawTransactionWithKey(hexstring string, privateKeyWif string, unspents *BTCUnspent, chainFlag int) (*SignRawTransactionResult, error)

SignRawTransactionWithKey Refer to https://bitcoin.org/en/developer-reference#signrawtransactionwithkey Diff from rpc:

sighashtype is set to "ALL"
single private key

func SignTransaction

func SignTransaction(tx *BTCTransaction, privateKeyWif string, chainFlag int) (*SignRawTransactionResult, error)

SignTransaction signs tx with wif privateKey tx: transaction privateKeyWif: private key in wallet import format(wif) chainFlag: chain id

return: {
    changed: (bool, 签名后的内容是否发生变化,),
	   complete: (bool, 含不同地址的输入或多重签名情况下即使提供正确的私钥也可能存在签名未完成的情况),
    hex: (string, 前后的rawTransactionHex)
    errors: (string 可作为调试参考的错误信息)
}

Directories

Path Synopsis
helpers
Package helpers provides convenience functions to simplify wallet code.
Package helpers provides convenience functions to simplify wallet code.
txauthor
Package txauthor provides transaction creation code for wallets.
Package txauthor provides transaction creation code for wallets.
txrules
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.
txscript
Package txscript implements the bitcoin transaction script language.
Package txscript implements the bitcoin transaction script language.

Jump to

Keyboard shortcuts

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