Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add proof type #245

Merged
merged 89 commits into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
1853d5a
Add proof type
MavenRain Jan 19, 2023
a7f129e
Remove deprecation warnings
MavenRain Jan 19, 2023
587d080
Clippy error
MavenRain Jan 19, 2023
b936af9
Rename Proof to ProofOperation
MavenRain Jan 23, 2023
ef86b26
Introduce context type
MavenRain Jan 24, 2023
d0b6455
Introduce concept of Context to many-module macros
MavenRain Jan 24, 2023
98415a8
Want to be able to add context to the balance call but can't
MavenRain Jan 24, 2023
e0f07ad
Fix macro for context expansion
MavenRain Jan 24, 2023
27e611f
Rectified merge with main branch
MavenRain Jan 24, 2023
cc04eef
Only look for proof transmission if requested
MavenRain Jan 24, 2023
aef8b1f
Add convenience methods to Context
MavenRain Jan 25, 2023
4996045
Add context to mint and burn functions
MavenRain Jan 25, 2023
bdc5cf9
Merge https://github.com/liftedinit/many-rs into oobi/proof
MavenRain Jan 25, 2023
b4c9b15
Move toward collecting proof from context in ProofOperation form
MavenRain Jan 26, 2023
7a8a46a
Move toward collecting proof from context in ProofOperation form
MavenRain Jan 26, 2023
a15e9f9
Relax iterator requirement to something implementing IntoIterator
MavenRain Jan 26, 2023
576f50d
Now working with fallible attribute list after CborAny decoding
MavenRain Jan 26, 2023
493e43f
Remove unneeded method
MavenRain Jan 26, 2023
cab84be
Post monorepo merge of many-framework portion of PR
MavenRain Jan 26, 2023
248b1bd
Merge https://github.com/liftedinit/many-rs into oobi/proof
MavenRain Jan 27, 2023
e9e9ae0
Proving store concept
MavenRain Feb 6, 2023
15d24ba
Proving store changes moved to separate branch
MavenRain Feb 6, 2023
16a5577
Refactor get_multiple_balances
MavenRain Feb 6, 2023
1a41d0c
Add ability to supply request attribute
MavenRain Feb 6, 2023
c55748f
Print AttributeSet from the response when many message is sent
MavenRain Feb 6, 2023
a76a93e
Too many arguments warnings
MavenRain Feb 6, 2023
99c4d6c
Additional Clippy warning overcome
MavenRain Feb 7, 2023
b01b76b
Rectify merge with main branch
MavenRain Feb 7, 2023
7865fb0
Revert staging settings in PR
MavenRain Feb 7, 2023
dd13ef6
Mint proving and fix bats test fail
MavenRain Feb 7, 2023
609627c
cargo fmt
MavenRain Feb 7, 2023
09e109b
Burn proving
MavenRain Feb 7, 2023
93114cb
Remove commented code
MavenRain Feb 7, 2023
de7e7e6
Add context to leddger.info call
MavenRain Feb 7, 2023
2df8976
ledger.info proving
MavenRain Feb 7, 2023
d963f8f
Add context to token send
MavenRain Feb 7, 2023
77cb0f1
Merge https://github.com/liftedinit/many-rs into oobi/proof
MavenRain Feb 7, 2023
266b939
Fixes to unbreak 3 feature tests
MavenRain Feb 7, 2023
b2b00ba
Complete token send proving
MavenRain Feb 7, 2023
1302cec
Verify acl refactor to expose keys
MavenRain Feb 8, 2023
355e5ac
Get next subresource surfaces keys
MavenRain Feb 8, 2023
513b82c
Update symbols returns keys
MavenRain Feb 8, 2023
54a3f00
create token surfaces keys
MavenRain Feb 8, 2023
48f4960
Token create proving
MavenRain Feb 8, 2023
389a661
Surface key from get-owner
MavenRain Feb 8, 2023
943de64
Update token method propagates keys
MavenRain Feb 8, 2023
e1e2690
Cargo lock changes
MavenRain Feb 8, 2023
03b2e46
Token update proving
MavenRain Feb 8, 2023
00d778a
Add/remove extended info keys surfaced from storage methods
MavenRain Feb 8, 2023
3f8304f
Try to clear weird CI compiler error
MavenRain Feb 8, 2023
2d9a4e3
Adding context to token extended info calls
MavenRain Feb 8, 2023
566e1a4
Token extended info proving
MavenRain Feb 8, 2023
d26017b
Keys needed for idstore
MavenRain Feb 8, 2023
05fd23e
idstore store keys added
MavenRain Feb 8, 2023
705f5f5
Context added to data interface
MavenRain Feb 8, 2023
b55f37b
Data proving
MavenRain Feb 8, 2023
0980a2a
TODO for account endpoints
MavenRain Feb 8, 2023
bb80056
Fix enum variant used in round-trip decoding test
MavenRain Feb 8, 2023
83f7cfe
Merge https://github.com/liftedinit/many-rs into oobi/proof
MavenRain Feb 9, 2023
8e25cef
Account creation proving
MavenRain Feb 10, 2023
35c3b79
Account creation proving
MavenRain Feb 10, 2023
71873b2
Small refactor
MavenRain Feb 10, 2023
747b211
rectified merge with main
MavenRain Feb 13, 2023
dd2b70a
Merge https://github.com/liftedinit/many-rs into oobi/proof
MavenRain Feb 13, 2023
88e62d6
KV store account proof
MavenRain Feb 14, 2023
84d4adc
Up to KvStore set description for proving
MavenRain Feb 15, 2023
a7f90c0
Account proving
MavenRain Feb 16, 2023
e2873c4
Rectified merge with main branch
MavenRain Feb 16, 2023
ad9c5b8
Refactor attribute to proof parameter in CLI and refactor return type…
MavenRain Feb 21, 2023
5958211
Remove proof functionality from send command
MavenRain Feb 21, 2023
5163736
Remove proof functionality from mint/burn
MavenRain Feb 21, 2023
c983f14
TryFrom for Proof to CborAny
MavenRain Feb 21, 2023
4c987de
Remove proof support from ledger token command calls
MavenRain Feb 21, 2023
50aca99
Remove proof functionality from account commands
MavenRain Feb 21, 2023
fecb5a9
Constructor for Context made
MavenRain Feb 21, 2023
09842be
Merge https://github.com/liftedinit/many-rs into oobi/proof
MavenRain Feb 21, 2023
692bba2
Default proof command line value
MavenRain Feb 22, 2023
a11eb34
Overcome clippy error
MavenRain Feb 22, 2023
18fc554
Use default clap option for proof boolean
MavenRain Feb 22, 2023
7e5d801
Try to fix bats error, attempt 1
MavenRain Feb 22, 2023
373c55b
Refactoring proof argument calculation in main
MavenRain Feb 22, 2023
8dc5d19
Pattern-match option for proof argument calculation
MavenRain Feb 22, 2023
a3f668f
Prefer collect to from_iter
MavenRain Feb 22, 2023
bff164c
Prefer collect to from_iter, second change
MavenRain Feb 22, 2023
0832ad4
Prefer collect to from_iter, third change
MavenRain Feb 22, 2023
c4e575b
Merge https://github.com/liftedinit/many-rs into oobi/proof
MavenRain Feb 22, 2023
230050d
Fix lock files
MavenRain Feb 22, 2023
411b8ad
Some bazel changes
MavenRain Feb 22, 2023
728cb06
Format changes made
MavenRain Feb 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/many-error/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ impl Display for ManyError {
}
}

