(VDB-110) cat wards storage transformer#88
Conversation
| header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, | ||
| log_id BIGINT NOT NULL REFERENCES header_sync_logs (id) ON DELETE CASCADE, | ||
| address_id INTEGER NOT NULL REFERENCES addresses (id) ON DELETE CASCADE, | ||
| msg_sender INTEGER NOT NULL REFERENCES addresses (id) ON DELETE CASCADE, |
There was a problem hiding this comment.
Had to make some event transformer updates, because we ended up needing the msg.sender of auth events (for all contracts besides Vat, which doesn't give us an easy way of finding msg.sender).
There was a problem hiding this comment.
Heads on up these for the rebase... header_sync_logs => event_logs and addresses => public.addresses
| header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, | ||
| address_id INTEGER NOT NULL REFERENCES addresses (id) ON DELETE CASCADE, | ||
| usr INTEGER NOT NULL REFERENCES addresses (id) ON DELETE CASCADE, | ||
| wards INTEGER NOT NULL, |
There was a problem hiding this comment.
This is a uint256 in the contract, but I figured a regular int would work here since the value can only be 0 or 1 :P
| TableName event.TableName | ||
| } | ||
|
|
||
| func (t Transformer) ToModels(_ string, logs []core.HeaderSyncLog, db *postgres.DB) ([]event.InsertionModel, error) { |
There was a problem hiding this comment.
Ended up separating out the vat_auth event transformer, because it's looking less and less like the generic auth one. I figured since both the structure of the log and the structure of the target InsertionModel are different from the generic version, it would make sense to just let vat_auth events have their own transformer.
| SELECT addresses.address | ||
| FROM maker.rely | ||
| LEFT JOIN public.addresses ON rely.usr = addresses.id | ||
| WHERE rely.address_id = $1 | ||
| UNION | ||
| SELECT addresses.address | ||
| FROM maker.rely | ||
| LEFT JOIN public.addresses ON rely.msg_sender = addresses.id | ||
| WHERE rely.address_id = $1 | ||
| UNION | ||
| SELECT addresses.address | ||
| FROM maker.deny | ||
| LEFT JOIN public.addresses ON deny.usr = addresses.id | ||
| WHERE deny.address_id = $1 | ||
| UNION | ||
| SELECT addresses.address | ||
| FROM maker.deny | ||
| LEFT JOIN public.addresses ON deny.msg_sender = addresses.id | ||
| WHERE deny.address_id = $1`, contractAddressID) |
There was a problem hiding this comment.
The only reason this query needs to combine more than just rely.usr and deny.usr is because we also want to find the msg_sender of the transaction that deployed the contract. Since we don't have a direct way of doing that (constructor doesn't emit an event), we have to infer it.
The msg_sender of the first rely event must be the msg_sender who deployed the contract, because at that point no one else is authorized to call rely (or any other method with the auth modifier). Technically I didn't need to UNION with all rely/deny msg_senders (just the 1st rely event's), but I figured we might as well for redundancy's sake.
Also worth noting that these tables will likely be very small, so hopefully there's no reason to worry about performance.
| Context("Cat deny events", func() { | ||
| usrAddress := "0x13141b8a5e4a82ebc6b636849dd6a515185d6236" | ||
| denyIntegrationTest(int64(14764643), test_data.CatAddress(), usrAddress, defaultOffset) | ||
| denyIntegrationTest(int64(14764643), test_data.CatAddress(), usrAddress, usrAddress) |
There was a problem hiding this comment.
Kind of weird that for all these integration tests I'm passing in usrAddress twice, but it's because I just happened to pick deny events where msg.senders are passing their own addresses in as the usr parameter. I didn't want to abstract usrAddressHex and msgSenderAddressHex (on line 59) into a single parameter, because I was worried that would imply that those 2 addresses have to be the same, which they don't.
eaccd13 to
f78198d
Compare
f6e442c to
0b19eed
Compare
| storageKeysLookup = storage.NewKeysLookup(cat.NewKeysLoader(&mcdStorage.MakerStorageRepository{})) | ||
| repository = cat.CatStorageRepository{} | ||
| contractAddress = "81f7aa9c1570de564eb511b3a1e57dae558c65b5" | ||
| contractAddress = test_data.CatAddress() |
| @@ -30,41 +30,25 @@ var _ = Describe("Deny Transformer", func() { | |||
| test_data.RelyHeaderSyncLog.Log.Address.String()) | |||
There was a problem hiding this comment.
RelyHeaderSyncLog => RelyEventLog
| repository.GetFlopBidIdsCalledWith = contractAddress | ||
| return repository.FlopBidIds, repository.GetFlopBidIdsError | ||
| } | ||
|
|
|
|
||
| var insertWardsQuery = `INSERT INTO maker.wards (diff_id, header_id, address_id, usr, wards) VALUES ($1, $2, $3, $4, $5) ON CONFLICT DO NOTHING` | ||
|
|
||
| func InsertWards(diffID, headerID int64, metadata storage.ValueMetadata, contractAddress, wards string, db *postgres.DB) error { |
Transform auth event msg.sender, separate out Vat auth transformer
Reduce wards duplication between transformers
| GetCdpis() ([]string, error) | ||
| GetDaiKeys() ([]string, error) | ||
| GetFlapBidIds(string) ([]string, error) | ||
| GetFlipBidIds(contractAddress string) ([]string, error) |
c827534 to
7609e50
Compare
Transforms
wardsstorage mapping for theCatcontract. Usingusrandmsg_senderofrelyanddenyevents for key discovery.