Skip to content

Commit

Permalink
[fix]: Compiling now. Tests need fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
batconjurer authored and brentstone committed Oct 30, 2023
1 parent c045f5a commit 87c954d
Show file tree
Hide file tree
Showing 42 changed files with 831 additions and 1,078 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions apps/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ num-rational.workspace = true
num-traits.workspace = true
once_cell.workspace = true
orion.workspace = true
pretty_assertions.workspace = true
prost-types.workspace = true
prost.workspace = true
rand_core.workspace = true
Expand Down
27 changes: 15 additions & 12 deletions apps/src/lib/bench_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,25 +682,26 @@ impl Default for BenchShieldedCtx {
fn default() -> Self {
let mut shell = BenchShell::default();

let mut ctx = Context::new::<StdIo>(crate::cli::args::Global {
let ctx = Context::new::<StdIo>(crate::cli::args::Global {
chain_id: None,
base_dir: shell.tempdir.as_ref().canonicalize().unwrap(),
wasm_dir: Some(WASM_DIR.into()),
})
.unwrap();
let mut chain_ctx = ctx.take_chain_or_exit();

// Generate spending key for Albert and Bertha
ctx.wallet.gen_spending_key(
chain_ctx.wallet.gen_spending_key(
ALBERT_SPENDING_KEY.to_string(),
None,
true,
);
ctx.wallet.gen_spending_key(
chain_ctx.wallet.gen_spending_key(
BERTHA_SPENDING_KEY.to_string(),
None,
true,
);
crate::wallet::save(&ctx.wallet).unwrap();
crate::wallet::save(&chain_ctx.wallet).unwrap();

// Generate payment addresses for both Albert and Bertha
for (alias, viewing_alias) in [
Expand All @@ -710,19 +711,21 @@ impl Default for BenchShieldedCtx {
.map(|(p, s)| (p.to_owned(), s.to_owned()))
{
let viewing_key: FromContext<ExtendedViewingKey> = FromContext::new(
ctx.wallet
chain_ctx
.wallet
.find_viewing_key(viewing_alias)
.unwrap()
.to_string(),
);
let viewing_key =
ExtendedFullViewingKey::from(ctx.get_cached(&viewing_key))
.fvk
.vk;
let viewing_key = ExtendedFullViewingKey::from(
chain_ctx.get_cached(&viewing_key),
)
.fvk
.vk;
let (div, _g_d) =
namada_sdk::masp::find_valid_diversifier(&mut OsRng);
let payment_addr = viewing_key.to_payment_address(div).unwrap();
let _ = ctx
let _ = chain_ctx
.wallet
.insert_payment_addr(
alias,
Expand All @@ -732,7 +735,7 @@ impl Default for BenchShieldedCtx {
.unwrap();
}

crate::wallet::save(&ctx.wallet).unwrap();
crate::wallet::save(&chain_ctx.wallet).unwrap();
namada::ledger::storage::update_allowed_conversions(
&mut shell.wl_storage,
)
Expand All @@ -741,7 +744,7 @@ impl Default for BenchShieldedCtx {
Self {
shielded: ShieldedContext::default(),
shell,
wallet: ctx.wallet,
wallet: chain_ctx.wallet,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4964,7 +4964,7 @@ pub mod args {
let query = self.query.to_sdk(ctx);
let chain_ctx = ctx.borrow_chain_or_exit();
GenIbcShieldedTransafer::<SdkTypes> {
query: self.query.to_sdk(ctx),
query,
output_folder: self.output_folder,
target: chain_ctx.get(&self.target),
token: chain_ctx.get(&self.token),
Expand Down
16 changes: 13 additions & 3 deletions apps/src/lib/cli/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,19 @@ impl CliApi {
});
client.wait_until_node_is_synced(io).await?;
let args = args.to_sdk(&mut ctx);
let mut config =
ctx.borrow_chain_or_exit().config.clone();
let namada = ctx.to_sdk(&client, io);
let cli::context::ChainContext {
mut wallet,
mut config,
mut shielded,
native_token,
} = ctx.take_chain_or_exit();
let namada = NamadaImpl::native_new(
&client,
&mut wallet,
&mut shielded,
io,
native_token,
);
tx::submit_init_validator(&namada, &mut config, args)
.await?;
}
Expand Down
62 changes: 25 additions & 37 deletions apps/src/lib/cli/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,20 +241,7 @@ impl ChainContext {
///
/// Note that in "dev" build, this may be the root `wasm` dir.
pub fn wasm_dir(&self) -> PathBuf {
let wasm_dir =
self.config.ledger.chain_dir().join(&self.config.wasm_dir);

// In dev-mode with dev chain (the default), load wasm directly from the
// root wasm dir instead of the chain dir
#[cfg(feature = "dev")]
let wasm_dir =
if self.global_config.default_chain_id == ChainId::default() {
"wasm".into()
} else {
wasm_dir
};

wasm_dir
self.config.ledger.chain_dir().join(&self.config.wasm_dir)
}

/// Read the given WASM file from the WASM directory or an absolute path.
Expand Down Expand Up @@ -309,10 +296,6 @@ impl<T> FromContext<T> {
phantom: PhantomData,
}
}

pub fn into_raw(self) -> String {
self.raw
}
}

impl FromContext<TransferSource> {
Expand Down Expand Up @@ -360,8 +343,8 @@ impl<T> FromContext<T>
where
T: ArgFromContext,
{
/// Parse and/or look-up the value from the context.
fn arg_from_ctx(&self, ctx: &Context) -> Result<T, String> {
/// Parse and/or look-up the value from the chain context.
fn arg_from_ctx(&self, ctx: &ChainContext) -> Result<T, String> {
T::arg_from_ctx(ctx, &self.raw)
}
}
Expand All @@ -370,32 +353,32 @@ impl<T> FromContext<T>
where
T: ArgFromMutContext,
{
/// Parse and/or look-up the value from the mutable context.
fn arg_from_mut_ctx(&self, ctx: &mut Context) -> Result<T, String> {
/// Parse and/or look-up the value from the mutable chain context.
fn arg_from_mut_ctx(&self, ctx: &mut ChainContext) -> Result<T, String> {
T::arg_from_mut_ctx(ctx, &self.raw)
}
}

/// CLI argument that found via the [`Context`].
/// CLI argument that found via the [`ChainContext`].
pub trait ArgFromContext: Sized {
fn arg_from_ctx(
ctx: &Context,
ctx: &ChainContext,
raw: impl AsRef<str>,
) -> Result<Self, String>;
}

/// CLI argument that found via the [`Context`] and cached (as in case of an
/// encrypted keypair that has been decrypted), hence using mutable context.
/// CLI argument that found via the [`ChainContext`] and cached (as in case of
/// an encrypted keypair that has been decrypted), hence using mutable context.
pub trait ArgFromMutContext: Sized {
fn arg_from_mut_ctx(
ctx: &mut Context,
ctx: &mut ChainContext,
raw: impl AsRef<str>,
) -> Result<Self, String>;
}

impl ArgFromContext for Address {
fn arg_from_ctx(
ctx: &Context,
ctx: &ChainContext,
raw: impl AsRef<str>,
) -> Result<Self, String> {
struct Skip;
Expand Down Expand Up @@ -429,14 +412,19 @@ impl ArgFromContext for Address {
.ok_or(Skip)
})
// Or it can be an alias that may be found in the wallet
.or_else(|_| ctx.wallet.find_address(raw).cloned().ok_or(Skip))
.or_else(|_| {
ctx.wallet
.find_address(raw)
.map(|x| x.into_owned())
.ok_or(Skip)
})
.map_err(|_| format!("Unknown address {raw}"))
}
}

impl ArgFromMutContext for common::SecretKey {
fn arg_from_mut_ctx(
ctx: &mut Context,
ctx: &mut ChainContext,
raw: impl AsRef<str>,
) -> Result<Self, String> {
let raw = raw.as_ref();
Expand All @@ -452,7 +440,7 @@ impl ArgFromMutContext for common::SecretKey {

impl ArgFromMutContext for common::PublicKey {
fn arg_from_mut_ctx(
ctx: &mut Context,
ctx: &mut ChainContext,
raw: impl AsRef<str>,
) -> Result<Self, String> {
let raw = raw.as_ref();
Expand All @@ -477,7 +465,7 @@ impl ArgFromMutContext for common::PublicKey {

impl ArgFromMutContext for ExtendedSpendingKey {
fn arg_from_mut_ctx(
ctx: &mut Context,
ctx: &mut ChainContext,
raw: impl AsRef<str>,
) -> Result<Self, String> {
let raw = raw.as_ref();
Expand All @@ -493,7 +481,7 @@ impl ArgFromMutContext for ExtendedSpendingKey {

impl ArgFromMutContext for ExtendedViewingKey {
fn arg_from_mut_ctx(
ctx: &mut Context,
ctx: &mut ChainContext,
raw: impl AsRef<str>,
) -> Result<Self, String> {
let raw = raw.as_ref();
Expand All @@ -510,7 +498,7 @@ impl ArgFromMutContext for ExtendedViewingKey {

impl ArgFromContext for PaymentAddress {
fn arg_from_ctx(
ctx: &Context,
ctx: &ChainContext,
raw: impl AsRef<str>,
) -> Result<Self, String> {
let raw = raw.as_ref();
Expand All @@ -527,7 +515,7 @@ impl ArgFromContext for PaymentAddress {

impl ArgFromMutContext for TransferSource {
fn arg_from_mut_ctx(
ctx: &mut Context,
ctx: &mut ChainContext,
raw: impl AsRef<str>,
) -> Result<Self, String> {
let raw = raw.as_ref();
Expand All @@ -543,7 +531,7 @@ impl ArgFromMutContext for TransferSource {

impl ArgFromContext for TransferTarget {
fn arg_from_ctx(
ctx: &Context,
ctx: &ChainContext,
raw: impl AsRef<str>,
) -> Result<Self, String> {
let raw = raw.as_ref();
Expand All @@ -558,7 +546,7 @@ impl ArgFromContext for TransferTarget {

impl ArgFromMutContext for BalanceOwner {
fn arg_from_mut_ctx(
ctx: &mut Context,
ctx: &mut ChainContext,
raw: impl AsRef<str>,
) -> Result<Self, String> {
let raw = raw.as_ref();
Expand Down
Loading

0 comments on commit 87c954d

Please sign in to comment.