-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(wasm): modularize wasm crate logic (#3432)
* update wasm npm publish script * add LTO flag * add bin folder to npm package * migrated 'build_action' to dedicated file * clippy and fmt * simplified 'build_action' wasm method * removed unused imports to pass CI * fmt transaction package * addressing gabe's comments * reverting NPM package changes
- Loading branch information
Showing
11 changed files
with
85 additions
and
141 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
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
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
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
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
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
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 |
---|---|---|
|
@@ -30,4 +30,4 @@ TARGETS.forEach(target => { | |
|
||
// Change working directory back to parent | ||
process.chdir('..'); | ||
}); | ||
}); |
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,45 @@ | ||
use crate::error::WasmResult; | ||
use std::str::FromStr; | ||
use wasm_bindgen::prelude::wasm_bindgen; | ||
use wasm_bindgen::JsValue; | ||
|
||
use crate::utils; | ||
use penumbra_keys::FullViewingKey; | ||
use penumbra_transaction::{ | ||
plan::{ActionPlan, TransactionPlan}, | ||
WitnessData, | ||
}; | ||
|
||
/// Builds a planned [`Action`] specified by | ||
/// the [`ActionPlan`] in a [`TransactionPlan`]. | ||
/// Arguments: | ||
/// transaction_plan: `TransactionPlan` | ||
/// action_plan: `ActionPlan` | ||
/// full_viewing_key: `bech32m String`, | ||
/// witness_data: `WitnessData`` | ||
/// Returns: `Action` | ||
#[wasm_bindgen] | ||
pub fn build_action( | ||
transaction_plan: JsValue, | ||
action_plan: JsValue, | ||
full_viewing_key: &str, | ||
witness_data: JsValue, | ||
) -> WasmResult<JsValue> { | ||
utils::set_panic_hook(); | ||
|
||
let transaction_plan: TransactionPlan = | ||
serde_wasm_bindgen::from_value(transaction_plan.clone())?; | ||
|
||
let witness: WitnessData = serde_wasm_bindgen::from_value(witness_data)?; | ||
|
||
let action_plan: ActionPlan = serde_wasm_bindgen::from_value(action_plan)?; | ||
|
||
let full_viewing_key: FullViewingKey = FullViewingKey::from_str(full_viewing_key)?; | ||
|
||
let memo_key = transaction_plan.memo_plan.map(|memo_plan| memo_plan.key); | ||
|
||
let action = ActionPlan::build_unauth(action_plan, &full_viewing_key, &witness, memo_key)?; | ||
|
||
let result = serde_wasm_bindgen::to_value(&action)?; | ||
Ok(result) | ||
} |
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,6 +1,7 @@ | ||
#![allow(dead_code)] | ||
extern crate core; | ||
|
||
pub mod build; | ||
pub mod error; | ||
pub mod keys; | ||
pub mod note_record; | ||
|
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
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