Interp class

Script Interpreter

Bitcoin transactions contain scripts. Each input has a script called the scriptSig, and each output has a script called the scriptPubKey. To validate an input, the ScriptSig is executed, then with the same stack, the scriptPubKey from the output corresponding to that input is run. The primary way to use this class is via the verify:

new Interp().verify( ... )

In some ways, the script interpreter is one of the most poorly architected components of Yours Bitcoin because of the giant switch statement in step(). But that is deliberately so to make it similar to bitcoin core, and thus easier to audit.

Constructors

Interp({Script? script, Tx? tx, int? nIn, List<List<int>>? stack, List<List<int>>? altStack, int pc = 0, int pBeginCodeHash = 0, int nOpCount = 0, List<bool>? ifStack, String errStr = '', int? flags, BigIntX? valueBn})
Interp.fromHex(String str)
factory

Properties

altStack List<List<int>>
getter/setter pair
errStr String?
getter/setter pair
flags int?
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
ifStack List<bool>
getter/setter pair
nIn int?
getter/setter pair
nOpCount int
getter/setter pair
pBeginCodeHash int?
getter/setter pair
pc int
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
script Script?
getter/setter pair
stack List<List<int>>
getter/setter pair
tx Tx?
getter/setter pair
valueBn BigIntX?
getter/setter pair

Methods

checkLockTime(int nLockTime) bool
Translated from bitcoin core's CheckLockTime
checkPubKeyEncoding(dynamic buf) bool
Translated from bitcoin core's CheckPubKeyEncoding
checkSequence(dynamic nSequence) bool
Translated from bitcoin core's CheckSequence.
checkSigEncoding(List<int> buf) bool
Translated from bitcoin core's CheckSigEncoding
eval() Stream<bool>
Based on bitcoin core's EvalScript, with the inner loop moved to Interp.prototype.step() bitcoin core commit: b5d1b1092998bc95313856d535c632ea5a8f9104
fromBr(Br br) Interp
fromBuffer(List<int> buf) Interp
fromHex(String str) Interp
fromJSON(Map json) Interp
fromJSONNoTx(Map json) Interp
Convert JSON containing everything but the tx to an interp object.
getDebugObject() Map<String, Object?>
If the script has failed, this methods returns valuable debug information about exactly where the script failed. It is a JSON-compatible object so it can be easily stringified. pc refers to the currently executing opcode.
getDebugString() String
initialize() Interp
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
results({Script? scriptSig, Script? scriptPubKey, Tx? tx, int? nIn, int? flags, BigIntX? valueBn}) Stream<bool>
Gives you the results of the execution each operation of the scripSig and scriptPubKey corresponding to a particular input (nIn) for the concerned transaction (tx). Each result can be either true or false. If true, then the operation did not invalidate the transaction. If false, then the operation has invalidated the script, and the transaction is not valid. flags is a number that can pass in some special flags, such as whether or not to execute the redeemScript in a p2sh transaction.
step() bool
Based on the inner loop of bitcoin core's EvalScript
toBuffer() List<int>
toBw([Bw? bw]) Bw
toJSON() Map<String, dynamic>
toJSONNoTx() → dynamic
toString() String
A string representation of this object.
inherited
verify({Script? scriptSig, Script? scriptPubKey, Tx? tx, int? nIn, int? flags, BigIntX? valueBn}) Future<bool>

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

castToBool(List<int?> buf) bool
getFlags(String flagstr) int
In order to make auduting the script interpreter easier, we use the same constants as bitcoin core, including the flags, which customize the operation of the interpreter.