CircuitExecutor
Executes Compact smart contract circuits on Android via QuickJS + Rust FFI.
Wraps the full lifecycle: QuickJS environment setup, native FFI registration, runtime loading, witness bridging, circuit execution, transcript transformation, and transaction assembly.
Usage:
val executor = CircuitExecutor(context)
val result = executor.executeCircuit(
contractJs = loadContractIife(),
contractAddress = "abcd...",
circuitName = "post",
circuitArgs = listOf("'Hello from Android!'"),
witnesses = mapOf("localSecretKey" to WitnessProvider {
WitnessResult(null, secretKeyBytes)
}),
initialPrivateState = "{ secretKey: new Uint8Array(32) }",
coinPublicKey = ByteArray(32),
)
// result.unprovenTxHex is ready for provingTypes
One view-circuit invocation inside a readManyCircuits batch, identified by key.
Per-key outcome of a batch read: the circuit's JSON result, or its error message.
Functions
Execute a contract circuit and assemble an UnprovenTransaction.
Run a view/getter circuit against the on-chain state and return its RETURN value as JSON — no proving, no transaction, no submit. BigInt → decimal string, Uint8Array → hex, nested structs preserved (see jsonSafe). Lets a dApp read a contract's computed views (balances, proposals, thresholds) that aren't exposed as raw ledger fields.
Run a circuit LOCALLY against the contract's initialState() — no on-chain state, no fetch. The engine-level counterpart of readCircuit for state-independent (pure) circuits: it omits the onChainStateHex entirely (null → executeInQuickJs builds from initialState()), so there is no deployed instance to validate and no hex to supply.
Run MANY view circuits in ONE engine session against ONE on-chain state — one runtime + contract load, one initialState, one state snapshot — instead of a full engine boot and state fetch per read. Every circuit runs against its own NATIVE CLONE of the fetched state, so reads are isolated (a circuit's context mutations can't leak into the next) and all see the SAME snapshot (no mixed-block reads within a batch).