Skip to content

Update creating an event transformer docs#182

Merged
paytonrules merged 4 commits intostagingfrom
vdb-421-update-event-transformer-docs
May 13, 2020
Merged

Update creating an event transformer docs#182
paytonrules merged 4 commits intostagingfrom
vdb-421-update-event-transformer-docs

Conversation

@paytonrules
Copy link
Copy Markdown
Contributor

No description provided.

@paytonrules paytonrules force-pushed the vdb-421-update-event-transformer-docs branch from 38ab3be to 2cc8adb Compare April 29, 2020 22:46
Copy link
Copy Markdown
Contributor

@rmulhol rmulhol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! 🙏 🙏 🙏

I left a bunch of comments but they may be extraneous - curious what you think

If the contract isn't already present in the environment you'll need to add it
before you can begin transforming its events. To do so:

1. Get the contract signature if you don't already have it.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the term we'd want to use here is contract address

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

1. Get the contract signature if you don't already have it.
1. Search for the contract on [etherscan](https://etherscan.io/). Bookmark this
page, it is your new best friend.
1. In each environment (at this time testing, docker and mcdTransformers) add a
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no oxford comma?!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't tell James.

abi = '[{"inputs":[{"internalType":"address","name":"vat_","type":"address"},{"internalType":"bytes32","name":"ilk_","type":"bytes32"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"lot","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"bid","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"tab","type":"uint256"},{"indexed":true,"internalType":"address","name":"usr","type":"address"},{"indexed":true,"internalType":"address","name":"gal","type":"address"}],"name":"Kick","type":"event"},{"anonymous":true,"inputs":[{"indexed":true,"internalType":"bytes4","name":"sig","type":"bytes4"},{"indexed":true,"internalType":"address","name":"usr","type":"address"},{"indexed":true,"internalType":"bytes32","name":"arg1","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"arg2","type":"bytes32"},{"indexed":false,"internalType":"bytes","name":"data","type":"bytes"}],"name":"LogNote","type":"event"},{"constant":true,"inputs":[],"name":"beg","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"bids","outputs":[{"internalType":"uint256","name":"bid","type":"uint256"},{"internalType":"uint256","name":"lot","type":"uint256"},{"internalType":"address","name":"guy","type":"address"},{"internalType":"uint48","name":"tic","type":"uint48"},{"internalType":"uint48","name":"end","type":"uint48"},{"internalType":"address","name":"usr","type":"address"},{"internalType":"address","name":"gal","type":"address"},{"internalType":"uint256","name":"tab","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"deal","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"uint256","name":"lot","type":"uint256"},{"internalType":"uint256","name":"bid","type":"uint256"}],"name":"dent","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"usr","type":"address"}],"name":"deny","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"what","type":"bytes32"},{"internalType":"uint256","name":"data","type":"uint256"}],"name":"file","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"ilk","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"usr","type":"address"},{"internalType":"address","name":"gal","type":"address"},{"internalType":"uint256","name":"tab","type":"uint256"},{"internalType":"uint256","name":"lot","type":"uint256"},{"internalType":"uint256","name":"bid","type":"uint256"}],"name":"kick","outputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"kicks","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"usr","type":"address"}],"name":"rely","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"tau","outputs":[{"internalType":"uint48","name":"","type":"uint48"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"uint256","name":"lot","type":"uint256"},{"internalType":"uint256","name":"bid","type":"uint256"}],"name":"tend","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"tick","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"ttl","outputs":[{"internalType":"uint48","name":"","type":"uint48"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"vat","outputs":[{"internalType":"contract VatLike","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"wards","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"yank","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}]'
deployed = 8928180
```
* The address is the signature you searched for, as a string.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recognize it sounds weird to say "The address is the address" but I think the most idiomatic description might be something like "The address field should contain the hex representation of the address you used to find the contract on Etherscan," or something like that

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about "The address field is the contract address you searched for, as a string."

like above.
* The deployed field is the block number the contract was deployed on. That
can be found on the Contract's page, by looking for the Contract Creator
and clicking it's transaction hash. That will take you to the block it was deployed on.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically it takes you to the transaction where it was deployed, which includes a link to the block that contains that transaction 🤓

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

(the raw, untransformed data) to an `event.InsertionModel` (the domain object).

Note that for this step you probably do _not_ need to create the database
migration. This is because the only thing you'll be saving are addresses, which
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible you could be saving other things that are stored in other tables and referenced via foreign key, like maker.ilks or maker.urns - but I think the larger point stands that you shouldn't need a migration to make the transformer, as the only thing a transformer inserts are fields referenced by FK

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some clarifying language here.

RunSpecs(t, "<PackageName> Suite")
}
```
1. Implement the toModels function in `transformer.go` with the appropriate
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:%s/toModels/ToModels

Maybe helpful to include a link to the interface?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

into a go struct.
1. For custom events you can convert each EventLog entry into an entity
using the function `contract.UnpackLog(&entity, "<EventLogName>", log.Log)`.
The entity is usually defined (by you) in a file called `entity.go` in the
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"by you" is probably the right answer here although in theory abigen may be helpful/necessary if figuring out the type mappings is challenging

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a note about abigen

1. Use the `make new_migration` task to create a new migration.
* Each event log has its own table in the database.
* The specific log event tables are all created in the `maker` schema.
1. The new migration can be run by running `make test` or `make migration NAME=vulcanize_test`.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe worth replacing vulcanize_test with <database_name>?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

1. The new migration can be run by running `make test` or `make migration NAME=vulcanize_test`.
1. To verify that the migration will work create an integration for the shiny
new transformer in [`integration_tests`](../integration_tests).
1. Integration tests can be run with `make integrationtest`.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sorta shudder at the thought of describing it in detail because it's something we need to streamline, but maybe worth covering something about what goes into writing an integration test for an event transformer?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably - I think I was running into some documentation fatigue at this point.


Simply replace the constants and package names with your transformer.

1. Finally add your package to the list of transformerExporters in `plugins/transformerExporter.go`. Again alphabetically.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe extraneous but you can generate the transformerExporter.go from the command line with ./vulcanizedb compose --config=/path/to/config.toml

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't know that!

Copy link
Copy Markdown
Contributor

@elizabethengelman elizabethengelman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking great! It's so nice to have accurate documentation again!

Just a few small comments, but nothing merge blocking.

migration, you'll know, because the tests won't pass. The directions here assume
you do not, yet.

1. Search for the contract on etherscan using it's signature.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this signature should be address here as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

thank me later.
* Update constants as needed. Look at older examples of test data for
inspiration.
* You do not need a database migration at this point.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this bullet point about a migration is necessary yet, since it's already mentioned above that a migration isn't likely necessary on this step.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

1. After converting the log entry to an entity, look up all of it's foreign
keys from it's data and assign them to the entity.
1. From the entity create an InsertionModel, which you return.
1. For `LogNote` events you'll need to look at the method signature of the
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it would be helpful to have directions for LogNote and directions for custom events as nested bullets to signify that the you need to do one or the other, not both?

Something like:

 1. Implement the ToModels function in `transformer.go`...
    - For custom events:
        - ...
    - For LogNoteEvents:
        - ...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

* the `tend` method is called on the [flip.sol
contract](https://github.com/makerdao/dss/blob/master/src/flip.sol#L123),
and its method signature looks like this: `tend(uint,uint,uint)`.
* The first four bytes of the Keccak-256 hashed method signature will be
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A small caveat to this is that for custom events the topic[0] will be the full Keccak-256 hashed method signature instead of just the first four bytes - that is special to LogNotes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a bit of clarification here.

@paytonrules paytonrules force-pushed the vdb-421-update-event-transformer-docs branch from 2cc8adb to 621b02f Compare May 12, 2020 16:29
Copy link
Copy Markdown
Contributor

@rmulhol rmulhol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just dropping in to make sure we don't accidentally merge #188 as part of this PR

The issues with formatting are causing a larger diff than I'd like, apologies.
@paytonrules paytonrules force-pushed the vdb-421-update-event-transformer-docs branch from 621b02f to a553198 Compare May 12, 2020 16:40
Copy link
Copy Markdown
Contributor

@rmulhol rmulhol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@paytonrules paytonrules merged commit 61e6bf6 into staging May 13, 2020
@paytonrules paytonrules deleted the vdb-421-update-event-transformer-docs branch August 26, 2020 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants