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

Merk hash scheme migration #338

Open
wants to merge 120 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 116 commits
Commits
Show all changes
120 commits
Select commit Hold shift + click to select a range
9c39f12
Very rough draft of merk key migration
MavenRain Mar 21, 2023
6569168
Branch broken due to Bazel problem
MavenRain Mar 21, 2023
7534813
New migration type
MavenRain Mar 21, 2023
015478f
Lock file changes
MavenRain Mar 21, 2023
9fc967a
Lock file changes
MavenRain Mar 22, 2023
186091b
fix: alias many-ledger test
fmorency Mar 22, 2023
df8814b
Factor complex type
MavenRain Mar 22, 2023
7091a87
Add hash migration to json config
MavenRain Mar 23, 2023
cd7c4b7
Fixed storage error by sorting batch in ledger tokens section
MavenRain Mar 27, 2023
f18d6dd
Remove unused imports
MavenRain Mar 27, 2023
b074ef0
cargo fmt
MavenRain Mar 27, 2023
1332d87
Lock file changes
MavenRain Mar 27, 2023
de63140
Lock file changes
MavenRain Mar 27, 2023
18f16ea
Lock file changes
MavenRain Mar 27, 2023
b9f0110
Flop over to v2 for idstore export
MavenRain Mar 27, 2023
c5a75b8
To merk v2 for ledger db CLI
MavenRain Mar 27, 2023
9cc2dcb
Choose v1 or v2 storage opening in ledger based on migration
MavenRain Mar 29, 2023
cac41ce
Storage opening in ledger dependent on hash migration
MavenRain Mar 29, 2023
2a3767b
KvStore only uses v2 storage
MavenRain Mar 29, 2023
d33d246
On write, all operations take merk version into account
MavenRain Mar 30, 2023
71adc6b
Use v2 merk error for KvStoreIterator
MavenRain Mar 30, 2023
9cb3ebe
Corrected some storage operations in the main ledger storage file
MavenRain Mar 30, 2023
907d5d7
Stub for hash migration resiliency test
MavenRain Mar 30, 2023
e2bb5e6
Rectify clippy errors
MavenRain Mar 30, 2023
050e039
Add setup/teardown for migration resiliency test
MavenRain Mar 30, 2023
0478be6
Fix bug causing staging e2e failure
MavenRain Mar 30, 2023
46b9aac
Some ledger main.rs cleanup
MavenRain Mar 30, 2023
7e6c718
More ledger main.rs cleanup
MavenRain Mar 30, 2023
1b4b088
Add initial consistency check to hash migraton resiliency test
MavenRain Mar 30, 2023
ca5814b
Edit toml files to remove redundant license fields
MavenRain Mar 30, 2023
8a22532
Cargo Bazel lock changes
MavenRain Mar 30, 2023
da1bf32
Fix imports in ledger main
MavenRain Mar 30, 2023
dffa8b4
Overcome clippy errors
MavenRain Mar 30, 2023
d3ca797
Completed hash migration resiliency test
MavenRain Mar 30, 2023
81a556c
Try hardcoded temp file for v2 storage
MavenRain Apr 3, 2023
42e5bc6
Merge https://github.com/liftedinit/many-rs into merk-migration
MavenRain Apr 3, 2023
252fef6
look for migrations config file in the right place
MavenRain Apr 3, 2023
6997d20
cargo fmt
MavenRain Apr 3, 2023
58ce7b0
Debugging commit for deserialization error in hash migration
MavenRain Apr 4, 2023
014067d
Rectified merge with main
MavenRain Apr 4, 2023
17a4709
Now debugging unexpected transport error
MavenRain Apr 4, 2023
2554e03
Attempt to print send envelope message before response is returned
MavenRain Apr 4, 2023
5fbcb2d
Print respone before failed attempt to deserialize
MavenRain Apr 4, 2023
3bed6b3
Log requests before cose packaging
MavenRain Apr 4, 2023
e745b8f
Instrument ledger.info call
MavenRain Apr 4, 2023
912620d
Capture response from client call to ledger.info
MavenRain Apr 4, 2023
0a18e90
Fix clippy error
MavenRain Apr 4, 2023
eb17ffd
Remove some debugging logs to restore webauthn bats tests
MavenRain Apr 4, 2023
da72e3f
Merge https://github.com/liftedinit/many-rs into merk-migration
MavenRain Apr 4, 2023
c02b7fc
Remove send_message logging
MavenRain Apr 4, 2023
d0f0510
Debugging symbols function
MavenRain Apr 4, 2023
dae0b50
RUST_BACKTRACE=1 to get backtrace
MavenRain Apr 4, 2023
bcbc627
Try to get backtrace to work
MavenRain Apr 4, 2023
ff4fbed
Get error for status from the response in the client call
MavenRain Apr 4, 2023
b7a4c0c
Attempt to log incoming request on server side
MavenRain Apr 5, 2023
90eebbc
Examine reqwest call in send_envelope
MavenRain Apr 5, 2023
fc8b0e9
cargo fmt
MavenRain Apr 5, 2023
da64fba
Log response again
MavenRain Apr 5, 2023
f575b00
Change transport error to unknown error
MavenRain Apr 5, 2023
2c0c000
Further scrutinize response
MavenRain Apr 5, 2023
cea55b6
Print response result
MavenRain Apr 5, 2023
a5572bf
Use modified reqwest repo for further debugging
MavenRain Apr 5, 2023
1033b96
Error for status
MavenRain Apr 5, 2023
b01dd7c
Error surfaced earlier
MavenRain Apr 5, 2023
d6291a5
Restore error conversion after error-for-status
MavenRain Apr 5, 2023
86712ac
Some error-handling in many main
MavenRain Apr 5, 2023
b1f5f84
Debug SYMBOLS_ROOT through migration
MavenRain Apr 5, 2023
a1de093
Now try to decode symbols into map during migration
MavenRain Apr 5, 2023
1acb6ae
Format change of symbol root log
MavenRain Apr 5, 2023
30346d2
Possible moment-of-truth: replacing to_vec with minicbor::to_vec
MavenRain Apr 5, 2023
042e192
Debug update_at_height
MavenRain Apr 5, 2023
162676e
Simply into replacing cbor (double?) encoding
MavenRain Apr 5, 2023
6183734
Try just migrating objects with known iterators
MavenRain Apr 5, 2023
78cf28c
Fix needless borrow
MavenRain Apr 5, 2023
28f30c9
multisig bug in migration fix
MavenRain Apr 5, 2023
03dd4d1
Specifically add symbols table
MavenRain Apr 5, 2023
def4139
Possible solution to iterate-all problem
MavenRain Apr 5, 2023
6500bf4
Cleanup of unwraps post debugging
MavenRain Apr 6, 2023
174c927
reqwest response handling cleanup
MavenRain Apr 6, 2023
60385a4
Refactor update_at_height call post hardcoding path for new storage
MavenRain Apr 6, 2023
bd74390
Refactor replacement from function pointer to more general closure
MavenRain Apr 6, 2023
6eefbd1
Fix clippy errors and remove unwraps post debugging
MavenRain Apr 6, 2023
e2c4f17
Refactoring of LedgerStorage::commit
MavenRain Apr 6, 2023
bc7493b
Overcome clippy error
MavenRain Apr 6, 2023
63b2ce4
Remove println statements post-debugging
MavenRain Apr 6, 2023
cf3d3c2
More migration related cleanup
MavenRain Apr 6, 2023
490f6f7
Introduce forests
MavenRain Apr 6, 2023
183715b
Return error message in payload with 500 from server
MavenRain Apr 6, 2023
caca26c
Fix clippy error
MavenRain Apr 6, 2023
5632885
Merge https://github.com/liftedinit/many-rs into merk-migration
MavenRain Apr 6, 2023
76ff5af
Deleting more debugging code and import formats
MavenRain Apr 6, 2023
702cf18
Remove dead code allowance
MavenRain Apr 10, 2023
f513be6
Restore dead code allowance temporarily
MavenRain Apr 10, 2023
74fb305
Now try to write to same v2 path as v1 path
MavenRain Apr 10, 2023
baa1f16
Merge branch 'detached-state' into merk-migration
MavenRain Apr 10, 2023
bc17301
Fix migration e2e tests
MavenRain Apr 10, 2023
eba86ea
Trying to destroy old v1 merk copy properly
MavenRain Apr 10, 2023
0b58318
Debugging new migration flow
MavenRain Apr 11, 2023
894bee5
Add another unwrapping
MavenRain Apr 11, 2023
ce75813
Straight unwrappings trip a clippy error
MavenRain Apr 11, 2023
c24902a
Debugging update_at_height
MavenRain Apr 11, 2023
a0eb7ba
Debugging initialize function
MavenRain Apr 11, 2023
35aec13
Propagate Debug requirements for error types
MavenRain Apr 11, 2023
3da8121
Further initialize debugging
MavenRain Apr 11, 2023
2639e9f
Inline initialize method for further debugging
MavenRain Apr 11, 2023
3fc1954
Move initialize inlining
MavenRain Apr 11, 2023
d66869b
Debug into hash migration initialization
MavenRain Apr 11, 2023
b70771e
Change to random file name inside created merk temporary operation
MavenRain Apr 11, 2023
95bce1e
Temp directory fixed and debugging removed
MavenRain Apr 11, 2023
cfdb514
Small migration error-handling edit and removing dead code annotation…
MavenRain Apr 11, 2023
f4fa962
Midstep to removing replacement argument of migration initializer
MavenRain Apr 12, 2023
986290c
Remove replacement field from hash migration function type
MavenRain Apr 12, 2023
24f91db
Abstract from PathBuf to Path in function signatures
MavenRain Apr 12, 2023
a83ff7d
Fix unnecessary to_owned
MavenRain Apr 12, 2023
0ca8182
Batch processing refactor
MavenRain Apr 17, 2023
e9d67c7
Fix clippy errors
MavenRain Apr 17, 2023
e62de6c
Test consuming db file path from extra config
MavenRain Apr 19, 2023
b3c8986
Add db file to migrations config
MavenRain Apr 19, 2023
fa7ad3a
Convert entry to PathBuf
MavenRain Apr 19, 2023
db0f739
Print and pass error in AbciCommitInfo
MavenRain Apr 21, 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
531 changes: 334 additions & 197 deletions Cargo.Bazel.lock

