Class: Stack

Stack

new Stack(itemsnullable)

Represents the stack of a Script during execution.

Parameters:
Name Type Attributes Description
items Array.<Buffer> <nullable>

Stack items.

Properties:
Name Type Description
items Array.<Buffer>

Stack items.

alt Array.<Buffer>

Alt stack items.

state Array.<Number>

State of if statements.

negate Boolean

State of if negations.

length Number

Size of stack.

Source:

Methods

(static) isStack(obj) → {Boolean}

Test an object to see if it is a Stack.

Parameters:
Name Type Description
obj Object
Source:
Returns:
Type
Boolean

clone() → {Stack}

Clone the stack.

Source:
Returns:

Cloned stack.

Type
Stack

depth()

Perform the OP_DEPTH operation.

Source:
Throws:

drop()

Perform the OP_DROP operation.

Source:
Throws:

drop2()

Perform the OP_2DROP operation.

Source:
Throws:

dup()

Perform the OP_DUP operation.

Source:
Throws:

dup2()

Perform the OP_2DUP operation.

Source:
Throws:

dup3()

Perform the OP_3DUP operation.

Source:
Throws:

fromalt()

Perform the OP_FROMALTSTACK operation.

Source:
Throws:

get(index) → {Buffer|null}

Get a stack item by index.

Parameters:
Name Type Description
index Number
Source:
Returns:
Type
Buffer | null

getRedeem() → {Script|null}

Pop the redeem script off the stack and deserialize it.

Source:
Returns:

The redeem script.

Type
Script | null

getSize() → {Number}

Get total size of the stack, including the alt stack.

Source:
Returns:
Type
Number

ifdup()

Perform the OP_IFDUP operation.

Source:
Throws:

inspect() → {String}

Inspect the stack.

Source:
Returns:

Human-readable stack.

Type
String

nip()

Perform the OP_NIP operation.

Source:
Throws:

over()

Perform the OP_OVER operation.

Source:
Throws:

over2()

Perform the OP_2OVER operation.

Source:
Throws:

pick(flags)

Perform the OP_PICK operation.

Parameters:
Name Type Description
flags VerifyFlags
Source:
Throws:

pop() → {Buffer|null}

Pop a stack item.

Source:
See:
  • Array#pop
Returns:
Type
Buffer | null

push(item) → {Number}

Push item onto stack.

Parameters:
Name Type Description
item Buffer
Source:
See:
  • Array#push
Returns:

Stack size.

Type
Number

roll(flags)

Perform the OP_ROLL operation.

Parameters:
Name Type Description
flags VerifyFlags
Source:
Throws:

rot()

Perform the OP_ROT operation.

Source:
Throws:

rot2()

Perform the OP_2ROT operation.

Source:
Throws:

set(index, value) → {Buffer}

Set stack item at index.

Parameters:
Name Type Description
index Number
value Buffer
Source:
Returns:
Type
Buffer

shift() → {Buffer|null}

Shift a stack item.

Source:
See:
  • Array#shift
Returns:
Type
Buffer | null

size()

Perform the OP_SIZE operation.

Source:
Throws:

slice(start, end) → {Array.<Buffer>}

Slice out part of the stack items.

Parameters:
Name Type Description
start Number
end Number
Source:
See:
  • Array#slice
Returns:
Type
Array.<Buffer>

splice(index, remove, insertnullable) → {Array.<Buffer>}

Splice stack items.

Parameters:
Name Type Attributes Description
index Number
remove Number
insert Buffer <nullable>
Source:
See:
  • Array#splice
Returns:
Type
Array.<Buffer>

swap()

Perform the OP_SWAP operation.

Source:
Throws:

swap2()

Perform the OP_2SWAP operation.

Source:
Throws:

toalt()

Perform the OP_TOALTSTACK operation.

Source:
Throws:

toASM(decodenullable) → {String}

Format the stack as bitcoind asm.

Parameters:
Name Type Attributes Description
decode Boolean <nullable>

Attempt to decode hash types.

Source:
Returns:

Human-readable script.

Type
String

top(index) → {Buffer|null}

Get a stack item relative to the top of the stack.

Parameters:
Name Type Description
index Number
Source:
Returns:
Type
Buffer | null
Example
stack.top(-1);

toString() → {String}

Convert the stack to a string.

Source:
Returns:

Human-readable stack.

Type
String

tuck()

Perform the OP_TUCK operation.

Source:
Throws:

unshift(item) → {Number}

Unshift item from stack.

Parameters:
Name Type Description
item Buffer
Source:
See:
  • Array#unshift
Returns:
Type
Number