Documentation ¶
Overview ¶
Package txscript implements a limited subset of the Bitcoin script language.
We support only standard transactions, and our definition of a standard transaction is more narrow than Bitcoin's. In particular, we support only native P2WPKH transactions.
Index ¶
- Constants
- Variables
- func ExecuteVerify(inScr, outScr *Script, witData [][]byte, tx SigHashable, txIdx int, ...) error
- func Hash160Sum(b []byte) []byte
- func MakeInputScript(pubkey ed25519.PublicKey) ([]byte, error)
- func MakeOutputScript(pubkey ed25519.PublicKey) ([]byte, error)
- type Script
- type ScriptStack
- func (st *ScriptStack) PeekBool(idx int) (bool, error)
- func (st *ScriptStack) PeekBytes(idx int) ([]byte, error)
- func (st *ScriptStack) PeekInt(idx int) (scriptNum, error)
- func (st *ScriptStack) PopBool() (bool, error)
- func (st *ScriptStack) PopBytes() ([]byte, error)
- func (st *ScriptStack) PopInt() (scriptNum, error)
- func (st *ScriptStack) PopNBytes(n int) ([]byte, error)
- func (st *ScriptStack) PushBool(v bool)
- func (st *ScriptStack) PushBytes(v []byte)
- func (st *ScriptStack) PushInt(v scriptNum)
- func (st *ScriptStack) Size() int
- type SigHashable
- type VirtualMachine
Constants ¶
Variables ¶
var BadOpcode = errors.New("unexpected opcode for handler")
var OPCODES = map[uint8]*opcode{ OP_0: {OP_0, 1, "OP_0", opConst}, OP_DATA_20: {OP_DATA_20, 21, "OP_DATA_20", opPushData}, OP_DUP: {OP_DUP, 1, "OP_DUP", opDup}, OP_HASH160: {OP_HASH160, 1, "OP_HASH160", opHash160}, OP_EQUALVERIFY: {OP_EQUALVERIFY, 1, "OP_EQUALVERIFY", opEqual}, OP_CHECKSIG: {OP_CHECKSIG, 1, "OP_CHECKSIG", opCheckSig}, }
Functions ¶
func ExecuteVerify ¶
func Hash160Sum ¶
Types ¶
type Script ¶
type Script struct {
// contains filtered or unexported fields
}
func MakeP2WPKHInputScript ¶
MakeP2WPKHInputScript creates a standard script suitable for use in a transaction input. Input scripts are also called `scriptSig`.
func MakeP2WPKHOutputScript ¶
MakeP2WPKHOutputScript creates a standard script suitable for use in a transaction output that is paying to a P2WPKH address. Output scripts are also called `scriptPubKey`.
TODO: When we implement better transaction-building/signing helpers, this might want to go live with them.
func ParseScript ¶
func (*Script) PrettyPrint ¶
func (*Script) StandardInput ¶
func (*Script) StandardOutput ¶
StandardOutput returns nil iff the transaction is standard; otherwise, it returns a descriptive error.
type ScriptStack ¶
type ScriptStack struct {
// contains filtered or unexported fields
}
ScriptStack represents a Bitcoin script stack. This type offers utility functions for interpreting values that will be pushed or popped as various types.
func (*ScriptStack) PeekBytes ¶
func (st *ScriptStack) PeekBytes(idx int) ([]byte, error)
TODO: Tests should cover the case where `idx<0`.
func (*ScriptStack) PeekInt ¶
func (st *ScriptStack) PeekInt(idx int) (scriptNum, error)
func (*ScriptStack) PopBool ¶
func (st *ScriptStack) PopBool() (bool, error)
func (*ScriptStack) PopBytes ¶
func (st *ScriptStack) PopBytes() ([]byte, error)
func (*ScriptStack) PopInt ¶
func (st *ScriptStack) PopInt() (scriptNum, error)
func (*ScriptStack) PushBool ¶
func (st *ScriptStack) PushBool(v bool)
func (*ScriptStack) PushBytes ¶
func (st *ScriptStack) PushBytes(v []byte)
func (*ScriptStack) PushInt ¶
func (st *ScriptStack) PushInt(v scriptNum)
func (*ScriptStack) Size ¶
func (st *ScriptStack) Size() int
type SigHashable ¶
type VirtualMachine ¶
type VirtualMachine struct {
// contains filtered or unexported fields
}
func NewVirtualMachine ¶
func NewVirtualMachine() *VirtualMachine
func (*VirtualMachine) Execute ¶
func (vm *VirtualMachine) Execute(scr *Script) error
func (*VirtualMachine) PushWitnessData ¶
func (vm *VirtualMachine) PushWitnessData(data [][]byte)
func (*VirtualMachine) Verify ¶
func (vm *VirtualMachine) Verify() error