Skip to content

Commit

Permalink
Update linera-protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
Twey committed Nov 5, 2024
1 parent 443af1d commit 104fed3
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 248 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,3 @@
path = linera-protocol
url = https://github.com/linera-io/linera-protocol

[submodule "wasm-thread"]
path = wasm_thread
url = https://github.com/linera-io/wasm-thread
11 changes: 10 additions & 1 deletion client-worker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,13 @@ wasm-bindgen-test = "0.3.43"
schemars = "*"

[patch.crates-io.wasm_thread]
path = "../wasm_thread"
git = "https://github.com/Twey/wasm_thread"
branch = "post-message"

[patch.crates-io.linera-wasmer]
git = "https://github.com/linera-io/wasmer"
branch = "module-from-jsvalue"

[patch.crates-io.linera-wasmer-compiler-singlepass]
git = "https://github.com/linera-io/wasmer"
branch = "module-from-jsvalue"
222 changes: 0 additions & 222 deletions client-worker/src/chain_listener.rs

This file was deleted.

30 changes: 12 additions & 18 deletions client-worker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,12 @@ use wasm_bindgen::prelude::*;
use web_sys::*;

use linera_base::identifiers::{ApplicationId, ChainId};
use linera_client::{chain_clients::ChainClients, chain_listener::{ChainListenerConfig, ClientContext as _}, client_options::ClientOptions, wallet::Wallet};
use linera_client::{chain_listener::{ChainListener, ChainListenerConfig, ClientContext as _}, client_options::ClientOptions, wallet::Wallet};

use std::{collections::HashMap, sync::Arc};
use futures::lock::Mutex as AsyncMutex;

mod chain_listener;
use chain_listener::ChainListener;

use linera_views::common::WithError;
use linera_views::store::WithError;

// TODO convert to IndexedDbStore once we refactor Context
type WebStorage = linera_storage::DbStorage<
Expand Down Expand Up @@ -64,8 +61,8 @@ pub const OPTIONS: ClientOptions = ClientOptions {
max_concurrent_queries: None,
max_stream_queries: 10,
cache_size: 1000,
notification_retry_delay: std::time::Duration::from_millis(1000),
notification_retries: 10,
retry_delay: std::time::Duration::from_millis(1000),
max_retries: 10,
wait_for_outgoing_messages: false,
blanket_message_policy: linera_core::client::BlanketMessagePolicy::Accept,
restrict_chain_ids_to: None,
Expand Down Expand Up @@ -102,7 +99,6 @@ impl JsWallet {
#[wasm_bindgen]
#[derive(Clone)]
pub struct Client {
chain_clients: ChainClients<linera_rpc::node_provider::NodeProvider, WebStorage>,
// This use of `futures::lock::Mutex` is safe because we only
// expose concurrency to the browser, which must always run all
// futures on the global task queue.
Expand All @@ -129,7 +125,7 @@ impl Client {
Fut: Future<Output = Result<ClientOutcome<T>, JsError>>,
{
loop {
let mut chain_client = self.chain_clients.try_client_lock(&chain_id).await?;
let mut chain_client = self.client_context.lock().await.make_chain_client(chain_id)?;
let mut stream = chain_client.subscribe().await?;
let result = f(&mut chain_client).await;
self.client_context.lock().await.update_wallet(&chain_client).await?;
Expand All @@ -147,14 +143,12 @@ impl Client {
let JsWallet(wallet) = wallet;
let mut storage = get_storage().await?;
wallet.genesis_config().initialize_storage(&mut storage).await?;
let chain_clients = ChainClients::default();
let client_context = Arc::new(AsyncMutex::new(ClientContext::new(storage.clone(), OPTIONS, wallet)));
ChainListener::new(ChainListenerConfig::default(), chain_clients.clone())
ChainListener::new(ChainListenerConfig::default())
.run(client_context.clone(), storage)
.await;
log::info!("Linera Web client successfully initialized");
Ok(Self {
chain_clients,
client_context,
})
}
Expand All @@ -178,7 +172,7 @@ impl Frontend {
pub async fn validator_version_info(&self) -> Result<JsValue, JsError> {
let mut client_context = self.0.client_context.lock().await;
let chain_id = client_context.wallet().default_chain().expect("No default chain");
let chain_client = self.0.chain_clients.try_client_lock(&chain_id).await?;
let chain_client = self.0.client_context.lock().await.make_chain_client(chain_id)?;
chain_client.synchronize_from_validators().await?;
let result = chain_client.local_committee().await;
client_context.update_and_save_wallet(&chain_client).await?;
Expand Down Expand Up @@ -206,24 +200,24 @@ impl Frontend {
}

#[wasm_bindgen]
pub async fn query_application(&self, application_id: JsValue, query: &[u8]) -> Result<Box<[u8]>, JsError> {
// TODO use bytes here not strings
pub async fn query_application(&self, application_id: JsValue, query: &str) -> Result<String, JsError> {
let chain_id = self.0.client_context.lock().await.wallet().default_chain().expect("there should be a default chain");
let application_id = serde_wasm_bindgen::from_value(application_id)?;
let chain_client = self.0.chain_clients.try_client_lock(&chain_id).await?;
let chain_client = self.0.client_context.lock().await.make_chain_client(chain_id)?;
let response = chain_client.query_application(linera_execution::Query::User {
application_id,
bytes: query.to_vec(),
bytes: query.as_bytes().to_vec(),
}).await?;
let linera_execution::Response::User(response) = response else {
panic!("system response to user query")
};
Ok(response.into_boxed_slice())
Ok(String::from_utf8(response)?)
}
}

#[wasm_bindgen(start)]
pub async fn main() {
std::panic::set_hook(Box::new(console_error_panic_hook::hook));
console_log::init_with_level(log::Level::Trace).unwrap();
linera_base::tracing::init();
}
1 change: 1 addition & 0 deletions extension/src/content-script/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ window.addEventListener('linera-wallet-request', async e => {
const event = e as RequestEvent;
let message = event.detail.message;
message.target = 'wallet';
console.debug('Sending message', message);
const response = await chrome.runtime.sendMessage(message);
respond(event.detail.id, response);
});
Expand Down
2 changes: 1 addition & 1 deletion linera-protocol
Submodule linera-protocol updated 235 files
5 changes: 3 additions & 2 deletions sample-app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
}

async function queryApplication() {
const response = await Linera.callClientFunction('query_application', '95e7dee915d2e3d12cf12715cbbeabf316fc607d55efc9c27f0a2114011a972291aa75c29eca77148df5a49cdc4c8c9802027220c411930b8e566d10e88942d8e476187f6ddfeb9d588c7b45d3df334d5501d6499b3f9ad5595cae86cce16a65010000000000000000000000', 'query { value }')
console.log(response);
const COUNTER_APP_ID = '95ad45ed433db1e40c9e5f677e9e1369fa4c207aeae67098ae668a2fdf241328557f90979fe8f4ef93225c8b3a9e5c9afb1e31884cd092e4ee1bdb5be90dcd0ee476187f6ddfeb9d588c7b45d3df334d5501d6499b3f9ad5595cae86cce16a65010000000000000000000000';
const response = await Linera.callClientFunction('query_application', COUNTER_APP_ID, '{ "query": "query { value }" }');
console.log(JSON.parse(response));
}
</script>
</head>
Expand Down
1 change: 0 additions & 1 deletion wasm_thread
Submodule wasm_thread deleted from 474249

0 comments on commit 104fed3

Please sign in to comment.