pub trait ConvertibleContract: Send {
// Required methods
fn encode_input_fn(
&self,
fn_name: &str,
json: &str,
) -> Result<Vec<u8>, Error>;
fn decode_input_fn(
&self,
fn_name: &str,
rkyv: &[u8],
) -> Result<JsonValue, Error>;
fn decode_output_fn(
&self,
fn_name: &str,
rkyv: &[u8],
) -> Result<JsonValue, Error>;
fn decode_event(
&self,
event_name: &str,
rkyv: &[u8],
) -> Result<JsonValue, Error>;
fn get_schema(&self) -> String;
// Provided method
fn get_version(&self) -> &'static str { ... }
}
Expand description
A trait for converting between JSON and native RKYV formats in a contract.
The ConvertibleContract
trait provides methods for encoding and decoding
function inputs, outputs, and events, as well as retrieving the contract’s
JSON schema.
Required Methods§
Sourcefn encode_input_fn(&self, fn_name: &str, json: &str) -> Result<Vec<u8>, Error>
fn encode_input_fn(&self, fn_name: &str, json: &str) -> Result<Vec<u8>, Error>
Encodes the input of a function from JSON into the native RKYV format.
§Parameters
fn_name
: The name of the function whose input is being encoded.json
: A JSON string representing the function’s input.
§Returns
Ok(Vec<u8>)
: A byte vector containing the serialized RKYV data.Err(Error)
: If encoding fails.
§Errors
- Returns
Error::Rkyv
if the serialization process fails. - Returns
Error::Serde
if the input JSON cannot be parsed.
Sourcefn decode_input_fn(
&self,
fn_name: &str,
rkyv: &[u8],
) -> Result<JsonValue, Error>
fn decode_input_fn( &self, fn_name: &str, rkyv: &[u8], ) -> Result<JsonValue, Error>
Decodes the input of a function from the native RKYV format into JSON.
§Parameters
fn_name
: The name of the function whose input is being decoded.rkyv
: A byte slice containing the RKYV-encoded function input.
§Returns
Ok(JsonValue)
: A JSON representation of the function input.Err(Error)
: If decoding fails.
§Errors
- Returns
Error::Rkyv
if the deserialization process fails. - Returns
Error::Serde
if the resulting object cannot be serialized to JSON.
Sourcefn decode_output_fn(
&self,
fn_name: &str,
rkyv: &[u8],
) -> Result<JsonValue, Error>
fn decode_output_fn( &self, fn_name: &str, rkyv: &[u8], ) -> Result<JsonValue, Error>
Decodes the output of a function from the native RKYV format into JSON.
§Parameters
fn_name
: The name of the function whose output is being decoded.rkyv
: A byte slice containing the RKYV-encoded function output.
§Returns
Ok(JsonValue)
: A JSON representation of the function output.Err(Error)
: If decoding fails.
§Errors
- Returns
Error::Rkyv
if the deserialization process fails. - Returns
Error::Serde
if the resulting object cannot be serialized to JSON.
Sourcefn decode_event(
&self,
event_name: &str,
rkyv: &[u8],
) -> Result<JsonValue, Error>
fn decode_event( &self, event_name: &str, rkyv: &[u8], ) -> Result<JsonValue, Error>
Decodes an event from the native RKYV format into JSON.
§Parameters
event_name
: The name of the event to be decoded.rkyv
: A byte slice containing the RKYV-encoded event data.
§Returns
Ok(JsonValue)
: A JSON representation of the event data.Err(Error)
: If decoding fails.
§Errors
- Returns
Error::Rkyv
if the deserialization process fails. - Returns
Error::Serde
if the resulting object cannot be serialized to JSON.
Sourcefn get_schema(&self) -> String
fn get_schema(&self) -> String
Provided Methods§
Sourcefn get_version(&self) -> &'static str
fn get_version(&self) -> &'static str
Returns the current version of the contract interface.
This is useful for ensuring compatibility between different contract consumers and implementations.
§Returns
&'static str
: A string representing the semantic version (e.g.,"0.10.1"
).