SatoshiScript

open class SatoshiScript(val chainSelector: ChainSelector) : BCHserializable

A script the can be run in Nexa or BCH transaction validation virtual machine

Inheritors

Constructors

Link copied to clipboard
constructor(chainSelector: ChainSelector, script: String, typ: SatoshiScript.Type = Type.SATOSCRIPT)

Construct a script from a hex string, which is a serialized script

constructor(chainSelector: ChainSelector, exactBytes: MutableList<ByteArray>, typ: SatoshiScript.Type = Type.SATOSCRIPT)

Construct a script from a list of raw bytes

constructor(chainSelector: ChainSelector, typ: SatoshiScript.Type, vararg instructions: ByteArray)

Construct a script from raw bytes

constructor(chainSelector: ChainSelector, typ: SatoshiScript.Type, vararg instructions: OP)

Construct a script from individual instructions

constructor(chainSelector: ChainSelector, buf: BCHserialized)

Create this script object from serialized data

constructor(chainSelector: ChainSelector)

Types

Link copied to clipboard
object Companion
Link copied to clipboard
data class MatchResult(val type: PayAddressType, val params: MutableList<ByteArray>, val grouped: Boolean = false)

The result of attempting to match a script to well known script forms, pulling out the variable parts, such as public keys.

Link copied to clipboard

Script type

Properties

Link copied to clipboard

Parse common script types (P2PKH, P2SH, script template) and return the address or null if the script is not standard.

Link copied to clipboard
Link copied to clipboard
val size: Int

The length of this script in bytes (serialized)

Link copied to clipboard

What type of script is this

Functions

Link copied to clipboard
fun add(vararg opcodes: OP): SatoshiScript

Append new instructions to this script

Append a raw instruction to this script

Append raw script bytes to this script. Note! Use add(OP.push(...)) to push data into a script

Link copied to clipboard
fun asSerializedByteArray(st: SerializationType = SerializationType.UNKNOWN): ByteArray

Wraps this script into a serialized byte array. That is, a byte array of script bytes. This is different than toByteArray which just returns the script bytes.

Link copied to clipboard
open override fun BCHdeserialize(stream: BCHserialized): BCHserialized

Clear any current script bytes, and replace them with the passed serialized script

Link copied to clipboard
open override fun BCHserialize(format: SerializationType): BCHserialized

Serialize this script

Link copied to clipboard

Compare whether 2 scripts are the same.

Link copied to clipboard

Make a copy of this script

Link copied to clipboard
Link copied to clipboard

Take a copy of stack element at offset as it would appear on the stack, returning the copy and the range copied from. Offset MUST point to a PUSH operation.

Link copied to clipboard

Turn a byte array (from the script stack) into a group amount

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean

Compare whether 2 scripts are the same. Same as contentEquals

Link copied to clipboard

Converts the internal representation to a single ByteArray

Link copied to clipboard

Replace any data currently in this script with the passed hex-encoded binary script. Note that this function does NOT check to ensure that the passed hex-encoded binary data is a valid script.

Link copied to clipboard

If this is a P2SH satisfier script, get its redeem script. Warning, this just returns the last script data push as a script, so if this is NOT a P2SH satisfier script, you will get weird results.

Link copied to clipboard
fun grouped(grpId: GroupId, tokenAmt: Long): SatoshiScript

If this script is a script template output, put a token group and token amount into the script template output

Link copied to clipboard
fun groupInfo(nativeAmount: Long): GroupInfo?

Return the Group annotation associated with this script, or null if ungrouped

Link copied to clipboard

Parse common script forms, P2PKH and P2PKT, and P2SH (in BCH only) and return useful data

Link copied to clipboard
fun matches(template: SatoshiScript, prefix: Boolean = false): MutableList<ByteArray>?

Attempt to match this script (or just the beginning of it) to a script form.

Link copied to clipboard
fun matchesByBytes(template: SatoshiScript, prefix: Boolean = false): MutableList<ByteArray>?

Attempt to match this script (or just the beginning of it) to a script form

Link copied to clipboard

Return the P2SH constraint (output) script corresponding to this redeem script

Link copied to clipboard

Return the P2SH part of the satisfier (input) script corresponding to this redeem script. You must subsequently append a push-only script that provides the arguments required by the redeem script.

Link copied to clipboard

Returns true if this script has replacable marker parameters in it (its not a valid executable script yet).

Link copied to clipboard

Parse is the opposite of flatten in the sense that each element in data will be 1 instruction

Link copied to clipboard
fun parseTemplate(nativeAmount: Long): ScriptTemplate?

Given an output script in script template format, parse its data items

Link copied to clipboard
operator fun plus(rawscript: ByteArray): SatoshiScript

Append raw script bytes to this script, returning a new script. Note! Use '+ OP.push(...)' to push data into a script")

operator fun plus(opcode: OP): SatoshiScript

Append an opcode to this script, returning a new script.

operator fun plus(script: SatoshiScript): SatoshiScript

concatenate a script to the end of this one, returning the joined script

Link copied to clipboard

iterate through the script, looking for replaceable marker opcodes. If a marker is found, call the callback with the marker.

Link copied to clipboard

The single SHA256 hash of this script. Used by some services as a global pointer identifying the script

Link copied to clipboard

The RIPEMD160 of the SHA256 hash of this script. Used by P2SH scripts

Link copied to clipboard
fun toAsm(separator: String = " "): String

Convert to assembly code

Link copied to clipboard
open fun toByteArray(format: SerializationType = SerializationType.UNKNOWN): ByteArray

Convert this script to a serialized byte array (suitable for network, execution or hashing)

Link copied to clipboard
fun toHex(): String

Convert to hex

Link copied to clipboard
fun toOPs(): List<OP>

Convert to a list of opcodes

Link copied to clipboard
open override fun toString(): String

convert this script to a human readable format

Link copied to clipboard

This script with native group annotation