-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f4efbe7
commit 06ac188
Showing
10 changed files
with
140 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ members = [ | |
"bitcoin.ordinals", | ||
"sx.stats", | ||
"blocks", | ||
"bitcoin.txo", | ||
] | ||
|
||
[workspace.dependencies] | ||
|
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,20 @@ | ||
[package] | ||
name = "bitcoin_txo" | ||
version = "0.1.0" | ||
authors = ["Yaro <[email protected]>"] | ||
description = "Bitcoin TXOs" | ||
license = "MIT OR Apache-2.0" | ||
edition = "2021" | ||
publish = false | ||
|
||
[badges] | ||
maintenance = { status = "actively-developed" } | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
substreams-bitcoin = { workspace = true } | ||
substreams = { workspace = true } | ||
prost = { workspace = true } | ||
prost-types = { workspace = true } |
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,34 @@ | ||
.PHONY: all | ||
all: | ||
make build | ||
make pack | ||
make graph | ||
make info | ||
|
||
.PHONY: build | ||
build: | ||
AR=/usr/local/opt/llvm/bin/llvm-ar CC=/usr/local/opt/llvm/bin/clang cargo build --target wasm32-unknown-unknown --release | ||
|
||
.PHONY: protogen | ||
protogen: | ||
substreams protogen --exclude-paths sf/substreams,google | ||
|
||
.PHONY: pack | ||
pack: | ||
substreams pack | ||
|
||
.PHONY: graph | ||
graph: | ||
substreams graph | ||
|
||
.PHONY: info | ||
info: | ||
substreams info | ||
|
||
.PHONY: run | ||
run: | ||
substreams run -e bitcoin.substreams.pinax.network:443 map_txo -s 1 -t +100 | ||
|
||
.PHONY: gui | ||
gui: | ||
substreams gui -e bitcoin.substreams.pinax.network:443 map_txo -s 1 -t +100 |
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,5 @@ | ||
# Bitcoin TXOs Substream | ||
|
||
> Bitcoin TXO counter | ||
## Usage |
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,5 @@ | ||
syntax = "proto3"; | ||
|
||
package bitcoin.txo; | ||
|
||
message Txo { int64 txo_count = 1; } |
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,25 @@ | ||
use pb::bitcoin::txo::Txo; | ||
use substreams::{ | ||
errors::Error, | ||
store::{StoreAddInt64, StoreGetInt64}, | ||
}; | ||
use substreams::{log, prelude::*}; | ||
use substreams_bitcoin::pb::btc::v1::Block; | ||
|
||
mod pb; | ||
|
||
#[substreams::handlers::store] | ||
pub fn store_txo(block: Block, s: StoreAddInt64) { | ||
log::info!("txs: {}", block.transactions().count()); | ||
for (i, tx) in block.transactions().enumerate() { | ||
log::info!("txos: {}", tx.vout.len()); | ||
s.add(i as u64, "txo", tx.vout.len() as i64); | ||
} | ||
} | ||
|
||
#[substreams::handlers::map] | ||
pub fn map_txo(txo_store: StoreGetInt64) -> Result<Txo, Error> { | ||
let txo_count = txo_store.get_last("txo").unwrap(); | ||
log::info!("txo_count: {}", txo_count); | ||
Ok(Txo { txo_count }) | ||
} |
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,8 @@ | ||
// @generated | ||
#[allow(clippy::derive_partial_eq_without_eq)] | ||
#[derive(Clone, PartialEq, ::prost::Message)] | ||
pub struct Txo { | ||
#[prost(int64, tag="1")] | ||
pub txo_count: i64, | ||
} | ||
// @@protoc_insertion_point(module) |
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,8 @@ | ||
// @generated | ||
pub mod bitcoin { | ||
// @@protoc_insertion_point(attribute:bitcoin.txo) | ||
pub mod txo { | ||
include!("bitcoin.txo.rs"); | ||
// @@protoc_insertion_point(bitcoin.txo) | ||
} | ||
} |
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,33 @@ | ||
specVersion: v0.1.0 | ||
package: | ||
name: bitcoin_txo | ||
version: v0.1.0 | ||
url: https://github.com/pinax-network/substreams | ||
doc: Bitcoin TXOs | ||
|
||
binaries: | ||
default: | ||
type: wasm/rust-v1 | ||
file: ../target/wasm32-unknown-unknown/release/bitcoin_txo.wasm | ||
|
||
protobuf: | ||
files: | ||
- bitcoin.txo.proto | ||
importPaths: | ||
- ./proto | ||
|
||
modules: | ||
- name: store_txo | ||
kind: store | ||
inputs: | ||
- source: sf.bitcoin.type.v1.Block | ||
valueType: int64 | ||
updatePolicy: add | ||
|
||
- name: map_txo | ||
kind: map | ||
inputs: | ||
- store: store_txo | ||
mode: get | ||
output: | ||
type: proto:bitcoin.txo |