Substrate runtime API definition for PVQ (PolkaVM Query). This crate exposes a single runtime API trait that runtimes implement to execute PVQ programs and expose PVQ-related metadata.
The trait exactly as defined in this crate:
use alloc::vec::Vec;
use pvq_primitives::PvqResult;
use sp_api::decl_runtime_apis;
decl_runtime_apis! {
/// The runtime API for the PVQ module.
pub trait PvqApi {
/// Execute a PVQ program with arguments.
///
/// - `program`: PolkaVM bytecode of the guest program
/// - `args`: SCALE-encoded call data
/// - `gas_limit`: Optional execution gas limit; `None` means use the default time boundary
fn execute_query(program: Vec<u8>, args: Vec<u8>, gas_limit: Option<i64>) -> PvqResult;
/// Return PVQ extensions metadata as an opaque byte blob.
fn metadata() -> Vec<u8>;
}
}Notes
PvqResultis defined inpvq-primitivesasResult<PvqResponse, PvqError>wherePvqResponse = Vec<u8>.- The
argsbuffer must match the PVQ guest ABI (seepvq-program): first byte is the entrypoint index, followed by SCALE-encoded arguments.
use sp_api::impl_runtime_apis;
use pvq_runtime_api::PvqApi;
use pvq_primitives::PvqResult;
impl_runtime_apis! {
impl PvqApi<Block> for Runtime {
fn execute_query(program: Vec<u8>, args: Vec<u8>, gas_limit: Option<i64>) -> PvqResult {
// Integrate with your PVQ executor here, e.g. pvq-executor
// Ok(result_bytes) or Err(pvq_error)
unimplemented!()
}
fn metadata() -> Vec<u8> {
// Return extension metadata bytes (format decided by the runtime)
Vec::new()
}
}
}metadata() returns a byte vector. The encoding and schema are defined by the runtime. Recommended format is either SCALE or JSON of the structure defined in pvq-extension (pvq-extension/src/metadata.rs).
Shape
{
"types": { /* scale-info PortableRegistry */ },
"extensions": {
"<extension_id_as_string>": {
"name": "<extension_name>",
"functions": [
{
"name": "<fn_name>",
"inputs": [ { "name": "<arg>", "ty": <type_id_u32> } ],
"output": <type_id_u32>
}
]
}
}
}Notes
typesis ascale-infoPortableRegistry describing all referenced types.tyandoutputare numeric type IDs that reference entries insidetypes.- The
extensionsobject is keyed by stringified extension IDs (u64 -> string) and maps to per-extension metadata: name and function signatures.