Skip to content

Commit

Permalink
Merge pull request #23 from KasarLabs/net/service
Browse files Browse the repository at this point in the history
correcting syntax errors
  • Loading branch information
eytanlvy authored Aug 28, 2023
2 parents ee2fe93 + ef33cac commit 0f4f3ef
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/client/data-availability/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ celestia-types = { git = "https://github.com/eigerco/celestia-node-rs" }
bitcoin = "0.30.1"
bitcoincore-rpc = "0.17.0"
hex = "0.4.2"
bitcoin-da = { git = "https://github.com/KasarLabs/da" }
bitcoin-da = { git = "https://github.com/KasarLabs/da", branch = "bitcoin-da/prod" }

26 changes: 11 additions & 15 deletions crates/client/data-availability/src/bitcoin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ use bitcoin_da::Config as BitcoinDAConfig;
// Witness};
use bitcoin_da::Relayer;
use bitcoincore_rpc::bitcoincore_rpc_json::{GetTransactionResultDetailCategory, ListTransactionResult};
use bitcoincore_rpc::Client as RpcClient;
// Bitcoincore RPC imports
use bitcoincore_rpc::{Auth, Error, RpcApi};
use bitcoincore_rpc::RpcApi;
use ethers::types::{I256, U256};

use crate::utils::is_valid_http_endpoint;
Expand Down Expand Up @@ -54,28 +53,27 @@ impl DaClient for BitcoinClient {
}

async fn last_published_state(&self) -> Result<I256> {
let last_tx = self.relayer.client.list_transactions("*", 15, None, true)?;
let last_tx = self.relayer.client.list_transactions(Some("*"), Some(15), None, Some(true))?;

let filtered_txs: Vec<&ListTransactionResult> =
let mut filtered_txs: Vec<&ListTransactionResult> =
last_tx.iter().filter(|tx| tx.detail.category == GetTransactionResultDetailCategory::Send).collect();
filtered_txs.sort_by(|a, b| a.info.blockheight.cmp(&b.info.blockheight));
let most_recent_tx = filtered_txs.last();
let most_recent_block_hash = match most_recent_tx.map_or(None, |tx| tx.info.blockhash) {
None => return Err(anyhow::anyhow!("No transactions found")),
Some(hash) => hash,
};
let txid = match most_recent_tx.map_or(None, |tx| tx.info.txid) {
let txid = match most_recent_tx {
None => return Err(anyhow::anyhow!("No transactions found")),
Some(hash) => hash,
Some(tx) => Some(tx.info.txid),
};

let last_data_raw = match last_tx {
Some(tx) => self
.relayer
.read_transaction(txid, most_recent_block_hash)
.map_err(|e| anyhow::anyhow!("bitcoin read err: {e}"))?,

let last_data_raw = match most_recent_tx {
Some(tx) => self.relayer.read_transaction(&tx.info.txid, Some(&most_recent_block_hash))
.map_err(|e| anyhow::anyhow!("bitcoin read err: {e}"))?,
None => return Err(anyhow::anyhow!("No transactions found")),
};

// change to rollup height
Ok(I256::from(1))
}
Expand All @@ -95,12 +93,10 @@ impl BitcoinClient {
host: conf.host,
user: conf.user,
pass: conf.pass,
http_post_mode: false,
disable_tls: false,
};

let client: Relayer =
Relayer::new_relayer(&bitcoin_da_conf).map_err(|e| format!("bitcoin new relayer err: {e}"))?;
Relayer::new(&bitcoin_da_conf).map_err(|e| format!("bitcoin new relayer err: {e}"))?;

Ok(Self { relayer: client, mode: conf.mode })
}
Expand Down

0 comments on commit 0f4f3ef

Please sign in to comment.