Skip to content

Commit

Permalink
update Subgraphs
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisCarriere committed Feb 27, 2025
1 parent 77ea18d commit 8eda220
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 43 deletions.
3 changes: 3 additions & 0 deletions subgraphs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
## Quickstart

> ... TO-DO ...
Timestamp support has been added in v0.36.0
https://github.com/graphprotocol/graph-node/releases/tag/v0.36.0
20 changes: 1 addition & 19 deletions subgraphs/schema.graphql
Original file line number Diff line number Diff line change
@@ -1,31 +1,14 @@
type BalanceChange @entity {
type Balance @entity {
id: ID!

# -- block --
block_num: Int!
block_hash: String!
timestamp: Timestamp!
date: String!

# -- transaction --
transaction_id: String!

# -- balance change --
contract: String!
owner: String!
old_balance: Int!
new_balance: Int!
}

type Balance @entity {
id: ID!

# -- block --
block_num: Int!
block_hash: String!
timestamp: Timestamp!
date: String!

# -- current balance --
contract: String!
owner: String!
Expand All @@ -37,7 +20,6 @@ type Transfer @entity {

# -- block --
block_num: Int!
block_hash: String!
timestamp: Timestamp!
date: String!

Expand Down
26 changes: 2 additions & 24 deletions subgraphs/src/graph_out.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,14 @@ pub fn graph_out(events: Events) -> Result<EntityChanges, Error> {
let mut tables = substreams_entity_change::tables::Tables::new();

for balance_change in events.balance_changes {
tables
.create_row(
"BalanceChange",
format!("{}:{}", &balance_change.block_num, &balance_change.storage_ordinal),
)
// -- block --
.set_bigint("block_num", &balance_change.block_num.to_string())
.set("block_hash", &balance_change.block_hash)
// Timestamp support has been added in v0.36.0
// https://github.com/graphprotocol/graph-node/releases/tag/v0.36.0
.set("timestamp", balance_change.timestamp.expect("missing timestamp"))
.set("date", &balance_change.date)

// -- transaction --
.set("transaction_id", &balance_change.transaction_id)

// -- balance change --
.set("contract", &balance_change.contract)
.set("owner", &balance_change.owner)
.set_bigint("old_balance", &balance_change.old_balance)
.set_bigint("new_balance", &balance_change.new_balance);

tables
.create_row("Balance", format!("{}:{}", balance_change.contract, balance_change.owner))
// -- block --
.set_bigint("block_num", &balance_change.block_num.to_string())
.set("block_hash", &balance_change.block_hash)
.set("timestamp", balance_change.timestamp.expect("missing timestamp"))
.set("date", balance_change.date)
// -- transaction --
.set("transaction_id", balance_change.transaction_id)
// -- current balance --
.set("contract", balance_change.contract)
.set("owner", balance_change.owner)
Expand All @@ -47,7 +26,6 @@ pub fn graph_out(events: Events) -> Result<EntityChanges, Error> {
.create_row("Transfer", format!("{}:{}", transfer.block_num, transfer.log_block_index))
// -- block --
.set_bigint("block_num", &transfer.block_num.to_string())
.set("block_hash", transfer.block_hash)
.set("timestamp", transfer.timestamp.expect("missing timestamp"))
.set("date", transfer.date)
// -- transaction --
Expand Down

0 comments on commit 8eda220

Please sign in to comment.