txscript

package
v0.0.0-...-9742f5a Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

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

View Source
const (
	OP_0           uint8 = 0x00
	OP_DATA_20     uint8 = 0x14
	OP_DUP         uint8 = 0x76
	OP_HASH160     uint8 = 0xa9 // XXX: Do we want to change this to something SHA256-related?
	OP_EQUALVERIFY uint8 = 0x88
	OP_CHECKSIG    uint8 = 0xac
)

Variables

View Source
var BadOpcode = errors.New("unexpected opcode for handler")
View Source
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 ExecuteVerify(inScr, outScr *Script, witData [][]byte, tx SigHashable, txIdx int, inputAmount int64) error

func Hash160Sum

func Hash160Sum(b []byte) []byte

func MakeInputScript

func MakeInputScript(pubkey ed25519.PublicKey) ([]byte, error)

func MakeOutputScript

func MakeOutputScript(pubkey ed25519.PublicKey) ([]byte, error)

Types

type Script

type Script struct {
	// contains filtered or unexported fields
}

func MakeP2WPKHInputScript

func MakeP2WPKHInputScript(pubKeyHash []byte) (*Script, error)

MakeP2WPKHInputScript creates a standard script suitable for use in a transaction input. Input scripts are also called `scriptSig`.

func MakeP2WPKHOutputScript

func MakeP2WPKHOutputScript(pubKeyHash []byte) (*Script, error)

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 ParseScript(buf []byte) (*Script, error)

func (*Script) Marshal

func (scr *Script) Marshal() ([]byte, error)

func (*Script) PrettyPrint

func (scr *Script) PrettyPrint() (string, error)

func (*Script) StandardInput

func (scr *Script) StandardInput() error

func (*Script) StandardOutput

func (scr *Script) StandardOutput() error

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

func (st *ScriptStack) PeekBool(idx int) (bool, error)

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

func (st *ScriptStack) PopNBytes(n int) ([]byte, 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 SigHashable interface {
	SigHash(script *Script, txIdx int, inputAmount int64) ([]byte, error)
}

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

Jump to

Keyboard shortcuts

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