Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion examples/bridge-demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ <h3>Chain <code id="chain-id-display" class="hex">-</code></h3>
lineraOwner = signer.address();
lineraChain = await faucet.claimChain(wallet, lineraOwner);

const client = await new linera.Client(wallet, signer);
const client = await (await new linera.Client(wallet, signer)).start();
const chain = await client.chain(lineraChain, { owner: lineraOwner });
wrappedApp = await chain.application(APP_ID);
console.log('[bridge-demo] Linera initialized', { lineraChain, lineraOwner, APP_ID, BRIDGE_APP_ID });
Expand Down
2 changes: 1 addition & 1 deletion examples/counter/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ <h2>Chain history for <code id="chain-id" class="hex">requesting chain…</code>
const chainId = await faucet.claimChain(wallet, owner);
document.getElementById('owner').innerText = owner;
document.getElementById('chain-id').innerText = chainId;
const client = await new linera.Client(wallet, signer);
const client = await (await new linera.Client(wallet, signer)).start();
let chain = await client.chain(chainId);
const counter = await chain.application(import.meta.env.LINERA_APPLICATION_ID);
const logs = document.getElementById('logs');
Expand Down
13 changes: 9 additions & 4 deletions examples/counter/metamask/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,16 @@ <h2>Chain history for <code id="chain-id" class="hex">requesting chain…</code>
const autosigner = linera.signer.PrivateKey.createRandom();
wallet.setOwner(chainId, autosigner.address());

const client = await new linera.Client(wallet, new linera.signer.Composite(autosigner, signer));
const chain = await client.chain(chainId, { owner });
const deferredClient = await new linera.Client(wallet, new linera.signer.Composite(autosigner, signer));

// For autosigning: add the in-memory signer as an owner before starting the chain listener,
// so the user only needs to sign once.
const deferredChain = await deferredClient.chain(chainId, { owner });
await deferredChain.addOwner(autosigner.address());
deferredChain.free();

// For autosigning: we then add the in-memory signer as an owner of the chain to allow it to sign transactions.
await chain.addOwner(autosigner.address());
const client = await deferredClient.start();
const chain = await client.chain(chainId, { owner });

// Connect to the counter application on the chain.
const counter = await chain.application(import.meta.env.LINERA_APPLICATION_ID);
Expand Down
2 changes: 1 addition & 1 deletion examples/native-fungible/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ <h2>Chain history for <code id="chain-id" class="hex">requesting a new microchai
const wallet = await faucet.createWallet();
const owner = signer.address();
const chainId = await faucet.claimChain(wallet, owner);
const client = await new linera.Client(wallet, signer);
const client = await (await new linera.Client(wallet, signer)).start();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

While maintaining the Client/RunningClient distinction in the statics on the Rust side is nice, I'm not sure about exposing it to JavaScript where the original object is still accessible. If anything I think a more idiomatic pattern might be for start() to return an object representing the additional capabilities.

document.querySelector('#chain-id').innerText = chainId;
document.querySelector('#owner').innerText = owner;

Expand Down
13 changes: 9 additions & 4 deletions examples/native-fungible/metamask/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,16 @@ <h2>Chain history for <code id="chain-id" class="hex">requesting a new microchai
const autosigner = linera.signer.PrivateKey.createRandom();
wallet.setOwner(chainId, autosigner.address());

const client = await new linera.Client(wallet, new linera.signer.Composite(autosigner, signer));
const chain = await client.chain(chainId, { owner });
const deferredClient = await new linera.Client(wallet, new linera.signer.Composite(autosigner, signer));

// For autosigning: add the in-memory signer as an owner before starting the chain listener,
// so the user only needs to sign once.
const deferredChain = await deferredClient.chain(chainId, { owner });
await deferredChain.addOwner(autosigner.address());
deferredChain.free();

// For autosigning: we then add the in-memory signer as an owner of the chain to allow it to sign transactions.
await chain.addOwner(autosigner.address());
const client = await deferredClient.start();
const chain = await client.chain(chainId, { owner });

// Connect to the fungible application on the chain.
const application = await chain.application(import.meta.env.LINERA_APPLICATION_ID);
Expand Down
7 changes: 5 additions & 2 deletions linera-client/src/chain_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,10 @@ impl<C: ClientContext + 'static> ChainListener<C> {

