From 209d4c331a281a48b0191ff8c4ebffa3fe41dcba Mon Sep 17 00:00:00 2001 From: woodser Date: Thu, 12 Sep 2024 14:19:04 -0400 Subject: [PATCH] rename dist assets to monero.js, monero.worker.js, and monero.tests.js --- CMakeLists.txt | 42 ++++++++++------------- bin/build_wasm_emscripten.sh | 4 +-- bin/postprocess_wasm.mjs | 2 +- package.json | 2 +- src/main/cpp/http_client_wasm.cpp | 2 +- src/main/ts/common/LibraryUtils.ts | 10 +++--- src/main/ts/common/MoneroRpcConnection.ts | 2 +- src/main/ts/common/MoneroUtils.ts | 10 +++--- src/main/ts/wallet/MoneroWalletFull.ts | 10 +++--- src/main/ts/wallet/MoneroWalletKeys.ts | 8 ++--- src/test/TestMoneroWalletCommon.ts | 2 +- src/test/browser/tests.html | 2 +- webpack.tests.js | 2 +- webpack.worker.js | 2 +- 14 files changed, 48 insertions(+), 52 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5c6ec2f20..bdb2366b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,8 +8,6 @@ string(REPLACE ";" "," WASM_EXCEPTION_WHITELIST "${WASM_EXCEPTION_WHITELIST}") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Oz -s EXCEPTION_CATCHING_ALLOWED='[${WASM_EXCEPTION_WHITELIST}]'") add_definitions(-DAUTO_INITIALIZE_EASYLOGGINGPP -DNO_AES) -set(BUILD_MONERO_WALLET_FULL_WASM ON) - ############## # C++ bridge ############## @@ -319,27 +317,25 @@ message(STATUS "EMCC_LINKER_FLAGS_FULL ${EMCC_LINKER_FLAGS_FULL}") # Build targets #################### -if (BUILD_MONERO_WALLET_FULL_WASM) - add_executable(monero_wallet_full ${MONERO_WALLET_FULL_SRC_FILES} ${MONERO_WALLET_KEYS_SRC_FILES}) - set_target_properties(monero_wallet_full PROPERTIES LINK_FLAGS "${EMCC_LINKER_FLAGS_FULL}") - target_compile_definitions(monero_wallet_full PRIVATE BUILD_WALLET_FULL=1) - target_link_libraries( - monero_wallet_full - # - #openssl_ssl - #openssl_crypto - # - boost_chrono - boost_system - boost_thread - boost_serialization - boost_filesystem - boost_regex - #boost_atomic - # - ${log-lib} - ) -endif() +add_executable(monero ${MONERO_WALLET_FULL_SRC_FILES} ${MONERO_WALLET_KEYS_SRC_FILES}) +set_target_properties(monero PROPERTIES LINK_FLAGS "${EMCC_LINKER_FLAGS_FULL}") +target_compile_definitions(monero PRIVATE BUILD_WALLET_FULL=1) +target_link_libraries( + monero + # + #openssl_ssl + #openssl_crypto + # + boost_chrono + boost_system + boost_thread + boost_serialization + boost_filesystem + boost_regex + #boost_atomic + # + ${log-lib} +) # build to bitcode instead of wasm #SET(CMAKE_EXECUTABLE_SUFFIX ".bc") \ No newline at end of file diff --git a/bin/build_wasm_emscripten.sh b/bin/build_wasm_emscripten.sh index a256dc3b3..d545fba90 100755 --- a/bin/build_wasm_emscripten.sh +++ b/bin/build_wasm_emscripten.sh @@ -21,7 +21,7 @@ emmake cmake --build . -j$HOST_NCORES || exit 1 # move available wasm files to ./dist cd .. mkdir -p ./dist || exit 1 -[ -f ./build/monero_wallet_full.js ] \ +[ -f ./build/monero.js ] \ && { - mv ./build/monero_wallet_full.js ./dist/ + mv ./build/monero.js ./dist/ } diff --git a/bin/postprocess_wasm.mjs b/bin/postprocess_wasm.mjs index 59508d07a..f645cd932 100644 --- a/bin/postprocess_wasm.mjs +++ b/bin/postprocess_wasm.mjs @@ -1,7 +1,7 @@ import fs from "fs"; import { Buffer } from "buffer"; -const fileNames = ["./dist/monero_wallet_full.js"]; +const fileNames = ["./dist/monero.js"]; const postprocess = async (fileName) => { diff --git a/package.json b/package.json index 7c610a1e9..0119a7b80 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "build_web_tests": "webpack --config ./webpack.tests.js", "test": "npm run build_commonjs && node --enable-source-maps node_modules/mocha/bin/_mocha --require @babel/register \"dist/src/test/TestAll\" --timeout 900000000 --exit", "typedoc": "typedoc ./index.ts --out ./docs/typedocs --excludePrivate --disableSources", - "build_commonjs": "babel ./src --extensions \".js,.ts\" --out-dir ./dist/src && babel ./index.ts --extensions \".ts\" --out-dir ./dist && shx mkdir -p dist/dist && shx cp dist/monero_wallet_full.js dist/dist && shx cp dist/*.js.map dist/dist", + "build_commonjs": "babel ./src --extensions \".js,.ts\" --out-dir ./dist/src && babel ./index.ts --extensions \".ts\" --out-dir ./dist && shx mkdir -p dist/dist && shx cp dist/monero.js dist/dist && shx cp dist/*.js.map dist/dist", "check_babel_version": "babel -V" }, "build": { diff --git a/src/main/cpp/http_client_wasm.cpp b/src/main/cpp/http_client_wasm.cpp index 5448dec6a..edb718bd2 100644 --- a/src/main/cpp/http_client_wasm.cpp +++ b/src/main/cpp/http_client_wasm.cpp @@ -75,7 +75,7 @@ EM_JS(const char*, js_send_binary_request, (const char* uri, const char* usernam return Asyncify.handleSleep(function(wakeUp) { // load full wasm module then convert from json to binary - LibraryUtils.loadFullModule().then(module => { + LibraryUtils.loadWasmModule().then(module => { // read binary data from heap to Uint8Array let ptr = body; diff --git a/src/main/ts/common/LibraryUtils.ts b/src/main/ts/common/LibraryUtils.ts index 7aad377a4..b653b5804 100644 --- a/src/main/ts/common/LibraryUtils.ts +++ b/src/main/ts/common/LibraryUtils.ts @@ -17,7 +17,7 @@ export default class LibraryUtils { static FULL_LOADED: any; static REJECT_UNAUTHORIZED_FNS: any; static readonly MUTEX = new ThreadPool(1); - static WORKER_DIST_PATH_DEFAULT = GenUtils.isBrowser() ? "/monero_web_worker.js" : function() { + static WORKER_DIST_PATH_DEFAULT = GenUtils.isBrowser() ? "/monero.worker.js" : function() { // get worker path in dist (assumes library is running from src or dist) let curPath = path.normalize(__dirname); @@ -84,7 +84,7 @@ export default class LibraryUtils { * * The full module is a superset of the keys module and overrides it. */ - static async loadFullModule() { + static async loadWasmModule() { // use cache if suitable, full module supersedes keys module because it is superset if (LibraryUtils.WASM_MODULE && LibraryUtils.FULL_LOADED) return LibraryUtils.WASM_MODULE; @@ -92,7 +92,7 @@ export default class LibraryUtils { // load module const fetch_ = globalThis.fetch; globalThis.fetch = undefined; // prevent fetch in worker - let module = await require("../../../../dist/monero_wallet_full")(); + let module = await require("../../../../dist/monero")(); globalThis.fetch = fetch_; LibraryUtils.WASM_MODULE = module; delete LibraryUtils.WASM_MODULE.then; @@ -125,7 +125,7 @@ export default class LibraryUtils { } /** - * Set the path to load the worker. Defaults to "/monero_web_worker.js" in the browser + * Set the path to load the worker. Defaults to "/monero.worker.js" in the browser * and "./MoneroWebWorker.js" in node. * * @param {string} workerDistPath - path to load the worker @@ -140,7 +140,7 @@ export default class LibraryUtils { * Set the worker loader closure to customize worker loading. * Takes precedence over default loading mechanisms. * - * Could be as simple as `() => new Worker(new URL("monero-ts/dist/monero_web_worker.js", import.meta.url));` for browsers. + * Could be as simple as `() => new Worker(new URL("monero-ts/dist/monero.worker.js", import.meta.url));` for browsers. * * @param {function} loader - loader function which instantiates a worker */ diff --git a/src/main/ts/common/MoneroRpcConnection.ts b/src/main/ts/common/MoneroRpcConnection.ts index 31e64e107..2c49b3302 100644 --- a/src/main/ts/common/MoneroRpcConnection.ts +++ b/src/main/ts/common/MoneroRpcConnection.ts @@ -182,7 +182,7 @@ export default class MoneroRpcConnection { */ async checkConnection(timeoutMs): Promise { return this.queueCheckConnection(async () => { - await LibraryUtils.loadFullModule(); // cache wasm for binary request + await LibraryUtils.loadWasmModule(); // cache wasm for binary request let isOnlineBefore = this.isOnline; let isAuthenticatedBefore = this.isAuthenticated; let startTime = Date.now(); diff --git a/src/main/ts/common/MoneroUtils.ts b/src/main/ts/common/MoneroUtils.ts index 9f8326548..a467d1729 100644 --- a/src/main/ts/common/MoneroUtils.ts +++ b/src/main/ts/common/MoneroUtils.ts @@ -162,7 +162,7 @@ export default class MoneroUtils { assert(GenUtils.isBase58(standardAddress), "Address is not base 58"); // load keys module by default - if (LibraryUtils.getWasmModule() === undefined) await LibraryUtils.loadFullModule(); + if (LibraryUtils.getWasmModule() === undefined) await LibraryUtils.loadWasmModule(); // get integrated address in queue return LibraryUtils.getWasmModule().queueTask(async () => { @@ -204,7 +204,7 @@ export default class MoneroUtils { networkType = MoneroNetworkType.from(networkType); // load keys module by default - if (LibraryUtils.getWasmModule() === undefined) await LibraryUtils.loadFullModule(); + if (LibraryUtils.getWasmModule() === undefined) await LibraryUtils.loadWasmModule(); // validate address in queue return LibraryUtils.getWasmModule().queueTask(async function() { @@ -308,7 +308,7 @@ export default class MoneroUtils { if (MoneroUtils.PROXY_TO_WORKER) return LibraryUtils.invokeWorker(undefined, "moneroUtilsJsonToBinary", Array.from(arguments)); // load keys module by default - if (LibraryUtils.getWasmModule() === undefined) await LibraryUtils.loadFullModule(); + if (LibraryUtils.getWasmModule() === undefined) await LibraryUtils.loadWasmModule(); // use wasm in queue return LibraryUtils.getWasmModule().queueTask(async function() { @@ -345,7 +345,7 @@ export default class MoneroUtils { if (MoneroUtils.PROXY_TO_WORKER) return LibraryUtils.invokeWorker(undefined, "moneroUtilsBinaryToJson", Array.from(arguments)); // load keys module by default - if (LibraryUtils.getWasmModule() === undefined) await LibraryUtils.loadFullModule(); + if (LibraryUtils.getWasmModule() === undefined) await LibraryUtils.loadWasmModule(); // use wasm in queue return LibraryUtils.getWasmModule().queueTask(async function() { @@ -382,7 +382,7 @@ export default class MoneroUtils { if (MoneroUtils.PROXY_TO_WORKER) return LibraryUtils.invokeWorker(undefined, "moneroUtilsBinaryBlocksToJson", Array.from(arguments)); // load keys module by default - if (LibraryUtils.getWasmModule() === undefined) await LibraryUtils.loadFullModule(); + if (LibraryUtils.getWasmModule() === undefined) await LibraryUtils.loadWasmModule(); // use wasm in queue return LibraryUtils.getWasmModule().queueTask(async function() { diff --git a/src/main/ts/wallet/MoneroWalletFull.ts b/src/main/ts/wallet/MoneroWalletFull.ts index 073f656c4..057d46ef4 100644 --- a/src/main/ts/wallet/MoneroWalletFull.ts +++ b/src/main/ts/wallet/MoneroWalletFull.ts @@ -201,7 +201,7 @@ export default class MoneroWalletFull extends MoneroWalletKeys { if (config.getSeedOffset() === undefined) config.setSeedOffset(""); // load full wasm module - let module = await LibraryUtils.loadFullModule(); + let module = await LibraryUtils.loadWasmModule(); // create wallet in queue let wallet = await module.queueTask(async () => { @@ -237,7 +237,7 @@ export default class MoneroWalletFull extends MoneroWalletKeys { if (config.getLanguage() === undefined) config.setLanguage("English"); // load full wasm module - let module = await LibraryUtils.loadFullModule(); + let module = await LibraryUtils.loadWasmModule(); // create wallet in queue let wallet = await module.queueTask(async () => { @@ -268,7 +268,7 @@ export default class MoneroWalletFull extends MoneroWalletKeys { let rejectUnauthorized = daemonConnection ? daemonConnection.getRejectUnauthorized() : true; // load wasm module - let module = await LibraryUtils.loadFullModule(); + let module = await LibraryUtils.loadWasmModule(); // create wallet in queue let wallet = await module.queueTask(async () => { @@ -292,7 +292,7 @@ export default class MoneroWalletFull extends MoneroWalletKeys { } static async getSeedLanguages() { - let module = await LibraryUtils.loadFullModule(); + let module = await LibraryUtils.loadWasmModule(); return module.queueTask(async () => { return JSON.parse(module.get_keys_wallet_seed_languages()).languages; }); @@ -1614,7 +1614,7 @@ export default class MoneroWalletFull extends MoneroWalletKeys { let rejectUnauthorized = daemonConnection ? daemonConnection.getRejectUnauthorized() : true; // load wasm module - let module = await LibraryUtils.loadFullModule(); + let module = await LibraryUtils.loadWasmModule(); // open wallet in queue return module.queueTask(async () => { diff --git a/src/main/ts/wallet/MoneroWalletKeys.ts b/src/main/ts/wallet/MoneroWalletKeys.ts index 92cab19bb..d3b32f911 100644 --- a/src/main/ts/wallet/MoneroWalletKeys.ts +++ b/src/main/ts/wallet/MoneroWalletKeys.ts @@ -83,7 +83,7 @@ export class MoneroWalletKeys extends MoneroWallet { if (config.getLanguage() === undefined) config.setLanguage("English"); // load wasm module - let module = await LibraryUtils.loadFullModule(); + let module = await LibraryUtils.loadWasmModule(); // queue call to wasm module return module.queueTask(async () => { @@ -107,7 +107,7 @@ export class MoneroWalletKeys extends MoneroWallet { if (config.getLanguage() !== undefined) throw new MoneroError("Cannot provide language when creating wallet from seed"); // load wasm module - let module = await LibraryUtils.loadFullModule(); + let module = await LibraryUtils.loadWasmModule(); // queue call to wasm module return module.queueTask(async () => { @@ -133,7 +133,7 @@ export class MoneroWalletKeys extends MoneroWallet { if (config.getLanguage() === undefined) config.setLanguage("English"); // load wasm module - let module = await LibraryUtils.loadFullModule(); + let module = await LibraryUtils.loadWasmModule(); // queue call to wasm module return module.queueTask(async () => { @@ -149,7 +149,7 @@ export class MoneroWalletKeys extends MoneroWallet { } static async getSeedLanguages(): Promise { - let module = await LibraryUtils.loadFullModule(); + let module = await LibraryUtils.loadWasmModule(); return module.queueTask(async () => { return JSON.parse(module.get_keys_wallet_seed_languages()).languages; }); diff --git a/src/test/TestMoneroWalletCommon.ts b/src/test/TestMoneroWalletCommon.ts index 1f616af43..d610a312b 100644 --- a/src/test/TestMoneroWalletCommon.ts +++ b/src/test/TestMoneroWalletCommon.ts @@ -70,7 +70,7 @@ export default class TestMoneroWalletCommon { this.wallet = await this.getTestWallet(); this.daemon = await this.getTestDaemon(); TestUtils.WALLET_TX_TRACKER.reset(); // all wallets need to wait for txs to confirm to reliably sync - await LibraryUtils.loadFullModule(); // for wasm dependents like address validation + await LibraryUtils.loadWasmModule(); // for wasm dependents like address validation } /** diff --git a/src/test/browser/tests.html b/src/test/browser/tests.html index 0ca366500..2171362a0 100644 --- a/src/test/browser/tests.html +++ b/src/test/browser/tests.html @@ -7,6 +7,6 @@
- + diff --git a/webpack.tests.js b/webpack.tests.js index 8c97f6f87..f1cc897d0 100644 --- a/webpack.tests.js +++ b/webpack.tests.js @@ -8,7 +8,7 @@ let configBrowserTest = Object.assign({}, configBase, { entry: "./dist/src/test/browser/tests.js", output: { path: path.resolve(__dirname, "browser_build"), - filename: "monero-ts-tests.js" + filename: "monero.tests.js" }, }); diff --git a/webpack.worker.js b/webpack.worker.js index 0071cfdd2..f07750e7a 100644 --- a/webpack.worker.js +++ b/webpack.worker.js @@ -8,7 +8,7 @@ let configMoneroWebWorker = Object.assign({}, configBase, { entry: "./src/main/ts/common/MoneroWebWorker.ts", output: { path: path.resolve(__dirname, "dist"), - filename: "monero_web_worker.js" + filename: "monero.worker.js" }, });