This repository has been archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
866 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
DROP TABLE maker.vat_toll; | ||
ALTER TABLE public.checked_headers | ||
DROP COLUMN vat_toll_checked; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
CREATE TABLE maker.vat_toll ( | ||
id SERIAL PRIMARY KEY, | ||
header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, | ||
ilk TEXT, | ||
urn TEXT, | ||
take NUMERIC, | ||
tx_idx INTEGER NOT NULL, | ||
raw_log JSONB, | ||
UNIQUE (header_id, tx_idx) | ||
); | ||
|
||
ALTER TABLE public.checked_headers | ||
ADD COLUMN vat_toll_checked BOOLEAN NOT NULL DEFAULT FALSE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package vat_toll | ||
|
||
import ( | ||
"github.com/ethereum/go-ethereum/core/types" | ||
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" | ||
"github.com/vulcanize/vulcanizedb/pkg/transformers/vat_toll" | ||
) | ||
|
||
type MockVatTollConverter struct { | ||
err error | ||
PassedLogs []types.Log | ||
} | ||
|
||
func (converter *MockVatTollConverter) ToModels(ethLogs []types.Log) ([]vat_toll.VatTollModel, error) { | ||
converter.PassedLogs = ethLogs | ||
return []vat_toll.VatTollModel{test_data.VatTollModel}, converter.err | ||
} | ||
|
||
func (converter *MockVatTollConverter) SetConverterError(e error) { | ||
converter.err = e | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package vat_toll | ||
|
||
import ( | ||
. "github.com/onsi/gomega" | ||
|
||
"github.com/vulcanize/vulcanizedb/pkg/core" | ||
"github.com/vulcanize/vulcanizedb/pkg/transformers/vat_toll" | ||
) | ||
|
||
type MockVatTollRepository struct { | ||
createErr error | ||
markHeaderCheckedErr error | ||
markHeaderCheckedPassedHeaderID int64 | ||
missingHeadersErr error | ||
missingHeaders []core.Header | ||
PassedStartingBlockNumber int64 | ||
PassedEndingBlockNumber int64 | ||
PassedHeaderID int64 | ||
PassedModels []vat_toll.VatTollModel | ||
} | ||
|
||
func (repository *MockVatTollRepository) Create(headerID int64, models []vat_toll.VatTollModel) error { | ||
repository.PassedHeaderID = headerID | ||
repository.PassedModels = models | ||
return repository.createErr | ||
} | ||
|
||
func (repository *MockVatTollRepository) MarkHeaderChecked(headerID int64) error { | ||
repository.markHeaderCheckedPassedHeaderID = headerID | ||
return repository.markHeaderCheckedErr | ||
} | ||
|
||
func (repository *MockVatTollRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { | ||
repository.PassedStartingBlockNumber = startingBlockNumber | ||
repository.PassedEndingBlockNumber = endingBlockNumber | ||
return repository.missingHeaders, repository.missingHeadersErr | ||
} | ||
|
||
func (repository *MockVatTollRepository) SetCreateError(e error) { | ||
repository.createErr = e | ||
} | ||
|
||
func (repository *MockVatTollRepository) SetMarkHeaderCheckedErr(e error) { | ||
repository.markHeaderCheckedErr = e | ||
} | ||
|
||
func (repository *MockVatTollRepository) SetMissingHeadersErr(e error) { | ||
repository.missingHeadersErr = e | ||
} | ||
|
||
func (repository *MockVatTollRepository) SetMissingHeaders(headers []core.Header) { | ||
repository.missingHeaders = headers | ||
} | ||
|
||
func (repository *MockVatTollRepository) AssertMarkHeaderCheckedCalledWith(i int64) { | ||
Expect(repository.markHeaderCheckedPassedHeaderID).To(Equal(i)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package test_data | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/common/hexutil" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
"github.com/vulcanize/vulcanizedb/pkg/transformers/vat_toll" | ||
"math/big" | ||
) | ||
|
||
var EthVatTollLog = types.Log{ | ||
Address: common.HexToAddress("0x239E6f0AB02713f1F8AA90ebeDeD9FC66Dc96CD6"), | ||
Topics: []common.Hash{ | ||
common.HexToHash("0x09b7a0b500000000000000000000000000000000000000000000000000000000"), | ||
common.HexToHash("0x66616b6520696c6b000000000000000000000000000000000000000000000000"), | ||
common.HexToHash("0xa3e37186e017747dba34042e83e3f76ad3cce9b0000000000000000000000000"), | ||
common.HexToHash("0x00000000000000000000000000000000000000000000000000000000075bcd15"), | ||
}, | ||
Data: hexutil.MustDecode("0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000006409b7a0b566616b6520696c6b000000000000000000000000000000000000000000000000a3e37186e017747dba34042e83e3f76ad3cce9b000000000000000000000000000000000000000000000000000000000000000000000000000000000075bcd15"), | ||
BlockNumber: 21, | ||
TxHash: common.HexToHash("0x0d59cb158b033ffdfb9a021d1e80bfbbcd99594c62c501897ccee446bcd33828"), | ||
TxIndex: 2, | ||
BlockHash: common.HexToHash("0xdbfda0ecb4ac6267c50be21db97874dc1203c22033e19733a6f67ca00b51dfc5"), | ||
Index: 4, | ||
Removed: false, | ||
} | ||
|
||
var rawVatTollLog, _ = json.Marshal(EthVatTollLog) | ||
var VatTollModel = vat_toll.VatTollModel{ | ||
Ilk: "fake ilk", | ||
Urn: "0xA3E37186E017747DbA34042e83e3F76Ad3CcE9b0", | ||
Take: big.NewInt(123456789).String(), | ||
TransactionIndex: EthVatTollLog.TxIndex, | ||
Raw: rawVatTollLog, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package vat_toll | ||
|
||
import "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" | ||
|
||
var VatTollConfig = shared.TransformerConfig{ | ||
ContractAddresses: []string{shared.VatContractAddress}, | ||
ContractAbi: shared.VatABI, | ||
Topics: []string{shared.VatTollSignature}, | ||
StartingBlockNumber: 0, | ||
EndingBlockNumber: 10000000, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
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, | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package vat_toll_test | ||
|
||
import ( | ||
"github.com/ethereum/go-ethereum/core/types" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
||
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" | ||
"github.com/vulcanize/vulcanizedb/pkg/transformers/vat_toll" | ||
) | ||
|
||
var _ = Describe("Vat toll converter", func() { | ||
It("returns err if log is missing topics", func() { | ||
converter := vat_toll.VatTollConverter{} | ||
badLog := types.Log{ | ||
Data: []byte{1, 1, 1, 1, 1}, | ||
} | ||
|
||
_, err := converter.ToModels([]types.Log{badLog}) | ||
|
||
Expect(err).To(HaveOccurred()) | ||
}) | ||
|
||
It("converts a log to an model", func() { | ||
converter := vat_toll.VatTollConverter{} | ||
|
||
models, err := converter.ToModels([]types.Log{test_data.EthVatTollLog}) | ||
|
||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(len(models)).To(Equal(1)) | ||
Expect(models[0]).To(Equal(test_data.VatTollModel)) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package vat_toll | ||
|
||
type VatTollModel struct { | ||
Ilk string | ||
Urn string | ||
Take string | ||
TransactionIndex uint `db:"tx_idx"` | ||
Raw []byte `db:"raw_log"` | ||
} |
Oops, something went wrong.