-
Notifications
You must be signed in to change notification settings - Fork 14
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
1 parent
9aafe89
commit 3bfb1c6
Showing
6 changed files
with
392 additions
and
33 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
resolver = "2" | ||
members = [ | ||
"core", | ||
"dave-compute", | ||
"dave-advance", | ||
"input-reader", | ||
] | ||
|
||
|
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,20 @@ | ||
[package] | ||
name = "dave-advance" | ||
version.workspace = true | ||
authors.workspace = true | ||
description.workspace = true | ||
edition.workspace = true | ||
homepage.workspace = true | ||
license-file.workspace = true | ||
readme.workspace = true | ||
repository.workspace = true | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
cartesi-machine-json-rpc = { path = "../../machine-json-rpc" } | ||
tokio = { workspace = true } | ||
base64 = "0.21.3" | ||
hex = "0.4.3" | ||
ethers.workspace = true | ||
serde_json = "1.0.100" |
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,34 @@ | ||
# dave-advance | ||
|
||
Crate for simplified input feeding to the Cartesi machine. | ||
|
||
```rs | ||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
/// The advance-state input that we need to change the machine | ||
let input = AdvanceInput { | ||
metadata: InputMetadata { | ||
msg_sender: Address::from_str("0x0000000000000000000000000000000000000000")?, | ||
block_number: 0, | ||
time_stamp: 0, | ||
epoch_index: 0, | ||
input_index: 0, | ||
}, | ||
data: "uwu".as_bytes().to_vec(), | ||
}; | ||
|
||
/// Connects to a remote machine. | ||
let mut machine = MachineClient::connect("http://127.0.0.1".to_string(), 5002).await?; | ||
|
||
/// Loads a machine that is with the `y` flag. | ||
machine.load(&PathBuf::from("/data/image"), &Default::default()).await?; | ||
|
||
/// Advances the state of the machine until a new [ManualYield] | ||
machine.advance(input.clone()).await? | ||
|
||
/// Destroys the current machine in order to load a new one | ||
machine.destroy().await?; | ||
|
||
Ok(()) | ||
} | ||
``` |
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,16 @@ | ||
//! Tools for encoding and decoding stuff that is sent to the Cartesi Machine. | ||
/// Writes a 64-bit big-endian integer to a 32-byte buffer. | ||
pub(crate) fn write_be256(value: u64) -> Vec<u8> { | ||
let mut buffer = [0; 32]; | ||
buffer[24..].copy_from_slice(&value.to_be_bytes()); | ||
buffer.to_vec() | ||
} | ||
|
||
/// Encodes a string putting 32 bytes in front of it and adding the length of the string. | ||
pub(crate) fn encode_string(payload: Vec<u8>) -> Vec<u8> { | ||
let mut encoded_string = write_be256(32); | ||
encoded_string.append(&mut write_be256(payload.len() as u64)); | ||
encoded_string.append(&mut payload.clone()); | ||
encoded_string | ||
} |
Oops, something went wrong.