// TODO: The fact that ManyErrorCode is constructed as a macro makes this annoying, instead of just deriving Default.
#[allow(clippy::derivable_impls)]
impl Default for ManyErrorCode {
#[inline]
fn default() -> Self {
Expand Down
2 changes: 0 additions & 2 deletions src/many-migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,6 @@ impl<'a, T, E, IDX: AsRef<str>> Index<IDX> for MigrationSet<'a, T, E> {
}

/// Kept for backward compatibility.
#[deprecated = "Should use MigrationSet::load() instead."]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These warnings were triggering on builds. Either these should be removed, or they should be re-added along with the remedies for the places where they are currently being used.

pub fn load_migrations<'a, T, E>(
registry: &'a [InnerMigration<T, E>],
config: &str,
Expand All @@ -565,7 +564,6 @@ pub fn load_migrations<'a, T, E>(

/// Enable all migrations from the registry EXCEPT the hotfix.
/// Should not be used outside of tests.
#[deprecated = "Should use MigrationSet::load() instead."]
pub fn load_enable_all_regular_migrations<T, E>(
registry: &[InnerMigration<T, E>],
) -> MigrationSet<T, E> {
Expand Down
1 change: 1 addition & 0 deletions src/many-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ many-error = { path = "../many-error", version = "0.1.0" }
many-identity = { path = "../many-identity", version = "0.1.0" }
base64 = "0.20.0"
coset = "0.3.2"
derive_more = "0.99"
fixed = "1.16.0"
hex = "0.4.3"
minicbor = { version = "0.18.0", features = ["derive", "std", "half"] }
Expand Down
1 change: 1 addition & 0 deletions src/many-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub mod identity {
}
pub mod ledger;
pub mod memo;
pub mod proof;

use attributes::AttributeId;
pub use either::Either;
Expand Down
154 changes: 154 additions & 0 deletions src/many-types/src/proof.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
use {
derive_more::{From, Into},
minicbor::{
decode,
encode::{Error, Write},
Decode, Decoder, Encode, Encoder,
},
};

#[derive(Clone, Debug, Eq, From, Into, PartialEq)]
pub struct Key(Vec<u8>);

#[derive(Clone, Debug, Eq, From, Into, PartialEq)]
pub struct Value(Vec<u8>);

#[derive(Clone, Debug, Eq, PartialEq)]
pub enum Proof {
Child,
KeyValueHash(Vec<u8>),
KeyValuePair(Key, Value),
NodeHash(Vec<u8>),
Parent,
}

impl<C> Encode<C> for Proof {
fn encode<W: Write>(&self, e: &mut Encoder<W>, _: &mut C) -> Result<(), Error<W::Error>> {
use Proof::{Child, KeyValueHash, KeyValuePair, NodeHash, Parent};
match &self {
Child => e.u8(0x11),
KeyValueHash(hash) => e.array(2).and_then(|e| e.u8(1)).and_then(|e| e.bytes(hash)),
KeyValuePair(Key(key), Value(value)) => e
.array(3)
.and_then(|e| e.u8(3))
.and_then(|e| e.bytes(key))
.and_then(|e| e.bytes(value)),
NodeHash(hash) => e.array(2).and_then(|e| e.u8(2)).and_then(|e| e.bytes(hash)),
Parent => e.u8(0x10),
}
.map(|_| ())
}
}

impl<'d, C> Decode<'d, C> for Proof {
fn decode(d: &mut Decoder<'d>, _: &mut C) -> Result<Self, decode::Error> {
use {
minicbor::data::Type::{
Array, ArrayIndef, Bool, Break, Bytes, BytesIndef, Int, Map, MapIndef, Null,
Simple, String, StringIndef, Tag, Undefined, Unknown, F16, F32, F64, I16, I32, I64,
I8, U16, U32, U64, U8,
},
Proof::{Child, KeyValueHash, KeyValuePair, NodeHash, Parent},
};
d.datatype().and_then(|datatype| match datatype {
Array | ArrayIndef => match d.array() {
Err(_) | Ok(None) => Err(decode::Error::message(
"Error parsing array type into array",
)),
Ok(Some(array_length)) if array_length == 2 => {
d.u8().and_then(|value| match value {
1 => d.bytes().map(|hash| KeyValueHash(hash.to_vec())),
2 => d.bytes().map(|hash| NodeHash(hash.to_vec())),
variant => Err(decode::Error::unknown_variant(variant.into())),
})
}
Ok(Some(array_length)) if array_length == 3 => {
d.u8().and_then(|_| d.bytes()).and_then(|key| {
d.bytes()
.map(|value| KeyValuePair(key.to_vec().into(), value.to_vec().into()))
})
}
Ok(Some(array_length)) => Err(decode::Error::message(format!(
"Unexpected array size {array_length}"
))),
},
U8 => d.u8().and_then(|value| match value {
0x10 => Ok(Parent),
0x11 => Ok(Child),
variant => Err(decode::Error::unknown_variant(variant.into())),
}),
Bool | Break | Bytes | BytesIndef | F16 | F32 | F64 | I8 | I16 | I32 | I64 | Int
| Map | MapIndef | Null | Simple | String | StringIndef | Tag | U16 | U32 | U64
| Undefined | Unknown(_) => Err(decode::Error::message("Expected either array or u8")),
})
}
}

#[cfg(test)]
mod tests {
use super::Proof;
#[test]
fn round_trip_parent() -> Result<(), ()> {
assert_eq!(
minicbor::decode::<Proof>(minicbor::to_vec(Proof::Parent).map_err(|_| ())?.as_slice())
.map_err(|_| ())?,
Proof::Parent
);
Ok(())
}

#[test]
fn round_trip_child() -> Result<(), ()> {
assert_eq!(
minicbor::decode::<Proof>(minicbor::to_vec(Proof::Child).map_err(|_| ())?.as_slice())
.map_err(|_| ())?,
Proof::Child
);
Ok(())
}

#[test]
fn round_trip_key_value_hash() -> Result<(), ()> {
let key_value_hash = Proof::KeyValueHash(vec![1, 2, 3]);
assert_eq!(
minicbor::decode::<Proof>(
minicbor::to_vec(key_value_hash.clone())
.map_err(|_| ())?
.as_slice()
)
.map_err(|_| ())?,
key_value_hash
);
Ok(())
}

#[test]
fn round_trip_node_hash() -> Result<(), ()> {
let node_hash = Proof::KeyValueHash(vec![1, 2, 3]);
assert_eq!(
minicbor::decode::<Proof>(
minicbor::to_vec(node_hash.clone())
.map_err(|_| ())?
.as_slice()
)
.map_err(|_| ())?,
node_hash
);
Ok(())
}

#[test]
fn round_trip_key_value_pair() -> Result<(), ()> {
let key_value_pair = Proof::KeyValuePair(vec![1, 2, 3].into(), vec![4, 5, 6].into());
assert_eq!(
minicbor::decode::<Proof>(
minicbor::to_vec(key_value_pair.clone())
.map_err(|_| ())?
.as_slice()
)
.map_err(|_| ())?,
key_value_pair
);
Ok(())
}
}