Skip to content

Commit

Permalink
linera-client: apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
Twey committed Sep 2, 2024
1 parent 7061052 commit 73fdb70
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 23 deletions.
6 changes: 3 additions & 3 deletions linera-client/src/client_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,9 @@ where
service: PathBuf,
) -> Result<BytecodeId, Error> {
info!("Loading bytecode files");
let contract_bytecode: Bytecode = Bytecode::load_from_file(&contract).await.context(
format!("failed to load contract bytecode from {:?}", &contract),
)?;
let contract_bytecode: Bytecode = Bytecode::load_from_file(&contract)
.await
.with_context(|| format!("failed to load contract bytecode from {:?}", &contract))?;
let service_bytecode = Bytecode::load_from_file(&service).await.context(format!(
"failed to load service bytecode from {:?}",
&service
Expand Down
12 changes: 3 additions & 9 deletions linera-client/src/persistent/indexed_db.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
// Copyright (c) Zefchain Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use std::ops::Deref;

use indexed_db_futures::prelude::*;
use wasm_bindgen::JsValue;
use wasm_bindgen_futures::wasm_bindgen;
use web_sys::DomException;

use super::LocalPersist;

/// An implementation of [`Persist`] based on an IndexedDB record with a given key.
#[derive(derive_more::Deref)]
pub struct IndexedDb<T> {
key: String,
#[deref]
value: T,
database: IdbDatabase,
}

impl<T> Deref for IndexedDb<T> {
type Target = T;
fn deref(&self) -> &T {
&self.value
}
}

const DATABASE_NAME: &str = "linera-client";
const STORE_NAME: &str = "linera-wallet";

Expand Down
12 changes: 2 additions & 10 deletions linera-client/src/persistent/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,11 @@ pub struct Memory<T> {
dirty: Dirty,
}

impl<T> std::ops::DerefMut for Memory<T> {
fn deref_mut(&mut self) -> &mut T {
// We set `dirty` to aid debugging, though it does nothing for this
// implementation.
*self.dirty = true;
&mut self.value
}
}

impl<T> Memory<T> {
pub fn new(value: T) -> Self {
Self {
value,
dirty: Dirty::new(false),
dirty: Dirty::new(true),
}
}
}
Expand All @@ -36,6 +27,7 @@ impl<T: Send> Persist for Memory<T> {
type Error = Error;

fn as_mut(&mut self) -> &mut T {
*self.dirty = true;
&mut self.value
}

Expand Down
2 changes: 1 addition & 1 deletion linera-client/src/persistent/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub trait LocalPersist: Deref {
type Error: std::error::Error + Send + Sync + 'static;

/// Gets a mutable reference to the value. This is not expressed as a
/// [`DerefMut`](std::ops::DerefMut) bound because it is discouraged to consume this
/// [`DerefMut`](std::ops::DerefMut) bound because it is discouraged to use this
/// function! Instead, use `mutate`.
fn as_mut(&mut self) -> &mut Self::Target;

Expand Down

0 comments on commit 73fdb70

Please sign in to comment.