-
Notifications
You must be signed in to change notification settings - Fork 0
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
0bf8f9a
commit 88e5a0a
Showing
24 changed files
with
1,237 additions
and
1,642 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 |
---|---|---|
@@ -1,36 +1,6 @@ | ||
[package] | ||
name = "sia_core" | ||
version = "0.0.1" | ||
edition = "2021" | ||
repository = "https://github.com/SiaFoundation/core-rs" | ||
license = "MIT" | ||
description = "Low-level SDK for interacting with the Sia decentralized storage network" | ||
authors = ["The Sia Foundation"] | ||
categories = ["cryptography::cryptocurrencies"] | ||
keywords = ["sia", "decentralized", "blockchain", "depin", "storage"] | ||
|
||
[lib] | ||
name = "sia_core" | ||
path = "src/lib.rs" | ||
|
||
[dependencies] | ||
base64 = "0.22.1" | ||
bip39 = "2.1.0" | ||
blake2b_simd = "1.0.2" | ||
ed25519-dalek = "2.1.1" | ||
hex = "0.4.3" | ||
rayon = "1.10.0" | ||
serde = { version = "1.0.214", features = ["derive"] } | ||
serde-big-array = "0.5.1" | ||
serde_json = "1.0.132" | ||
sha2 = "0.10.8" | ||
thiserror = "1.0.65" | ||
time = {version = "0.3.36", features = ["serde"] } | ||
|
||
[dev-dependencies] | ||
rand = "0.8.5" | ||
criterion = { version = "0.5" } | ||
|
||
[[bench]] | ||
name = "merkle_root" | ||
harness = false | ||
[workspace] | ||
resolver = "2" | ||
members = [ | ||
"sia", | ||
"sia-derive", | ||
] |
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,12 @@ | ||
[package] | ||
name = "sia-derive" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[lib] | ||
proc-macro = true | ||
|
||
[dependencies] | ||
syn = "2.0" | ||
quote = "1.0" | ||
proc-macro2 = "1.0" |
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,184 @@ | ||
use proc_macro::TokenStream; | ||
use quote::quote; | ||
use syn::{parse_macro_input, Data, DeriveInput, Fields}; | ||
|
||
#[proc_macro_derive(SiaEncode)] | ||
pub fn derive_sia_encode(input: TokenStream) -> TokenStream { | ||
let input = parse_macro_input!(input as DeriveInput); | ||
let name = &input.ident; | ||
|
||
let encode_impl = match &input.data { | ||
Data::Struct(data) => { | ||
let fields = match &data.fields { | ||
Fields::Named(fields) => { | ||
let encodes = fields.named.iter().map(|f| { | ||
let name = &f.ident; | ||
quote! { self.#name.encode(w)?; } | ||
}); | ||
quote! { #(#encodes)* } | ||
} | ||
Fields::Unnamed(fields) => { | ||
let encodes = fields.unnamed.iter().enumerate().map(|(i, _)| { | ||
let index = syn::Index::from(i); | ||
quote! { self.#index.encode(w)?; } | ||
}); | ||
quote! { #(#encodes)* } | ||
} | ||
Fields::Unit => quote! {}, | ||
}; | ||
quote! { | ||
#fields | ||
Ok(()) | ||
} | ||
} | ||
Data::Enum(_) => panic!("enums not supported"), | ||
Data::Union(_) => panic!("unions not supported"), | ||
}; | ||
|
||
let expanded = quote! { | ||
impl SiaEncodable for #name { | ||
fn encode<W: std::io::Write>(&self, w: &mut W) -> crate::encoding::Result<()> { | ||
#encode_impl | ||
} | ||
} | ||
}; | ||
|
||
TokenStream::from(expanded) | ||
} | ||
|
||
#[proc_macro_derive(SiaDecode)] | ||
pub fn derive_sia_decode(input: TokenStream) -> TokenStream { | ||
let input = parse_macro_input!(input as DeriveInput); | ||
let name = &input.ident; | ||
|
||
let decode_impl = match &input.data { | ||
Data::Struct(data) => { | ||
let fields = match &data.fields { | ||
Fields::Named(fields) => { | ||
let decodes = fields.named.iter().map(|f| { | ||
let name = &f.ident; | ||
let ty = &f.ty; | ||
quote! { #name: <#ty>::decode(r)?, } | ||
}); | ||
quote! { | ||
Ok(Self { | ||
#(#decodes)* | ||
}) | ||
} | ||
} | ||
Fields::Unnamed(fields) => { | ||
let decodes = fields.unnamed.iter().map(|f| { | ||
let ty = &f.ty; | ||
quote! { <#ty>::decode(r)?, } | ||
}); | ||
quote! { | ||
Ok(Self(#(#decodes)*)) | ||
} | ||
} | ||
Fields::Unit => quote! { Ok(Self) }, | ||
}; | ||
fields | ||
} | ||
Data::Enum(_) => panic!("enums not supported"), | ||
Data::Union(_) => panic!("unions not supported"), | ||
}; | ||
|
||
let expanded = quote! { | ||
impl SiaDecodable for #name { | ||
fn decode<R: std::io::Read>(r: &mut R) -> crate::encoding::Result<Self> { | ||
#decode_impl | ||
} | ||
} | ||
}; | ||
TokenStream::from(expanded) | ||
} | ||
|
||
#[proc_macro_derive(V1SiaEncode)] | ||
pub fn derive_v1_sia_encode(input: TokenStream) -> TokenStream { | ||
let input = parse_macro_input!(input as DeriveInput); | ||
let name = &input.ident; | ||
|
||
let encode_impl = match &input.data { | ||
Data::Struct(data) => { | ||
let fields = match &data.fields { | ||
Fields::Named(fields) => { | ||
let encodes = fields.named.iter().map(|f| { | ||
let name = &f.ident; | ||
quote! { self.#name.encode_v1(enc)?; } | ||
}); | ||
quote! { #(#encodes)* } | ||
} | ||
Fields::Unnamed(fields) => { | ||
let encodes = fields.unnamed.iter().enumerate().map(|(i, _)| { | ||
let index = syn::Index::from(i); | ||
quote! { self.#index.encode_v1(enc)?; } | ||
}); | ||
quote! { #(#encodes)* } | ||
} | ||
Fields::Unit => quote! {}, | ||
}; | ||
quote! { | ||
#fields | ||
Ok(()) | ||
} | ||
} | ||
Data::Enum(_) => panic!("enums not supported"), | ||
Data::Union(_) => panic!("unions not supported"), | ||
}; | ||
|
||
let expanded = quote! { | ||
impl V1SiaEncodable for #name { | ||
fn encode_v1<W: std::io::Write>(&self, enc: &mut W) -> crate::encoding::Result<()> { | ||
#encode_impl | ||
} | ||
} | ||
}; | ||
TokenStream::from(expanded) | ||
} | ||
|
||
#[proc_macro_derive(V1SiaDecode)] | ||
pub fn derive_v1_sia_decode(input: TokenStream) -> TokenStream { | ||
let input = parse_macro_input!(input as DeriveInput); | ||
let name = &input.ident; | ||
|
||
let decode_impl = match &input.data { | ||
Data::Struct(data) => { | ||
let fields = match &data.fields { | ||
Fields::Named(fields) => { | ||
let decodes = fields.named.iter().map(|f| { | ||
let name = &f.ident; | ||
let ty = &f.ty; | ||
quote! { #name: <#ty>::decode_v1(r)?, } | ||
}); | ||
quote! { | ||
Ok(Self { | ||
#(#decodes)* | ||
}) | ||
} | ||
} | ||
Fields::Unnamed(fields) => { | ||
let decodes = fields.unnamed.iter().map(|f| { | ||
let ty = &f.ty; | ||
quote! { <#ty>::decode_v1(r)?, } | ||
}); | ||
quote! { | ||
Ok(Self(#(#decodes)*)) | ||
} | ||
} | ||
Fields::Unit => quote! { Ok(Self) }, | ||
}; | ||
fields | ||
} | ||
Data::Enum(_) => panic!("enums not supported"), | ||
Data::Union(_) => panic!("unions not supported"), | ||
}; | ||
|
||
let expanded = quote! { | ||
impl V1SiaDecodable for #name { | ||
fn decode_v1<R: std::io::Read>(r: &mut R) -> crate::encoding::Result<Self> { | ||
#decode_impl | ||
} | ||
} | ||
}; | ||
TokenStream::from(expanded) | ||
} |
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,37 @@ | ||
[package] | ||
name = "sia" | ||
version = "0.0.1" | ||
edition = "2021" | ||
repository = "https://github.com/SiaFoundation/sia-rs" | ||
license = "MIT" | ||
description = "Low-level SDK for interacting with the Sia decentralized storage network" | ||
authors = ["The Sia Foundation"] | ||
categories = ["cryptography::cryptocurrencies"] | ||
keywords = ["sia", "decentralized", "blockchain", "depin", "storage"] | ||
|
||
[lib] | ||
name = "sia" | ||
path = "src/lib.rs" | ||
|
||
[dependencies] | ||
base64 = "0.22.1" | ||
bip39 = "2.1.0" | ||
blake2b_simd = "1.0.2" | ||
ed25519-dalek = "2.1.1" | ||
hex = "0.4.3" | ||
rayon = "1.10.0" | ||
serde = { version = "1.0.213", features = ["derive"] } | ||
serde-big-array = "0.5.1" | ||
serde_json = "1.0.132" | ||
sha2 = "0.10.8" | ||
thiserror = "1.0.65" | ||
time = {version = "0.3.36", features = ["serde"] } | ||
sia-derive = { path = "../sia-derive" } | ||
|
||
[dev-dependencies] | ||
rand = "0.8.5" | ||
criterion = { version = "0.5" } | ||
|
||
[[bench]] | ||
name = "merkle_root" | ||
harness = false |
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
Oops, something went wrong.