Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Numscript

Mid-script Function Calls

Use experimental function calls in variable declarations and within Numscript scripts.

Numscript

Requires flag: experimental-mid-script-function-call

This is a feature of the experimental Numscript interpreter. To run it through the API, set runtime: experimental-interpreter in the transaction request body (the default is machine) and enable the relevant feature flag. See Selecting an Interpreter for per-feature availability.

Call functions like balance() directly in variable declarations, and use arithmetic expressions in the vars block.

Function calls in vars#

numscript
#![feature("experimental-mid-script-function-call")]vars {  monetary $current = balance(@users:1234, USD/2)}
send $current (  source = @users:1234  destination = @savings:1234)

Without this feature, balance() can only be used inline. With it, you can capture the result in a variable and reference it multiple times.

Arithmetic expressions#

numscript
#![feature("experimental-mid-script-function-call")]vars {  portion $fee = 80%  monetary $total = balance(@users:1234, USD/2)}
send $total (  source = @users:1234  destination = {    $fee to @platform:fees    remaining to @merchants:5678  })
set_tx_meta("fee", $fee)set_tx_meta("total", $total)