/// Runs the chain listener.
#[instrument(skip(self))]
pub async fn run(mut self) -> Result<impl Future<Output = Result<(), Error>>, Error> {
pub async fn run(
mut self,
) -> Result<impl Future<Output = Result<<C::Environment as Environment>::Storage, Error>>, Error>
{
let chain_ids = {
let guard = self.context.lock().await;
let admin_chain_id = guard.admin_chain_id();
Expand Down Expand Up @@ -340,7 +343,7 @@ impl<C: ClientContext + 'static> ChainListener<C> {
}
}
future::join_all(self.listening.into_values().map(|client| client.stop())).await;
Ok(())
Ok(self.storage)
})
}

Expand Down
2 changes: 1 addition & 1 deletion linera-faucet/server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1292,7 +1292,7 @@ where
.with_graceful_shutdown(cancellation_token.cancelled_owned())
.into_future();
futures::select! {
result = Box::pin(chain_listener).fuse() => result?,
result = Box::pin(chain_listener).fuse() => { result?; },
_ = Box::pin(batch_processor_task).fuse() => {},
result = Box::pin(server).fuse() => result?,
};
Expand Down
2 changes: 1 addition & 1 deletion linera-service/src/node_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,7 @@ where
.with_graceful_shutdown(cancellation_token.cancelled_owned())
.into_future();
futures::select! {
result = chain_listener => result?,
result = chain_listener => { result?; },
result = Box::pin(server).fuse() => result?,
};

Expand Down
5 changes: 2 additions & 3 deletions web/@linera/client/src/chain/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use linera_core::client::ChainClient;
use wasm_bindgen::prelude::*;
use web_sys::wasm_bindgen;

use crate::{Client, Environment, JsResult};
use crate::{client::ClientContext, Environment, JsResult};

#[wasm_bindgen]
pub struct Application {
pub(crate) client: Client,
pub(crate) client_context: ClientContext,
pub(crate) chain_client: ChainClient<Environment>,
pub(crate) id: ApplicationId,
}
Expand Down Expand Up @@ -70,7 +70,6 @@ impl Application {

if !operations.is_empty() {
let _hash = self
.client
.client_context
.lock()
.await
Expand Down
12 changes: 5 additions & 7 deletions web/@linera/client/src/chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ use serde::ser::Serialize as _;
use wasm_bindgen::prelude::*;
use web_sys::{js_sys, wasm_bindgen};

use crate::{Client, Environment, JsResult};
use crate::{client::ClientContext, Environment, JsResult};

pub mod application;
pub use application::Application;

#[wasm_bindgen]
pub struct Chain {
pub(crate) client: Client,
pub(crate) client_context: ClientContext,
pub(crate) chain_client: ChainClient<Environment>,
}

Expand Down Expand Up @@ -80,7 +80,6 @@ impl Chain {
#[wasm_bindgen]
pub async fn transfer(&self, params: TransferParams) -> JsResult<()> {
let _hash = self
.client
.client_context
.lock()
.await
Expand Down Expand Up @@ -124,8 +123,7 @@ impl Chain {
options: Option<AddOwnerOptions>,
) -> JsResult<()> {
let AddOwnerOptions { weight } = options.unwrap_or_default();
self.client
.client_context
self.client_context
.lock()
.await
.apply_client_command(&self.chain_client, |_chain_client| {
Expand All @@ -143,7 +141,7 @@ impl Chain {
pub async fn validator_version_info(&self) -> JsResult<JsValue> {
self.chain_client.synchronize_from_validators().await?;
let result = self.chain_client.local_committee().await;
let mut client = self.client.client_context.lock().await;
let mut client = self.client_context.lock().await;
client.update_wallet(&self.chain_client).await?;
let committee = result?;
let node_provider = client.make_node_provider();
Expand Down Expand Up @@ -187,7 +185,7 @@ impl Chain {
pub async fn application(&self, id: &str) -> JsResult<Application> {
web_sys::console::debug_1(&format!("connecting to Linera application {id}").into());
Ok(Application {
client: self.client.clone(),
client_context: self.client_context.clone(),
chain_client: self.chain_client.clone(),
id: id.parse()?,
})
Expand Down
Loading
Loading