Skip to content

Commit

Permalink
Codegen: substreams-database-change to v1.3, generate primary key to …
Browse files Browse the repository at this point in the history
…support chain reorgs in postgres sink.
  • Loading branch information
sduchesneau committed Nov 6, 2023
1 parent ce69aa4 commit 627bf91
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 130 deletions.
40 changes: 20 additions & 20 deletions codegen/templates/ethereum/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion codegen/templates/ethereum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ prost = "0.11"
prost-types = "0.11"
substreams = "0.5"
substreams-ethereum = "0.9"
substreams-database-change = "1"
substreams-database-change = "1.3"
substreams-entity-change = "1"

# Required so that ethabi > ethereum-types build correctly under wasm32-unknown-unknown
Expand Down
16 changes: 4 additions & 12 deletions codegen/templates/ethereum/results/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ fn db_out(events: contract::Events) -> Result<DatabaseChanges, substreams::error
// Loop over all the abis events to create changes
events.approvals.into_iter().for_each(|evt| {
tables
.create_row("approval", format!("{}-{}", evt.evt_tx_hash, evt.evt_index))
.set("evt_tx_hash", evt.evt_tx_hash)
.set("evt_index", evt.evt_index)
.create_row("approval", [("evt_tx_hash", evt.evt_tx_hash),("evt_index", evt.evt_index.to_string())])
.set("evt_block_time", evt.evt_block_time.unwrap())
.set("evt_block_number", evt.evt_block_number)
.set("approved", Hex(&evt.approved).to_string())
Expand All @@ -131,9 +129,7 @@ fn db_out(events: contract::Events) -> Result<DatabaseChanges, substreams::error
});
events.approval_for_alls.into_iter().for_each(|evt| {
tables
.create_row("approval_for_all", format!("{}-{}", evt.evt_tx_hash, evt.evt_index))
.set("evt_tx_hash", evt.evt_tx_hash)
.set("evt_index", evt.evt_index)
.create_row("approval_for_all", [("evt_tx_hash", evt.evt_tx_hash),("evt_index", evt.evt_index.to_string())])
.set("evt_block_time", evt.evt_block_time.unwrap())
.set("evt_block_number", evt.evt_block_number)
.set("approved", evt.approved)
Expand All @@ -142,19 +138,15 @@ fn db_out(events: contract::Events) -> Result<DatabaseChanges, substreams::error
});
events.ownership_transferreds.into_iter().for_each(|evt| {
tables
.create_row("ownership_transferred", format!("{}-{}", evt.evt_tx_hash, evt.evt_index))
.set("evt_tx_hash", evt.evt_tx_hash)
.set("evt_index", evt.evt_index)
.create_row("ownership_transferred", [("evt_tx_hash", evt.evt_tx_hash),("evt_index", evt.evt_index.to_string())])
.set("evt_block_time", evt.evt_block_time.unwrap())
.set("evt_block_number", evt.evt_block_number)
.set("new_owner", Hex(&evt.new_owner).to_string())
.set("previous_owner", Hex(&evt.previous_owner).to_string());
});
events.transfers.into_iter().for_each(|evt| {
tables
.create_row("transfer", format!("{}-{}", evt.evt_tx_hash, evt.evt_index))
.set("evt_tx_hash", evt.evt_tx_hash)
.set("evt_index", evt.evt_index)
.create_row("transfer", [("evt_tx_hash", evt.evt_tx_hash),("evt_index", evt.evt_index.to_string())])
.set("evt_block_time", evt.evt_block_time.unwrap())
.set("evt_block_number", evt.evt_block_number)
.set("from", Hex(&evt.from).to_string())
Expand Down
55 changes: 37 additions & 18 deletions codegen/templates/ethereum/results/multiple_contracts/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ CREATE TABLE IF NOT EXISTS moonbird_approval (
"evt_block_number" DECIMAL,
"approved" VARCHAR(40),
"owner" VARCHAR(40),
"token_id" DECIMAL
"token_id" DECIMAL,
PRIMARY KEY(evt_tx_hash,evt_index)
);
CREATE TABLE IF NOT EXISTS moonbird_approval_for_all (
"evt_tx_hash" VARCHAR(64),
Expand All @@ -14,44 +15,50 @@ CREATE TABLE IF NOT EXISTS moonbird_approval_for_all (
"evt_block_number" DECIMAL,
"approved" BOOL,
"operator" VARCHAR(40),
"owner" VARCHAR(40)
"owner" VARCHAR(40),
PRIMARY KEY(evt_tx_hash,evt_index)
);
CREATE TABLE IF NOT EXISTS moonbird_expelled (
"evt_tx_hash" VARCHAR(64),
"evt_index" INT,
"evt_block_time" TIMESTAMP,
"evt_block_number" DECIMAL,
"token_id" DECIMAL
"token_id" DECIMAL,
PRIMARY KEY(evt_tx_hash,evt_index)
);
CREATE TABLE IF NOT EXISTS moonbird_nested (
"evt_tx_hash" VARCHAR(64),
"evt_index" INT,
"evt_block_time" TIMESTAMP,
"evt_block_number" DECIMAL,
"token_id" DECIMAL
"token_id" DECIMAL,
PRIMARY KEY(evt_tx_hash,evt_index)
);
CREATE TABLE IF NOT EXISTS moonbird_ownership_transferred (
"evt_tx_hash" VARCHAR(64),
"evt_index" INT,
"evt_block_time" TIMESTAMP,
"evt_block_number" DECIMAL,
"new_owner" VARCHAR(40),
"previous_owner" VARCHAR(40)
"previous_owner" VARCHAR(40),
PRIMARY KEY(evt_tx_hash,evt_index)
);
CREATE TABLE IF NOT EXISTS moonbird_paused (
"evt_tx_hash" VARCHAR(64),
"evt_index" INT,
"evt_block_time" TIMESTAMP,
"evt_block_number" DECIMAL,
"account" VARCHAR(40)
"account" VARCHAR(40),
PRIMARY KEY(evt_tx_hash,evt_index)
);
CREATE TABLE IF NOT EXISTS moonbird_refund (
"evt_tx_hash" VARCHAR(64),
"evt_index" INT,
"evt_block_time" TIMESTAMP,
"evt_block_number" DECIMAL,
"amount" DECIMAL,
"buyer" VARCHAR(40)
"buyer" VARCHAR(40),
PRIMARY KEY(evt_tx_hash,evt_index)
);
CREATE TABLE IF NOT EXISTS moonbird_revenue (
"evt_tx_hash" VARCHAR(64),
Expand All @@ -60,7 +67,8 @@ CREATE TABLE IF NOT EXISTS moonbird_revenue (
"evt_block_number" DECIMAL,
"amount" DECIMAL,
"beneficiary" VARCHAR(40),
"num_purchased" DECIMAL
"num_purchased" DECIMAL,
PRIMARY KEY(evt_tx_hash,evt_index)
);
CREATE TABLE IF NOT EXISTS moonbird_role_admin_changed (
"evt_tx_hash" VARCHAR(64),
Expand All @@ -69,7 +77,8 @@ CREATE TABLE IF NOT EXISTS moonbird_role_admin_changed (
"evt_block_number" DECIMAL,
"new_admin_role" TEXT,
"previous_admin_role" TEXT,
"role" TEXT
"role" TEXT,
PRIMARY KEY(evt_tx_hash,evt_index)
);
CREATE TABLE IF NOT EXISTS moonbird_role_granted (
"evt_tx_hash" VARCHAR(64),
Expand All @@ -78,7 +87,8 @@ CREATE TABLE IF NOT EXISTS moonbird_role_granted (
"evt_block_number" DECIMAL,
"account" VARCHAR(40),
"role" TEXT,
"sender" VARCHAR(40)
"sender" VARCHAR(40),
PRIMARY KEY(evt_tx_hash,evt_index)
);
CREATE TABLE IF NOT EXISTS moonbird_role_revoked (
"evt_tx_hash" VARCHAR(64),
Expand All @@ -87,7 +97,8 @@ CREATE TABLE IF NOT EXISTS moonbird_role_revoked (
"evt_block_number" DECIMAL,
"account" VARCHAR(40),
"role" TEXT,
"sender" VARCHAR(40)
"sender" VARCHAR(40),
PRIMARY KEY(evt_tx_hash,evt_index)
);
CREATE TABLE IF NOT EXISTS moonbird_transfer (
"evt_tx_hash" VARCHAR(64),
Expand All @@ -96,21 +107,24 @@ CREATE TABLE IF NOT EXISTS moonbird_transfer (
"evt_block_number" DECIMAL,
"from" VARCHAR(40),
"to" VARCHAR(40),
"token_id" DECIMAL
"token_id" DECIMAL,
PRIMARY KEY(evt_tx_hash,evt_index)
);
CREATE TABLE IF NOT EXISTS moonbird_unnested (
"evt_tx_hash" VARCHAR(64),
"evt_index" INT,
"evt_block_time" TIMESTAMP,
"evt_block_number" DECIMAL,
"token_id" DECIMAL
"token_id" DECIMAL,
PRIMARY KEY(evt_tx_hash,evt_index)
);
CREATE TABLE IF NOT EXISTS moonbird_unpaused (
"evt_tx_hash" VARCHAR(64),
"evt_index" INT,
"evt_block_time" TIMESTAMP,
"evt_block_number" DECIMAL,
"account" VARCHAR(40)
"account" VARCHAR(40),
PRIMARY KEY(evt_tx_hash,evt_index)
);
CREATE TABLE IF NOT EXISTS bayc_approval (
"evt_tx_hash" VARCHAR(64),
Expand All @@ -119,7 +133,8 @@ CREATE TABLE IF NOT EXISTS bayc_approval (
"evt_block_number" DECIMAL,
"approved" VARCHAR(40),
"owner" VARCHAR(40),
"token_id" DECIMAL
"token_id" DECIMAL,
PRIMARY KEY(evt_tx_hash,evt_index)
);
CREATE TABLE IF NOT EXISTS bayc_approval_for_all (
"evt_tx_hash" VARCHAR(64),
Expand All @@ -128,15 +143,17 @@ CREATE TABLE IF NOT EXISTS bayc_approval_for_all (
"evt_block_number" DECIMAL,
"approved" BOOL,
"operator" VARCHAR(40),
"owner" VARCHAR(40)
"owner" VARCHAR(40),
PRIMARY KEY(evt_tx_hash,evt_index)
);
CREATE TABLE IF NOT EXISTS bayc_ownership_transferred (
"evt_tx_hash" VARCHAR(64),
"evt_index" INT,
"evt_block_time" TIMESTAMP,
"evt_block_number" DECIMAL,
"new_owner" VARCHAR(40),
"previous_owner" VARCHAR(40)
"previous_owner" VARCHAR(40),
PRIMARY KEY(evt_tx_hash,evt_index)
);
CREATE TABLE IF NOT EXISTS bayc_transfer (
"evt_tx_hash" VARCHAR(64),
Expand All @@ -145,5 +162,7 @@ CREATE TABLE IF NOT EXISTS bayc_transfer (
"evt_block_number" DECIMAL,
"from" VARCHAR(40),
"to" VARCHAR(40),
"token_id" DECIMAL
"token_id" DECIMAL,
PRIMARY KEY(evt_tx_hash,evt_index)
);

Loading

0 comments on commit 627bf91

Please sign in to comment.