Skip to content

Commit

Permalink
add support for MapCreate burn
Browse files Browse the repository at this point in the history
  • Loading branch information
billettc committed Sep 3, 2024
1 parent 1919367 commit 9ec0f52
Show file tree
Hide file tree
Showing 6 changed files with 229 additions and 115 deletions.
303 changes: 190 additions & 113 deletions data/pb/hivemapper/v1/hivemapper.pb.go

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions data/psql.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,26 @@ func (p *Psql) HandleRewardPayments(dbBlockID int64, payments []*pb.RewardPaymen

return nil
}
func (p *Psql) HandleMapCreate(dbBlockID int64, payments []*pb.MapCreate) error {
for _, payment := range payments {
dbTransactionID, err := p.handleTransaction(dbBlockID, payment.Burn.TrxHash)
if err != nil {
return fmt.Errorf("inserting transaction: %w", err)
}

burnDbID, err := p.insertBurns(dbTransactionID, payment.Burn)
if err != nil {
return fmt.Errorf("inserting mint: %w", err)
}

_, err = p.tx.Exec("INSERT INTO hivemapper.map_create (burn_id) VALUES ($1) RETURNING id", burnDbID)
if err != nil {
return fmt.Errorf("inserting reward_payments: %w", err)
}
}

return nil
}

func (p *Psql) insertBurns(dbTransactionID int64, burn *pb.Burn) (dbMintID int64, err error) {
row := p.tx.QueryRow("INSERT INTO hivemapper.burns (transaction_id, from_address, amount) VALUES ($1, $2, $3) RETURNING id", dbTransactionID, burn.From, burn.Amount)
Expand Down
4 changes: 4 additions & 0 deletions data/sinker.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ func (s *Sinker) HandleBlockScopedData(ctx context.Context, data *pbsubstreamsrp
return fmt.Errorf("handle HandleRewardPayments: %w", err)
}

if err := s.db.HandleMapCreate(dbBlockID, moduleOutput.MapCreate); err != nil {
return fmt.Errorf("handle HandleMapCreate: %w", err)
}

if err := s.db.HandleSplitPayments(dbBlockID, moduleOutput.TokenSplittingPayments); err != nil {
return fmt.Errorf("handle split payments: %w", err)
}
Expand Down
6 changes: 6 additions & 0 deletions data/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ CREATE TABLE IF NOT EXISTS hivemapper.payments (
CONSTRAINT fk_mint FOREIGN KEY (mint_id) REFERENCES hivemapper.mints(id)
);
CREATE TABLE IF NOT EXISTS hivemapper.map_create (
id SERIAL PRIMARY KEY,
burn_id INTEGER NOT NULL,
CONSTRAINT fk_mint FOREIGN KEY (burn_id) REFERENCES hivemapper.burns(id)
);
CREATE TABLE IF NOT EXISTS hivemapper.ai_payments (
id SERIAL PRIMARY KEY,
mint_id INTEGER NOT NULL,
Expand Down
7 changes: 7 additions & 0 deletions dbt/hivemapper/models/example/dbt_mint_per_month.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{ config(materialized='table') }}

select DATE_TRUNC('month', b.timestamp) as month, COALESCE(SUM(br.amount), 0) as total
from hivemapper.mints br
inner join hivemapper.transactions t on t.id = br.transaction_id
inner join hivemapper.blocks b on b.id = t.block_id
group by DATE_TRUNC('month', b.timestamp)
4 changes: 2 additions & 2 deletions proto/buf.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ deps:
- remote: buf.build
owner: streamingfast
repository: hivemapper
commit: 0acc9cdb55ff4ac9970272514acc3ebc
digest: shake256:2d67b2a28df875fccfdd0c4db36971be72ccbaa4c889932618f9550c2129e3a355f1099bc29c2952e7e83d0dc8afcaa741785f84d1055400b1e045a4da5db332
commit: 9eceba3b1aa44864aa4e9d415dec10e2
digest: shake256:2d49d9e45b354fc3020053c30537f44e59160b688a62bcbef6fb13d03e8893aaeac155b596e31afd81486e863f06406792bf3208e26b6b4cef96a96b15c97b5e

0 comments on commit 9ec0f52

Please sign in to comment.