Skip to content

Commit

Permalink
add map_unknown_balance_changes to help with future debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
colindickson committed Aug 28, 2023
1 parent 70862e8 commit 28aa522
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 3 deletions.
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,30 @@ As of block 18005744, the sum of type 1 and type 2 matches accounts for approxim
"validRate": "0.9671385488303694890529305171717793142603506581308747872905614795055919001005685856860791544131205324",
"blockNumber": "18005744"
}
```
```

## Running

### Generate protos

```bash
make protogen
```

### Build substreams

```bash
make build
```

### Build spkg

```bash
make pack
```

### Example run

```bash
substreams gui ./erc20-balance-changes-v0.0.4.spkg map_valid_balance_changes -e mainnet.eth.streamingfast.io:443 -s 17000000 -t +10 --production-mode
```
11 changes: 11 additions & 0 deletions proto/v1/erc20.proto
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ message ValidBalanceChange {
string transaction = 5;
}

message UnknownBalanceChanges {
repeated UnknownBalanceChange unknown_balance_changes = 1;
}

message UnknownBalanceChange {
string contract = 1;
string owner = 2;
string transaction = 3;
uint32 call_index = 4;
string transfer_value = 5;
}


message BalanceChangeStats {
Expand Down
24 changes: 23 additions & 1 deletion src/maps.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::abi::{self};
use crate::pb::erc20::types::v1::{BalanceChange, BalanceChangeType, BalanceChanges, BalanceChangeStats, ValidBalanceChange, ValidBalanceChanges};
use crate::pb::erc20::types::v1::{BalanceChange, BalanceChangeType, BalanceChanges, BalanceChangeStats, ValidBalanceChange, ValidBalanceChanges, UnknownBalanceChanges, UnknownBalanceChange};
use abi::erc20::events::Transfer;
use hex_literal::hex;
use std::collections::HashMap;
Expand All @@ -22,6 +22,28 @@ pub fn map_balance_changes(block: Block) -> Result<BalanceChanges, Error> {
})
}

#[substreams::handlers::map]
pub fn map_unknown_balance_changes(balance_changes: BalanceChanges) -> Result<UnknownBalanceChanges, Error> {
let mut out = Vec::new();
for change in balance_changes.balance_changes {
if change.change_type != BalanceChangeType::TypeUnknown as i32 {
continue;
}

out.push(UnknownBalanceChange{
contract: change.contract,
owner: change.owner,
transaction: change.transaction,
call_index: change.call_index,
transfer_value: change.transfer_value,
})
}

Ok(UnknownBalanceChanges {
unknown_balance_changes: out,
})
}

#[substreams::handlers::map]
pub fn map_valid_balance_changes(balance_changes: BalanceChanges) -> Result<ValidBalanceChanges, Error> {
let mut out = Vec::new();
Expand Down
20 changes: 20 additions & 0 deletions src/pb/erc20.types.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,26 @@ pub struct ValidBalanceChange {
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct UnknownBalanceChanges {
#[prost(message, repeated, tag="1")]
pub unknown_balance_changes: ::prost::alloc::vec::Vec<UnknownBalanceChange>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct UnknownBalanceChange {
#[prost(string, tag="1")]
pub contract: ::prost::alloc::string::String,
#[prost(string, tag="2")]
pub owner: ::prost::alloc::string::String,
#[prost(string, tag="3")]
pub transaction: ::prost::alloc::string::String,
#[prost(uint32, tag="4")]
pub call_index: u32,
#[prost(string, tag="5")]
pub transfer_value: ::prost::alloc::string::String,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct BalanceChangeStats {
#[prost(uint64, tag="1")]
pub type0_count: u64,
Expand Down
10 changes: 9 additions & 1 deletion substreams.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
specVersion: v0.1.0
package:
name: erc20_balance_changes
version: v0.0.4
version: v0.0.5
url: https://github.com/streamingfast/erc20-balance-changes
doc: ERC-20

Expand Down Expand Up @@ -39,6 +39,14 @@ modules:
output:
type: proto:erc20.types.v1.ValidBalanceChanges

- name: map_unknown_balance_changes
kind: map
initialBlock: 1397553
inputs:
- map: map_balance_changes
output:
type: proto:erc20.types.v1.UnknownBalanceChanges

- name: db_out
kind: map
inputs:
Expand Down

0 comments on commit 28aa522

Please sign in to comment.