Skip to content

Core API Reference

Bool

Bytes

Construction Examples:

  • 0xC0FFEE (hex)
  • 0zSGVsbG8gV29ybGQ= (base64, = is optional)
  • bytes("Hello")
  • bytes($tx)
  • bytes(xpub661MyMwAZ92K…cotpLmSkMxrp99L)
  • cf24d08f2d5b63cc564ad83a4e6e1bae359a049c (0x is optional for lengths 20/32/33)

Coerces from:

Underlying type: Vec<u8>

String

str()

str(Any) -> String

Int

int()

int(Int|Float|String) -> Int

MAX_INTEGER Int

MAX_INTEGER = 9223372036854775807

MIN_INTEGER Int

MIN_INTEGER = -9223372036854775808

Float

float()

float(Int|Float|String) -> Float

MAX_FLOAT Float

MIN_FLOAT Float

NaN Float

NaN = NaN_f64

Not a Number. Returned by some floating-point operations, like 0.0/0.0.

inf Float

inf = +Inf_f64

Point at Infinity. Returned by some floating-point operations, like 1.0/0.0.

Symbol

symbol()

symbol(name: String = None) -> Symbol

Function

Array

(𝘢𝘯𝘺)

ArrayLike

The types listed below are Array-like – they have a len(), can be used with the . index access operator, work with array utility functions like map(), and can be unpacked using destructuring assignment.

Policy<MultiPath> should be array-like too, but currently isn't.

General

typeof()

typeof(Any) -> String

One of: int, float, bool, bytes, string, array, function, symbol, pubkey, seckey, policy, withprob, descriptor, address, script, transaction, network, tapinfo, wshinfo or psbt

throw()

throw(...String)

concat()

concat(Array<T>) -> T|null

Concatenates array elements by applying the + operator.

If there are no elements, null is returned.

Can be used with an explicit initial element to force a return type and avoid nulls.
For example: concat([0x]+$maybe_empty_array_of_bytes) or concat([""]+$array_to_stringify)

Works with all +-supporting types (Bytes|String|Array|Int|Float), however the specialized join()/flatten()/sum()/fsum() functions on top of concat() should be preferred since they return ""/[]/0/0.0 for empty arrays rather than null.

Numeric

abs()

abs(Int|Float) -> Int|Float

min()

max()

sum()

sum(Array<Int>) -> Int

fsum()

fsum(Array<Float>) -> Float

String

join()

join(strs: Array<String>, separator: String = "") -> String

Array

map()

map(arr: Array, fn: Function) -> Array

flatMap()

flatMap(arr: Array, fn: Function) -> Array

filter()

filter(arr: Array, predicate: Function) -> Array

filterMap()

filterMap(arr: Array, fn: Function) -> Array

filterMap::skip Symbol

each()

each(arr: Array, fn: Function)

reduce()

reduce(arr: Array, fn: Function) -> Any

fold()

fold(arr: Array, initial: Any, fn: Function) -> Any

foldUntil()

foldUntil(arr: Array, initial: Any, fn: Function) -> Any

slice()

slice(arr: Array<T>, start: Int, len: Int = {ALL}) -> Array<T>

tail()

tail(Array<T>) -> Array<T>

initial()

initial(Array<T>) -> Array<T>

last()

last(Array<T>) -> T

find()

find(arr: Array<T>, predicate: Function) -> T|null

some()

some(arr: Array<T>, predicate: Function) -> Bool

every()

every(arr: Array<T>, predicate: Function) -> Bool

contains()

contains(arr: Array<T>, needle: T) -> Bool

startsWith()

startsWith(arr: Array<T>, prefix: Array<T>) -> Bool

indices()

indices(Array) -> Array<Int>

enumerated()

enumerated(Array<T>) -> Array<Int:T>

reverse()

reverse(Array<T>) -> Array<T>

flatten()

flatten(Array<Array<T>>) -> Array<T>

fillArray()

fillArray(size: Int, value: Any|Function) -> Array

range()

range(start: Int, end: Int) -> Array<Int>

Tagged Arrays

keys()

keys(Array<Key:Val>) -> Array<Key>

values()

values(Array<Key:Val>) -> Array<Val>

get()

get(tagged: Array<Key:Val>, key: Key, default_val: Any = null) -> Val|default_val

Get the value for key, or the default_val (null) if it does not exists.

Typically the $tagged->key field getter syntax can be used instead, however it throws an error when the field doesn't exists rather than return a default.

If the key has multiple values, returns MULTIVAL_TAG. Use mget() to get the actual values as an array.

mget()

mget(tagged: Array<Key:Val>, key: Key) -> Array<Val>

Get the value(s) for the given key as an array. Returns an empty array if none exists.

To get a single value, use the $tagged->key field getter syntax or get().

set()

set(original: Array<Key:Val>, fields: Array<Key:Val>) -> Array<Key:Val>

set::UNSET Symbol

unset()

unset(original: Array<Key:Val>, keys: Array<Key>) -> Array<Key:Val>

MULTIVAL_TAG Symbol

A sentinel value returned by get() and $tagged->key to indicate the requested key has multiple values. mget() can be used to get them.

Encoding

hex()

hex(Bytes) -> String

base64()

base64(Bytes) -> String

repr()

repr(Any) -> String

pretty()

pretty(Any) -> String

le64()

le64(Int) -> Bytes<8>

Also see: compactsize() and scriptnum()

Logging

print()

print(...String)

log()

log(...String)

warn()

warn(...String)

Symbols

null Symbol

default Symbol

BOO Symbol

Boo

Dev Utils

debug()

debug(Any) -> String

Get the debug representation of the given value in Rust's std::fmt::Debug formatting

env()

env(depth: Int = -1) -> Array<Key:Value>

env::debug()

env::debug(depth: Int = -1) -> Symbol

env::repr()

env::repr(depth: Int = -1) -> Symbol

env::pretty()

env::pretty(depth: Int = -1) -> Symbol