Skip to content

Commit

Permalink
fix: can't fetch asset transaction for chain asset lock proof
Browse files Browse the repository at this point in the history
  • Loading branch information
shumkov committed Oct 28, 2023
1 parent b53e1f8 commit dfa80fd
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use crate::error::execution::ExecutionError;
use crate::error::Error;
use crate::rpc::core::{CoreRPCLike, CORE_RPC_INVALID_ADDRESS_OR_KEY};
use dashcore_rpc::dashcore_rpc_json::GetTransactionResult;
use crate::rpc::core::CoreRPCLike;
use dpp::consensus::basic::identity::{
IdentityAssetLockTransactionIsNotFoundError, IdentityAssetLockTransactionOutputNotFoundError,
InvalidAssetLockProofTransactionHeightError,
};
use dpp::dashcore::secp256k1::ThirtyTwoByteHash;
use dpp::dashcore::transaction::special_transaction::TransactionPayload;
use dpp::dashcore::{TxOut, Txid};
use dpp::dashcore::TxOut;
use dpp::identity::state_transition::asset_lock_proof::validate_asset_lock_transaction_structure::validate_asset_lock_transaction_structure;
use dpp::prelude::{AssetLockProof, ConsensusValidationResult};
use dpp::validation::ValidationResult;
Expand Down Expand Up @@ -37,8 +36,15 @@ pub fn fetch_asset_lock_transaction_output_sync_v0<C: CoreRPCLike>(

// Fetch transaction

let Some(transaction_info) = fetch_transaction_info(core_rpc, &transaction_hash)?
else {
let maybe_transaction_info = core_rpc
.get_optional_transaction_extended_info(&transaction_hash)
.map_err(|e| {
Error::Execution(ExecutionError::DashCoreBadResponseError(format!(
"can't fetch asset transaction for chain asset lock proof: {e}",
)))
})?;

let Some(transaction_info) = maybe_transaction_info else {
// Transaction hash bytes needs to be reversed to match actual transaction hash
let mut hash = transaction_hash.as_raw_hash().into_32();
hash.reverse();
Expand All @@ -50,7 +56,7 @@ pub fn fetch_asset_lock_transaction_output_sync_v0<C: CoreRPCLike>(

// Make sure transaction is mined on the chain locked block or before

let Some(transaction_height) = transaction_info.blockindex else {
let Some(transaction_height) = transaction_info.height else {
return Ok(ConsensusValidationResult::new_with_error(
InvalidAssetLockProofTransactionHeightError::new(
proof.core_chain_locked_height,
Expand Down Expand Up @@ -106,22 +112,3 @@ pub fn fetch_asset_lock_transaction_output_sync_v0<C: CoreRPCLike>(
}
}
}

fn fetch_transaction_info<C: CoreRPCLike>(
core_rpc: &C,
transaction_id: &Txid,
) -> Result<Option<GetTransactionResult>, Error> {
match core_rpc.get_transaction_extended_info(transaction_id) {
Ok(transaction) => Ok(Some(transaction)),
// Return None if transaction with specified tx id is not present
Err(dashcore_rpc::Error::JsonRpc(dashcore_rpc::jsonrpc::error::Error::Rpc(
dashcore_rpc::jsonrpc::error::RpcError {
code: CORE_RPC_INVALID_ADDRESS_OR_KEY,
..
},
))) => Ok(None),
Err(e) => Err(Error::Execution(ExecutionError::DashCoreBadResponseError(
format!("can't fetch asset lock transaction for chain asset lock proof: {e}",),
))),
}
}
31 changes: 27 additions & 4 deletions packages/rs-drive-abci/src/rpc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use dashcore_rpc::dashcore_rpc_json::{
GetTransactionLockedResult, MasternodeListDiff, MnSyncStatus, QuorumInfoResult, QuorumType,
SoftforkInfo,
};
use dashcore_rpc::json::GetTransactionResult;
use dashcore_rpc::json::GetRawTransactionResult;
use dashcore_rpc::{Auth, Client, Error, RpcApi};
use dpp::dashcore::{hashes::Hash, InstantLock};
use serde_json::Value;
Expand Down Expand Up @@ -37,7 +37,27 @@ pub trait CoreRPCLike {
) -> Result<Vec<GetTransactionLockedResult>, Error>;

/// Get transaction
fn get_transaction_extended_info(&self, tx_id: &Txid) -> Result<GetTransactionResult, Error>;
fn get_transaction_extended_info(&self, tx_id: &Txid)
-> Result<GetRawTransactionResult, Error>;

/// Get optional transaction extended info
/// Returns None if transaction doesn't exists
fn get_optional_transaction_extended_info(
&self,
transaction_id: &Txid,
) -> Result<Option<GetRawTransactionResult>, Error> {
match self.get_transaction_extended_info(transaction_id) {
Ok(transaction_info) => Ok(Some(transaction_info)),
// Return None if transaction with specified tx id is not present
Err(Error::JsonRpc(dashcore_rpc::jsonrpc::error::Error::Rpc(
dashcore_rpc::jsonrpc::error::RpcError {
code: CORE_RPC_INVALID_ADDRESS_OR_KEY,
..
},
))) => Ok(None),
Err(e) => Err(e),
}
}

/// Get block by hash
fn get_fork_info(&self, name: &str) -> Result<Option<SoftforkInfo>, Error>;
Expand Down Expand Up @@ -208,8 +228,11 @@ impl CoreRPCLike for DefaultCoreRPC {
retry!(self.inner.get_transaction_are_locked(&tx_ids))
}

fn get_transaction_extended_info(&self, tx_id: &Txid) -> Result<GetTransactionResult, Error> {
retry!(self.inner.get_transaction(tx_id, None))
fn get_transaction_extended_info(
&self,
tx_id: &Txid,
) -> Result<GetRawTransactionResult, Error> {
retry!(self.inner.get_raw_transaction_info(tx_id, None))
}

fn get_fork_info(&self, name: &str) -> Result<Option<SoftforkInfo>, Error> {
Expand Down

0 comments on commit dfa80fd

Please sign in to comment.