Skip to content

Commit

Permalink
Added get_firehose_block_by_hash and changed default confirm blocks t…
Browse files Browse the repository at this point in the history
…o 50
  • Loading branch information
chamorin committed Feb 21, 2024
1 parent 61a3e53 commit 7efcdb0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ FLAGS:
OPTIONS:
-B, --batch-blocks <batch-blocks> how many blocks polling at one time [default: 20]
-b, --block-time <block-time> time cost for producing a new block in arweave [default: 20000]
-c, --confirms <confirms> safe blocks against to reorg in polling [default: 20]
-c, --confirms <confirms> safe blocks against to reorg in polling [default: 50]
-e, --endpoints <endpoints>... client endpoints [default: https://arweave.net/]
-p, --ptr-path <ptr-path> block ptr file path
-r, --retry <retry> retry times when failed on http requests [default: 10]
Expand All @@ -41,7 +41,7 @@ OPTIONS:
|---------------|--------------------------|---------------------------------------------|
| ENDPOINTS | `"https://arweave.net"` | for multiple endpoints, split them with ',' |
| BATCH\_BLOCKS | `50` | how many blocks batch at one time |
| CONFIRMS | `20` | irreversibility condition |
| CONFIRMS | `50` | irreversibility condition |
| PTR\_PATH | `$APP_DATA/thegarii/ptr` | the file stores the block ptr for polling |
| retry | `10` | retry times when failed on http requests |
| timeout | `120_000` | timeout of http requests |
Expand Down
32 changes: 32 additions & 0 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,38 @@ impl Client {
Ok(firehose_block)
}

/// get and parse firehose blocks by hash
///
/// ```rust
/// let client = thegarii::Client::from_env().unwrap();
/// let rt = tokio::runtime::Runtime::new().unwrap();
///
/// { // block hash 5H-hJycMS_PnPOpobXu2CNobRlgqmw4yEMQSc5LeBfS7We63l8HjS-Ek3QaxK8ug - https://arweave.net/block/hash/5H-hJycMS_PnPOpobXu2CNobRlgqmw4yEMQSc5LeBfS7We63l8HjS-Ek3QaxK8ug
/// let firehose_block = rt.block_on(client.get_firehose_block_by_hash("5H-hJycMS_PnPOpobXu2CNobRlgqmw4yEMQSc5LeBfS7We63l8HjS-Ek3QaxK8ug")).unwrap();
///
/// let mut block_without_txs = firehose_block.clone();
/// block_without_txs.txs = vec![];
///
/// assert_eq!(block_without_txs, rt.block_on(client.get_block_by_hash("5H-hJycMS_PnPOpobXu2CNobRlgqmw4yEMQSc5LeBfS7We63l8HjS-Ek3QaxK8ug")).unwrap().into());
/// for (idx, tx) in firehose_block.txs.iter().map(|tx| tx.id.clone()).enumerate() {
/// assert_eq!(firehose_block.txs[idx], rt.block_on(client.get_tx_by_id(&tx)).unwrap());
/// }
/// }
/// ```
pub async fn get_firehose_block_by_hash(&self, hash: &str) -> Result<FirehoseBlock> {
log::info!("resolving firehose block {}", hash);

let block = self.get_block_by_hash(hash).await?;
let txs: Vec<Transaction> = join_all(block.txs.iter().map(|tx| self.get_tx_by_id(tx)))
.await
.into_iter()
.collect::<Result<Vec<Transaction>>>()?;

let mut firehose_block: FirehoseBlock = block.into();
firehose_block.txs = txs;
Ok(firehose_block)
}

/// poll blocks from iterator
///
/// ```rust
Expand Down
4 changes: 2 additions & 2 deletions src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const DEFAULT_BATCH_BLOCKS: u16 = 50;
const RETRY: &str = "RETRY";
const DEFAULT_RETRY: u8 = 10;
const CONFIRMS: &str = "CONFIRMS";
const DEFAULT_CONFIRMS: u64 = 20;
const DEFAULT_CONFIRMS: u64 = 50;
const TIMEOUT: &str = "TIMEOUT";
const DEFAULT_TIMEOUT: u64 = 120_000;
const PTR_FILE: &str = "PTR_FILE";
Expand All @@ -31,7 +31,7 @@ pub struct EnvArguments {
#[structopt(short, long, default_value = "60000")]
pub block_time: u64,
/// safe blocks against to reorg in polling
#[structopt(short, long, default_value = "20")]
#[structopt(short, long, default_value = "50")]
pub confirms: u64,
/// client endpoints
#[structopt(short, long, default_value = "https://arweave.net/")]
Expand Down

0 comments on commit 7efcdb0

Please sign in to comment.