internal

package
v0.10.0-beta.20200911 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2020 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const ChainMainNet = 0

ChainMainNet 链:MainNet

View Source
const ChainRegtest = 2

ChainRegtest 链:Regression

View Source
const ChainTestNet3 = 1

ChainTestNet3 链:TestNet3

Variables

This section is empty.

Functions

func ChainFlag2ChainParams

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

ChainFlag2ChainParams get chainParams from const

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

BTC key derivation service

func New

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

New Factory of BTC key derivation service

The order of publicKeys is important.

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

Jump to

Keyboard shortcuts

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