Documentation ¶
Index ¶
- Constants
- Variables
- type OpCode
- type R
- type Script
- type Stack
- func (s *Stack) Compare() (a, b *math.Int, cmp int, rc int)
- func (s *Stack) Dup(n int) int
- func (s *Stack) Len() int
- func (s *Stack) Peek() (*math.Int, int)
- func (s *Stack) PeekAt(i int) (*math.Int, int)
- func (s *Stack) Pop() (*math.Int, int)
- func (s *Stack) Push(v interface{}) int
- func (s *Stack) RemoveAt(i int) (*math.Int, int)
- func (s *Stack) Values() []*math.Int
- type Statement
- type Tx
Constants ¶
const ( OpFALSE = 0 OpPUSHDATA1 = 76 OpPUSHDATA2 = 77 OpPUSHDATA4 = 78 Op1NEGATE = 79 OpRESERVED = 80 OpTRUE = 81 Op2 = 82 Op3 = 83 Op4 = 84 Op5 = 85 Op6 = 86 Op7 = 87 Op8 = 88 Op9 = 89 Op10 = 90 Op11 = 91 Op12 = 92 Op13 = 93 Op14 = 94 Op15 = 95 Op16 = 96 OpNOP = 97 OpVER = 98 OpIF = 99 OpNOTIF = 100 OpVERIF = 101 OpVERNOTIF = 102 OpELSE = 103 OpENDIF = 104 OpVERIFY = 105 OpRETURN = 106 OpTOALTSTACK = 107 OpFROMALTSTACK = 108 Op2DROP = 109 Op2DUP = 110 Op3DUP = 111 Op2OVER = 112 Op2ROT = 113 Op2SWAP = 114 OpIFDUP = 115 OpDEPTH = 116 OpDROP = 117 OpDUP = 118 OpNIP = 119 OpOVER = 120 OpPICK = 121 OpROLL = 122 OpROT = 123 OpSWAP = 124 OpTUCK = 125 OpCAT = 126 OpSUBSTR = 127 OpLEFT = 128 OpRIGHT = 129 OpSIZE = 130 OpINVERT = 131 OpAND = 132 OpOR = 133 OpXOR = 134 OpEQUAL = 135 OpEQUALVERIFY = 136 OpRESERVED1 = 137 OpRESERVED2 = 138 Op1ADD = 139 Op1SUB = 140 Op2MUL = 141 Op2DIV = 142 OpNEGATE = 143 OpABS = 144 OpNOT = 145 Op0NOTEQUAL = 146 OpADD = 147 OpSUB = 148 OpMUL = 149 OpDIV = 150 OpMOD = 151 OpLSHIFT = 152 OpRSHIFT = 153 OpBOOLAND = 154 OpBOOLOR = 155 OpNUMEQUAL = 156 OpNUMEQUALVERIFY = 157 OpNUMNOTEQUAL = 158 OpLESSTHAN = 159 OpGREATERTHAN = 160 OpLESSTHANOREQUAL = 161 OpGREATERTHANOREQUAL = 162 OpMIN = 163 OpMAX = 164 OpWITHIN = 165 OpRIPEMD160 = 166 OpSHA1 = 167 OpSHA256 = 168 OpHASH160 = 169 OpHASH256 = 170 OpCODESEPARATOR = 171 OpCHECKSIG = 172 OpCHECKSIGVERIFY = 173 OpCHECKMULTISIG = 174 OpCHECKMULTISIGVERIFY = 175 OpNOP1 = 176 OpCHECKLOCKTIMEVERIFY = 177 OpCHECKSEQUENCEVERIFY = 178 OpNOP4 = 179 OpNOP5 = 180 OpNOP6 = 181 OpNOP7 = 182 OpNOP8 = 183 OpNOP9 = 184 OpNOP10 = 185 OpPUBKEYHASH = 253 OpPUBKEY = 254 OpINVALIDOPCODE = 255 )
Standard Bitcoin script opcodes
const ( RcOK = iota RcErr RcExceeds RcParseError RcScriptError RcLengthMismatch RcEmptyStack RcInvalidFinalStack RcNotImplemented RcInvalidOpcode RcReservedOpcode RcTxInvalid RcTypeMismatch RcInvalidStackType RcExceedsStack RcNoTransaction RcUnclosedIf RcDoubleElse RcInvalidTransaction RcInvalidPubkey RcInvalidUint RcInvalidSignature RcInvalidTransfer RcNotVerified RcDisabledOpcode RcTxNotSignable RcEmptyScript RcDone )
Result codes returned by script functions.
Variables ¶
var ( // OpCodes is a list of all valid opcodes in a Bitcoin script. OpCodes = []*OpCode{}/* 114 elements not displayed */ )
var (
RcString = []string{
"OK",
"Generic error",
"Operation exceeds available data",
"Parse error",
"Script error",
"Length mismatch",
"Empty stack",
"Invalid final stack",
"Not implemented yet",
"Invalid opcode",
"Reserved opcode",
"Invalid transaction",
"Type mismatch",
"Invalid stack type",
"Operation exceeds stack",
"No transaction available",
"Unclosed IF",
"Double ELSE",
"Invalid transaction",
"Invalid pubkey",
"Invalid Uint",
"Invalid signature",
"Invalid transfer",
"Not verified",
"Disabled opcode",
"Transaction not signable",
"Empty script",
"Script done",
}
)
Human-readable result codes
Functions ¶
This section is empty.
Types ¶
type OpCode ¶
type OpCode struct { // Name is the mnemonic name of the opcode. Name string // Short name Short string // Value is the byte code of the opcode. Value byte // Exec is function that performs the stack operations for the opcode. Exec func(r *R) int }
OpCode describes a Bitcoin script opcode with a symbolic name and a value.
func GetOpcodeTR ¶ added in v1.2.23
GetOpcodeTR returns a opcode for a given byte value in a tapscript.
type R ¶
type R struct { CbStep func(stack *Stack, stmt *Statement, rc int) // contains filtered or unexported fields }
R is the Bitcoin script runtime environment
func NewRuntime ¶
NewRuntime creates a new script parser and execution runtime.
func (*R) CheckMultiSig ¶
CheckMultiSig performs a OpCHECKMULTISIG operation on the stack (without pushing a result onto the stack).
func (*R) CheckSig ¶
CheckSig performs a OpCHECKSIG operation on the stack (without pushing a result onto the stack)
func (*R) ExecScript ¶
ExecScript executes a script belonging to a transaction. If no transaction is specified, some script opcodes like OpCHECKSIG could not be executed. N.B.: To successfully execute 'script' that involves OpCHECKSIG it needs to be assembled (concatenated) and cleaned up from the prev.sigScript and curr.pkScript (see https://en.bitcoin.it/wiki/OpCHECKSIG); 'tx' is the current transaction in dissected format already prepared for signature.
type Script ¶
type Script struct {
Stmts []*Statement
}
Script is an ordered list of statements.
func ParseBin ¶
ParseBin dissects binary scripts into a sequence of statements that constitutes a script.
func (*Script) Decompile ¶
Decompile returns a human-readable Bitcoin script source from a binary script representation.
func (*Script) GetTemplate ¶
GetTemplate returns a template derived from a script. A template only contains a sequence of opcodes; it is used to find structural equivalent scripts (but with varying data).
type Stack ¶
type Stack struct {
// contains filtered or unexported fields
}
Stack represents the FIFO stack used during the processing of a script. Objects on the stack are of type math.Int; byte arrays and intrinsic integers are converted in both way when necessary.
func (*Stack) PeekAt ¶
PeekAt looks up the object at depth 'i' of the stack (top-level is depth 0) without removing it.
func (*Stack) Push ¶
Push an object onto the stack. Objects can be of type int, []byte, *math.Int or bool; other types return a result code 'RcInvalidStackType'.
type Statement ¶
Statement is a single script statement.
func NewDataStatement ¶
NewDataStatement creates a data statement.
func NewStatement ¶
NewStatement creates a statement with an opcode.