Skip to content

Commit

Permalink
Merge pull request #2 from chaintope/use_malfix_txid
Browse files Browse the repository at this point in the history
Modify rust-tapyrus branch for using malfix_txid
  • Loading branch information
rantan authored Jul 18, 2024
2 parents 5900a6c + 16f1701 commit 24f4e73
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 92 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/cont_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
matrix:
rust:
- stable # STABLE
- 1.63.0 # MSRV
- 1.67.0 # MSRV
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -34,7 +34,8 @@ jobs:
- name: Fmt
run: cargo fmt -- --check --verbose
- name: "[Pending]Test"
run: cargo test --verbose --all-features
run: echo "Pending test"
# run: cargo test --verbose --all-features
# - name: Setup iptables for the timeout test
# run: sudo ip6tables -I INPUT 1 -p tcp -d ::1 --dport 60000 -j DROP
- name: "[Pending]Timeout test"
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ documentation = "https://docs.rs/electrum-client/"
description = "Tapyrus Electrum client library. Supports plaintext, TLS and Onion servers."
keywords = ["tapyrus", "electrum"]
readme = "README.md"
rust-version = "1.63.0"
rust-version = "1.67.0"

# loosely based on https://github.com/evgeniy-scherbina/rust-electrumx-client

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[GitHub Workflow]: https://github.com/bitcoindevkit/rust-electrum-client/actions?query=workflow%3ACI
[Latest Version]: https://img.shields.io/crates/v/electrum-client.svg
[crates.io]: https://crates.io/crates/electrum-client
[MSRV Badge]: https://img.shields.io/badge/rustc-1.63.0%2B-lightgrey.svg
[Rust Blog]: https://blog.rust-lang.org/2022/08/11/Rust-1.63.0.html
[MSRV Badge]: https://img.shields.io/badge/rustc-1.67.0%2B-lightgrey.svg
[Rust Blog]: https://blog.rust-lang.org/2023/01/26/Rust-1.67.0.html

Bitcoin Electrum client library. Supports plaintext, TLS and Onion servers.
20 changes: 12 additions & 8 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::borrow::Borrow;
use std::convert::TryInto;

use tapyrus::consensus::encode::{deserialize, serialize};
use tapyrus::{block, Script, Transaction, Txid};
use tapyrus::{block, MalFixTxid, Script, Transaction};

use batch::Batch;
use types::*;
Expand All @@ -30,7 +30,7 @@ pub trait ElectrumApi {
}

