-
Notifications
You must be signed in to change notification settings - Fork 46
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
Showing
15 changed files
with
524 additions
and
0 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 |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
members = [ | ||
"sigma-chain", | ||
"sigma-chain-c", | ||
"sigma-ser", | ||
] |
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,5 @@ | ||
use std::collections::HashMap; | ||
|
||
pub struct ContextExtension { | ||
pub values: HashMap<u8, Box<[u8]>>, | ||
} |
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 @@ | ||
use crate::ergo_box::BoxId; | ||
use sigma_ser::serializer::SerializationError; | ||
use sigma_ser::serializer::SigmaSerializable; | ||
use sigma_ser::vlq_encode; | ||
use std::io; | ||
|
||
pub struct DataInput { | ||
pub box_id: BoxId, | ||
} | ||
|
||
impl SigmaSerializable for DataInput { | ||
fn sigma_serialize<W: vlq_encode::WriteSigmaVlqExt>(&self, w: W) -> Result<(), io::Error> { | ||
self.box_id.sigma_serialize(w)?; | ||
Ok(()) | ||
} | ||
fn sigma_parse<R: vlq_encode::ReadSigmaVlqExt>(r: R) -> Result<Self, SerializationError> { | ||
let box_id = BoxId::sigma_parse(r)?; | ||
Ok(DataInput { box_id }) | ||
} | ||
} |
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,39 @@ | ||
use crate::ergo_tree::ErgoTree; | ||
use sigma_ser::serializer::SerializationError; | ||
use sigma_ser::serializer::SigmaSerializable; | ||
use sigma_ser::vlq_encode; | ||
use std::collections::HashMap; | ||
use std::io; | ||
|
||
// TODO: extract BoxId | ||
pub const DIGEST32_SIZE: usize = 32; | ||
pub struct BoxId(pub [u8; DIGEST32_SIZE]); | ||
|
||
impl SigmaSerializable for BoxId { | ||
fn sigma_serialize<W: vlq_encode::WriteSigmaVlqExt>(&self, mut w: W) -> Result<(), io::Error> { | ||
w.write_all(&self.0)?; | ||
Ok(()) | ||
} | ||
fn sigma_parse<R: vlq_encode::ReadSigmaVlqExt>(mut r: R) -> Result<Self, SerializationError> { | ||
let mut bytes = [0; DIGEST32_SIZE]; | ||
r.read_exact(&mut bytes)?; | ||
Ok(Self(bytes)) | ||
} | ||
} | ||
|
||
pub struct TokenId(Box<[u8; DIGEST32_SIZE]>); | ||
|
||
pub struct TokenInfo { | ||
pub token_id: TokenId, | ||
pub amount: u64, | ||
} | ||
|
||
pub struct NonMandatoryRegisterId(u8); | ||
|
||
pub struct ErgoBoxCandidate { | ||
pub value: u64, | ||
pub ergo_tree: ErgoTree, | ||
pub tokens: Vec<TokenInfo>, | ||
pub additional_registers: HashMap<NonMandatoryRegisterId, Box<[u8]>>, | ||
pub creation_height: u32, | ||
} |
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 @@ | ||
pub struct ErgoTree {} |
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,7 @@ | ||
use crate::ergo_box::BoxId; | ||
use crate::prover_result::ProverResult; | ||
|
||
pub struct Input { | ||
pub box_id: BoxId, | ||
pub spending_proof: ProverResult, | ||
} |
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,6 @@ | ||
use crate::context_extension::ContextExtension; | ||
|
||
pub struct ProverResult { | ||
pub proof: Box<[u8]>, | ||
pub extension: ContextExtension, | ||
} |
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 @@ | ||
use crate::data_input::DataInput; | ||
use crate::ergo_box::ErgoBoxCandidate; | ||
use crate::input::Input; | ||
use sigma_ser::serializer::SerializationError; | ||
use sigma_ser::serializer::SigmaSerializable; | ||
use sigma_ser::vlq_encode; | ||
use std::io; | ||
|
||
pub struct Transaction { | ||
pub inputs: Vec<Input>, | ||
pub data_inputs: Vec<DataInput>, | ||
pub outputs: Vec<ErgoBoxCandidate>, | ||
} | ||
|
||
impl SigmaSerializable for Transaction { | ||
fn sigma_serialize<W: vlq_encode::WriteSigmaVlqExt>(&self, mut w: W) -> Result<(), io::Error> { | ||
w.put_u16(self.inputs.len() as u16)?; | ||
Ok(()) | ||
} | ||
fn sigma_parse<R: vlq_encode::ReadSigmaVlqExt>(_: R) -> Result<Self, SerializationError> { | ||
unimplemented!() | ||
} | ||
} |
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,29 @@ | ||
[package] | ||
name = "sigma-ser" | ||
version = "0.1.0" | ||
authors = ["Denys Zadorozhnyi <denys@zadorozhnyi.com>"] | ||
edition = "2018" | ||
|
||
[lib] | ||
crate-type = ["cdylib", "rlib"] | ||
|
||
[features] | ||
default = ["console_error_panic_hook"] | ||
|
||
[dependencies] | ||
wasm-bindgen = "0.2" | ||
|
||
# The `console_error_panic_hook` crate provides better debugging of panics by | ||
# logging them with `console.error`. This is great for development, but requires | ||
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for | ||
# code size when deploying. | ||
console_error_panic_hook = { version = "0.1.6", optional = true } | ||
|
||
[dev-dependencies] | ||
wasm-bindgen-test = "0.3.10" | ||
proptest = "0.9" | ||
proptest-derive = "0.1.2" | ||
|
||
[profile.release] | ||
# Tell `rustc` to optimize for small code size. | ||
opt-level = "s" |
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,3 @@ | ||
pub mod serializer; | ||
pub mod vlq_encode; | ||
pub mod zig_zag_encode; |
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,25 @@ | ||
use super::vlq_encode; | ||
use std::io; | ||
|
||
#[derive(Debug)] | ||
pub enum SerializationError { | ||
VlqEncode(vlq_encode::VlqEncodingError), | ||
Io(io::Error), | ||
} | ||
|
||
impl From<vlq_encode::VlqEncodingError> for SerializationError { | ||
fn from(error: vlq_encode::VlqEncodingError) -> Self { | ||
SerializationError::VlqEncode(error) | ||
} | ||
} | ||
|
||
impl From<io::Error> for SerializationError { | ||
fn from(error: io::Error) -> Self { | ||
SerializationError::Io(error) | ||
} | ||
} | ||
|
||
pub trait SigmaSerializable: Sized { | ||
fn sigma_serialize<W: vlq_encode::WriteSigmaVlqExt>(&self, w: W) -> Result<(), io::Error>; | ||
fn sigma_parse<R: vlq_encode::ReadSigmaVlqExt>(r: R) -> Result<Self, SerializationError>; | ||
} |
Oops, something went wrong.