BSV.Contract.Helpers (bsv_sdk v1.5.1)

Copy Markdown View Source

Pipeline helpers for building scripts in BSV.Contract modules.

When you use BSV.Contract, this module is automatically imported, providing:

Summary

Functions

Decode top stack item as unsigned integer (little-endian ScriptNum).

Iterate over an enumerable, applying a function that takes (element, contract).

Push OP_0 onto the script.

Push OP_0NOTEQUAL onto the script.

Push OP_1 onto the script.

Push OP_1ADD onto the script.

Push OP_1NEGATE onto the script.

Push OP_1SUB onto the script.

Push OP_2 onto the script.

Push OP_2DROP onto the script.

Push OP_2DUP onto the script.

Push OP_2OVER onto the script.

Push OP_2ROT onto the script.

Push OP_2SWAP onto the script.

Push OP_3 onto the script.

Push OP_3DUP onto the script.

Push OP_4 onto the script.

Push OP_5 onto the script.

Push OP_6 onto the script.

Push OP_7 onto the script.

Push OP_8 onto the script.

Push OP_9 onto the script.

Push OP_10 onto the script.

Push OP_11 onto the script.

Push OP_12 onto the script.

Push OP_13 onto the script.

Push OP_14 onto the script.

Push OP_15 onto the script.

Push OP_16 onto the script.

Push OP_ABS onto the script.

Push OP_ADD onto the script.

Push OP_AND onto the script.

Push OP_BIN2NUM onto the script.

Push OP_BOOLAND onto the script.

Push OP_BOOLOR onto the script.

Push OP_CAT onto the script.

Push OP_CHECKMULTISIG onto the script.

Push OP_CHECKMULTISIGVERIFY onto the script.

Push OP_CHECKSIG onto the script.

Push OP_CHECKSIGVERIFY onto the script.

Push OP_CODESEPARATOR onto the script.

Push OP_DEPTH onto the script.

Push OP_DIV onto the script.

Push OP_DROP onto the script.

Push OP_DUP onto the script.

Push OP_ELSE onto the script.

Push OP_ENDIF onto the script.

Push OP_EQUAL onto the script.

Push OP_EQUALVERIFY onto the script.

Push OP_0 onto the script.

Push OP_FROMALTSTACK onto the script.

Push OP_GREATERTHAN onto the script.

Push OP_GREATERTHANOREQUAL onto the script.

Push OP_HASH160 onto the script.

Push OP_HASH256 onto the script.

Push OP_IF onto the script.

Wrap handle_if between OP_IF and OP_ENDIF.

Wrap handle_if/handle_else between OP_IF, OP_ELSE, OP_ENDIF.

Push OP_IFDUP onto the script.

Push OP_INVERT onto the script.

Push OP_LESSTHAN onto the script.

Push OP_LESSTHANOREQUAL onto the script.

Push OP_LSHIFT onto the script.

Push OP_MAX onto the script.

Push OP_MIN onto the script.

Push OP_MOD onto the script.

Push OP_MUL onto the script.

Push OP_NEGATE onto the script.

Push OP_NIP onto the script.

Push OP_NOP onto the script.

Push OP_NOT onto the script.

Push OP_NOTIF onto the script.

Wrap handle between OP_NOTIF and OP_ENDIF.

Wrap handle_if/handle_else between OP_NOTIF, OP_ELSE, OP_ENDIF.

Push OP_NUM2BIN onto the script.

Push OP_NUMEQUAL onto the script.

Push OP_NUMEQUALVERIFY onto the script.

Push OP_NUMNOTEQUAL onto the script.

Push OP_OR onto the script.

Push OP_OVER onto the script.

Push OP_PICK onto the script.

Push OP_RETURN onto the script.

Push OP_RIPEMD160 onto the script.

Push OP_ROLL onto the script.

Push OP_ROT onto the script.

Push OP_RSHIFT onto the script.

Push OP_SHA1 onto the script.

Push OP_SHA256 onto the script.

Push OP_SIZE onto the script.

Push OP_SPLIT onto the script.

Push OP_SUB onto the script.

Push OP_SWAP onto the script.

Push OP_TOALTSTACK onto the script.

Push OP_1 onto the script.

Push OP_TUCK onto the script.

Push OP_VERIFY onto the script.

Push OP_WITHIN onto the script.

Push OP_XOR onto the script.

Push data (binary), an opcode tuple, or a list of items onto the script.

Repeat n times, calling fun.(index, contract).

Reverse the top stack item of length bytes using script ops.

Sign the transaction context and push the DER signature (with sighash flag) onto the script.

Extract bytes from top stack item: start index for length bytes.

Trim leading (positive) or trailing (negative) bytes from top stack item.

