Skip to content

Commit

Permalink
Optimize wasm for explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
Thoralf-M committed Apr 16, 2024
1 parent fba9feb commit 8188e68
Show file tree
Hide file tree
Showing 14 changed files with 124 additions and 36 deletions.
9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,12 @@ codegen-units = 1
inherits = "release"
lto = true
strip = "symbols"
incremental = false

[profile.wasm]
codegen-units = 1
inherits = "release"
lto = true
strip = "symbols"
opt-level = "z"
incremental = false
3 changes: 2 additions & 1 deletion bindings/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ publish = false

[dependencies]
iota-sdk = { path = "../../sdk", default-features = false, features = [
"wallet",
"client",
"tls",
] }

Expand Down Expand Up @@ -46,3 +46,4 @@ rocksdb = ["iota-sdk/rocksdb"]
storage = ["iota-sdk/storage"]
stronghold = ["iota-sdk/stronghold"]
private_key_secret_manager = ["iota-sdk/private_key_secret_manager"]
wallet = ["iota-sdk/wallet"]
1 change: 1 addition & 0 deletions bindings/core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub enum Error {
/// Client errors.
#[error("{0}")]
Client(#[from] iota_sdk::client::Error),
#[cfg(feature = "wallet")]
/// Wallet errors.
#[error("{0}")]
Wallet(#[from] iota_sdk::wallet::Error),
Expand Down
17 changes: 14 additions & 3 deletions bindings/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ mod response;

use std::fmt::{Formatter, Result as FmtResult};

#[cfg(feature = "wallet")]
use derivative::Derivative;
use fern_logger::{logger_init, LoggerConfig, LoggerOutputConfigBuilder};
pub use iota_sdk;
use iota_sdk::client::secret::SecretManagerDto;
#[cfg(feature = "wallet")]
use iota_sdk::{
client::secret::{SecretManager, SecretManagerDto},
client::secret::SecretManager,
wallet::{ClientOptions, Wallet},
};
#[cfg(feature = "wallet")]
use serde::Deserialize;

#[cfg(feature = "mqtt")]
Expand All @@ -26,17 +30,23 @@ pub use self::method_handler::listen_mqtt;
pub use self::method_handler::CallMethod;
pub use self::{
error::{Error, Result},
method::{AccountMethod, ClientMethod, SecretManagerMethod, UtilsMethod, WalletMethod},
method_handler::{call_client_method, call_secret_manager_method, call_utils_method, call_wallet_method},
method::{ClientMethod, SecretManagerMethod, UtilsMethod},
method_handler::{call_client_method, call_secret_manager_method, call_utils_method},
response::Response,
};
#[cfg(feature = "wallet")]
pub use self::{
method::{AccountMethod, WalletMethod},
method_handler::call_wallet_method,
};

pub fn init_logger(config: String) -> std::result::Result<(), fern_logger::Error> {
let output_config: LoggerOutputConfigBuilder = serde_json::from_str(&config).expect("invalid logger config");
let config = LoggerConfig::build().with_output(output_config).finish();
logger_init(config)
}

#[cfg(feature = "wallet")]
#[derive(Derivative, Deserialize, Default)]
#[derivative(Debug)]
#[serde(rename_all = "camelCase")]
Expand All @@ -48,6 +58,7 @@ pub struct WalletOptions {
pub secret_manager: Option<SecretManagerDto>,
}

#[cfg(feature = "wallet")]
impl WalletOptions {
pub fn with_storage_path(mut self, storage_path: impl Into<Option<String>>) -> Self {
self.storage_path = storage_path.into();
Expand Down
9 changes: 5 additions & 4 deletions bindings/core/src/method/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

#[cfg(feature = "wallet")]
mod account;
mod client;
mod secret_manager;
mod utils;
#[cfg(feature = "wallet")]
mod wallet;

pub use self::{
account::AccountMethod, client::ClientMethod, secret_manager::SecretManagerMethod, utils::UtilsMethod,
wallet::WalletMethod,
};
#[cfg(feature = "wallet")]
pub use self::{account::AccountMethod, wallet::WalletMethod};
pub use self::{client::ClientMethod, secret_manager::SecretManagerMethod, utils::UtilsMethod};
15 changes: 9 additions & 6 deletions bindings/core/src/method_handler/call_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
use std::pin::Pin;

use futures::Future;
use iota_sdk::{
client::{secret::SecretManager, Client},
wallet::Wallet,
};
use iota_sdk::client::{secret::SecretManager, Client};
#[cfg(feature = "wallet")]
use iota_sdk::wallet::Wallet;
use tokio::sync::RwLock;

#[cfg(feature = "wallet")]
use crate::{method::WalletMethod, method_handler::wallet::call_wallet_method_internal};
use crate::{
method::{ClientMethod, SecretManagerMethod, WalletMethod},
method::{ClientMethod, SecretManagerMethod},
method_handler::{
client::call_client_method_internal, secret_manager::call_secret_manager_method_internal,
utils::call_utils_method_internal, wallet::call_wallet_method_internal,
utils::call_utils_method_internal,
},
panic::{convert_async_panics, convert_panics},
response::Response,
Expand All @@ -36,6 +37,7 @@ impl CallMethod for Client {
}
}

#[cfg(feature = "wallet")]
impl CallMethod for Wallet {
type Method = WalletMethod;

Expand All @@ -55,6 +57,7 @@ pub async fn call_client_method(client: &Client, method: ClientMethod) -> Respon
response
}

#[cfg(feature = "wallet")]
/// Call a wallet method.
pub async fn call_wallet_method(wallet: &Wallet, method: WalletMethod) -> Response {
log::debug!("Wallet method: {method:?}");
Expand Down
8 changes: 5 additions & 3 deletions bindings/core/src/method_handler/mod.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

#[cfg(feature = "wallet")]
mod account;
mod call_method;
mod client;
mod secret_manager;
mod utils;
#[cfg(feature = "wallet")]
mod wallet;

pub use call_method::{
call_client_method, call_secret_manager_method, call_utils_method, call_wallet_method, CallMethod,
};
#[cfg(feature = "wallet")]
pub use call_method::call_wallet_method;
pub use call_method::{call_client_method, call_secret_manager_method, call_utils_method, CallMethod};
#[cfg(feature = "mqtt")]
pub use client::listen_mqtt;
21 changes: 17 additions & 4 deletions bindings/core/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ use std::collections::HashSet;
use derivative::Derivative;
#[cfg(feature = "ledger_nano")]
use iota_sdk::client::secret::LedgerNanoStatus;
#[cfg(feature = "wallet")]
use iota_sdk::wallet::account::{
types::{AccountAddress, AddressWithUnspentOutputs, Balance, OutputDataDto, TransactionDto},
AccountDetailsDto, PreparedCreateNativeTokenTransactionDto,
};
use iota_sdk::{
client::{
api::{PreparedTransactionDataDto, SignedTransactionDataDto},
Expand Down Expand Up @@ -38,10 +43,6 @@ use iota_sdk::{
BlockDto, BlockId,
},
},
wallet::account::{
types::{AccountAddress, AddressWithUnspentOutputs, Balance, OutputDataDto, TransactionDto},
AccountDetailsDto, PreparedCreateNativeTokenTransactionDto,
},
};
use serde::Serialize;
#[cfg(feature = "participation")]
Expand Down Expand Up @@ -300,19 +301,23 @@ pub enum Response {
Panic(String),

// wallet responses
#[cfg(feature = "wallet")]
/// Response for:
/// - [`CreateAccount`](crate::method::WalletMethod::CreateAccount),
/// - [`GetAccount`](crate::method::WalletMethod::GetAccount)
Account(AccountDetailsDto),
/// Response for:
/// - [`GetAccountIndexes`](crate::method::WalletMethod::GetAccountIndexes)
AccountIndexes(Vec<u32>),
#[cfg(feature = "wallet")]
/// Response for:
/// - [`GetAccounts`](crate::method::WalletMethod::GetAccounts)
Accounts(Vec<AccountDetailsDto>),
#[cfg(feature = "wallet")]
/// Response for:
/// - [`Addresses`](crate::method::AccountMethod::Addresses)
Addresses(Vec<AccountAddress>),
#[cfg(feature = "wallet")]
/// Response for:
/// - [`AddressesWithUnspentOutputs`](crate::method::AccountMethod::AddressesWithUnspentOutputs)
AddressesWithUnspentOutputs(Vec<AddressWithUnspentOutputs>),
Expand All @@ -326,9 +331,11 @@ pub enum Response {
/// Response for:
/// - [`ClaimableOutputs`](crate::method::AccountMethod::ClaimableOutputs)
OutputIds(Vec<OutputId>),
#[cfg(feature = "wallet")]
/// Response for:
/// - [`GetOutput`](crate::method::AccountMethod::GetOutput)
OutputData(Option<Box<OutputDataDto>>),
#[cfg(feature = "wallet")]
/// Response for:
/// - [`Outputs`](crate::method::AccountMethod::Outputs),
/// - [`UnspentOutputs`](crate::method::AccountMethod::UnspentOutputs)
Expand All @@ -350,13 +357,16 @@ pub enum Response {
/// - [`PrepareTransaction`](crate::method::AccountMethod::PrepareTransaction)
/// - [`PrepareVote`](crate::method::AccountMethod::PrepareVote)
PreparedTransaction(PreparedTransactionDataDto),
#[cfg(feature = "wallet")]
/// Response for:
/// - [`PrepareCreateNativeToken`](crate::method::AccountMethod::PrepareCreateNativeToken),
PreparedCreateNativeTokenTransaction(PreparedCreateNativeTokenTransactionDto),
#[cfg(feature = "wallet")]
/// Response for:
/// - [`GetIncomingTransaction`](crate::method::AccountMethod::GetIncomingTransaction)
/// - [`GetTransaction`](crate::method::AccountMethod::GetTransaction),
Transaction(Option<Box<TransactionDto>>),
#[cfg(feature = "wallet")]
/// Response for:
/// - [`IncomingTransactions`](crate::method::AccountMethod::IncomingTransactions)
/// - [`PendingTransactions`](crate::method::AccountMethod::PendingTransactions),
Expand All @@ -365,14 +375,17 @@ pub enum Response {
/// Response for:
/// - [`SignTransactionEssence`](crate::method::AccountMethod::SignTransactionEssence)
SignedTransactionData(SignedTransactionDataDto),
#[cfg(feature = "wallet")]
/// GenerateAddress response.
/// Response for:
/// - [`GenerateEd25519Addresses`](crate::method::AccountMethod::GenerateEd25519Addresses)
GeneratedAccountAddresses(Vec<AccountAddress>),
#[cfg(feature = "wallet")]
/// Response for:
/// - [`GetBalance`](crate::method::AccountMethod::GetBalance),
/// - [`Sync`](crate::method::AccountMethod::Sync)
Balance(Balance),
#[cfg(feature = "wallet")]
/// Response for:
/// - [`ClaimOutputs`](crate::method::AccountMethod::ClaimOutputs)
/// - [`Send`](crate::method::AccountMethod::Send)
Expand Down
1 change: 1 addition & 0 deletions bindings/nodejs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ iota-sdk-bindings-core = { path = "../core", default-features = false, features
"rocksdb",
"mqtt",
"private_key_secret_manager",
"wallet",
] }

log = { version = "0.4.20", default-features = false }
Expand Down
6 changes: 0 additions & 6 deletions bindings/package-lock.json

This file was deleted.

2 changes: 2 additions & 0 deletions bindings/python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ iota-sdk-bindings-core = { path = "../core", default-features = false, features
"storage",
"stronghold",
"mqtt",
"private_key_secret_manager",
"wallet",
] }

futures = { version = "0.3.30", default-features = false }
Expand Down
12 changes: 7 additions & 5 deletions bindings/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ crate-type = ["cdylib"]
doc = false

[dependencies]
iota-sdk-bindings-core = { path = "../core", default-features = false, features = [
"events",
"storage",
"private_key_secret_manager",
] }
iota-sdk-bindings-core = { path = "../core", default-features = false }

console_error_panic_hook = { version = "0.1.7", default-features = false }
js-sys = { version = "0.3.68", default-features = false, features = [] }
Expand All @@ -41,3 +37,9 @@ getrandom = { version = "0.2.12", default-features = false, features = ["js"] }
instant = { version = "0.1.12", default-features = false, features = [
"wasm-bindgen",
] }

[features]
default = ["private_key_secret_manager", "wallet"]

private_key_secret_manager = [ "iota-sdk-bindings-core/private_key_secret_manager" ]
wallet = [ "iota-sdk-bindings-core/events", "iota-sdk-bindings-core/storage", "iota-sdk-bindings-core/wallet" ]
3 changes: 3 additions & 0 deletions bindings/wasm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
"build:web": "node ./build_scripts/copyNodejsDefs.js && yarn run build:src && yarn run bundle:web && wasm-opt -O web/wasm/iota_sdk_wasm_bg.wasm -o web/wasm/iota_sdk_wasm_bg.wasm",
"bundle:nodejs": "wasm-bindgen ../../target/wasm32-unknown-unknown/production/iota_sdk_wasm.wasm --typescript --weak-refs --target nodejs --out-dir node/wasm && node ./build_scripts/node && tsc --project tsconfig.node.json --outDir node/lib",
"bundle:web": "wasm-bindgen ../../target/wasm32-unknown-unknown/production/iota_sdk_wasm.wasm --typescript --weak-refs --target web --out-dir web/wasm && node ./build_scripts/web && tsc --project tsconfig.web.json --outDir web/lib",
"build:src-client-only": "cargo build --lib --profile=wasm --target wasm32-unknown-unknown --no-default-features",
"build:web-client-only": "node ./build_scripts/copyNodejsDefs.js && yarn run build:src-client-only && yarn run bundle:web-client-only && wasm-opt -Oz web/wasm/iota_sdk_wasm_bg.wasm -o web/wasm/iota_sdk_wasm_bg.wasm",
"bundle:web-client-only": "wasm-bindgen ../../target/wasm32-unknown-unknown/wasm/iota_sdk_wasm.wasm --typescript --weak-refs --target web --out-dir web/wasm && node ./build_scripts/web && tsc --project tsconfig.node.json --outDir node/lib",
"copy-nodejs-defs": "node ./build_scripts/copyNodejsDefs.js",
"lint": "eslint --ignore-path .eslintignore --ext .js,.ts .",
"format": "prettier --ignore-path .eslintignore -w \"{,*/**/}*.{ts,js,json}\"",
Expand Down
Loading

0 comments on commit 8188e68

Please sign in to comment.