Skip to content

Commit

Permalink
api: strict serializaiton and ids
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Nov 20, 2024
1 parent 1bbc147 commit 016a724
Show file tree
Hide file tree
Showing 22 changed files with 552 additions and 217 deletions.
121 changes: 121 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = [".", "inmem", "request"]
members = [".", "cli", "inmem", "request"]
default-members = [".", "inmem", "request"]

[workspace.package]
Expand Down
17 changes: 17 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "sonare-cli"
description = "SONARE command-line interface"
categories = ["cryptography", "science", "command-line-interface"]
version.workspace = true
authors.workspace = true
repository.workspace = true
homepage.workspace = true
keywords.workspace = true
readme.workspace = true
license.workspace = true
edition.workspace = true
rust-version.workspace = true

[dependencies]
sonare = { version = "0.12.0-alpha.1", path = ".." }
clap = { version = "4.5.21", features = ["derive", "env"] }
78 changes: 78 additions & 0 deletions cli/src/cmd.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// SONARE: Runtime environment for formally-verifiable distributed software
//
// SPDX-License-Identifier: Apache-2.0
//
// Designed in 2019-2024 by Dr Maxim Orlovsky <[email protected]>
// Written in 2024-2025 by Dr Maxim Orlovsky <[email protected]>
//
// Copyright (C) 2019-2025 LNP/BP Standards Association, Switzerland.
// Copyright (C) 2024-2025 Laboratories for Ubiquitous Deterministic Computing (UBIDECO),
// Institute for Distributed and Cognitive Systems (InDCS), Switzerland.
// Copyright (C) 2019-2025 Dr Maxim Orlovsky.
// All rights under the above copyrights are reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
// in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
// or implied. See the License for the specific language governing permissions and limitations under
// the License.

use std::path::PathBuf;

use sonare::util::ContractRef;

pub enum Command {
/// Import kit
Import {
path: PathBuf,
},

/// List known objects
List,

/// Issue a new contract
Issue {
/// Contract information
///
/// If not provided, read from the user input.
path: Option<PathBuf>,
},

/// Retrieve contract information
Info {
contract_id: ContractRef,
},

/// Display contract state
State {
contract_id: ContractRef,
},

/// Call contract read method
Read {
contract_id: ContractRef,
},

/// Execute contract operation
Exec {
contract_id: ContractRef,
},

/// Transfer contract state
Transfer {
contract_id: ContractRef,
path: PathBuf,
},

Validate {
path: PathBuf,
},

Accept {
path: PathBuf,
},
}
26 changes: 26 additions & 0 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SONARE: Runtime environment for formally-verifiable distributed software
//
// SPDX-License-Identifier: Apache-2.0
//
// Designed in 2019-2024 by Dr Maxim Orlovsky <[email protected]>
// Written in 2024-2025 by Dr Maxim Orlovsky <[email protected]>
//
// Copyright (C) 2019-2025 LNP/BP Standards Association, Switzerland.
// Copyright (C) 2024-2025 Laboratories for Ubiquitous Deterministic Computing (UBIDECO),
// Institute for Distributed and Cognitive Systems (InDCS), Switzerland.
// Copyright (C) 2019-2025 Dr Maxim Orlovsky.
// All rights under the above copyrights are reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
// in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
// or implied. See the License for the specific language governing permissions and limitations under
// the License.

mod cmd;

fn main() { todo!() }
13 changes: 0 additions & 13 deletions examples/dao.con
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
{--
A smart contract written for SONIC runtime environment
SONIC stands for "State machine with ownership notation for indeterministic contracts"

A contract calls are URIs and URLS, which may have multiple forms (depending on the backend).
Here are the examples for the `castVote` call:
- Using SONARE runtime:
`contract:DAO.indsc.org/castVote?voting=id&with=(id,preimage)&next=(id,hash)&vote=pro`
- Using a server providing SONIC API:
`contract://any.sonicapi.node/DAO.indsc.org/castVote?voting=id&with=(id,preimage)&next=(id,hash)&vote=pro`
- Using a server providing HTTP REST SONIC API:
`https://[email protected]/DAO.indsc.org/castVote?voting=id&with=(id,preimage)&next=(id,hash)&vote=pro`
- Using a websocket connection:
`wws://[email protected]/DAO.indsc.org/castVote?voting=id&with=(id,preimage)&next=(id,hash)&vote=pro`
- Using a Storm node server which contains SONARE runtime:
`storm://any.storm.node/contract:DAO.indsc.org/castVote?voting=id&with=(id,preimage)&next=(id,hash)&vote=pro`
--}

data PartyId: U64
Expand Down
9 changes: 5 additions & 4 deletions examples/dao.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ extern crate strict_types;

use amplify::confinement::{SmallString, TinyString};
use sonare::api::embedded::{EmbeddedAdaptors, EmbeddedArithm, EmbeddedProc, EmbeddedReaders, Source};
use sonare::api::{Api, ApiVm, AppendApi, CollectionType, DestructibleApi};
use sonare::api::{Api, ApiInner, AppendApi, CollectionType, DestructibleApi};
use sonare::containers::Ffv;
use strict_types::stl::std_stl;
use strict_types::{SemId, SymbolicSys, SystemBuilder, TypeSystem};
Expand Down Expand Up @@ -87,11 +87,12 @@ fn main() {
reserved: default!(),
};

let api = Api::<EmbeddedProc> {
let api = Api::Embedded(ApiInner::<EmbeddedProc> {
version: Ffv::default(),
codex_id: codex.codex_id(),
api_version: 0,
name: None,
vm: EmbeddedProc::TYPE,
developer: tiny_s!("ssi:anonymous"),
append_only: tiny_bmap! {
vname!("parties") => AppendApi {
published: true,
Expand Down Expand Up @@ -138,5 +139,5 @@ fn main() {
vname!("castVote") => 2,
},
errors: Default::default(),
};
});
}
2 changes: 1 addition & 1 deletion request/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
// the License.

use amplify::confinement::{TinyString, TinyVec};
use sonare::containers::contract::ProofOfPubl;
use sonare::containers::ProofOfPubl;
use strict_types::StrictVal;
use ultrasonic::ContractId;

Expand Down
15 changes: 15 additions & 0 deletions request/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@
//! # URL Representation
//!
//! `contract:[//USER@NODE:PORT/]CONTRACT_ID[/API][/METHOD?ARGS]`
//!
//! A contract calls are URIs and URLS, which may have multiple forms (depending on the backend).
//! Here are the examples for the `castVote` call for the DAO contract from the examples directory:
//! - Using SONARE runtime:
//! `contract:DAO.indsc.org/castVote?voting=id&with=(id,preimage)&next=(id,hash)&vote=pro`
//! - Using a server providing SONIC API:
//! `contract://any.sonicapi.node/DAO.indsc.org/castVote?voting=id&with=(id,preimage)&next=(id,
//! hash)&vote=pro`
//! - Using a server providing HTTP REST SONIC API: `https://[email protected]/DAO.indsc.org/castVote?voting=id&with=(id,preimage)&next=(id,hash)&vote=pro`
//! - Using a websocket connection:
//! `wws://[email protected]/DAO.indsc.org/castVote?voting=id&with=(id,preimage)&
//! next=(id,hash)&vote=pro`
//! - Using a Storm node server which contains SONARE runtime:
//! `storm://any.storm.node/contract:DAO.indsc.org/castVote?voting=id&with=(id,preimage)&next=(id,
//! hash)&vote=pro`
mod data;

Expand Down
Loading

0 comments on commit 016a724

Please sign in to comment.