Skip to content

Commit

Permalink
Merge pull request #3 from zianksm/refactor-error-signer
Browse files Browse the repository at this point in the history
added error propagating at tx builder
  • Loading branch information
zianksm authored Jun 13, 2023
2 parents 88388bc + c3f1dbe commit a454a7e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
9 changes: 7 additions & 2 deletions dhatu/src/error/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::{
registrar::key_manager::prelude::KeypairGenerationError,
tx::extrinsics::prelude::{reserve::FundsReserveError, CallbackExecutorError, calldata::ToPayloadError},
registrar::{key_manager::prelude::KeypairGenerationError, signer::TxBuilderError},
tx::extrinsics::prelude::{
calldata::ToPayloadError, reserve::FundsReserveError, CallbackExecutorError,
},
types::MandalaClientErorr,
};

Expand All @@ -26,4 +28,7 @@ pub enum Error {

#[error("error when converting to payload : {0}")]
PayloadError(#[from] ToPayloadError),

#[error("error when signing transaction : {0}")]
SignTransactionError(#[from] TxBuilderError),
}
10 changes: 8 additions & 2 deletions dhatu/src/registrar/signer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@ pub(crate) trait WrappedExtrinsic<T: EncodeAsFields> {

pub(crate) struct TxBuilder;

#[derive(thiserror::Error,Debug)]
pub enum TxBuilderError{
#[error("{0}")]
SignErorr(#[from] subxt::Error),
}

impl TxBuilder {
/// create a new unsigned transaction from a transaction payload
pub fn unsigned<T: EncodeAsFields>(
client: &crate::types::NodeClient,
payload: impl WrappedExtrinsic<T>,
) -> Result<Extrinsic, Box<dyn std::error::Error>> {
) -> Result<Extrinsic, crate::error::Error> {
Ok(client.tx().create_unsigned(&payload.into_inner())?)
}

Expand All @@ -30,7 +36,7 @@ impl TxBuilder {
client: &crate::types::NodeClient,
acc: Pair,
payload: impl WrappedExtrinsic<T>,
) -> Result<Extrinsic, Box<dyn std::error::Error>> {
) -> Result<Extrinsic, crate::error::Error> {
let signer = PairSigner::new(acc);

let tx = client
Expand Down

0 comments on commit a454a7e

Please sign in to comment.