From be2204427b4fe9bfd7696a5483a0c0c04626d5bb Mon Sep 17 00:00:00 2001 From: Michael Turner Date: Thu, 5 Oct 2023 13:48:47 +0200 Subject: [PATCH] Update aleo.tools to use the latest api endpoint --- wasm/Cargo.toml | 1 + wasm/build.rs | 3 +- wasm/src/lib.rs | 6 +-- wasm/src/programs/manager/deploy.rs | 2 +- wasm/src/programs/manager/execute.rs | 2 +- wasm/src/programs/manager/join.rs | 2 +- wasm/src/programs/manager/transfer.rs | 4 +- wasm/src/thread_pool/mod.rs | 43 ++++++------------- website/package-lock.json | 24 +++++------ website/package.json | 2 +- website/src/tabs/develop/Deploy.jsx | 2 +- website/src/tabs/develop/ExecuteLegacy.jsx | 2 +- website/src/tabs/develop/Join.jsx | 2 +- website/src/tabs/develop/Split.jsx | 2 +- website/src/tabs/develop/Transfer.jsx | 2 +- website/src/tabs/develop/execute/index.jsx | 2 +- website/src/tabs/rest/GetBlockByHash.jsx | 2 +- website/src/tabs/rest/GetBlockByHeight.jsx | 2 +- website/src/tabs/rest/GetLatestBlock.jsx | 2 +- .../src/tabs/rest/GetLatestBlockHeight.jsx | 2 +- website/src/tabs/rest/GetMappingNames.jsx | 2 +- website/src/tabs/rest/GetMappingValue.jsx | 2 +- website/src/tabs/rest/GetProgram.jsx | 2 +- website/src/tabs/rest/GetTransaction.jsx | 2 +- website/src/workers/worker.js | 2 +- 25 files changed, 51 insertions(+), 68 deletions(-) diff --git a/wasm/Cargo.toml b/wasm/Cargo.toml index a60a25588..bd044c909 100644 --- a/wasm/Cargo.toml +++ b/wasm/Cargo.toml @@ -111,6 +111,7 @@ version = "0.3.64" features = [ "Url", "Navigator", + "Window", ] [dev-dependencies.wasm-bindgen-test] diff --git a/wasm/build.rs b/wasm/build.rs index 932f3bfe5..85fa6b702 100644 --- a/wasm/build.rs +++ b/wasm/build.rs @@ -22,7 +22,8 @@ use walkdir::WalkDir; const EXPECTED_LICENSE_TEXT: &[u8] = include_bytes!("../.resources/license_header"); // The following directories will be excluded from the license scan. -const DIRS_TO_SKIP: [&str; 9] = [".cargo", ".circleci", ".git", ".github", ".resources", "examples", "sdk", "target", "node_modules"]; +const DIRS_TO_SKIP: [&str; 9] = + [".cargo", ".circleci", ".git", ".github", ".resources", "examples", "sdk", "target", "node_modules"]; fn check_file_licenses>(path: P) { let path = path.as_ref(); diff --git a/wasm/src/lib.rs b/wasm/src/lib.rs index 39d99851a..442d25858 100644 --- a/wasm/src/lib.rs +++ b/wasm/src/lib.rs @@ -206,7 +206,6 @@ impl Credits for RecordPlaintextNative { } } - #[cfg(not(test))] pub use thread_pool::initialize_worker; @@ -215,10 +214,7 @@ pub use thread_pool::initialize_worker; pub async fn init_thread_pool(url: web_sys::Url, num_threads: usize) -> Result<(), JsValue> { console_error_panic_hook::set_once(); - ThreadPool::builder() - .url(url) - .num_threads(num_threads) - .build_global().await?; + ThreadPool::builder().url(url).num_threads(num_threads).build_global().await?; Ok(()) } diff --git a/wasm/src/programs/manager/deploy.rs b/wasm/src/programs/manager/deploy.rs index 86a83ad6a..c9cfad7bb 100644 --- a/wasm/src/programs/manager/deploy.rs +++ b/wasm/src/programs/manager/deploy.rs @@ -77,7 +77,7 @@ impl ProgramManager { // Convert fee to microcredits and check that the fee record has enough credits to pay it let fee_microcredits = match &fee_record { Some(fee_record) => Self::validate_amount(fee_credits, fee_record, true)?, - None => (fee_credits as u64) * 1_000_000, + None => (fee_credits * 1_000_000.0) as u64, }; let mut new_process; diff --git a/wasm/src/programs/manager/execute.rs b/wasm/src/programs/manager/execute.rs index 8cff98e91..7088c64cf 100644 --- a/wasm/src/programs/manager/execute.rs +++ b/wasm/src/programs/manager/execute.rs @@ -140,7 +140,7 @@ impl ProgramManager { log(&format!("Executing function: {function} on-chain")); let fee_microcredits = match &fee_record { Some(fee_record) => Self::validate_amount(fee_credits, fee_record, true)?, - None => (fee_credits as u64) * 1_000_000, + None => (fee_credits * 1_000_000.0) as u64, }; let mut new_process; diff --git a/wasm/src/programs/manager/join.rs b/wasm/src/programs/manager/join.rs index bfe77e24f..0e766d838 100644 --- a/wasm/src/programs/manager/join.rs +++ b/wasm/src/programs/manager/join.rs @@ -71,7 +71,7 @@ impl ProgramManager { log("Executing join program"); let fee_microcredits = match &fee_record { Some(fee_record) => Self::validate_amount(fee_credits, fee_record, true)?, - None => (fee_credits as u64) * 1_000_000, + None => (fee_credits * 1_000_000.0) as u64, }; let rng = &mut StdRng::from_entropy(); diff --git a/wasm/src/programs/manager/transfer.rs b/wasm/src/programs/manager/transfer.rs index 10e2f61c9..443c6bdb4 100644 --- a/wasm/src/programs/manager/transfer.rs +++ b/wasm/src/programs/manager/transfer.rs @@ -76,11 +76,11 @@ impl ProgramManager { log("Executing transfer program"); let fee_microcredits = match &fee_record { Some(fee_record) => Self::validate_amount(fee_credits, fee_record, true)?, - None => (fee_credits as u64) * 1_000_000, + None => (fee_credits * 1_000_000.0) as u64, }; let amount_microcredits = match &amount_record { Some(amount_record) => Self::validate_amount(amount_credits, amount_record, true)?, - None => (fee_credits as u64) * 1_000_000, + None => (amount_credits * 1_000_000.0) as u64, }; log("Setup the program and inputs"); diff --git a/wasm/src/thread_pool/mod.rs b/wasm/src/thread_pool/mod.rs index 8e2098a80..f7965c271 100644 --- a/wasm/src/thread_pool/mod.rs +++ b/wasm/src/thread_pool/mod.rs @@ -14,13 +14,12 @@ // You should have received a copy of the GNU General Public License // along with the Aleo SDK library. If not, see . -use wasm_bindgen::prelude::*; -use wasm_bindgen_futures::JsFuture; -use rayon::ThreadBuilder; use futures::future::try_join_all; +use rayon::ThreadBuilder; +use spmc::{channel, Receiver, Sender}; use std::future::Future; -use spmc::{channel, Sender, Receiver}; - +use wasm_bindgen::prelude::*; +use wasm_bindgen_futures::JsFuture; #[wasm_bindgen(inline_js = r###" export function spawnWorker(url, module, memory, address) { @@ -54,7 +53,6 @@ extern "C" { ) -> js_sys::Promise; } - async fn spawn_workers(url: web_sys::Url, num_threads: usize) -> Result, JsValue> { let module = wasm_bindgen::module(); let memory = wasm_bindgen::memory(); @@ -63,9 +61,8 @@ async fn spawn_workers(url: web_sys::Url, num_threads: usize) -> Result Resul let pool; if num_threads == 1 { - pool = rayon::ThreadPoolBuilder::new() - .num_threads(1) - .use_current_thread() - .build() - .unwrap_throw(); - + pool = rayon::ThreadPoolBuilder::new().num_threads(1).use_current_thread().build().unwrap_throw(); } else { let mut sender = spawn_workers(url, num_threads).await?; @@ -102,12 +94,7 @@ async fn spawn_local_thread_pool(url: web_sys::Url, num_threads: usize) -> Resul async fn spawn_global_thread_pool(url: web_sys::Url, num_threads: usize) -> Result<(), JsValue> { if num_threads == 1 { - rayon::ThreadPoolBuilder::new() - .num_threads(1) - .use_current_thread() - .build_global() - .unwrap_throw(); - + rayon::ThreadPoolBuilder::new().num_threads(1).use_current_thread().build_global().unwrap_throw(); } else { let mut sender = spawn_workers(url, num_threads).await?; @@ -124,7 +111,6 @@ async fn spawn_global_thread_pool(url: web_sys::Url, num_threads: usize) -> Resu Ok(()) } - pub struct ThreadPool { url: Option, num_threads: Option, @@ -132,10 +118,7 @@ pub struct ThreadPool { impl ThreadPool { pub fn builder() -> Self { - Self { - url: None, - num_threads: None, - } + Self { url: None, num_threads: None } } pub fn url(mut self, url: web_sys::Url) -> Self { @@ -151,7 +134,6 @@ impl ThreadPool { fn defaults(self) -> (web_sys::Url, usize) { ( self.url.expect("Missing url for ThreadPool"), - self.num_threads.unwrap_or_else(|| { let window: web_sys::Window = js_sys::global().unchecked_into(); window.navigator().hardware_concurrency() as usize @@ -171,9 +153,12 @@ impl ThreadPool { } } - #[wasm_bindgen(js_name = initializeWorker)] -pub fn initialize_worker(receiver: *const Receiver) where Receiver: Sync { +#[allow(clippy::not_unsafe_ptr_arg_deref)] +pub fn initialize_worker(receiver: *const Receiver) +where + Receiver: Sync, +{ // This is safe because it uses `Box::leak` so the Receiver lives forever let receiver = unsafe { &*receiver }; receiver.recv().unwrap_throw().run(); diff --git a/website/package-lock.json b/website/package-lock.json index aa55002c4..6109a27e3 100644 --- a/website/package-lock.json +++ b/website/package-lock.json @@ -8,7 +8,7 @@ "name": "aleo-website", "version": "0.1.0", "dependencies": { - "@aleohq/sdk": "0.5.11", + "@aleohq/sdk": "0.5.12", "@ant-design/icons": "^4.4.0", "@codemirror/language": "^6.8.0", "@codemirror/legacy-modes": "^6.3.3", @@ -59,17 +59,17 @@ } }, "node_modules/@aleohq/nodejs": { - "version": "0.5.10", - "resolved": "https://registry.npmjs.org/@aleohq/nodejs/-/nodejs-0.5.10.tgz", - "integrity": "sha512-hfSn8yHAn3HwA2/xSuovXo/3yhnYH0OqDd8Z/q/R6gLBWu2CKfjGY6BZ7CpLaThWM5lczsdEui/mULHJjHAQ1Q==" + "version": "0.5.12", + "resolved": "https://registry.npmjs.org/@aleohq/nodejs/-/nodejs-0.5.12.tgz", + "integrity": "sha512-i+mc7N2GnnRypQa4ouhLdIQgCemDVx6EV6cq7OMbFCzFcy4Pa58oJBY/xLJ0kLBLkJv1nPzDrv1yKDw+55RsKQ==" }, "node_modules/@aleohq/sdk": { - "version": "0.5.11", - "resolved": "https://registry.npmjs.org/@aleohq/sdk/-/sdk-0.5.11.tgz", - "integrity": "sha512-4Go5Eg7beRC0vXkQZiIAi0xbHk3MO0GhCiLpMXBtFlkgZFcDY2Hb/DxOR/JOUYJOpRtDS3Ft8CbOg9XgrWUFPA==", + "version": "0.5.12", + "resolved": "https://registry.npmjs.org/@aleohq/sdk/-/sdk-0.5.12.tgz", + "integrity": "sha512-nzkSGeBfx8OEBJKkPHw4gLrjOWCmrkMw9gxifgE22ydk5zcCen/3ru0bEF3iIthFGWQjR7QWxD8RIb9v5KV01A==", "dependencies": { - "@aleohq/nodejs": "0.5.10", - "@aleohq/wasm": "0.5.10", + "@aleohq/nodejs": "0.5.12", + "@aleohq/wasm": "0.5.12", "axios": "^1.1.3", "comlink": "^4.4.1", "jsdoc": "^3.6.11", @@ -77,9 +77,9 @@ } }, "node_modules/@aleohq/wasm": { - "version": "0.5.10", - "resolved": "https://registry.npmjs.org/@aleohq/wasm/-/wasm-0.5.10.tgz", - "integrity": "sha512-3e7hEudk54NwpGl0A7Kr+/LlMfFyJivOrRu+HgDw9rFnat+p20cSv/sWACTbmAd+p9DUFs+Xk/CpxDPXp/zt3Q==" + "version": "0.5.12", + "resolved": "https://registry.npmjs.org/@aleohq/wasm/-/wasm-0.5.12.tgz", + "integrity": "sha512-vpNlbAiVq/C+0At4BWaXVeDdrOuf0iRTACZpf0SD/czDYGxwQV0nmQaheCOFyfn6Ef4aMb3DckqGataPg947yA==" }, "node_modules/@ampproject/remapping": { "version": "2.2.1", diff --git a/website/package.json b/website/package.json index 2f65c7b76..d86bdcd4e 100644 --- a/website/package.json +++ b/website/package.json @@ -13,7 +13,7 @@ "preview": "vite preview" }, "dependencies": { - "@aleohq/sdk": "0.5.11", + "@aleohq/sdk": "0.5.12", "@ant-design/icons": "^4.4.0", "@codemirror/language": "^6.8.0", "@codemirror/legacy-modes": "^6.3.3", diff --git a/website/src/tabs/develop/Deploy.jsx b/website/src/tabs/develop/Deploy.jsx index b2ba8588c..be2a5e420 100644 --- a/website/src/tabs/develop/Deploy.jsx +++ b/website/src/tabs/develop/Deploy.jsx @@ -19,7 +19,7 @@ export const Deploy = () => { const [form] = Form.useForm(); const [deploymentFeeRecord, setDeploymentFeeRecord] = useState(null); - const [deployUrl, setDeployUrl] = useState("https://vm.aleo.org/api"); + const [deployUrl, setDeployUrl] = useState("https://api.explorer.aleo.org/v1"); const [deploymentFee, setDeploymentFee] = useState("1"); const [loading, setLoading] = useState(false); const [feeLoading, setFeeLoading] = useState(false); diff --git a/website/src/tabs/develop/ExecuteLegacy.jsx b/website/src/tabs/develop/ExecuteLegacy.jsx index 6df59e29f..455ffde7a 100644 --- a/website/src/tabs/develop/ExecuteLegacy.jsx +++ b/website/src/tabs/develop/ExecuteLegacy.jsx @@ -19,7 +19,7 @@ import { useAleoWASM } from "../../aleo-wasm-hook"; export const ExecuteLegacy = () => { const [executionFeeRecord, setExecutionFeeRecord] = useState(null); - const [executeUrl, setExecuteUrl] = useState("https://vm.aleo.org/api"); + const [executeUrl, setExecuteUrl] = useState("https://api.explorer.aleo.org/v1"); const [functionID, setFunctionID] = useState(null); const [executionFee, setExecutionFee] = useState("1"); const [inputs, setInputs] = useState(null); diff --git a/website/src/tabs/develop/Join.jsx b/website/src/tabs/develop/Join.jsx index e9e2b74af..67767a520 100644 --- a/website/src/tabs/develop/Join.jsx +++ b/website/src/tabs/develop/Join.jsx @@ -6,7 +6,7 @@ export const Join = () => { const [joinFeeRecord, setJoinFeeRecord] = useState(null); const [recordOne, setRecordOne] = useState(null); const [recordTwo, setRecordTwo] = useState(null); - const [joinUrl, setJoinUrl] = useState("https://vm.aleo.org/api"); + const [joinUrl, setJoinUrl] = useState("https://api.explorer.aleo.org/v1"); const [joinFee, setJoinFee] = useState("1.0"); const [privateFee, setPrivateFee] = useState(true); const [loading, setLoading] = useState(false); diff --git a/website/src/tabs/develop/Split.jsx b/website/src/tabs/develop/Split.jsx index 4ccbd379f..fb5cc9157 100644 --- a/website/src/tabs/develop/Split.jsx +++ b/website/src/tabs/develop/Split.jsx @@ -4,7 +4,7 @@ import axios from "axios"; export const Split = () => { const [amountRecord, setAmountRecord] = useState(null); - const [splitUrl, setSplitUrl] = useState("https://vm.aleo.org/api"); + const [splitUrl, setSplitUrl] = useState("https://api.explorer.aleo.org/v1"); const [splitAmount, setSplitAmount] = useState("1.0"); const [loading, setLoading] = useState(false); const [privateKey, setPrivateKey] = useState(null); diff --git a/website/src/tabs/develop/Transfer.jsx b/website/src/tabs/develop/Transfer.jsx index 834006e97..c3f49e982 100644 --- a/website/src/tabs/develop/Transfer.jsx +++ b/website/src/tabs/develop/Transfer.jsx @@ -6,7 +6,7 @@ import axios from "axios"; export const Transfer = () => { const [transferFeeRecord, setTransferFeeRecord] = useState(null); const [amountRecord, setAmountRecord] = useState(null); - const [transferUrl, setTransferUrl] = useState("https://vm.aleo.org/api"); + const [transferUrl, setTransferUrl] = useState("https://api.explorer.aleo.org/v1"); const [transferAmount, setTransferAmount] = useState("1.0"); const [transferFee, setTransferFee] = useState("1.0"); const [privateFee, setPrivateFee] = useState(true); diff --git a/website/src/tabs/develop/execute/index.jsx b/website/src/tabs/develop/execute/index.jsx index 14c848596..d5ecee87a 100644 --- a/website/src/tabs/develop/execute/index.jsx +++ b/website/src/tabs/develop/execute/index.jsx @@ -335,7 +335,7 @@ export const Execute = () => {