-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: introduce warp_contracts macro
- Loading branch information
1 parent
0fae2a0
commit f4f7b72
Showing
22 changed files
with
1,054 additions
and
4 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# Dependency directories | ||
|
||
node_modules/ | ||
crates/warp-contracts/target | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
[package] | ||
name = "warp-contracts" | ||
version = "0.1.1" | ||
edition = "2021" | ||
description = "Warp WASM contract utils for rust contracts" | ||
license = "MIT" | ||
documentation = "https://academy.warp.cc/docs/sdk/advanced/wasm" | ||
homepage = "https://warp.cc" | ||
repository = "https://github.com/warp-contracts/warp" | ||
keywords = ["warp", "smart-contract", "SmartWeave", "web3"] | ||
categories = ["api-bindings", "development-tools::ffi", "finance", "wasm"] | ||
|
||
[dependencies] | ||
wasm-bindgen = { workspace = true } | ||
wasm-bindgen-futures = { workspace = true } | ||
js-sys = { workspace = true } | ||
serde = { workspace = true } | ||
serde-wasm-bindgen = { workspace = true } | ||
warp-contracts-macro = { version = "0.1.1", path = "warp-contracts-macro" } | ||
warp-contracts-core = { version = "0.1.1", path = "warp-contracts-core" } | ||
|
||
[features] | ||
debug = ["warp-contracts-core/debug"] | ||
|
||
[workspace] | ||
members = ["warp-contracts-macro", "warp-contracts-core"] | ||
|
||
[workspace.dependencies] | ||
wasm-bindgen = "=0.2.84" | ||
wasm-bindgen-futures = { version = "=0.4.34" } | ||
js-sys = "=0.3.61" | ||
serde = { version = "1.0", features = ["derive"] } | ||
serde-wasm-bindgen = "=0.5.0" | ||
web-sys = { version = "=0.3.61" } |
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,23 @@ | ||
# Warp contracts | ||
|
||
`warp-contracts` is an inherent part of [Warp SDK](https://github.com/warp-contracts/warp). This library allows for smooth integration with Warp implementation of SmartWeave protocol. | ||
|
||
| Feature | Yes/No | | ||
| ---------------------- | ----------- | | ||
| Sandboxing | ✅ | | ||
| Foreign contract read | ✅ | | ||
| Foreign contract view | ✅ | | ||
| Foreign contract write | ✅ | | ||
| Arweave.utils | Soon | | ||
| Evolve | ✅ | | ||
| Logging from contract | ✅ | | ||
| Transaction data (1) | ✅ | | ||
| Block data (2) | ✅ | | ||
| Contract data (3) | ✅ | | ||
| Gas metering | ✅ | | ||
|
||
Legend: | ||
- `Soon` - the technology is already there, we just need to find some time to add the missing features :-) | ||
- `(1)` - access current transaction data (id, owner, etc.) | ||
- `(2)` - access current block data (indep_hash, height, timestamp) | ||
- `(3)` - access current contract data (id, owner) |
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,4 @@ | ||
# contract_utils module | ||
|
||
This is a module with boilerplate code for each SmartWeave RUST contract. | ||
**Please don't modify it unless you 100% know what you are doing!** |
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,65 @@ | ||
use super::js_imports::SmartWeave; | ||
use serde::de::DeserializeOwned; | ||
use serde::Serialize; | ||
use serde_wasm_bindgen::from_value; | ||
use core::fmt::Debug; | ||
use warp_contracts_core::{ | ||
handler_result::{ViewResult, WriteResult}, | ||
methods::to_json_value, | ||
warp_result::{transmission::from_json, WarpResult}, | ||
}; | ||
|
||
pub async fn read_foreign_contract_state<T: DeserializeOwned>( | ||
contract_address: &str, | ||
) -> Result<T, String> { | ||
match SmartWeave::read_contract_state(contract_address).await { | ||
Ok(s) => match from_value::<T>(s) { | ||
Ok(v) => Ok(v), | ||
Err(e) => Err(format!("{e:?}")), | ||
}, | ||
Err(e) => Err(format!("{e:?}")), | ||
} | ||
} | ||
|
||
pub async fn view_foreign_contract_state< | ||
V: DeserializeOwned + Debug, | ||
I: Serialize, | ||
E: DeserializeOwned + Debug, | ||
>( | ||
contract_address: &str, | ||
input: I, | ||
) -> ViewResult<V, E> { | ||
let input = match to_json_value(&input) { | ||
Ok(v) => v, | ||
Err(e) => return ViewResult::RuntimeError(format!("{e:?}")), | ||
}; | ||
match SmartWeave::view_contract_state(contract_address, input).await { | ||
Ok(s) => match from_json::<V, E>(s) { | ||
WarpResult::WriteSuccess() => { | ||
ViewResult::RuntimeError("got WriteResponse for view call".to_owned()) | ||
} | ||
v => v.into(), | ||
}, | ||
Err(e) => ViewResult::RuntimeError(format!("{e:?}")), | ||
} | ||
} | ||
|
||
pub async fn write_foreign_contract<I: Serialize, E: DeserializeOwned + Debug>( | ||
contract_address: &str, | ||
input: I, | ||
) -> WriteResult<(), E> { | ||
let input = match to_json_value(&input) { | ||
Ok(v) => v, | ||
Err(e) => return WriteResult::RuntimeError(format!("{e:?}")), | ||
}; | ||
let write_result = SmartWeave::write(contract_address, input).await; | ||
match write_result { | ||
Ok(s) => match from_json::<(), E>(s) { | ||
WarpResult::ViewSuccess(_) => { | ||
WriteResult::RuntimeError("got ViewResponse for write call".to_owned()) | ||
} | ||
v => v.into(), | ||
}, | ||
Err(e) => WriteResult::RuntimeError(format!("{e:?}")), | ||
} | ||
} |
Oops, something went wrong.