Skip to content

Commit

Permalink
rename dist assets to monero.js, monero.worker.js, and monero.tests.js
Browse files Browse the repository at this point in the history
  • Loading branch information
woodser committed Sep 14, 2024
1 parent 0020b9d commit 209d4c3
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 52 deletions.
42 changes: 19 additions & 23 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
##############
Expand Down Expand Up @@ -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")
4 changes: 2 additions & 2 deletions bin/build_wasm_emscripten.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/
}
2 changes: 1 addition & 1 deletion bin/postprocess_wasm.mjs
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion src/main/cpp/http_client_wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions src/main/ts/common/LibraryUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -84,15 +84,15 @@ 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;

// 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;
Expand Down Expand Up @@ -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
Expand All @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion src/main/ts/common/MoneroRpcConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export default class MoneroRpcConnection {
*/
async checkConnection(timeoutMs): Promise<boolean> {
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();
Expand Down
10 changes: 5 additions & 5 deletions src/main/ts/common/MoneroUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down
10 changes: 5 additions & 5 deletions src/main/ts/wallet/MoneroWalletFull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand All @@ -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;
});
Expand Down Expand Up @@ -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 () => {
Expand Down
8 changes: 4 additions & 4 deletions src/main/ts/wallet/MoneroWalletKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -149,7 +149,7 @@ export class MoneroWalletKeys extends MoneroWallet {
}

static async getSeedLanguages(): Promise<string[]> {
let module = await LibraryUtils.loadFullModule();
let module = await LibraryUtils.loadWasmModule();
return module.queueTask(async () => {
return JSON.parse(module.get_keys_wallet_seed_languages()).languages;
});
Expand Down
2 changes: 1 addition & 1 deletion src/test/TestMoneroWalletCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/test/browser/tests.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<body>
<div id="mocha"></div>
<script src="mocha.js"></script>
<script type="text/javascript" src="monero-ts-tests.js"></script>
<script type="text/javascript" src="monero.tests.js"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion webpack.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
});

Expand Down
2 changes: 1 addition & 1 deletion webpack.worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
});

Expand Down

0 comments on commit 209d4c3

Please sign in to comment.