Documentation ¶
Index ¶
- Constants
- func GetSighashForInput(transaction *BitcoinTransaction, sighashType uint32, inputNumber uint32) string
- type BitcoinTransaction
- func (bt *BitcoinTransaction) AddInput(input *Input)
- func (bt *BitcoinTransaction) AddOutput(output *Output)
- func (bt *BitcoinTransaction) AddUTXO(txID string, vout uint32, script string, satoshis uint64) error
- func (bt *BitcoinTransaction) ApplySignatures(signingPayload *SigningPayload, sigType uint32) error
- func (bt *BitcoinTransaction) ApplySignaturesWithoutP2PKHCheck(signingPayload *SigningPayload, sigType uint32) error
- func (bt *BitcoinTransaction) GetInputs() []*Input
- func (bt *BitcoinTransaction) GetOutputs() []*Output
- func (bt *BitcoinTransaction) GetSighashPayload(sigType uint32) (*SigningPayload, error)
- func (bt *BitcoinTransaction) GetTxID() string
- func (bt *BitcoinTransaction) HasWitnessData() bool
- func (bt *BitcoinTransaction) Hex() []byte
- func (bt *BitcoinTransaction) HexWithClearedInputs(index int, scriptPubKey []byte) []byte
- func (bt *BitcoinTransaction) InputCount() int
- func (bt *BitcoinTransaction) IsCoinbase() bool
- func (bt *BitcoinTransaction) OutputCount() int
- func (bt *BitcoinTransaction) PayTo(address string, amount uint64) error
- func (bt *BitcoinTransaction) Sign(privateKey *btcec.PrivateKey, sigType uint32) error
- func (bt *BitcoinTransaction) SignWithoutP2PKHCheck(privateKey *btcec.PrivateKey, sigType uint32) error
- type Input
- type Output
- type RedeemScript
- type Script
- type SigningItem
- type SigningPayload
Constants ¶
const ( SighashAll = 0x00000001 SighashNone = 0x00000002 SighashSingle = 0x00000003 SighashForkID = 0x00000040 SighashAnyoneCanPay = 0x00000080 SighashAllForkID = (0x00000001 | 0x00000040) )
Signature constants
Variables ¶
This section is empty.
Functions ¶
func GetSighashForInput ¶
func GetSighashForInput(transaction *BitcoinTransaction, sighashType uint32, inputNumber uint32) string
GetSighashForInput function
Types ¶
type BitcoinTransaction ¶
type BitcoinTransaction struct { Bytes []byte Version uint32 Witness bool Inputs []*Input Outputs []*Output Locktime uint32 }
A BitcoinTransaction wraps a bitcoin transaction
func NewFromBytes ¶
func NewFromBytes(bytes []byte) *BitcoinTransaction
NewFromBytes takes an array of bytes and constructs a BitcoinTransaction.
func NewFromBytesWithUsed ¶
func NewFromBytesWithUsed(bytes []byte) (*BitcoinTransaction, int)
NewFromBytesWithUsed takes an array of bytes and constructs a BitcoinTransaction and returns the offset (length of tx).
func NewFromString ¶
func NewFromString(str string) (*BitcoinTransaction, error)
NewFromString takes a hex string representation of a bitcoin transaction and returns a BitcoinTransaction object.
func (*BitcoinTransaction) AddInput ¶
func (bt *BitcoinTransaction) AddInput(input *Input)
AddInput adds a new input to the transaction.
func (*BitcoinTransaction) AddOutput ¶
func (bt *BitcoinTransaction) AddOutput(output *Output)
AddOutput adds a new output to the transaction.
func (*BitcoinTransaction) AddUTXO ¶
func (bt *BitcoinTransaction) AddUTXO(txID string, vout uint32, script string, satoshis uint64) error
AddUTXO function
func (*BitcoinTransaction) ApplySignatures ¶
func (bt *BitcoinTransaction) ApplySignatures(signingPayload *SigningPayload, sigType uint32) error
ApplySignatures applies the signatures passed in through SigningPayload parameter to the transaction inputs The signing payload from the signing service should contain a signing item for each of the tx inputs. If the TX input does not belong to us, its signature will be blank unless its owner has already signed it. If the signing payload contains a signature for a given input, we apply that to the tx regardless of whether we own it or not.
func (*BitcoinTransaction) ApplySignaturesWithoutP2PKHCheck ¶
func (bt *BitcoinTransaction) ApplySignaturesWithoutP2PKHCheck(signingPayload *SigningPayload, sigType uint32) error
ApplySignaturesWithoutP2PKHCheck applies signatures without checking if the input previous script equals to a P2PKH script matching the private key (see func SignWithoutP2PKHCheck below)
func (*BitcoinTransaction) GetInputs ¶
func (bt *BitcoinTransaction) GetInputs() []*Input
GetInputs returns an array of all inputs in the transaction.
func (*BitcoinTransaction) GetOutputs ¶
func (bt *BitcoinTransaction) GetOutputs() []*Output
GetOutputs returns an array of all outputs in the transaction.
func (*BitcoinTransaction) GetSighashPayload ¶
func (bt *BitcoinTransaction) GetSighashPayload(sigType uint32) (*SigningPayload, error)
GetSighashPayload assembles a payload of sighases for this TX, to be submitted to signing service.
func (*BitcoinTransaction) GetTxID ¶
func (bt *BitcoinTransaction) GetTxID() string
GetTxID returns the transaction ID of the transaction (which is also the transaction hash).
func (*BitcoinTransaction) HasWitnessData ¶
func (bt *BitcoinTransaction) HasWitnessData() bool
HasWitnessData returns true if the optional Witness flag == 0001
func (*BitcoinTransaction) Hex ¶
func (bt *BitcoinTransaction) Hex() []byte
Hex encodes the transaction into a hex byte array. See https://chainquery.com/bitcoin-cli/decoderawtransaction
func (*BitcoinTransaction) HexWithClearedInputs ¶
func (bt *BitcoinTransaction) HexWithClearedInputs(index int, scriptPubKey []byte) []byte
HexWithClearedInputs encodes the transaction into a hex byte array but clears its inputs first. This is used when signing transactions.
func (*BitcoinTransaction) InputCount ¶
func (bt *BitcoinTransaction) InputCount() int
InputCount returns the number of transaction inputs.
func (*BitcoinTransaction) IsCoinbase ¶
func (bt *BitcoinTransaction) IsCoinbase() bool
IsCoinbase determines if this transaction is a coinbase by seeing if any of the inputs have no inputs.
func (*BitcoinTransaction) OutputCount ¶
func (bt *BitcoinTransaction) OutputCount() int
OutputCount returns the number of transaction inputs.
func (*BitcoinTransaction) PayTo ¶
func (bt *BitcoinTransaction) PayTo(address string, amount uint64) error
PayTo function
func (*BitcoinTransaction) Sign ¶
func (bt *BitcoinTransaction) Sign(privateKey *btcec.PrivateKey, sigType uint32) error
Sign the transaction Normally we'd expect the signing service to do this, but we include this for testing purposes
func (*BitcoinTransaction) SignWithoutP2PKHCheck ¶
func (bt *BitcoinTransaction) SignWithoutP2PKHCheck(privateKey *btcec.PrivateKey, sigType uint32) error
SignWithoutP2PKHCheck signs the transaction without checking if the input previous script equals to a P2PKH script matching the private key
type Input ¶
type Input struct { PreviousTxHash [32]byte PreviousTxOutIndex uint32 PreviousTxSatoshis uint64 PreviousTxScript *Script SigScript *Script SequenceNumber uint32 }
Input is a representation of a transaction input
func NewInput ¶
func NewInput() *Input
NewInput creates a new Input object with a finalised sequence number.
func NewInputFromBytes ¶
NewInputFromBytes returns a transaction input from the bytes provided.
type Output ¶
Output is a representation of a transaction output
func NewOutputForPublicKeyHash ¶
NewOutputForPublicKeyHash makes an output to a PKH with a value.
func NewOutputFromBytes ¶
NewOutputFromBytes returns a transaction Output from the bytes provided
func NewOutputOpReturn ¶
NewOutputOpReturn creates a new Output with OP_FALSE OP_RETURN and then the data passed in encoded as hex.
func NewOutputOpReturnPush ¶
NewOutputOpReturnPush creates a new Output with OP_FALSE OP_RETURN and then uses OP_PUSHDATA format to encode the multiple byte arrays passed in.
func (*Output) GetOutputScript ¶
GetOutputScript returns the script of the output
type RedeemScript ¶
RedeemScript contains the metadata used when creating an unlocking script (SigScript) for a multisig output.
func NewRedeemScript ¶
func NewRedeemScript(signaturesRequired int) (*RedeemScript, error)
NewRedeemScript creates a new RedeemScript with minimum signature threshold needed.
func NewRedeemScriptFromElectrum ¶
func NewRedeemScriptFromElectrum(script string) (*RedeemScript, error)
NewRedeemScriptFromElectrum TODO:
func (*RedeemScript) AddPublicKey ¶
func (rs *RedeemScript) AddPublicKey(pkey string, derivationPath []uint32) error
AddPublicKey appends a public key to the RedeemScript.
type Script ¶
type Script []byte
Script type
func NewScriptFromBytes ¶
NewScriptFromBytes wraps a byte slice with the Script type.
func NewScriptFromString ¶
NewScriptFromString creates a new script from a hex encoded string.
func (*Script) AppendPushDataToScript ¶
AppendPushDataToScript take data bytes and appends the length (see VarInt) and the data to the script.
func (*Script) GetPublicKeyHash ¶
GetPublicKeyHash returns a public key hash byte array if the script is a P2PKH script
func (*Script) IsMultisigOut ¶
IsMultisigOut returns true if this is a multisig output script.
func (*Script) IsPublicKeyHashOut ¶
IsPublicKeyHashOut returns true if this is a pay to pubkey hash output script.
func (*Script) IsPublicKeyOut ¶
IsPublicKeyOut returns true if this is a public key output script.
func (*Script) IsScriptHashOut ¶
IsScriptHashOut returns true if this is a p2sh output script.
type SigningItem ¶
type SigningItem struct { PublicKeyHash string `json:"publicKeyHash"` SigHash string `json:"sigHash"` PublicKey string `json:"publicKey,omitempty"` Signature string `json:"signature,omitempty"` }
SigningItem contains the metadata neeeded to sign a transaction.
type SigningPayload ¶
type SigningPayload []*SigningItem
SigningPayload type
func NewSigningPayload ¶
func NewSigningPayload() *SigningPayload
NewSigningPayload creates a new SigningPayload.
func NewSigningPayloadFromTx ¶
func NewSigningPayloadFromTx(bt *BitcoinTransaction, sigType uint32) (*SigningPayload, error)
NewSigningPayloadFromTx creates a new SigningPayload from a BitcoinTransaction and a SIGHASH type.
func (*SigningPayload) AddItem ¶
func (sp *SigningPayload) AddItem(publicKeyHash string, sigHash string)
AddItem appends a new SigningItem to the SigningPayload array.