Skip to content

Commit

Permalink
Change UtxoTransactionUtil to BitcoinTransactionUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
10gic committed Sep 2, 2024
1 parent 1f1ee33 commit 1c96dd4
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
1 change: 0 additions & 1 deletion rust/frameworks/tw_utxo/src/modules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ pub mod fee_estimator;
pub mod keys_manager;
pub mod sighash_computer;
pub mod sighash_verifier;
pub mod transaction_util;
pub mod tx_compiler;
pub mod tx_planner;
pub mod tx_signer;
Expand Down
6 changes: 3 additions & 3 deletions rust/tw_bitcoin/src/entry.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::modules::compiler::BitcoinCompiler;
use crate::modules::planner::BitcoinPlanner;
use crate::modules::signer::BitcoinSigner;
use crate::modules::transaction_util::BitcoinTransactionUtil;
use std::str::FromStr;
use tw_coin_entry::coin_context::CoinContext;
use tw_coin_entry::coin_entry::{CoinEntry, PublicKeyBytes, SignatureBytes};
Expand All @@ -13,7 +14,6 @@ use tw_coin_entry::modules::wallet_connector::NoWalletConnector;
use tw_keypair::tw::PublicKey;
use tw_proto::BitcoinV2::Proto;
use tw_utxo::address::standard_bitcoin::{StandardBitcoinAddress, StandardBitcoinPrefix};
use tw_utxo::modules::transaction_util::UtxoTransactionUtil;

pub struct BitcoinEntry;

Expand All @@ -30,7 +30,7 @@ impl CoinEntry for BitcoinEntry {
type MessageSigner = NoMessageSigner;
type WalletConnector = NoWalletConnector;
type TransactionDecoder = NoTransactionDecoder;
type TransactionUtil = UtxoTransactionUtil;
type TransactionUtil = BitcoinTransactionUtil;

#[inline]
fn parse_address(
Expand Down Expand Up @@ -94,6 +94,6 @@ impl CoinEntry for BitcoinEntry {

#[inline]
fn transaction_util(&self) -> Option<Self::TransactionUtil> {
Some(UtxoTransactionUtil)
Some(BitcoinTransactionUtil)
}
}
1 change: 1 addition & 0 deletions rust/tw_bitcoin/src/modules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ pub mod planner;
pub mod protobuf_builder;
pub mod signer;
pub mod signing_request;
pub mod transaction_util;
pub mod tx_builder;
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,19 @@ use tw_coin_entry::error::prelude::*;
use tw_coin_entry::modules::transaction_util::TransactionUtil;
use tw_encoding::hex::decode;

pub struct UtxoTransactionUtil;
pub struct BitcoinTransactionUtil;

impl TransactionUtil for UtxoTransactionUtil {
impl TransactionUtil for BitcoinTransactionUtil {
fn calc_tx_hash(&self, coin: &dyn CoinContext, encoded_tx: &str) -> SigningResult<String> {
Self::calc_tx_hash_impl(coin, encoded_tx)
}
}

impl UtxoTransactionUtil {
impl BitcoinTransactionUtil {
fn calc_tx_hash_impl(_coin: &dyn CoinContext, encoded_tx: &str) -> SigningResult<String> {
let tx = decode(encoded_tx).map_err(|_| SigningErrorType::Error_input_parse)?;

// Deserialize the transaction
// Note: The following deserialization only works for Bitcoin, Dogecoin, Litecoin, Bitcoin Cash, etc.
// However, it does not work for Zcash or Verge. So, we need to implement a custom calc_tx_hash_impl for Zcash and Verge.
let tx: Transaction = deserialize(&tx).map_err(|_| SigningErrorType::Error_input_parse)?;

// Calculate the transaction ID
Expand Down

0 comments on commit 1c96dd4

Please sign in to comment.