2018-03-16 19:34:18 +00:00
|
|
|
# Transformers
|
2018-02-13 16:31:57 +00:00
|
|
|
|
|
|
|
## Description
|
2018-03-16 19:34:18 +00:00
|
|
|
Transformers must be defined in order to define what events should trigger data updates and how those are performed.
|
2018-02-13 16:31:57 +00:00
|
|
|
|
|
|
|
## Interface
|
|
|
|
|
|
|
|
### Initializer
|
2018-03-16 19:34:18 +00:00
|
|
|
Accepts DB and Blockchain from Vulcanize and returns a new transformer. E.g. for a new object "Cup":
|
|
|
|
`func NewCupTransformer(db *postgres.DB, blockchain core.ContractDataFetcher) transformers.Transformer`
|
2018-02-13 16:31:57 +00:00
|
|
|
|
|
|
|
### Execute
|
|
|
|
Triggers operations to take in response to a given log event.
|
|
|
|
Can persist data from logs, fetch and persist arbitrary data from outside services (e.g. contract state), or take any number of other actions. E.g.:
|
2018-03-16 19:34:18 +00:00
|
|
|
`func (cupTransformer *CupTransformer) Execute() error`
|
2018-02-13 16:31:57 +00:00
|
|
|
|
|
|
|
## Additional Requirements
|
2018-03-16 19:34:18 +00:00
|
|
|
Transformers must define log filters and create them so that relevant watched events can be identified and retrieved. E.g.:
|
2018-02-13 16:31:57 +00:00
|
|
|
```$xslt
|
|
|
|
{
|
|
|
|
Name: "CupsBite",
|
|
|
|
FromBlock: 0,
|
|
|
|
ToBlock: -1,
|
|
|
|
Address: "0x448a5065aebb8e423f0896e6c5d525c040f59af3",
|
|
|
|
Topics: core.Topics{"0x40cc885400000000000000000000000000000000000000000000000000000000"},
|
|
|
|
},
|
|
|
|
```
|