Large diffs are not rendered by default.

715 changes: 437 additions & 278 deletions Cargo.lock

Large diffs are not rendered by default.

2,591 changes: 1,700 additions & 891 deletions cargo-bazel-lock.json

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion src/idstore-export/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
name = "idstore-export"
version = "0.1.1" # managed by release.sh
edition = "2021"
readme = "README.md"
keywords = ["cli", "web3", "blockchain", "tendermint", "proto", "crypto", "liftedinit"]
categories = ["command-line-utilities"]
description = "Export IdStore credentials from storage."
license-file = "../../LICENSE"
homepage = "https://liftedinit.org/"
Expand All @@ -15,7 +18,9 @@ doc = false
[dependencies]
base64 = "0.21.0"
clap = { version = "3.2.23", features = ["derive"] }
merk = { git = "https://github.com/liftedinit/merk.git", rev = "857bf81963d9282ab03438da5013e1f816bd9da1" }
derive_more = "0.99"
merk_v1 = { package = "merk", git = "https://github.com/liftedinit/merk.git", rev = "857bf81963d9282ab03438da5013e1f816bd9da1" }
merk_v2 = { package = "merk", git = "https://github.com/MavenRain/merk.git", branch = "merk-hash-migration" }
serde = "1.0.137"
serde_derive = "1.0.137"
serde_json = "1.0.81"
50 changes: 28 additions & 22 deletions src/idstore-export/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
extern crate core;

