forked from linera-io/linera-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate frontend and client worker
- Loading branch information
Showing
46 changed files
with
1,167 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1 @@ | ||
/target | ||
/pkg | ||
Cargo.lock | ||
|
||
/.direnv |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/target | ||
/pkg | ||
Cargo.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
[package] | ||
name = "linera-web" | ||
description = "The Linera Web client" | ||
version = "0.1.0" | ||
authors = ["Linera <[email protected]>"] | ||
edition = "2021" | ||
repository = "https://github.com/linera-io/linera-web/" | ||
license = "Apache-2.0" | ||
|
||
[lib] | ||
crate-type = ["cdylib", "rlib"] | ||
|
||
[dependencies] | ||
wasm-bindgen = "0.2" | ||
js-sys = "0.3" | ||
wasm-bindgen-futures = "0.4" | ||
console_error_panic_hook = "0.1.6" | ||
anyhow = "1.0.82" | ||
console_log = "1.0.0" | ||
log = "0.4.21" | ||
serde = "1.0.198" | ||
rand = "0.8.5" | ||
chrono = "0.4.38" | ||
serde_json = "1.0.116" | ||
|
||
[dependencies.linera-base] | ||
path = "../linera-protocol/linera-base" | ||
features = ["web"] | ||
|
||
[dependencies.linera-chain] | ||
path = "../linera-protocol/linera-chain" | ||
features = ["web"] | ||
|
||
[dependencies.linera-core] | ||
path = "../linera-protocol/linera-core" | ||
features = ["web"] | ||
|
||
# TODO I'm not totally convinced this should be here — used just for | ||
# some network config that I'm not sure belongs in `linera-execution` | ||
[dependencies.linera-execution] | ||
path = "../linera-protocol/linera-execution" | ||
features = ["web"] | ||
|
||
[dependencies.linera-rpc] | ||
path = "../linera-protocol/linera-rpc" | ||
features = ["web"] | ||
|
||
[dependencies.linera-storage] | ||
path = "../linera-protocol/linera-storage" | ||
features = ["web"] | ||
|
||
[dependencies.linera-views] | ||
path = "../linera-protocol/linera-views" | ||
features = ["web", "indexeddb"] | ||
|
||
[dependencies.web-sys] | ||
version = "0.3" | ||
features = [ | ||
"console", | ||
"Window", | ||
] | ||
|
||
[dependencies.getrandom] | ||
version = "*" | ||
features = ["js"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,4 @@ | ||
#!/bin/sh | ||
|
||
rm -rf pkg | ||
|
||
# Build for release or debug | ||
wasm-pack build --target=web "$@" | ||
|
||
ln js/* manifest.json pkg/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
// Copyright (c) Facebook, Inc. and its affiliates. | ||
// Copyright (c) Zefchain Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use std::{ | ||
io::{BufRead, BufReader, BufWriter, Write}, | ||
path::{Path, PathBuf}, | ||
}; | ||
|
||
use anyhow::{bail, Context as _}; | ||
use linera_base::{ | ||
crypto::{BcsSignable, KeyPair, PublicKey}, | ||
data_types::{Amount, Timestamp}, | ||
identifiers::{ChainDescription, ChainId}, | ||
}; | ||
use linera_execution::{ | ||
committee::{Committee, ValidatorName, ValidatorState}, | ||
ResourceControlPolicy, | ||
}; | ||
use linera_rpc::config::{ValidatorInternalNetworkConfig, ValidatorPublicNetworkConfig}; | ||
use linera_storage::Storage; | ||
use linera_views::views::ViewError; | ||
use serde::{de::DeserializeOwned, Deserialize, Serialize}; | ||
|
||
use wasm_bindgen::JsError; | ||
|
||
use crate::wallet::Wallet; | ||
|
||
pub trait Import: DeserializeOwned { | ||
fn read(path: &Path) -> Result<Self, std::io::Error> { | ||
unimplemented!() | ||
} | ||
} | ||
|
||
pub trait Export: Serialize { | ||
fn write(&self, path: &Path) -> Result<(), std::io::Error> { | ||
unimplemented!() | ||
} | ||
} | ||
|
||
/// The public configuration of a validator. | ||
#[derive(Clone, Debug, Serialize, Deserialize)] | ||
pub struct ValidatorConfig { | ||
/// The public key of the validator. | ||
pub name: ValidatorName, | ||
/// The network configuration for the validator. | ||
pub network: ValidatorPublicNetworkConfig, | ||
} | ||
|
||
/// The private configuration of a validator service. | ||
#[derive(Serialize, Deserialize)] | ||
pub struct ValidatorServerConfig { | ||
pub validator: ValidatorConfig, | ||
pub key: KeyPair, | ||
pub internal_network: ValidatorInternalNetworkConfig, | ||
} | ||
|
||
impl Import for ValidatorServerConfig {} | ||
impl Export for ValidatorServerConfig {} | ||
|
||
/// The (public) configuration for all validators. | ||
#[derive(Debug, Default, Clone, Deserialize, Serialize)] | ||
pub struct CommitteeConfig { | ||
pub validators: Vec<ValidatorConfig>, | ||
} | ||
|
||
impl Import for CommitteeConfig {} | ||
impl Export for CommitteeConfig {} | ||
|
||
impl CommitteeConfig { | ||
pub fn into_committee(self, policy: ResourceControlPolicy) -> Committee { | ||
let validators = self | ||
.validators | ||
.into_iter() | ||
.map(|v| { | ||
( | ||
v.name, | ||
ValidatorState { | ||
network_address: v.network.to_string(), | ||
votes: 1, | ||
}, | ||
) | ||
}) | ||
.collect(); | ||
Committee::new(validators, policy) | ||
} | ||
} | ||
|
||
pub struct WalletState { inner: Wallet } | ||
|
||
impl WalletState { | ||
pub fn inner(&self) -> &Wallet { | ||
&self.inner | ||
} | ||
|
||
pub fn inner_mut(&mut self) -> &mut Wallet { | ||
&mut self.inner | ||
} | ||
|
||
pub fn into_inner(self) -> Wallet { | ||
self.inner | ||
} | ||
|
||
pub fn create( | ||
path: &Path, | ||
genesis_config: GenesisConfig, | ||
testing_prng_seed: Option<u64>, | ||
) -> Result<Self, anyhow::Error> { | ||
unimplemented!() | ||
// let file = OpenOptions::new() | ||
// .create(true) | ||
// .write(true) | ||
// .read(true) | ||
// .open(path)?; | ||
// let file_lock = FileLock::new(file, path)?; | ||
// let mut reader = BufReader::new(&file_lock.file); | ||
// if reader.fill_buf()?.is_empty() { | ||
// Ok(Self { | ||
// inner: Wallet::new(genesis_config, testing_prng_seed), | ||
// wallet_path: path.into(), | ||
// _lock: file_lock, | ||
// }) | ||
// } else { | ||
// let inner = serde_json::from_reader(reader)?; | ||
// Ok(Self { | ||
// inner, | ||
// wallet_path: path.into(), | ||
// _lock: file_lock, | ||
// }) | ||
// } | ||
} | ||
|
||
pub fn write(&mut self) -> Result<(), anyhow::Error> { | ||
unimplemented!(); | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug, Serialize, Deserialize)] | ||
pub struct GenesisConfig { | ||
pub committee: CommitteeConfig, | ||
pub admin_id: ChainId, | ||
pub timestamp: Timestamp, | ||
pub chains: Vec<(PublicKey, Amount)>, | ||
pub policy: ResourceControlPolicy, | ||
pub network_name: String, | ||
} | ||
|
||
impl Import for GenesisConfig {} | ||
impl Export for GenesisConfig {} | ||
impl BcsSignable for GenesisConfig {} | ||
|
||
impl GenesisConfig { | ||
pub fn new( | ||
committee: CommitteeConfig, | ||
admin_id: ChainId, | ||
timestamp: Timestamp, | ||
policy: ResourceControlPolicy, | ||
network_name: String, | ||
) -> Self { | ||
Self { | ||
committee, | ||
admin_id, | ||
timestamp, | ||
chains: Vec::new(), | ||
policy, | ||
network_name, | ||
} | ||
} | ||
|
||
pub async fn initialize_storage<S>(&self, storage: &mut S) -> Result<(), JsError> | ||
where | ||
S: Storage + Clone + Send + Sync + 'static, | ||
ViewError: From<S::ContextError>, | ||
{ | ||
let committee = self.create_committee(); | ||
for (chain_number, (public_key, balance)) in (0..).zip(&self.chains) { | ||
let description = ChainDescription::Root(chain_number); | ||
storage | ||
.create_chain( | ||
committee.clone(), | ||
self.admin_id, | ||
description, | ||
*public_key, | ||
*balance, | ||
self.timestamp, | ||
) | ||
.await?; | ||
} | ||
Ok(()) | ||
} | ||
|
||
pub fn create_committee(&self) -> Committee { | ||
self.committee.clone().into_committee(self.policy.clone()) | ||
} | ||
} |
Oops, something went wrong.