Skip to content

Commit

Permalink
Added from_json to wasm bindigns for ErgoBox / UnsignedTransaction
Browse files Browse the repository at this point in the history
  • Loading branch information
rooooooooob committed Jan 6, 2021
1 parent fb70d6b commit b5b2edd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions bindings/ergo-lib-wasm/src/ergo_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ impl ErgoBox {
pub fn to_json(&self) -> Result<JsValue, JsValue> {
JsValue::from_serde(&self.0.clone()).map_err(|e| JsValue::from_str(&format!("{}", e)))
}

/// JSON representation
pub fn from_json(json: &str) -> Result<ErgoBox, JsValue> {
serde_json::from_str(json)
.map(Self)
.map_err(|e| JsValue::from_str(&format!("{}", e)))
}
}

impl From<ErgoBox> for chain::ergo_box::ErgoBox {
Expand Down
7 changes: 7 additions & 0 deletions bindings/ergo-lib-wasm/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ impl UnsignedTransaction {
pub fn to_json(&self) -> Result<JsValue, JsValue> {
JsValue::from_serde(&self.0.clone()).map_err(|e| JsValue::from_str(&format!("{}", e)))
}

/// JSON representation
pub fn from_json(json: &str) -> Result<UnsignedTransaction, JsValue> {
serde_json::from_str(json)
.map(Self)
.map_err(|e| JsValue::from_str(&format!("{}", e)))
}
}

impl From<chain::transaction::unsigned::UnsignedTransaction> for UnsignedTransaction {
Expand Down

0 comments on commit b5b2edd

Please sign in to comment.