-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ludo Galabru
committed
Oct 20, 2022
1 parent
bc64f82
commit 1c11851
Showing
12 changed files
with
1,229 additions
and
80 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
[package] | ||
name = "clarity-jupyter-kernel" | ||
description = "Jupyter kernel for Clarity" | ||
version = "1.0.0" | ||
authors = ["Ludo Galabru <[email protected]>"] | ||
edition = "2018" | ||
readme = "README.md" | ||
license = "GPL-3.0-only" | ||
keywords = ["blockchain", "clarity", "smart-contract", "jupyter", "notebook"] | ||
repository = "https://github.com/hirosystems/clarinet/components/clarity-jupyter-kernel" | ||
categories = ["command-line-utilities", "development-tools", "development-tools::build-utils"] | ||
|
||
[dependencies] | ||
clarity_repl = { package = "clarity-repl", path = "../clarity-repl" } | ||
lazy_static = "1.4.0" | ||
regex = "1.3.4" | ||
sha2 = "0.8.1" | ||
sha3 = "0.8.2" | ||
ripemd160 = "0.8.0" | ||
json = { version = "0.11.15" } # should use serde_json instead | ||
failure = { version = "0.1.5", default-features = false, features = [ "std" ] } | ||
zmq = { version = "0.9.1", default-features = false } | ||
uuid = { version = "0.7.4", features = [ "v4" ] } | ||
hmac = { version = "0.7.1" } | ||
hex = { version = "0.3.2" } | ||
colored = { version = "1.8.0" } # should use ansi_term instead | ||
dirs = { version = "2.0.2" } | ||
chrono = { version = "0.4.7" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# clarity-jupyter-kernel | ||
|
||
Clarity is a **decidable** smart contract language that optimizes for predictability and security, designed by Blockstack. Smart contracts allow developers to encode essential business logic on a blockchain. | ||
|
||
A programming language is decidable if you can know, with certainty, from the code itself what the program will do. Clarity is intentionally Turing incomplete as it avoids `Turing complexity`. This allows for complete static analysis of the entire call graph of a given smart contract. Further, our support for types and type checker can eliminate whole classes of bugs like unintended casts, reentrancy bugs, and reads of uninitialized values. | ||
|
||
The Jupyter Notebook is an open-source web application that allows you to create and share documents that contain live code, equations, visualizations and narrative text. Uses include: data cleaning and transformation, numerical simulation, statistical modeling, data visualization, machine learning, and much more. | ||
|
||
A notebook kernel is a `computational engine` that executes the code contained in a Notebook document. | ||
|
||
When you open a Notebook document, the associated kernel is automatically launched. When the notebook is executed (either cell-by-cell or with menu Cell -> Run All), the kernel performs the computation and produces the results. Depending on the type of computations, the kernel may consume significant CPU and RAM. Note that the RAM is not released until the kernel is shut-down. | ||
|
||
 | ||
|
||
## Quick Start | ||
|
||
The first step is to install jupyter-notebook, with pip or your favourite packet manager (brew, pacman, etc). | ||
You can then build and install the kernel handling Clarity: | ||
|
||
### Building from source | ||
|
||
The first step is to ensure that you have Rust and the support software installed. | ||
|
||
```bash | ||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh | ||
``` | ||
|
||
From there, you can clone this repository: | ||
|
||
```bash | ||
git clone https://github.com/lgalabru/clarity-jupyter-kernel.git | ||
|
||
cd clarity-jupyter-kernel | ||
``` | ||
|
||
|
||
```bash | ||
cargo install --path . | ||
clarity-jupyter-kernel --install | ||
``` | ||
|
||
By starting jupyter-notebook | ||
```bash | ||
jupyter-notebook | ||
``` | ||
|
||
You can now create a new Notebook with Clarity. | ||
|
22 changes: 22 additions & 0 deletions
22
components/clarity-jupyter-kernel/src/jupyter/connection.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use failure::Error; | ||
use hmac::{Hmac, Mac}; | ||
use sha2::Sha256; | ||
use zmq; | ||
|
||
pub type HmacSha256 = Hmac<Sha256>; | ||
|
||
pub struct Connection { | ||
pub socket: zmq::Socket, | ||
pub mac: Option<HmacSha256>, | ||
} | ||
|
||
impl Connection { | ||
pub fn new(socket: zmq::Socket, key: &str) -> Result<Connection, Error> { | ||
let mac = if key.is_empty() { | ||
None | ||
} else { | ||
Some(HmacSha256::new_varkey(key.as_bytes()).expect("Shouldn't fail with HMAC")) | ||
}; | ||
Ok(Connection { socket, mac }) | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
components/clarity-jupyter-kernel/src/jupyter/control_file.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use failure::Error; | ||
use json; | ||
use std::fs; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct Control { | ||
pub control_port: u16, | ||
pub shell_port: u16, | ||
pub stdin_port: u16, | ||
pub hb_port: u16, | ||
pub iopub_port: u16, | ||
pub transport: String, | ||
pub signature_scheme: String, | ||
pub ip: String, | ||
pub key: String, | ||
} | ||
|
||
macro_rules! parse_to_var { | ||
($control_json:expr, $name:ident, $convert:ident) => { | ||
let $name = $control_json[stringify!($name)] | ||
.$convert() | ||
.ok_or_else(|| format_err!("Missing JSON field {}", stringify!($name)))?; | ||
}; | ||
} | ||
|
||
impl Control { | ||
pub fn parse_file(file_name: &str) -> Result<Control, Error> { | ||
let control_file_contents = fs::read_to_string(file_name)?; | ||
let control_json = json::parse(&control_file_contents)?; | ||
parse_to_var!(control_json, control_port, as_u16); | ||
parse_to_var!(control_json, shell_port, as_u16); | ||
parse_to_var!(control_json, stdin_port, as_u16); | ||
parse_to_var!(control_json, hb_port, as_u16); | ||
parse_to_var!(control_json, iopub_port, as_u16); | ||
parse_to_var!(control_json, transport, as_str); | ||
parse_to_var!(control_json, signature_scheme, as_str); | ||
parse_to_var!(control_json, ip, as_str); | ||
parse_to_var!(control_json, key, as_str); | ||
Ok(Control { | ||
control_port, | ||
shell_port, | ||
stdin_port, | ||
hb_port, | ||
iopub_port, | ||
transport: transport.to_owned(), | ||
signature_scheme: signature_scheme.to_owned(), | ||
key: key.to_owned(), | ||
ip: ip.to_owned(), | ||
}) | ||
} | ||
} |
Oops, something went wrong.