forked from kaspanet/rusty-kaspa
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactorize some addresses and Script related parts (#61)
* Refactorize some addresses and Script related parts * A ScriptBuilder example on TypeScript * addOps Opcodes are now BinaryT * Move txscript bindings to relevant folders * Sort lines of deps and imports * Lint
- Loading branch information
Showing
15 changed files
with
371 additions
and
212 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
use crate::script_builder; | ||
use thiserror::Error; | ||
use wasm_bindgen::{JsError, JsValue}; | ||
use workflow_wasm::jserror::JsErrorData; | ||
|
||
#[derive(Debug, Error, Clone)] | ||
pub enum Error { | ||
#[error("{0}")] | ||
Custom(String), | ||
|
||
#[error(transparent)] | ||
JsValue(JsErrorData), | ||
|
||
#[error(transparent)] | ||
Wasm(#[from] workflow_wasm::error::Error), | ||
|
||
#[error(transparent)] | ||
ScriptBuilder(#[from] script_builder::ScriptBuilderError), | ||
|
||
#[error("{0}")] | ||
ParseInt(#[from] std::num::ParseIntError), | ||
|
||
#[error(transparent)] | ||
SerdeWasmBindgen(JsErrorData), | ||
|
||
#[error(transparent)] | ||
NetworkType(#[from] kaspa_consensus_core::network::NetworkTypeError), | ||
|
||
#[error("Error converting property `{0}`: {1}")] | ||
Convert(&'static str, String), | ||
|
||
#[error("Error processing JSON: {0}")] | ||
SerdeJson(String), | ||
} | ||
|
||
impl Error { | ||
pub fn custom<T: Into<String>>(msg: T) -> Self { | ||
Error::Custom(msg.into()) | ||
} | ||
|
||
pub fn convert<S: std::fmt::Display>(prop: &'static str, msg: S) -> Self { | ||
Self::Convert(prop, msg.to_string()) | ||
} | ||
} | ||
|
||
impl From<String> for Error { | ||
fn from(err: String) -> Self { | ||
Self::Custom(err) | ||
} | ||
} | ||
|
||
impl From<&str> for Error { | ||
fn from(err: &str) -> Self { | ||
Self::Custom(err.to_string()) | ||
} | ||
} | ||
|
||
impl From<Error> for JsValue { | ||
fn from(value: Error) -> Self { | ||
match value { | ||
Error::JsValue(js_error_data) => js_error_data.into(), | ||
_ => JsValue::from(value.to_string()), | ||
} | ||
} | ||
} | ||
|
||
impl From<JsValue> for Error { | ||
fn from(err: JsValue) -> Self { | ||
Self::JsValue(err.into()) | ||
} | ||
} | ||
|
||
impl From<JsError> for Error { | ||
fn from(err: JsError) -> Self { | ||
Self::JsValue(err.into()) | ||
} | ||
} | ||
|
||
impl From<serde_json::Error> for Error { | ||
fn from(err: serde_json::Error) -> Self { | ||
Self::SerdeJson(err.to_string()) | ||
} | ||
} | ||
|
||
impl From<serde_wasm_bindgen::Error> for Error { | ||
fn from(err: serde_wasm_bindgen::Error) -> Self { | ||
Self::SerdeWasmBindgen(JsValue::from(err).into()) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
pub type Result<T, E = super::error::Error> = std::result::Result<T, E>; |
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
Oops, something went wrong.