Documentation ¶
Overview ¶
Implementation of Bitcoin transaction. Reference: https://en.bitcoin.it/wiki/Transaction
Index ¶
- Constants
- type Tx
- func (t *Tx) Fee() (int, error)
- func (t *Tx) Id() (string, error)
- func (t *Tx) Marshal() ([]byte, error)
- func (t *Tx) SighashBip143(index int, scriptPubKey script.Script, value uint64) ([32]byte, error)
- func (t *Tx) SighashLegacy(index int) ([32]byte, error)
- func (t *Tx) SignInput(index int, priv *ecdsa.PrivateKey) (bool, error)
- func (t *Tx) Unmarshal(r io.Reader) (*Tx, error)
- func (t *Tx) Verify() (bool, error)
- func (t *Tx) VerifyInput(index int) (bool, error)
- type TxIn
- type TxOut
Constants ¶
const ( // Sighash Types SighashAll = uint32(iota + 1) SighashNone SighashSingle )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Tx ¶
type Tx struct { Version uint32 TxIns []TxIn TxOuts []TxOut LockTime uint32 // Utility, not transmitted over the wire. TestNet bool SegWit bool // contains filtered or unexported fields }
func (*Tx) Marshal ¶
Marshal converts Tx t to []byte.
Legacy format:
[Version][NumIns][TxIns][NumOuts][TxOuts][LockTime]
SegWit format:
[Version][Marker][Flag][NumIns][TxIns][NumOuts][TxOuts][Witness][LockTime]
func (*Tx) SighashBip143 ¶
SighashBip143 returns the message that needs to get signed for the input with the index. Fixes the O(n^2) hashing problem. ref: https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki#Specification
func (*Tx) SighashLegacy ¶
SighashLegacy returns the message that needs to get signed for the input with the index.
func (*Tx) SignInput ¶
SignInput signs the input with the index using the private key TODO: make SegWit compatible
func (*Tx) Unmarshal ¶
Unmarshal parses a Tx from the Reader r.
Legacy format:
[Version][NumIns][TxIns][NumOuts][TxOuts][LockTime]
SegWit format:
[Version][Marker][Flag][NumIns][TxIns][NumOuts][TxOuts][Witness][LockTime]
type TxIn ¶
type TxIn struct { PrevTxId [32]byte // prev transaction ID: hash256 of prev tx contents PrevIndex uint32 // UTXO output index in the prev transaction ScriptSig script.Script // unlocking script Sequence uint32 // originally intended for "high frequency trades", with locktime // Utility, not transmitted over the wire. TestNet bool // whether this tx is on testnet or mainnet // SegWit specific Witness [][]byte // stack elements }
func (*TxIn) ScriptPubKey ¶
ScriptPubKey returns the ScriptPubKey of the UTXO from the previous transaction