-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from lomasson/main
[dev]: Script to generate a test data
- Loading branch information
Showing
6 changed files
with
110 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
def block: | ||
" | ||
use raito::state::{Block, Header, Transaction, TxIn, TxOut}; | ||
pub fn test_data_block() -> Block { | ||
Block { | ||
header : Header { | ||
version: \(.version), | ||
prev_block_hash: 0x\(.previousblockhash), | ||
merkle_root_hash: 0x\(.merkle_root), | ||
time: \(.timestamp), | ||
bits: \(.bits), | ||
nonce: \(.nonce) | ||
}," | ||
|
||
; | ||
|
||
block |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#! /usr/bin/env bash | ||
|
||
destPath="./src/" | ||
tx_inJqPath="./scripts/data/tx_in.jq" | ||
tx_outJqPath="./scripts/data/tx_out.jq" | ||
blockJqPath="./scripts/data/block.jq" | ||
blockHash="" | ||
api="https://mempool.space/api/block/" | ||
|
||
if [ ! -z "$1" ]; then | ||
blockHash="$1" | ||
else | ||
read -p "Enter bitcoin block hash: " blockHash | ||
fi | ||
|
||
fileName="${destPath}block_$blockHash.cairo" | ||
|
||
|
||
# Recive informations | ||
btcBlock=$(curl -sSL "$api$blockHash") | ||
btcBlockTxs=$(curl -sSL "$api$blockHash/txs") | ||
|
||
#total transactions of the block | ||
tx_count=$(echo $btcBlock | jq -r ".tx_count") | ||
echo "Total of transactions: " $tx_count | ||
|
||
#Put the header block in file | ||
echo $btcBlock | jq -r -f $blockJqPath > $fileName | ||
echo " txs: array![" >> $fileName | ||
|
||
#declare at 1 for skipping the coinbase transaction | ||
idx=1 | ||
total=1 | ||
|
||
#Put transactions in file | ||
while (( $total < $tx_count )); do | ||
if (( $idx % 25 == 0)) then | ||
btcBlockTxs=$(curl -sSL "$api$blockHash/txs/$total") | ||
idx=0 | ||
echo "$total / $tx_count transactions recived" | ||
fi | ||
tx=$(echo $btcBlockTxs | jq -r ".[$idx]") | ||
echo " Transaction {" >> $fileName | ||
echo " version: $(echo $tx | jq -r ".version")," >> $fileName | ||
echo " lock_time: $(echo $tx | jq -r ".locktime")," >> $fileName | ||
echo " inputs: array![" >> $fileName | ||
echo $tx | jq -r ".vin[]" | jq -r -f $tx_inJqPath >> $fileName | ||
echo " ].span()," >> $fileName | ||
echo " outputs: array![" >> $fileName | ||
echo $tx | jq -r ".vout[]" | jq -r -f $tx_outJqPath >> $fileName | ||
echo " ].span()," >> $fileName | ||
echo " }," >> $fileName | ||
((idx++)) | ||
((total++)) | ||
done | ||
if (( $total == $tx_count)) then | ||
echo "$total / $tx_count transactions recived" | ||
echo "Execution successful, file created in $fileName" | ||
fi | ||
|
||
#end file | ||
echo " ].span()" >> $fileName | ||
echo " }" >> $fileName | ||
echo "}" >> $fileName | ||
echo "" | ||
echo -e "${green}add: \"pub mod block_$blockHash;\" in lib.cairo${reset}" | ||
echo -e "${green}add: \"use raito::block_$blockHash::test_data_block;\" in your file${reset}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
def tx_in: | ||
" TxIn { | ||
txid: 0x\(.txid), | ||
index: \(.vout), | ||
script: @\"\(.scriptsig)\", | ||
sequence: \(.sequence), | ||
}," | ||
; | ||
tx_in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
def tx_out: | ||
" TxOut { | ||
value : \(.value), | ||
pk_script: @\"\(.scriptpubkey)\", | ||
}," | ||
; | ||
tx_out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters