Documentation ¶
Index ¶
- Constants
- func ChainFlag2ChainParams(chainID int) (*chaincfg.Params, error)
- func CreateMultiSig(cmd *btcjson.CreateMultisigCmd, chainParam *chaincfg.Params) (*btcjson.CreateMultiSigResult, error)
- func DecodeHexStr(hexStr string) ([]byte, error)
- func DecodeRawTransaction(c *btcjson.DecodeRawTransactionCmd, chainCfg *chaincfg.Params) (txReply btcjson.TxRawDecodeResult, err error)
- func DecodeScript(c *btcjson.DecodeScriptCmd, chainCfg *chaincfg.Params) (reply btcjson.DecodeScriptResult, err error)
- func GenerateScriptPubKey4PayToPubkeyHash(pubk []byte) string
- func SignRawTransaction(cmd *SignRawTransactionCmd, chainCfg *chaincfg.Params) (*btcjson.SignRawTransactionResult, error)
- type BTC
- func (c *BTC) DecodeTx(msgTx string) (tx string, err error)
- func (c *BTC) DeriveAddress() (address string, err error)
- func (c *BTC) DerivePrivateKey() (privateKey string, err error)
- func (c *BTC) DerivePublicKey() (publicKey string, err error)
- func (c *BTC) Sign(rawTx, privateKeyWif string) (signedRawTx string, err error)
- func (c *BTC) VerifySignature(pubKey, rawTx, signedRawTx string) error
- type CustomHexMsg
- type RawTxInput
- type SignRawTransactionCmd
- type SignatureError
- type WalletTx
Constants ¶
const ChainMainNet = 0
ChainMainNet 链:MainNet
const ChainRegtest = 2
ChainRegtest 链:Regression
const ChainTestNet3 = 1
ChainTestNet3 链:TestNet3
Variables ¶
This section is empty.
Functions ¶
func ChainFlag2ChainParams ¶
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 ¶
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 ¶
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 ¶
BTC key derivation service
func NewFromMetadata ¶
func NewFromMetadata(metadata core.MetadataProvider) (c *BTC, err error)
NewFromMetadata .
func (*BTC) DecodeTx ¶
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 ¶
DeriveAddress derives the account address of the derivation path.
func (*BTC) DerivePrivateKey ¶
DerivePrivateKey derives the private key of the derivation path, encoded in string with WIF format
func (*BTC) DerivePublicKey ¶
DerivePublicKey derives the public key of the derivation path.
func (*BTC) VerifySignature ¶
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 ¶
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}]
Source Files ¶
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. |