5682ee988b
* Add log_index field to flip kick * Add log index to flop kick * Add repo tests for Cat.file * Add log_index to vat_flux * Add log_index to vat_slip * Add log_index to vat_toll * Add log_index to vat_tune * Add test to repos for updating checked headers
53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
package vat_toll
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"errors"
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
"github.com/ethereum/go-ethereum/core/types"
|
|
)
|
|
|
|
type Converter interface {
|
|
ToModels(ethLogs []types.Log) ([]VatTollModel, error)
|
|
}
|
|
|
|
type VatTollConverter struct{}
|
|
|
|
func (VatTollConverter) ToModels(ethLogs []types.Log) ([]VatTollModel, error) {
|
|
var models []VatTollModel
|
|
for _, ethLog := range ethLogs {
|
|
err := verifyLog(ethLog)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ilk := string(bytes.Trim(ethLog.Topics[1].Bytes(), "\x00"))
|
|
urn := common.BytesToAddress(ethLog.Topics[2].Bytes()[:common.AddressLength])
|
|
take := ethLog.Topics[3].Big()
|
|
|
|
raw, err := json.Marshal(ethLog)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
model := VatTollModel{
|
|
Ilk: ilk,
|
|
Urn: urn.String(),
|
|
Take: take.String(),
|
|
TransactionIndex: ethLog.TxIndex,
|
|
LogIndex: ethLog.Index,
|
|
Raw: raw,
|
|
}
|
|
models = append(models, model)
|
|
}
|
|
return models, nil
|
|
}
|
|
|
|
func verifyLog(log types.Log) error {
|
|
numTopicInValidLog := 4
|
|
if len(log.Topics) < numTopicInValidLog {
|
|
return errors.New("log missing topics")
|
|
}
|
|
return nil
|
|
}
|