Skip to content

Commit

Permalink
Check transaction on submit
Browse files Browse the repository at this point in the history
  • Loading branch information
OBorce committed Jan 26, 2024
1 parent cb872b0 commit 43c3ce8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
22 changes: 13 additions & 9 deletions wallet/wallet-rpc-lib/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ mod interface;
mod server_impl;
pub mod types;

use chainstate::{ChainInfo, TokenIssuanceError};
use chainstate::{tx_verifier::check_transaction, ChainInfo, TokenIssuanceError};
use crypto::key::hdkd::u31::U31;
use mempool::tx_accumulator::PackingStrategy;
use mempool_types::tx_options::TxOptionsOverrides;
Expand Down Expand Up @@ -53,9 +53,9 @@ use crate::{service::CreatedWallet, WalletHandle, WalletRpcConfig};

pub use self::types::RpcError;
use self::types::{
AddressInfo, AddressWithUsageInfo, DelegationInfo, EmptyArgs, LegacyVrfPublicKeyInfo,
NewAccountInfo, NewDelegation, NewTransaction, PoolInfo, PublicKeyInfo, RpcTokenId,
StakingStatus, VrfPublicKeyInfo,
AddressInfo, AddressWithUsageInfo, DelegationInfo, LegacyVrfPublicKeyInfo, NewAccountInfo,
NewDelegation, NewTransaction, PoolInfo, PublicKeyInfo, RpcTokenId, StakingStatus,
VrfPublicKeyInfo,
};

#[derive(Clone)]
Expand Down Expand Up @@ -149,7 +149,7 @@ impl<N: NodeInterface + Clone + Send + Sync + 'static> WalletRpc<N> {
self.wallet.call(|w| w.lock_wallet()).await?
}

async fn best_block(&self, _: EmptyArgs) -> WRpcResult<BlockInfo, N> {
async fn best_block(&self) -> WRpcResult<BlockInfo, N> {
let res = self.wallet.call(|w| Ok::<_, RpcError<N>>(w.best_block())).await??;
Ok(BlockInfo::from_tuple(res))
}
Expand Down Expand Up @@ -340,10 +340,14 @@ impl<N: NodeInterface + Clone + Send + Sync + 'static> WalletRpc<N> {
tx: HexEncoded<SignedTransaction>,
options: TxOptionsOverrides,
) -> WRpcResult<(), N> {
self.node
.submit_transaction(tx.take(), options)
.await
.map_err(RpcError::RpcError)
let tx = tx.take();
let block_height = self.best_block().await?.height;
check_transaction(&self.chain_config, block_height, &tx).map_err(|err| {
RpcError::Controller(ControllerError::WalletError(
WalletError::InvalidTransaction(err),
))
})?;
self.node.submit_transaction(tx, options).await.map_err(RpcError::RpcError)
}

pub async fn sign_raw_transaction(
Expand Down
4 changes: 2 additions & 2 deletions wallet/wallet-rpc-lib/src/rpc/server_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ impl<N: NodeInterface + Clone + Send + Sync + 'static + Debug> WalletRpcServer f
rpc::handle_result(self.lock_private_keys().await)
}

async fn best_block(&self, empty_args: EmptyArgs) -> rpc::RpcResult<BlockInfo> {
rpc::handle_result(self.best_block(empty_args).await)
async fn best_block(&self, _empty_args: EmptyArgs) -> rpc::RpcResult<BlockInfo> {
rpc::handle_result(self.best_block().await)
}

async fn create_account(
Expand Down

0 comments on commit 43c3ce8

Please sign in to comment.