feat: add examples

This commit is contained in:
2020-11-07 19:37:36 +08:00
parent c51d2bb576
commit 3321c4720d
7 changed files with 74 additions and 2 deletions

View File

@@ -0,0 +1,3 @@
pub mod qjs;
pub mod sig;
pub mod rpc;

View File

@@ -1,8 +1,8 @@
mod qjs;
mod sig;
include!("lib.rs");
pub use qjs::*;
pub use sig::*; // TODO
pub use rpc::*;
fn main() {
let context = QuickJSContext::new().unwrap();

View File

@@ -4,6 +4,14 @@ use quick_js::console::Level;
use quick_js::console::ConsoleBackend;
use serde::{ Serialize, Deserialize };
use rust_util::XResult;
use crate::sig::*;
#[derive(Serialize, Deserialize)]
pub struct QuickJSPack {
hash: String, // hash in hex == HEX(SHA256(self.script))
script: String,
sig: SignedMessage, // sig.msg = SHA256(self.script)
}
pub struct QuickJSContext {
context: Context,

View File

@@ -0,0 +1,17 @@
use serde::{ Serialize, Deserialize };
#[derive(Serialize, Deserialize)]
pub struct InvokeRequest {
hash: String,
method: String,
params: String, // JSON, empty: []
}
#[derive(Serialize, Deserialize)]
pub struct InvokeResponse {
request_id: String,
hash: String,
method: String,
result: String,
}