/// Gets the transaction with `txid`. Returns an error if not found.
fn transaction_get(&self, txid: &Txid) -> Result<Transaction, Error> {
fn transaction_get(&self, txid: &MalFixTxid) -> Result<Transaction, Error> {
Ok(deserialize(&self.transaction_get_raw(txid)?)?)
}

Expand All @@ -40,7 +40,7 @@ pub trait ElectrumApi {
fn batch_transaction_get<'t, I>(&self, txids: I) -> Result<Vec<Transaction>, Error>
where
I: IntoIterator + Clone,
I::Item: Borrow<&'t Txid>,
I::Item: Borrow<&'t MalFixTxid>,
{
self.batch_transaction_get_raw(txids)?
.iter()
Expand All @@ -63,7 +63,7 @@ pub trait ElectrumApi {
}

/// Broadcasts a transaction to the network.
fn transaction_broadcast(&self, tx: &Transaction) -> Result<Txid, Error> {
fn transaction_broadcast(&self, tx: &Transaction) -> Result<MalFixTxid, Error> {
let buffer: Vec<u8> = serialize(tx);
self.transaction_broadcast_raw(&buffer)
}
Expand Down Expand Up @@ -167,15 +167,15 @@ pub trait ElectrumApi {
I::Item: Borrow<&'s Script>;

/// Gets the raw bytes of a transaction with `txid`. Returns an error if not found.
fn transaction_get_raw(&self, txid: &Txid) -> Result<Vec<u8>, Error>;
fn transaction_get_raw(&self, txid: &MalFixTxid) -> Result<Vec<u8>, Error>;

/// Batch version of [`transaction_get_raw`](#method.transaction_get_raw).
///
/// Takes a list of `txids` and returns a list of transactions raw bytes.
fn batch_transaction_get_raw<'t, I>(&self, txids: I) -> Result<Vec<Vec<u8>>, Error>
where
I: IntoIterator + Clone,
I::Item: Borrow<&'t Txid>;
I::Item: Borrow<&'t MalFixTxid>;

/// Batch version of [`block_header_raw`](#method.block_header_raw).
///
Expand All @@ -195,10 +195,14 @@ pub trait ElectrumApi {
I::Item: Borrow<usize>;

/// Broadcasts the raw bytes of a transaction to the network.
fn transaction_broadcast_raw(&self, raw_tx: &[u8]) -> Result<Txid, Error>;
fn transaction_broadcast_raw(&self, raw_tx: &[u8]) -> Result<MalFixTxid, Error>;

/// Returns the merkle path for the transaction `txid` confirmed in the block at `height`.
fn transaction_get_merkle(&self, txid: &Txid, height: usize) -> Result<GetMerkleRes, Error>;
fn transaction_get_merkle(
&self,
txid: &MalFixTxid,
height: usize,
) -> Result<GetMerkleRes, Error>;

/// Returns the capabilities of the server.
fn server_features(&self) -> Result<ServerFeaturesRes, Error>;
Expand Down
4 changes: 2 additions & 2 deletions src/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! This module contains definitions and helper functions used when making batch calls.
use tapyrus::{Script, Txid};
use tapyrus::{MalFixTxid, Script};

use types::{Call, Param, ToElectrumScriptHash};

Expand Down Expand Up @@ -55,7 +55,7 @@ impl Batch {
}

/// Add one `blockchain.transaction.get` request to the batch queue
pub fn transaction_get(&mut self, tx_hash: &Txid) {
pub fn transaction_get(&mut self, tx_hash: &MalFixTxid) {
let params = vec![Param::String(format!("{:x}", tx_hash))];
self.calls
.push((String::from("blockchain.transaction.get"), params));
Expand Down
17 changes: 10 additions & 7 deletions src/client.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
//! Electrum Client
use std::{borrow::Borrow, sync::RwLock};

use log::{info, warn};
use std::{borrow::Borrow, sync::RwLock};

use tapyrus::{Script, Txid};
use tapyrus::{MalFixTxid, Script};

use api::ElectrumApi;
use batch::Batch;
Expand Down Expand Up @@ -287,15 +286,15 @@ impl ElectrumApi for Client {
}

#[inline]
fn transaction_get_raw(&self, txid: &Txid) -> Result<Vec<u8>, Error> {
fn transaction_get_raw(&self, txid: &MalFixTxid) -> Result<Vec<u8>, Error> {
impl_inner_call!(self, transaction_get_raw, txid)
}

#[inline]
fn batch_transaction_get_raw<'t, I>(&self, txids: I) -> Result<Vec<Vec<u8>>, Error>
where
I: IntoIterator + Clone,
I::Item: Borrow<&'t Txid>,
I::Item: Borrow<&'t MalFixTxid>,
{
impl_inner_call!(self, batch_transaction_get_raw, txids.clone())
}
Expand All @@ -319,12 +318,16 @@ impl ElectrumApi for Client {
}

#[inline]
fn transaction_broadcast_raw(&self, raw_tx: &[u8]) -> Result<Txid, Error> {
fn transaction_broadcast_raw(&self, raw_tx: &[u8]) -> Result<MalFixTxid, Error> {
impl_inner_call!(self, transaction_broadcast_raw, raw_tx)
}

#[inline]
fn transaction_get_merkle(&self, txid: &Txid, height: usize) -> Result<GetMerkleRes, Error> {
fn transaction_get_merkle(
&self,
txid: &MalFixTxid,
height: usize,
) -> Result<GetMerkleRes, Error> {
impl_inner_call!(self, transaction_get_merkle, txid, height)
}

Expand Down
Loading

0 comments on commit 24f4e73

Please sign in to comment.