Functions

decode_uint(ctx)

@spec decode_uint(BSV.Contract.t()) :: BSV.Contract.t()

Decode top stack item as unsigned integer (little-endian ScriptNum).

each(ctx, enum, fun)

Iterate over an enumerable, applying a function that takes (element, contract).

op_0(ctx)

@spec op_0(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_0 onto the script.

op_0notequal(ctx)

@spec op_0notequal(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_0NOTEQUAL onto the script.

op_1(ctx)

@spec op_1(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_1 onto the script.

op_1add(ctx)

@spec op_1add(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_1ADD onto the script.

op_1negate(ctx)

@spec op_1negate(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_1NEGATE onto the script.

op_1sub(ctx)

@spec op_1sub(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_1SUB onto the script.

op_2(ctx)

@spec op_2(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_2 onto the script.

op_2drop(ctx)

@spec op_2drop(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_2DROP onto the script.

op_2dup(ctx)

@spec op_2dup(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_2DUP onto the script.

op_2over(ctx)

@spec op_2over(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_2OVER onto the script.

op_2rot(ctx)

@spec op_2rot(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_2ROT onto the script.

op_2swap(ctx)

@spec op_2swap(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_2SWAP onto the script.

op_3(ctx)

@spec op_3(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_3 onto the script.

op_3dup(ctx)

@spec op_3dup(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_3DUP onto the script.

op_4(ctx)

@spec op_4(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_4 onto the script.

op_5(ctx)

@spec op_5(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_5 onto the script.

op_6(ctx)

@spec op_6(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_6 onto the script.

op_7(ctx)

@spec op_7(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_7 onto the script.

op_8(ctx)

@spec op_8(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_8 onto the script.

op_9(ctx)

@spec op_9(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_9 onto the script.

op_10(ctx)

@spec op_10(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_10 onto the script.

op_11(ctx)

@spec op_11(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_11 onto the script.

op_12(ctx)

@spec op_12(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_12 onto the script.

op_13(ctx)

@spec op_13(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_13 onto the script.

op_14(ctx)

@spec op_14(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_14 onto the script.

op_15(ctx)

@spec op_15(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_15 onto the script.

op_16(ctx)

@spec op_16(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_16 onto the script.

op_abs(ctx)

@spec op_abs(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_ABS onto the script.

op_add(ctx)

@spec op_add(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_ADD onto the script.

op_and(ctx)

@spec op_and(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_AND onto the script.

op_bin2num(ctx)

@spec op_bin2num(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_BIN2NUM onto the script.

op_booland(ctx)

@spec op_booland(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_BOOLAND onto the script.

op_boolor(ctx)

@spec op_boolor(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_BOOLOR onto the script.

op_cat(ctx)

@spec op_cat(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_CAT onto the script.

op_checkmultisig(ctx)

@spec op_checkmultisig(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_CHECKMULTISIG onto the script.

op_checkmultisigverify(ctx)

@spec op_checkmultisigverify(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_CHECKMULTISIGVERIFY onto the script.

op_checksig(ctx)

@spec op_checksig(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_CHECKSIG onto the script.

op_checksigverify(ctx)

@spec op_checksigverify(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_CHECKSIGVERIFY onto the script.

op_codeseparator(ctx)

@spec op_codeseparator(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_CODESEPARATOR onto the script.

op_depth(ctx)

@spec op_depth(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_DEPTH onto the script.

op_div(ctx)

@spec op_div(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_DIV onto the script.

op_drop(ctx)

@spec op_drop(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_DROP onto the script.

op_dup(ctx)

@spec op_dup(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_DUP onto the script.

op_else(ctx)

@spec op_else(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_ELSE onto the script.

op_endif(ctx)

@spec op_endif(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_ENDIF onto the script.

op_equal(ctx)

@spec op_equal(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_EQUAL onto the script.

op_equalverify(ctx)

@spec op_equalverify(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_EQUALVERIFY onto the script.

op_false(ctx)

@spec op_false(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_0 onto the script.

op_fromaltstack(ctx)

@spec op_fromaltstack(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_FROMALTSTACK onto the script.

op_greaterthan(ctx)

@spec op_greaterthan(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_GREATERTHAN onto the script.

op_greaterthanorequal(ctx)

@spec op_greaterthanorequal(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_GREATERTHANOREQUAL onto the script.

op_hash160(ctx)

@spec op_hash160(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_HASH160 onto the script.

op_hash256(ctx)

@spec op_hash256(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_HASH256 onto the script.

op_if(ctx)

@spec op_if(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_IF onto the script.

op_if(ctx, handle_if)

Wrap handle_if between OP_IF and OP_ENDIF.

op_if(ctx, handle_if, handle_else)

Wrap handle_if/handle_else between OP_IF, OP_ELSE, OP_ENDIF.

op_ifdup(ctx)

@spec op_ifdup(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_IFDUP onto the script.

op_invert(ctx)

@spec op_invert(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_INVERT onto the script.

op_lessthan(ctx)

@spec op_lessthan(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_LESSTHAN onto the script.

op_lessthanorequal(ctx)

@spec op_lessthanorequal(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_LESSTHANOREQUAL onto the script.

op_lshift(ctx)

@spec op_lshift(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_LSHIFT onto the script.

op_max(ctx)

@spec op_max(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_MAX onto the script.

op_min(ctx)

@spec op_min(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_MIN onto the script.

op_mod(ctx)

@spec op_mod(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_MOD onto the script.

op_mul(ctx)

@spec op_mul(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_MUL onto the script.

op_negate(ctx)

@spec op_negate(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_NEGATE onto the script.

op_nip(ctx)

@spec op_nip(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_NIP onto the script.

op_nop(ctx)

@spec op_nop(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_NOP onto the script.

op_not(ctx)

@spec op_not(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_NOT onto the script.

op_notif(ctx)

@spec op_notif(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_NOTIF onto the script.

op_notif(ctx, handle)

@spec op_notif(BSV.Contract.t(), (BSV.Contract.t() -> BSV.Contract.t())) ::
  BSV.Contract.t()

Wrap handle between OP_NOTIF and OP_ENDIF.

op_notif(ctx, handle_if, handle_else)

Wrap handle_if/handle_else between OP_NOTIF, OP_ELSE, OP_ENDIF.

op_num2bin(ctx)

@spec op_num2bin(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_NUM2BIN onto the script.

op_numequal(ctx)

@spec op_numequal(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_NUMEQUAL onto the script.

op_numequalverify(ctx)

@spec op_numequalverify(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_NUMEQUALVERIFY onto the script.

op_numnotequal(ctx)

@spec op_numnotequal(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_NUMNOTEQUAL onto the script.

op_or(ctx)

@spec op_or(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_OR onto the script.

op_over(ctx)

@spec op_over(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_OVER onto the script.

op_pick(ctx)

@spec op_pick(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_PICK onto the script.

op_return(ctx)

@spec op_return(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_RETURN onto the script.

op_ripemd160(ctx)

@spec op_ripemd160(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_RIPEMD160 onto the script.

op_roll(ctx)

@spec op_roll(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_ROLL onto the script.

op_rot(ctx)

@spec op_rot(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_ROT onto the script.

op_rshift(ctx)

@spec op_rshift(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_RSHIFT onto the script.

op_sha1(ctx)

@spec op_sha1(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_SHA1 onto the script.

op_sha256(ctx)

@spec op_sha256(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_SHA256 onto the script.

op_size(ctx)

@spec op_size(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_SIZE onto the script.

op_split(ctx)

@spec op_split(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_SPLIT onto the script.

op_sub(ctx)

@spec op_sub(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_SUB onto the script.

op_swap(ctx)

@spec op_swap(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_SWAP onto the script.

op_toaltstack(ctx)

@spec op_toaltstack(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_TOALTSTACK onto the script.

op_true(ctx)

@spec op_true(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_1 onto the script.

op_tuck(ctx)

@spec op_tuck(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_TUCK onto the script.

op_verify(ctx)

@spec op_verify(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_VERIFY onto the script.

op_within(ctx)

@spec op_within(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_WITHIN onto the script.

op_xor(ctx)

@spec op_xor(BSV.Contract.t()) :: BSV.Contract.t()

Push OP_XOR onto the script.

push(ctx, items)

@spec push(BSV.Contract.t(), binary() | Script.chunk() | [binary() | Script.chunk()]) ::
  BSV.Contract.t()

Push data (binary), an opcode tuple, or a list of items onto the script.

repeat(ctx, n, fun)

Repeat n times, calling fun.(index, contract).

reverse(ctx, length)

@spec reverse(BSV.Contract.t(), pos_integer()) :: BSV.Contract.t()

Reverse the top stack item of length bytes using script ops.

sig(ctx, keys)

Sign the transaction context and push the DER signature (with sighash flag) onto the script.

If the contract has a transaction context (ctx), computes the BIP-143 sighash and signs with the private key. Otherwise pushes 71 zero bytes as a placeholder.

Accepts a single private key or a list (for multisig).

slice(ctx, start, length)

Extract bytes from top stack item: start index for length bytes.

trim(ctx, n)

@spec trim(BSV.Contract.t(), integer()) :: BSV.Contract.t()

Trim leading (positive) or trailing (negative) bytes from top stack item.