use base64::{engine::general_purpose, Engine as _};
use clap::Parser;
use merk::rocksdb;
use merk::rocksdb::{IteratorMode, ReadOptions};
use merk::tree::Tree;
use std::collections::BTreeMap;
use std::path::PathBuf;
use {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure how you got this refactor... We don't use a use { /* all imports */ } pattern anywhere else, so if you could revert this that would be great.

base64::{engine::general_purpose, Engine as _},
clap::Parser,
derive_more::{From, TryInto},
merk_v2::rocksdb::{self, IteratorMode, ReadOptions},
merk_v2::tree::Tree,
std::collections::BTreeMap,
std::path::PathBuf,
};

pub(crate) const IDSTORE_ROOT: &[u8] = b"/idstore/";
pub(crate) const IDSTORE_SEED_ROOT: &[u8] = b"/config/idstore_seed";

type InnerStorage = merk_v2::Merk;

#[derive(Parser)]
struct Opts {
/// The RocksDB store to load.
Expand All @@ -23,18 +27,25 @@ struct JsonRoot {
id_store_keys: BTreeMap<String, String>,
}

fn main() {
#[derive(Debug, From, TryInto)]
enum Error {
Merk(merk_v2::Error),
Rocks(merk_v2::rocksdb::Error),
Serde(serde_json::Error),
}

fn main() -> Result<(), Error> {
let Opts { store } = Opts::parse();

let merk = merk::Merk::open(store).expect("Could not open the store.");
let merk = InnerStorage::open(store)?;

let mut opts = ReadOptions::default();
opts.set_iterate_range(rocksdb::PrefixRange(IDSTORE_ROOT));
let it = merk.iter_opt(IteratorMode::Start, opts);

let mut idstore = BTreeMap::new();
for item in it {
let (key, value) = item.expect("Error while reading the DB");
let (key, value) = item?;
let new_v = Tree::decode(key.to_vec(), value.as_ref());
let value = new_v.value().to_vec();

Expand All @@ -45,19 +56,14 @@ fn main() {
}

let root = JsonRoot {
id_store_seed: merk
.get(IDSTORE_SEED_ROOT)
.expect("Could not read seed")
.map_or(0u64, |x| {
let mut bytes = [0u8; 8];
bytes.copy_from_slice(x.as_slice());
u64::from_be_bytes(bytes)
}),
id_store_seed: merk.get(IDSTORE_SEED_ROOT)?.map_or(0u64, |x| {
let mut bytes = [0u8; 8];
bytes.copy_from_slice(x.as_slice());
u64::from_be_bytes(bytes)
}),
id_store_keys: idstore,
};

println!(
"{}",
serde_json::to_string_pretty(&root).expect("Could not serialize")
);
println!("{}", serde_json::to_string_pretty(&root)?);
Ok(())
}
7 changes: 6 additions & 1 deletion src/ledger-db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
name = "ledger-db"
version = "0.1.1" # managed by release.sh
edition = "2021"
readme = "README.md"
keywords = ["cli", "web3", "blockchain", "tendermint", "proto", "crypto", "liftedinit"]
categories = ["command-line-utilities"]
description = "Ledger storage debugging CLI."
license-file = "../../LICENSE"
homepage = "https://liftedinit.org/"
Expand All @@ -14,8 +17,10 @@ doc = false

[dependencies]
clap = { version = "3.2.23", features = ["derive"] }
derive_more = "0.99"
hex = "0.4.3"
merk = { git = "https://github.com/liftedinit/merk.git", rev = "857bf81963d9282ab03438da5013e1f816bd9da1" }
merk_v1 = { package = "merk", git = "https://github.com/liftedinit/merk.git", rev = "857bf81963d9282ab03438da5013e1f816bd9da1" }
merk_v2 = { package = "merk", git = "https://github.com/MavenRain/merk.git", branch = "merk-hash-migration" }
many-modules = { path = "../many-modules", version = "0.1.1" } # managed by release.sh
many-types = { path = "../many-types", version = "0.1.1" } # managed by release.sh
minicbor = "0.19.1"
37 changes: 27 additions & 10 deletions src/ledger-db/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,37 @@
use clap::Parser;
use many_types::ledger::TokenAmount;
use merk::rocksdb::{IteratorMode, ReadOptions};
use merk::tree::Tree;
use std::path::PathBuf;
use {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above, I'd like to keep it to one use per import module.

clap::Parser,
derive_more::{From, TryInto},
many_types::ledger::TokenAmount,
merk_v1::rocksdb::{IteratorMode, ReadOptions},
merk_v1::tree::Tree,
std::path::PathBuf,
};

#[derive(Parser)]
struct Opts {
/// The RocksDB store to load.
store: PathBuf,
}

fn main() {
type InnerStorage = merk_v2::Merk;

#[derive(Debug, From, TryInto)]
enum Error {
Decode(minicbor::decode::Error),
EndOfIterator,
Merk(merk_v2::Error),
Rocks(merk_v2::rocksdb::Error),
}

fn main() -> Result<(), Error> {
let Opts { store } = Opts::parse();

let merk = merk::Merk::open(store).expect("Could not open the store.");
let merk = InnerStorage::open(store)?;

let it = merk.iter_opt(IteratorMode::Start, ReadOptions::default());

for kv_result in it {
let (k, v) = kv_result.unwrap();
let (k, v) = kv_result?;
let new_v = Tree::decode(k.to_vec(), v.as_ref());

let k: Vec<u8> = k.into();
Expand All @@ -27,14 +40,17 @@ fn main() {
// Try to "smartly" decode the key.
if k.starts_with(b"/events/") {
let k = hex::encode(&k[8..]);
let log = minicbor::decode::<many_modules::events::EventLog>(v).unwrap();
let log = minicbor::decode::<many_modules::events::EventLog>(v)?;
println!("event {k} => {log:?}",)
} else if k.starts_with(b"/balances/") {
let k = &k[10..];
// This should be utf8.
let k = String::from_utf8_lossy(k);
let mut it = k.split('/');
let (id, symbol) = (it.next().unwrap(), it.next().unwrap());
let (id, symbol) = it
.next()
.and_then(|id| it.next().map(|symbol| (id, symbol)))
.ok_or(Error::EndOfIterator)?;
let t = TokenAmount::from(v.to_vec());
println!("balance {id} => {t} {symbol}");
} else if k.starts_with(b"/multisig/") {
Expand All @@ -47,4 +63,5 @@ fn main() {
println!("unknown 0x {} => {}", hex::encode(k), hex::encode(v));
}
}
Ok(())
}
2 changes: 1 addition & 1 deletion src/many-abci/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ fn main() -> Result<(), Box<dyn Error>> {
// Emit the instructions
EmitBuilder::builder().git_sha(false).emit()?;
Ok(())
}
}
34 changes: 19 additions & 15 deletions src/many-abci/src/abci_app.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
use crate::migration::error_code::LEGACY_ERROR_CODE_TRIGGER;
use crate::migration::{AbciAppMigrations, MIGRATIONS};
use coset::{CborSerializable, CoseSign1};
use many_client::client::blocking::{block_on, ManyClient};
use many_error::{ManyError, ManyErrorCode};
use many_identity::{Address, AnonymousIdentity};
use many_migration::MigrationConfig;
use many_modules::abci_backend::{AbciBlock, AbciCommitInfo, AbciInfo};
use many_protocol::ResponseMessage;
use reqwest::{IntoUrl, Url};
use std::sync::{Arc, RwLock};
use tendermint_abci::Application;
use tendermint_proto::abci::*;
use tracing::{debug, error};
use {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same.

crate::migration::{error_code::LEGACY_ERROR_CODE_TRIGGER, AbciAppMigrations, MIGRATIONS},
coset::{CborSerializable, CoseSign1},
many_client::client::blocking::{block_on, ManyClient},
many_error::{ManyError, ManyErrorCode},
many_identity::{Address, AnonymousIdentity},
many_migration::MigrationConfig,
many_modules::abci_backend::{AbciBlock, AbciCommitInfo, AbciInfo},
many_protocol::ResponseMessage,
reqwest::{IntoUrl, Url},
std::{
path::PathBuf,
sync::{Arc, RwLock},
},
tendermint_abci::Application,
tendermint_proto::abci::*,
tracing::{debug, error},
};

lazy_static::lazy_static!(
static ref EPOCH: many_types::Timestamp = many_types::Timestamp::new(0).unwrap();
Expand Down Expand Up @@ -161,7 +165,7 @@ impl Application for AbciApp {
if let Ok(mut m) = self.migrations.write() {
// Since it's impossible to truly handle error here, and
// we don't actually want to panic, just ignore any errors.
let _ = m.update_at_height(&mut (), height);
let _ = m.update_at_height(&mut (), height, [""].iter().collect::<PathBuf>());
} else {
error!("Migration: Could not acquire migration lock...");
}
Expand Down
13 changes: 8 additions & 5 deletions src/many-abci/src/migration.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
use linkme::distributed_slice;
use many_error::ManyError;
use many_migration::{InnerMigration, MigrationSet};
use {
Copy link
Contributor

Choose a reason for hiding this comment

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

Here too.

linkme::distributed_slice,
many_error::ManyError,
many_migration::{InnerMigration, MigrationSet},
std::path::PathBuf,
};

pub mod error_code;

pub type AbciAppMigrations = MigrationSet<'static, ()>;
pub type AbciAppMigrations = MigrationSet<'static, (), PathBuf>;

// This is the global migration registry
// Doesn't contain any metadata
#[distributed_slice]
pub static MIGRATIONS: [InnerMigration<(), ManyError>] = [..];
pub static MIGRATIONS: [InnerMigration<(), ManyError, PathBuf>] = [..];
19 changes: 10 additions & 9 deletions src/many-abci/src/migration/error_code.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use crate::migration::MIGRATIONS;
use linkme::distributed_slice;
use many_error::ManyError;
use many_migration::InnerMigration;
use {
crate::migration::MIGRATIONS, linkme::distributed_slice, many_error::ManyError,
many_migration::InnerMigration, std::path::PathBuf,
};

#[distributed_slice(MIGRATIONS)]
pub static LEGACY_ERROR_CODE_TRIGGER: InnerMigration<(), ManyError> = InnerMigration::new_trigger(
true,
"LegacyErrorCode",
"Trigger a legacy bug in attribute-specific error codes decoding in ABCI.",
);
pub static LEGACY_ERROR_CODE_TRIGGER: InnerMigration<(), ManyError, PathBuf> =
InnerMigration::new_trigger(
true,
"LegacyErrorCode",
"Trigger a legacy bug in attribute-specific error codes decoding in ABCI.",
);
75 changes: 40 additions & 35 deletions src/many-client-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,42 +36,47 @@ pub fn many_client(attr: TokenStream, input: TokenStream) -> TokenStream {

let input_trait = parse_macro_input!(input as ItemTrait);

let methods_vec = input_trait.items.iter().map(|func| {
let namespace = namespace.clone();
let func = func.to_token_stream();
let method: syn::TraitItemFn =
parse2(func)?;
let mut method = method.sig;
method.asyncness = parse_quote! { async };
let mut args_iter = method.inputs.iter();
let _self_arg = args_iter.next().ok_or_else(|| syn::Error::new(method.span(), "Should have a &self argument"))?;
let args_param = args_iter.next();
let args_var = if let Some(FnArg::Typed(args)) = args_param {
let args = &args.pat;
quote! { #args }
} else {
quote! { () }
};
let server_method = if let Some(namespace) = namespace {
format!("{}.{}", namespace.value(), method.ident)
} else {
format!("{}", method.ident)
};
let server_method: LitStr = parse_quote! { #server_method };
let q = quote! {
pub #method {
let response = self.0.call_(#server_method, #args_var).await?;
minicbor::decode(&response).map_err(many_server::ManyError::deserialization_error)
let methods_vec = input_trait
.items
.iter()
.map(|func| {
let namespace = namespace.clone();
let func = func.to_token_stream();
let method: syn::TraitItemFn = parse2(func)?;
let mut method = method.sig;
method.asyncness = parse_quote! { async };
let mut args_iter = method.inputs.iter();
let _self_arg = args_iter
.next()
.ok_or_else(|| syn::Error::new(method.span(), "Should have a &self argument"))?;
let args_param = args_iter.next();
let args_var = if let Some(FnArg::Typed(args)) = args_param {
let args = &args.pat;
quote! { #args }
} else {
quote! { () }
};
let server_method = if let Some(namespace) = namespace {
format!("{}.{}", namespace.value(), method.ident)
} else {
format!("{}", method.ident)
};
let server_method: LitStr = parse_quote! { #server_method };
let q = quote! {
pub #method {
let response = self.0.call_(#server_method, #args_var).await?;
minicbor::decode(&response).map_err(many_server::ManyError::deserialization_error)
}
};
Ok(q.into_token_stream())
})
.try_fold(vec![], |mut acc, curr: syn::Result<TokenStream2>| {
match curr {
Ok(c) => acc.push(c),
Err(e) => return Err(e),
}
};
Ok(q.into_token_stream())
}).try_fold(vec![], |mut acc, curr: syn::Result<TokenStream2>| {
match curr {
Ok(c) => acc.push(c),
Err(e) => return Err(e)
}
Ok(acc)
});
Ok(acc)
});
let methods_vec = match methods_vec {
Ok(v) => v,
Err(e) => return e.to_compile_error().into(),
Expand Down
1 change: 1 addition & 0 deletions src/many-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ecdsa = "0.16.0"
ed25519 = { version = "2.2.0", features = [ "std" ] }
ed25519-dalek = { version = "1.0.1", features = [ "std" ] }
fixed = "1.16.0"
futures-util = "0.3"
hex = "0.4.3"
many-client-macros = { path = "../many-client-macros", version = "0.1.1" } # managed by release.sh
many-identity = { path = "../many-identity", version = "0.1.1" } # managed by release.sh
Expand Down
Loading