Skip to content

Commit 8085048

Browse files
authored
Port to Testnet Babbage (#44)
* Bump `linera-protocol` to `testnet_babbage` * `client`: port to `testnet_babbage` * `examples/hosted-fungible`: port to `testnet_babbage` * `examples/hosted-counter`: port to `testnet_babbage` * `client`: bump to version `0.14` to match `linera-protocol`
1 parent 6c28986 commit 8085048

File tree

8 files changed

+180
-202
lines changed

8 files changed

+180
-202
lines changed

client/Cargo.lock

Lines changed: 85 additions & 119 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@linera/client",
3-
"version": "0.0.3",
3+
"version": "0.14.0",
44
"description": "Web client for the Linera blockchain",
55
"main": "dist/linera_web.js",
66
"types": "dist/linera_web.d.ts",

client/src/lib.rs

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ This module defines the client API for the Web extension.
99
use std::{collections::HashMap, future::Future, sync::Arc};
1010

1111
use futures::{lock::Mutex as AsyncMutex, stream::StreamExt};
12-
use linera_base::identifiers::ApplicationId;
12+
use linera_base::identifiers::{AccountOwner, ApplicationId};
1313
use linera_client::{
1414
chain_listener::{ChainListener, ChainListenerConfig, ClientContext as _},
15-
client_options::ClientOptions,
15+
client_options::ClientContextOptions,
1616
wallet::Wallet,
1717
};
1818
use linera_core::{
@@ -33,8 +33,8 @@ type JsResult<T> = Result<T, JsError>;
3333

3434
async fn get_storage() -> Result<WebStorage, <linera_views::memory::MemoryStore as WithError>::Error>
3535
{
36-
linera_storage::DbStorage::initialize(
37-
linera_views::memory::MemoryStoreConfig::new(1),
36+
linera_storage::DbStorage::maybe_create_and_connect(
37+
&linera_views::memory::MemoryStoreConfig::new(1),
3838
"linera",
3939
Some(linera_execution::WasmRuntime::Wasmer),
4040
)
@@ -47,15 +47,11 @@ type ChainClient =
4747
linera_core::client::ChainClient<linera_rpc::node_provider::NodeProvider, WebStorage>;
4848

4949
// TODO(#13): get from user
50-
pub const OPTIONS: ClientOptions = ClientOptions {
50+
pub const OPTIONS: ClientContextOptions = ClientContextOptions {
5151
send_timeout: std::time::Duration::from_millis(4000),
5252
recv_timeout: std::time::Duration::from_millis(4000),
5353
max_pending_message_bundles: 10,
54-
wasm_runtime: Some(linera_execution::WasmRuntime::Wasmer),
55-
max_concurrent_queries: None,
5654
max_loaded_chains: nonzero_lit::usize!(40),
57-
max_stream_queries: 10,
58-
cache_size: 1000,
5955
retry_delay: std::time::Duration::from_millis(1000),
6056
max_retries: 10,
6157
wait_for_outgoing_messages: false,
@@ -68,10 +64,7 @@ pub const OPTIONS: ClientOptions = ClientOptions {
6864
// TODO(linera-protocol#2944): separate these out from the
6965
// `ClientOptions` struct, since they apply only to the CLI/native
7066
// client
71-
tokio_threads: Some(1),
72-
command: linera_client::client_options::ClientCommand::Keygen,
7367
wallet_state_path: None,
74-
storage_config: None,
7568
with_wallet: None,
7669
};
7770

@@ -107,12 +100,15 @@ impl JsFaucet {
107100
/// - if we fail to get the list of current validators from the faucet
108101
/// - if we fail to claim the chain from the faucet
109102
/// - if we fail to persist the new chain or keypair to the wallet
103+
///
104+
/// # Panics
105+
/// If an error occurs in the chain listener task.
110106
#[wasm_bindgen(js_name = claimChain)]
111107
pub async fn claim_chain(&self, client: &mut Client) -> JsResult<String> {
112108
use linera_client::persistent::LocalPersistExt as _;
113109
let mut context = client.client_context.lock().await;
114110
let key_pair = context.wallet.generate_key_pair();
115-
let owner: linera_base::identifiers::Owner = key_pair.public().into();
111+
let owner: AccountOwner = key_pair.public().into();
116112
tracing::info!(
117113
"Requesting a new chain for owner {} using the faucet at address {}",
118114
owner,
@@ -203,7 +199,7 @@ pub struct Frontend(Client);
203199

204200
#[derive(serde::Deserialize)]
205201
struct TransferParams {
206-
donor: Option<linera_base::identifiers::Owner>,
202+
donor: Option<AccountOwner>,
207203
amount: u64,
208204
recipient: linera_base::identifiers::Account,
209205
}
@@ -228,14 +224,18 @@ impl Client {
228224
OPTIONS,
229225
wallet,
230226
)));
231-
ChainListener::new(ChainListenerConfig::default())
232-
.run(client_context.clone(), storage)
233-
.await;
227+
ChainListener::new(
228+
ChainListenerConfig::default(),
229+
client_context.clone(),
230+
storage,
231+
)
232+
.run()
233+
.await;
234234
log::info!("Linera Web client successfully initialized");
235235
Ok(Self { client_context })
236236
}
237237

238-
/// Set a callback to be called when a notification is received
238+
/// Sets a callback to be called when a notification is received
239239
/// from the network.
240240
///
241241
/// # Panics
@@ -301,6 +301,15 @@ impl Client {
301301
result
302302
}
303303

304+
/// Transfers funds from one account to another.
305+
///
306+
/// `options` should be an options object of the form `{ donor,
307+
/// recipient, amount }`; omitting `donor` will cause the funds to
308+
/// come from the chain balance.
309+
///
310+
/// # Errors
311+
/// - if the options object is of the wrong form
312+
/// - if the transfer fails
304313
#[wasm_bindgen]
305314
pub async fn transfer(&self, options: wasm_bindgen::JsValue) -> JsResult<()> {
306315
let params: TransferParams = serde_wasm_bindgen::from_value(options)?;
@@ -309,7 +318,7 @@ impl Client {
309318
let _hash = self
310319
.apply_client_command(&chain_client, || {
311320
chain_client.transfer(
312-
params.donor,
321+
params.donor.unwrap_or(AccountOwner::CHAIN),
313322
linera_base::data_types::Amount::from_tokens(params.amount.into()),
314323
linera_execution::system::Recipient::Account(params.recipient),
315324
)
@@ -319,6 +328,10 @@ impl Client {
319328
Ok(())
320329
}
321330

331+
/// Gets the identity of the default chain.
332+
///
333+
/// # Errors
334+
/// If the chain couldn't be established.
322335
pub async fn identity(&self) -> JsResult<JsValue> {
323336
Ok(serde_wasm_bindgen::to_value(
324337
&self.default_chain_client().await?.identity().await?,

examples/hosted-counter/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ <h2>Chain history for <code id="chain-id" class="hex">requesting chain…</code>
5858
<script type="module">
5959
import * as linera from '@linera/client';
6060

61-
const COUNTER_APP_ID = 'a2b93d1da68bc052f5b8650b5484103244ab9662c3a2e7112c71acc825f8f76e1073f4e0775a9212fff735f4fa30c228334a44d098e81a828839ef22f927f461ee44e4b2c6372d9d235c7beecaa08697cbb9d62685c409d70f3374b00d4abd7c00';
61+
const COUNTER_APP_ID = '2b1a0df8868206a4b7d6c2fdda911e4355d6c0115b896d4947ef8e535ee3c6b8';
6262

6363
async function run() {
6464
await linera.default();
65-
const faucet = await new linera.Faucet('https://faucet.mini-net.linera.net');
65+
const faucet = await new linera.Faucet('https://faucet.testnet-babbage.linera.net');
6666
const wallet = await faucet.createWallet();
6767
const client = await new linera.Client(wallet);
6868
document.getElementById('chain-id').innerText = await faucet.claimChain(client);

examples/hosted-fungible/index.html

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ <h2>Chain history for <code id="chain-id" class="hex">requesting a new microchai
141141
<script type="module">
142142
import * as linera from '@linera/client';
143143

144-
const NATIVE_FUNGIBLE_APP_ID = '58299de6f0c2e9bddcee29aff497c7d47c728ec3b3ded01a4d45948a10a56221e7b40ec580a96e033c2f03c3464872d5a001e16506320a13b1264f153d64e3c9c398d551aeef7a38d0f5e26f315e63bb2357b7ed14901a3a580826a4199488ea00';
144+
const FUNGIBLE_APP_ID = '465e465b050db5034fd8a51df46b9a7cf02a8a6414cc2b94b102e912208d4a4b';
145145

146146
const gql = (query, variables = {}) => JSON.stringify({ query, variables });
147147

@@ -157,8 +157,11 @@ <h2>Chain history for <code id="chain-id" class="hex">requesting a new microchai
157157

158158
async function updateBalance(application) {
159159
const response = JSON.parse(await application.query(gql(`query { tickerSymbol, accounts { entries { key value } } }`)));
160+
console.debug('application response:', response);
160161
document.querySelector('#ticker-symbol').textContent = response.data.tickerSymbol;
161-
document.querySelector('#balance').textContent = (+response.data.accounts.entries[0].value).toFixed(2);
162+
163+
if (response?.data?.accounts?.entries?.[0])
164+
document.querySelector('#balance').textContent = (+response.data.accounts.entries[0].value).toFixed(2);
162165
}
163166

164167
async function transfer(application, donor, amount, recipient) {
@@ -169,7 +172,7 @@ <h2>Chain history for <code id="chain-id" class="hex">requesting a new microchai
169172

170173
let errors = [];
171174
try {
172-
const match = recipient.match(/^([0-9a-f]{64})@([0-9a-f]{64})$/);
175+
const match = recipient.match(/^(0x[0-9a-f]{64})@([0-9a-f]{64})$/);
173176
if (!match) throw new Error('Invalid recipient address: expected `owner@chain_id`');
174177

175178
const query = gql(`mutation(
@@ -181,7 +184,7 @@ <h2>Chain history for <code id="chain-id" class="hex">requesting a new microchai
181184
}`, {
182185
donor,
183186
amount,
184-
recipient: { owner: `User:${match[1]}`, chainId: match[2] },
187+
recipient: { owner: match[1], chainId: match[2] },
185188
});
186189

187190
errors = JSON.parse(await application.query(query)).errors || [];
@@ -203,7 +206,7 @@ <h2>Chain history for <code id="chain-id" class="hex">requesting a new microchai
203206
event.preventDefault();
204207
transfer(
205208
application,
206-
`User:${me}`,
209+
me,
207210
event.target.elements.amount.value,
208211
event.target.elements.recipient.value,
209212
);
@@ -215,13 +218,13 @@ <h2>Chain history for <code id="chain-id" class="hex">requesting a new microchai
215218
});
216219

217220
await linera.default();
218-
const faucet = await new linera.Faucet('https://faucet.mini-net.linera.net');
221+
const faucet = await new linera.Faucet('https://faucet.testnet-babbage.linera.net');
219222
const wallet = await faucet.createWallet();
220223
const client = await new linera.Client(wallet);
221224
const chainId = await faucet.claimChain(client);
222225
document.querySelector('#chain-id').innerText = chainId;
223226

224-
const application = await client.frontend().application(NATIVE_FUNGIBLE_APP_ID);
227+
const application = await client.frontend().application(FUNGIBLE_APP_ID);
225228

226229
client.onNotification(notification => {
227230
let newBlock = notification.reason.NewBlock;
@@ -238,7 +241,7 @@ <h2>Chain history for <code id="chain-id" class="hex">requesting a new microchai
238241
await client.transfer({
239242
recipient: {
240243
chain_id: chainId,
241-
owner: `User:${me}`,
244+
owner: me,
242245
},
243246
amount: 10,
244247
});

0 commit comments

Comments
 (0)