mirror of
https://github.com/uqbar-dao/nectar.git
synced 2024-12-22 08:01:47 +03:00
packages: update to use wit apis
This commit is contained in:
parent
477d02ac7a
commit
8837a22f6e
3
.gitignore
vendored
3
.gitignore
vendored
@ -2,6 +2,7 @@ target/
|
||||
wit/
|
||||
**/target/
|
||||
**/wit/
|
||||
**/api/
|
||||
**/*.wasm
|
||||
.vscode
|
||||
.app-signing
|
||||
@ -10,8 +11,6 @@ wit/
|
||||
*.swo
|
||||
*.zip
|
||||
/home
|
||||
packages/**/pkg/*.wasm
|
||||
packages/**/wit
|
||||
*/**/node_modules
|
||||
.env
|
||||
kinode/src/bootstrapped_processes.rs
|
||||
|
@ -14,7 +14,7 @@ path = "src/main.rs"
|
||||
|
||||
[build-dependencies]
|
||||
anyhow = "1.0.71"
|
||||
kit = { git = "https://github.com/kinode-dao/kit", rev = "659f59e" }
|
||||
kit = { git = "https://github.com/kinode-dao/kit", rev = "249960d" }
|
||||
rayon = "1.8.1"
|
||||
sha2 = "0.10"
|
||||
tokio = "1.28"
|
||||
|
@ -404,7 +404,7 @@ fn handle_remote_request(
|
||||
},
|
||||
));
|
||||
}
|
||||
let file_name = format!("/{}-v0.1.0-api.zip", package_id); // TODO: actual version
|
||||
let file_name = format!("/{}-api-v0.1.0.zip", package_id); // TODO: actual version
|
||||
// get the .zip from VFS and attach as blob to response
|
||||
let file_path = format!("/{}/pkg/api.zip", package_id);
|
||||
let Ok(Ok(_)) = Request::to(("our", "vfs", "distro", "sys"))
|
||||
@ -670,7 +670,7 @@ fn handle_receive_download(
|
||||
let package_name = package_name[1..].trim_end_matches(".zip");
|
||||
let Ok(package_id) = package_name.parse::<PackageId>() else {
|
||||
let package_name_split = package_name.split('-').collect::<Vec<_>>();
|
||||
let [package_name, version, api] = package_name_split.as_slice() else {
|
||||
let [package_name, api, version] = package_name_split.as_slice() else {
|
||||
return Err(anyhow::anyhow!(
|
||||
"bad package filename fron download: {package_name}"
|
||||
));
|
||||
|
4
kinode/packages/chess/chess/src/chess.wit
Normal file
4
kinode/packages/chess/chess/src/chess.wit
Normal file
@ -0,0 +1,4 @@
|
||||
world chess {
|
||||
import chess-sys-api-v0;
|
||||
include process;
|
||||
}
|
@ -8,6 +8,8 @@ use serde::{Deserialize, Serialize};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
extern crate base64;
|
||||
|
||||
use crate::kinode::process::chess_sys_api_v0::{ChessRequest, ChessResponse, NewGameRequest, MoveRequest};
|
||||
|
||||
const ICON: &str = include_str!("icon");
|
||||
|
||||
//
|
||||
@ -15,20 +17,20 @@ const ICON: &str = include_str!("icon");
|
||||
// to a byte vector and send them over IPC.
|
||||
//
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
enum ChessRequest {
|
||||
NewGame { white: String, black: String },
|
||||
Move { game_id: String, move_str: String },
|
||||
Resign(String),
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Serialize, Deserialize)]
|
||||
enum ChessResponse {
|
||||
NewGameAccepted,
|
||||
NewGameRejected,
|
||||
MoveAccepted,
|
||||
MoveRejected,
|
||||
}
|
||||
//#[derive(Debug, Serialize, Deserialize)]
|
||||
//enum ChessRequest {
|
||||
// NewGame { white: String, black: String },
|
||||
// Move { game_id: String, move_str: String },
|
||||
// Resign(String),
|
||||
//}
|
||||
//
|
||||
//#[derive(Debug, Eq, PartialEq, Serialize, Deserialize)]
|
||||
//enum ChessResponse {
|
||||
// NewGameAccepted,
|
||||
// NewGameRejected,
|
||||
// MoveAccepted,
|
||||
// MoveRejected,
|
||||
//}
|
||||
|
||||
//
|
||||
// Our serializable state format.
|
||||
@ -99,7 +101,9 @@ fn send_ws_update(our: &Address, game: &Game, open_channels: &HashSet<u32>) -> a
|
||||
// Boilerplate: generate the wasm bindings for a process
|
||||
wit_bindgen::generate!({
|
||||
path: "wit",
|
||||
world: "process",
|
||||
world: "chess",
|
||||
generate_unused_types: true,
|
||||
additional_derives: [Deserialize, Serialize],
|
||||
});
|
||||
// After generating bindings, use this macro to define the Component struct
|
||||
// and its init() function, which the kernel will look for on startup.
|
||||
@ -250,7 +254,7 @@ fn handle_chess_request(
|
||||
let game_id = source_node;
|
||||
|
||||
match action {
|
||||
ChessRequest::NewGame { white, black } => {
|
||||
ChessRequest::NewGame(NewGameRequest { white, black }) => {
|
||||
// Make a new game with source.node
|
||||
// This will replace any existing game with source.node!
|
||||
if state.games.contains_key(game_id) {
|
||||
@ -277,7 +281,7 @@ fn handle_chess_request(
|
||||
.body(serde_json::to_vec(&ChessResponse::NewGameAccepted)?)
|
||||
.send()
|
||||
}
|
||||
ChessRequest::Move { ref move_str, .. } => {
|
||||
ChessRequest::Move(MoveRequest { ref move_str, .. }) => {
|
||||
// Get the associated game, and respond with an error if
|
||||
// we don't have it in our state.
|
||||
let Some(game) = state.games.get_mut(game_id) else {
|
||||
|
24
kinode/packages/chess/chess:sys-api-v0.wit
Normal file
24
kinode/packages/chess/chess:sys-api-v0.wit
Normal file
@ -0,0 +1,24 @@
|
||||
interface chess-sys-api-v0.1.0 {
|
||||
variant chess-request {
|
||||
new-game(new-game-request),
|
||||
move(move-request),
|
||||
resign(string),
|
||||
}
|
||||
|
||||
variant chess-response {
|
||||
new-game-accepted,
|
||||
new-game-rejected,
|
||||
move-accepted,
|
||||
move-rejected,
|
||||
}
|
||||
|
||||
record new-game-request {
|
||||
white: string,
|
||||
black: string,
|
||||
}
|
||||
|
||||
record move-request {
|
||||
game-id: string,
|
||||
move-str: string,
|
||||
}
|
||||
}
|
4
kinode/packages/homepage/homepage/src/homepage.wit
Normal file
4
kinode/packages/homepage/homepage/src/homepage.wit
Normal file
@ -0,0 +1,4 @@
|
||||
world homepage {
|
||||
import homepage-sys-api-v0;
|
||||
include process;
|
||||
}
|
@ -10,20 +10,22 @@ use kinode_process_lib::{
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
/// The request format to add or remove an app from the homepage. You must have messaging
|
||||
/// access to `homepage:homepage:sys` in order to perform this. Serialize using serde_json.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum HomepageRequest {
|
||||
/// the package and process name will come from request source.
|
||||
/// the path will automatically have the process_id prepended.
|
||||
/// the icon is a base64 encoded image.
|
||||
Add {
|
||||
label: String,
|
||||
icon: String,
|
||||
path: String,
|
||||
},
|
||||
Remove,
|
||||
}
|
||||
use crate::kinode::process::homepage_sys_api_v0::{HomepageRequest, AddRequest};
|
||||
|
||||
// /// The request format to add or remove an app from the homepage. You must have messaging
|
||||
// /// access to `homepage:homepage:sys` in order to perform this. Serialize using serde_json.
|
||||
// #[derive(Serialize, Deserialize)]
|
||||
// enum HomepageRequest {
|
||||
// /// the package and process name will come from request source.
|
||||
// /// the path will automatically have the process_id prepended.
|
||||
// /// the icon is a base64 encoded image.
|
||||
// Add {
|
||||
// label: String,
|
||||
// icon: String,
|
||||
// path: String,
|
||||
// },
|
||||
// Remove,
|
||||
// }
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct HomepageApp {
|
||||
@ -35,7 +37,9 @@ struct HomepageApp {
|
||||
|
||||
wit_bindgen::generate!({
|
||||
path: "wit",
|
||||
world: "process",
|
||||
world: "homepage",
|
||||
generate_unused_types: true,
|
||||
additional_derives: [Deserialize, Serialize],
|
||||
});
|
||||
|
||||
call_init!(init);
|
||||
@ -84,7 +88,7 @@ fn init(our: Address) {
|
||||
// they must have messaging access to us in order to perform this.
|
||||
if let Ok(request) = serde_json::from_slice::<HomepageRequest>(message.body()) {
|
||||
match request {
|
||||
HomepageRequest::Add { label, icon, path } => {
|
||||
HomepageRequest::Add(AddRequest { label, icon, path }) => {
|
||||
app_data.insert(
|
||||
message.source().process.to_string(),
|
||||
HomepageApp {
|
||||
|
18
kinode/packages/homepage/homepage:sys-api-v0.wit
Normal file
18
kinode/packages/homepage/homepage:sys-api-v0.wit
Normal file
@ -0,0 +1,18 @@
|
||||
interface homepage-sys-api-v0 {
|
||||
/// The request format to add or remove an app from the homepage. You must have messaging
|
||||
/// access to `homepage:homepage:sys` in order to perform this. Serialize using serde_json.
|
||||
variant homepage-request {
|
||||
/// the package and process name will come from request source.
|
||||
/// the path will automatically have the process_id prepended.
|
||||
/// the icon is a base64 encoded image.
|
||||
add(add-request),
|
||||
remove,
|
||||
}
|
||||
|
||||
add-request {
|
||||
package-name: string,
|
||||
path: string,
|
||||
label: string,
|
||||
base64-icon: string,
|
||||
}
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
world kns-indexer {
|
||||
import kns-indexer-sys-api-v0;
|
||||
include process;
|
||||
}
|
@ -9,9 +9,13 @@ use std::collections::{
|
||||
BTreeMap,
|
||||
};
|
||||
|
||||
use crate::kinode::process::kns_indexer_sys_api_v0::{IndexerRequests, NamehashToNameRequest, NodeInfoRequest, GetStateRequest};
|
||||
|
||||
wit_bindgen::generate!({
|
||||
path: "wit",
|
||||
world: "process",
|
||||
world: "kns-indexer",
|
||||
generate_unused_types: true,
|
||||
additional_derives: [Deserialize, Serialize],
|
||||
});
|
||||
|
||||
// perhaps a constant in process_lib?
|
||||
@ -32,27 +36,6 @@ struct State {
|
||||
block: u64,
|
||||
}
|
||||
|
||||
/// IndexerRequests are used to query discrete information from the indexer
|
||||
/// for example, if you want to know the human readable name for a namehash,
|
||||
/// you would send a NamehashToName request.
|
||||
/// If you want to know the most recent on-chain routing information for a
|
||||
/// human readable name, you would send a NodeInfo request.
|
||||
/// The block parameter specifies the recency of the data: the indexer will
|
||||
/// not respond until it has processed events up to the specified block.
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub enum IndexerRequests {
|
||||
/// return the human readable name for a namehash
|
||||
/// returns an Option<String>
|
||||
NamehashToName { hash: String, block: u64 },
|
||||
/// return the most recent on-chain routing information for a node name.
|
||||
/// returns an Option<KnsUpdate>
|
||||
/// set block to 0 if you just want to get the current state of the indexer
|
||||
NodeInfo { name: String, block: u64 },
|
||||
/// return the entire state of the indexer at the given block
|
||||
/// set block to 0 if you just want to get the current state of the indexer
|
||||
GetState { block: u64 },
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub enum NetAction {
|
||||
KnsUpdate(KnsUpdate),
|
||||
@ -249,7 +232,7 @@ fn main(our: Address, mut state: State) -> anyhow::Result<()> {
|
||||
};
|
||||
|
||||
match request {
|
||||
IndexerRequests::NamehashToName { ref hash, block } => {
|
||||
IndexerRequests::NamehashToName(NamehashToNameRequest { ref hash, block }) => {
|
||||
if block <= state.block {
|
||||
Response::new()
|
||||
.body(serde_json::to_vec(&state.names.get(hash))?)
|
||||
@ -261,7 +244,7 @@ fn main(our: Address, mut state: State) -> anyhow::Result<()> {
|
||||
.push(request);
|
||||
}
|
||||
}
|
||||
IndexerRequests::NodeInfo { ref name, block } => {
|
||||
IndexerRequests::NodeInfo(NodeInfoRequest { ref name, block }) => {
|
||||
if block <= state.block {
|
||||
Response::new()
|
||||
.body(serde_json::to_vec(&state.nodes.get(name))?)
|
||||
@ -273,7 +256,7 @@ fn main(our: Address, mut state: State) -> anyhow::Result<()> {
|
||||
.push(request);
|
||||
}
|
||||
}
|
||||
IndexerRequests::GetState { block } => {
|
||||
IndexerRequests::GetState(GetStateRequest { block }) => {
|
||||
if block <= state.block {
|
||||
Response::new().body(serde_json::to_vec(&state)?).send()?;
|
||||
} else {
|
||||
@ -324,19 +307,19 @@ fn handle_eth_message(
|
||||
if *block <= state.block {
|
||||
for request in requests.iter() {
|
||||
match request {
|
||||
IndexerRequests::NamehashToName { hash, .. } => {
|
||||
IndexerRequests::NamehashToName(NamehashToNameRequest { hash, .. }) => {
|
||||
Response::new()
|
||||
.body(serde_json::to_vec(&state.names.get(hash))?)
|
||||
.send()
|
||||
.unwrap();
|
||||
}
|
||||
IndexerRequests::NodeInfo { name, .. } => {
|
||||
IndexerRequests::NodeInfo(NodeInfoRequest { name, .. }) => {
|
||||
Response::new()
|
||||
.body(serde_json::to_vec(&state.nodes.get(name))?)
|
||||
.send()
|
||||
.unwrap();
|
||||
}
|
||||
IndexerRequests::GetState { .. } => {
|
||||
IndexerRequests::GetState(GetStateRequest { .. }) => {
|
||||
Response::new()
|
||||
.body(serde_json::to_vec(&state)?)
|
||||
.send()
|
||||
|
35
kinode/packages/kns_indexer/kns_indexer:sys-api-v0.wit
Normal file
35
kinode/packages/kns_indexer/kns_indexer:sys-api-v0.wit
Normal file
@ -0,0 +1,35 @@
|
||||
interface kns-indexer-sys-api-v0 {
|
||||
/// IndexerRequests are used to query discrete information from the indexer
|
||||
/// for example, if you want to know the human readable name for a namehash,
|
||||
/// you would send a NamehashToName request.
|
||||
/// If you want to know the most recent on-chain routing information for a
|
||||
/// human readable name, you would send a NodeInfo request.
|
||||
/// The block parameter specifies the recency of the data: the indexer will
|
||||
/// not respond until it has processed events up to the specified block.
|
||||
variant indexer-requests {
|
||||
/// return the human readable name for a namehash
|
||||
/// returns an Option<String>
|
||||
namehash-to-name(namehash-to-name-requests),
|
||||
/// return the most recent on-chain routing information for a node name.
|
||||
/// returns an Option<KnsUpdate>
|
||||
/// set block to 0 if you just want to get the current state of the indexer
|
||||
node-info(node-info-requests),
|
||||
/// return the entire state of the indexer at the given block
|
||||
/// set block to 0 if you just want to get the current state of the indexer
|
||||
get-state(get-state-requests),
|
||||
}
|
||||
|
||||
record namehash-to-name-request {
|
||||
hash: string,
|
||||
block: u64,
|
||||
}
|
||||
|
||||
record node-info-request {
|
||||
name: string,
|
||||
block: u64,
|
||||
}
|
||||
|
||||
record get-state-request {
|
||||
block: u64,
|
||||
}
|
||||
}
|
@ -10,7 +10,7 @@ use std::collections::{HashMap, HashSet};
|
||||
|
||||
wit_bindgen::generate!({
|
||||
path: "wit",
|
||||
world: "process",
|
||||
world: "terminal",
|
||||
});
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
|
Loading…
Reference in New Issue
Block a user