internal

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: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ChainMainNet 链:MainNet
	ChainMainNet = 0
	// ChainTestNet3 链:TestNet3
	ChainTestNet3 = 1
	// ChainRegtest 链:Regression
	ChainRegtest = 2

	// FlagBTCUseSegWitFormat BTC使用隔离见证地址
	FlagUseSegWitFormat = "btc_use_segwit_fmt"
)

Variables

This section is empty.

Functions

func ChainFlag2ChainParams

func ChainFlag2ChainParams(chainID int) (*chaincfg.Params, error)

ChainFlag2ChainParams get chainParams from const

func ConvertPubk2segWitP2WSHAddress

func ConvertPubk2segWitP2WSHAddress(pubKey *btcec.PublicKey, chainParams *chaincfg.Params) (string, error)

ConvertPubk2segWitP2WSHAddress 把公钥转换为隔离见证地址(p2sh-p2wpkh / p2wsh)

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 DecodeHexStr

func DecodeHexStr(hexStr string) ([]byte, error)

DecodeHexStr decodes the hex encoding of a string, possibly prepending a leading '0' character if there is an odd number of bytes in the hex string. This is to prevent an error for an invalid hex string when using an odd number of bytes when calling hex.Decode.

func DecodeRawTransaction

func DecodeRawTransaction(c *btcjson.DecodeRawTransactionCmd, chainCfg *chaincfg.Params) (txReply btcjson.TxRawDecodeResult, err error)

DecodeRawTransaction handles decoderawtransaction commands.

func DecodeScript

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

DecodeScript handles decodescript commands.

func GenerateScriptPubKey4P2SHP2WPKH

func GenerateScriptPubKey4P2SHP2WPKH(pubKey *btcec.PublicKey) (redeemScript string, scriptPubk string)

GenerateScriptPubKey4P2SHP2WPKH https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#p2wpkh-nested-in-bip16-p2sh 相当于listunspent时获取的隔离见证地址的scriptPubk, redeemScript

func GenerateScriptPubKey4PayToPubkeyHash

func GenerateScriptPubKey4PayToPubkeyHash(pubk []byte) string

GenerateScriptPubKey4PayToPubkeyHash pay to public key hash -> scriptPubKey

func SignRawTransaction

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

SignRawTransaction handles the signrawtransaction command.

Types

type BTC

type BTC struct {
	core.CoinInfo
	// contains filtered or unexported fields
}

BTC key derivation service

func New

func New(bip44Path string, isSegWit bool, seed []byte, chainID int) (c *BTC, err error)

New Factory of BTC key derivation service

The order of publicKeys is important. using segWit will replace m/44'... ==> m/49'

func NewFromMetadata

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

NewFromMetadata .

func (*BTC) DecodeTx

func (c *BTC) DecodeTx(msgTx string) (tx string, err error)

DecodeTx decodes raw tx to human readable format

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

func (*BTC) DeriveAddress

func (c *BTC) DeriveAddress() (address string, err error)

DeriveAddress derives the account address of the derivation path.

func (*BTC) DerivePrivateKey

func (c *BTC) DerivePrivateKey() (privateKey string, err error)

DerivePrivateKey derives the private key of the derivation path, encoded in string with WIF format

func (*BTC) DerivePublicKey

func (c *BTC) DerivePublicKey() (publicKey string, err error)

DerivePublicKey derives the public key of the derivation path.

func (*BTC) RawKey

func (c *BTC) RawKey() ([]byte, error)

32 + 33 (format+pubk)

func (*BTC) Sign

func (c *BTC) Sign(rawTx, privateKeyWif string) (signedRawTx string, err error)

Sign signs raw tx with wif privateKey

func (*BTC) VerifySignature

func (c *BTC) VerifySignature(pubKey, rawTx, signedRawTx string) error

VerifySignature verifies rawTx's signature is intact If signedRawTx is not signed by pubKey, an error will raise.

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.
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