fix: insert correct contract address
* closes #7 every specific event now links to the contract address that emitted the event log.
This commit is contained in:
parent
5df4b89123
commit
1b4a43450f
@ -37,7 +37,6 @@ type (
|
||||
InsertPoolSwap string `query:"insert-pool-swap"`
|
||||
InsertPoolDeposit string `query:"insert-pool-deposit"`
|
||||
InsertPriceQuoteUpdate string `query:"insert-price-quote-update"`
|
||||
CheckAddressExists string `query:"address-exists"`
|
||||
}
|
||||
)
|
||||
|
||||
@ -87,6 +86,7 @@ func (pg *Pg) InsertTokenTransfer(ctx context.Context, eventPayload event.Event)
|
||||
eventPayload.Payload["from"].(string),
|
||||
eventPayload.Payload["to"].(string),
|
||||
eventPayload.Payload["value"].(string),
|
||||
eventPayload.ContractAddress,
|
||||
)
|
||||
return err
|
||||
})
|
||||
@ -106,6 +106,7 @@ func (pg *Pg) InsertTokenMint(ctx context.Context, eventPayload event.Event) err
|
||||
eventPayload.Payload["tokenMinter"].(string),
|
||||
eventPayload.Payload["to"].(string),
|
||||
eventPayload.Payload["value"].(string),
|
||||
eventPayload.ContractAddress,
|
||||
)
|
||||
return err
|
||||
})
|
||||
@ -124,6 +125,7 @@ func (pg *Pg) InsertTokenBurn(ctx context.Context, eventPayload event.Event) err
|
||||
txID,
|
||||
eventPayload.Payload["tokenBurner"].(string),
|
||||
eventPayload.Payload["value"].(string),
|
||||
eventPayload.ContractAddress,
|
||||
)
|
||||
return err
|
||||
})
|
||||
@ -143,6 +145,7 @@ func (pg *Pg) InsertFaucetGive(ctx context.Context, eventPayload event.Event) er
|
||||
eventPayload.Payload["token"].(string),
|
||||
eventPayload.Payload["recipient"].(string),
|
||||
eventPayload.Payload["amount"].(string),
|
||||
eventPayload.ContractAddress,
|
||||
)
|
||||
return err
|
||||
})
|
||||
@ -165,6 +168,7 @@ func (pg *Pg) InsertPoolSwap(ctx context.Context, eventPayload event.Event) erro
|
||||
eventPayload.Payload["amountIn"].(string),
|
||||
eventPayload.Payload["amountOut"].(string),
|
||||
eventPayload.Payload["fee"].(string),
|
||||
eventPayload.ContractAddress,
|
||||
)
|
||||
return err
|
||||
})
|
||||
@ -184,6 +188,7 @@ func (pg *Pg) InsertPoolDeposit(ctx context.Context, eventPayload event.Event) e
|
||||
eventPayload.Payload["initiator"].(string),
|
||||
eventPayload.Payload["tokenIn"].(string),
|
||||
eventPayload.Payload["amountIn"].(string),
|
||||
eventPayload.ContractAddress,
|
||||
)
|
||||
return err
|
||||
})
|
||||
@ -202,6 +207,7 @@ func (pg *Pg) InsertPriceQuoteUpdate(ctx context.Context, eventPayload event.Eve
|
||||
txID,
|
||||
eventPayload.Payload["token"].(string),
|
||||
eventPayload.Payload["exchangeRate"].(string),
|
||||
eventPayload.ContractAddress,
|
||||
)
|
||||
return err
|
||||
})
|
||||
@ -214,7 +220,6 @@ func (pg *Pg) insertTx(ctx context.Context, tx pgx.Tx, eventPayload event.Event)
|
||||
pg.queries.InsertTx,
|
||||
eventPayload.TxHash,
|
||||
eventPayload.Block,
|
||||
eventPayload.ContractAddress,
|
||||
time.Unix(int64(eventPayload.Timestamp), 0).UTC(),
|
||||
eventPayload.Success,
|
||||
).Scan(&txID); err != nil {
|
||||
|
@ -65,7 +65,6 @@ CREATE TABLE IF NOT EXISTS price_index_updates (
|
||||
exchange_rate NUMERIC NOT NULL
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS contracts (
|
||||
id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
contract_address VARCHAR(42) UNIQUE NOT NULL,
|
||||
|
29
migrations/002_fix_contract_address.sql
Normal file
29
migrations/002_fix_contract_address.sql
Normal file
@ -0,0 +1,29 @@
|
||||
ALTER TABLE tx DROP COLUMN contract_address;
|
||||
|
||||
ALTER TABLE token_transfer ADD COLUMN contract_address VARCHAR(42);
|
||||
UPDATE token_transfer SET contract_address = '0x0000000000000000000000000000000000000000';
|
||||
ALTER TABLE token_transfer ALTER COLUMN contract_address SET NOT NULL;
|
||||
|
||||
ALTER TABLE token_mint ADD COLUMN contract_address VARCHAR(42);
|
||||
UPDATE token_mint SET contract_address = '0x0000000000000000000000000000000000000000';
|
||||
ALTER TABLE token_mint ALTER COLUMN contract_address SET NOT NULL;
|
||||
|
||||
ALTER TABLE token_burn ADD COLUMN contract_address VARCHAR(42);
|
||||
UPDATE token_burn SET contract_address = '0x0000000000000000000000000000000000000000';
|
||||
ALTER TABLE token_burn ALTER COLUMN contract_address SET NOT NULL;
|
||||
|
||||
ALTER TABLE faucet_give ADD COLUMN contract_address VARCHAR(42);
|
||||
UPDATE faucet_give SET contract_address = '0x0000000000000000000000000000000000000000';
|
||||
ALTER TABLE faucet_give ALTER COLUMN contract_address SET NOT NULL;
|
||||
|
||||
ALTER TABLE pool_swap ADD COLUMN contract_address VARCHAR(42);
|
||||
UPDATE pool_swap SET contract_address = '0x0000000000000000000000000000000000000000';
|
||||
ALTER TABLE pool_swap ALTER COLUMN contract_address SET NOT NULL;
|
||||
|
||||
ALTER TABLE pool_deposit ADD COLUMN contract_address VARCHAR(42);
|
||||
UPDATE pool_deposit SET contract_address = '0x0000000000000000000000000000000000000000';
|
||||
ALTER TABLE pool_deposit ALTER COLUMN contract_address SET NOT NULL;
|
||||
|
||||
ALTER TABLE price_index_updates ADD COLUMN contract_address VARCHAR(42);
|
||||
UPDATE price_index_updates SET contract_address = '0x0000000000000000000000000000000000000000';
|
||||
ALTER TABLE price_index_updates ALTER COLUMN contract_address SET NOT NULL;
|
59
queries.sql
59
queries.sql
@ -1,17 +1,15 @@
|
||||
--name: insert-tx
|
||||
-- $1: tx_hash
|
||||
-- $2: block_number
|
||||
-- $3: contract_address
|
||||
-- $4: date_block
|
||||
-- $5: success
|
||||
-- $3: date_block
|
||||
-- $4: success
|
||||
WITH insert_tx AS (
|
||||
INSERT INTO tx(
|
||||
tx_hash,
|
||||
block_number,
|
||||
contract_address,
|
||||
date_block,
|
||||
success
|
||||
) VALUES($1, $2, $3, $4, $5) ON CONFLICT DO NOTHING RETURNING id
|
||||
) VALUES($1, $2, $3, $4) ON CONFLICT DO NOTHING RETURNING id
|
||||
)
|
||||
SELECT id FROM insert_tx
|
||||
UNION ALL
|
||||
@ -23,46 +21,54 @@ LIMIT 1
|
||||
-- $2: sender_address
|
||||
-- $3: recipient_address
|
||||
-- $4: transfer_value
|
||||
-- $5: contract_address
|
||||
INSERT INTO token_transfer(
|
||||
tx_id,
|
||||
sender_address,
|
||||
recipient_address,
|
||||
transfer_value
|
||||
) VALUES($1, $2, $3, $4) ON CONFLICT DO NOTHING
|
||||
transfer_value,
|
||||
contract_address
|
||||
) VALUES($1, $2, $3, $4, $5) ON CONFLICT DO NOTHING
|
||||
|
||||
--name: insert-token-mint
|
||||
-- $1: tx_id
|
||||
-- $2: minter_address
|
||||
-- $3: recipient_address
|
||||
-- $4: mint_value
|
||||
-- $5: contract_address
|
||||
INSERT INTO token_mint(
|
||||
tx_id,
|
||||
minter_address,
|
||||
recipient_address,
|
||||
mint_value
|
||||
) VALUES($1, $2, $3, $4) ON CONFLICT DO NOTHING
|
||||
mint_value,
|
||||
contract_address
|
||||
) VALUES($1, $2, $3, $4, $5) ON CONFLICT DO NOTHING
|
||||
|
||||
--name: insert-token-burn
|
||||
-- $1: tx_id
|
||||
-- $2: burner_address
|
||||
-- $3: burn_value
|
||||
-- $4: contract_address
|
||||
INSERT INTO token_burn(
|
||||
tx_id,
|
||||
burner_address,
|
||||
burn_value
|
||||
) VALUES($1, $2, $3) ON CONFLICT DO NOTHING
|
||||
burn_value,
|
||||
contract_address
|
||||
) VALUES($1, $2, $3, $4) ON CONFLICT DO NOTHING
|
||||
|
||||
--name: insert-faucet-give
|
||||
-- $1: tx_id
|
||||
-- $2: token_address
|
||||
-- $3: recipient_address
|
||||
-- $4: give_value
|
||||
-- $5: contract_address
|
||||
INSERT INTO faucet_give(
|
||||
tx_id,
|
||||
token_address,
|
||||
recipient_address,
|
||||
give_value
|
||||
) VALUES($1, $2, $3, $4) ON CONFLICT DO NOTHING
|
||||
give_value,
|
||||
contract_address
|
||||
) VALUES($1, $2, $3, $4, $5) ON CONFLICT DO NOTHING
|
||||
|
||||
--name: insert-pool-swap
|
||||
-- $1: tx_id
|
||||
@ -72,6 +78,7 @@ INSERT INTO faucet_give(
|
||||
-- $5: in_value
|
||||
-- $6: out_value
|
||||
-- $7: fee
|
||||
-- $8: contract_address
|
||||
INSERT INTO pool_swap(
|
||||
tx_id,
|
||||
initiator_address,
|
||||
@ -80,36 +87,30 @@ INSERT INTO pool_swap(
|
||||
in_value,
|
||||
out_value,
|
||||
fee
|
||||
) VALUES($1, $2, $3, $4, $5, $6, $7) ON CONFLICT DO NOTHING
|
||||
) VALUES($1, $2, $3, $4, $5, $6, $7, $8) ON CONFLICT DO NOTHING
|
||||
|
||||
--name: insert-pool-deposit
|
||||
-- $1: tx_id
|
||||
-- $2: initiator_address
|
||||
-- $3: token_in_address
|
||||
-- $4: token_out_address
|
||||
-- $5: in_value
|
||||
-- $6: out_value
|
||||
-- $7: fee
|
||||
-- $4: in_value
|
||||
-- $5: contract_address
|
||||
INSERT INTO pool_deposit(
|
||||
tx_id,
|
||||
initiator_address,
|
||||
token_in_address,
|
||||
in_value
|
||||
) VALUES($1, $2, $3, $4) ON CONFLICT DO NOTHING
|
||||
in_value,
|
||||
contract_address
|
||||
) VALUES($1, $2, $3, $4, $5) ON CONFLICT DO NOTHING
|
||||
|
||||
--name: insert-price-quote-update
|
||||
-- $1: tx_id
|
||||
-- $2: token
|
||||
-- $3: exchange_rate
|
||||
-- $4: contract_address
|
||||
INSERT INTO price_index_updates(
|
||||
tx_id,
|
||||
token,
|
||||
exchange_rate
|
||||
) VALUES($1, $2, $3) ON CONFLICT DO NOTHING
|
||||
|
||||
--name: address-exists
|
||||
-- $1: blockchain_address_1
|
||||
-- $2: blockchain_address_2
|
||||
SELECT EXISTS(
|
||||
SELECT 1 FROM sarafu_network.accounts WHERE blockchain_address=$1 OR blockchain_address=$2
|
||||
)
|
||||
exchange_rate.
|
||||
contract_address
|
||||
) VALUES($1, $2, $3, $4) ON CONFLICT DO NOTHING
|
||||
|
Loading…
Reference in New Issue
Block a user