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
17 changed files
with
830 additions
and
2 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP TABLE maker.drip_drip; |
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,8 @@ | ||
CREATE TABLE maker.drip_drip ( | ||
id SERIAL PRIMARY KEY, | ||
header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, | ||
ilk TEXT, | ||
tx_idx INTEGER NOT NUll, | ||
raw_log JSONB, | ||
UNIQUE (header_id, tx_idx) | ||
); |
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,25 @@ | ||
// Copyright 2018 Vulcanize | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package drip_drip | ||
|
||
import "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" | ||
|
||
var DripDripConfig = shared.TransformerConfig{ | ||
ContractAddress: shared.DripContractAddress, | ||
ContractAbi: shared.DripABI, | ||
Topics: []string{shared.DripDripSignature}, | ||
StartingBlockNumber: 0, | ||
EndingBlockNumber: 100, | ||
} |
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,49 @@ | ||
// Copyright 2018 Vulcanize | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package drip_drip | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"errors" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
) | ||
|
||
type Converter interface { | ||
ToModel(ethLog types.Log) (DripDripModel, error) | ||
} | ||
|
||
type DripDripConverter struct{} | ||
|
||
func (DripDripConverter) ToModel(ethLog types.Log) (DripDripModel, error) { | ||
err := verifyLog(ethLog) | ||
if err != nil { | ||
return DripDripModel{}, err | ||
} | ||
ilk := string(bytes.Trim(ethLog.Topics[2].Bytes(), "\x00")) | ||
raw, err := json.Marshal(ethLog) | ||
return DripDripModel{ | ||
Ilk: ilk, | ||
TransactionIndex: ethLog.TxIndex, | ||
Raw: raw, | ||
}, err | ||
} | ||
|
||
func verifyLog(log types.Log) error { | ||
if len(log.Topics) < 3 { | ||
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,44 @@ | ||
// Copyright 2018 Vulcanize | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package drip_drip_test | ||
|
||
import ( | ||
"github.com/ethereum/go-ethereum/core/types" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
||
"github.com/vulcanize/vulcanizedb/pkg/transformers/drip_drip" | ||
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" | ||
) | ||
|
||
var _ = Describe("Drip drip converter", func() { | ||
It("returns err if log is missing topics", func() { | ||
converter := drip_drip.DripDripConverter{} | ||
badLog := types.Log{} | ||
|
||
_, err := converter.ToModel(badLog) | ||
|
||
Expect(err).To(HaveOccurred()) | ||
}) | ||
|
||
It("converts a log to an model", func() { | ||
converter := drip_drip.DripDripConverter{} | ||
|
||
model, err := converter.ToModel(test_data.EthDripDripLog) | ||
|
||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(model).To(Equal(test_data.DripDripModel)) | ||
}) | ||
}) |
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,27 @@ | ||
// Copyright 2018 Vulcanize | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package drip_drip_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestDripDrip(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "DripDrip Suite") | ||
} |
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 @@ | ||
// Copyright 2018 Vulcanize | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package drip_drip | ||
|
||
type DripDripModel struct { | ||
Ilk string | ||
TransactionIndex uint `db:"tx_idx"` | ||
Raw []byte `db:"raw_log"` | ||
} |
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,59 @@ | ||
// Copyright 2018 Vulcanize | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package drip_drip | ||
|
||
import ( | ||
"github.com/vulcanize/vulcanizedb/pkg/core" | ||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" | ||
) | ||
|
||
type Repository interface { | ||
Create(headerID int64, model DripDripModel) error | ||
MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) | ||
} | ||
|
||
type DripDripRepository struct { | ||
db *postgres.DB | ||
} | ||
|
||
func NewDripDripRepository(db *postgres.DB) DripDripRepository { | ||
return DripDripRepository{db: db} | ||
} | ||
|
||
func (repository DripDripRepository) Create(headerID int64, model DripDripModel) error { | ||
_, err := repository.db.Exec( | ||
`INSERT into maker.drip_drip (header_id, ilk, tx_idx, raw_log) | ||
VALUES($1, $2, $3, $4)`, | ||
headerID, model.Ilk, model.TransactionIndex, model.Raw, | ||
) | ||
return err | ||
} | ||
|
||
func (repository DripDripRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { | ||
var result []core.Header | ||
err := repository.db.Select( | ||
&result, | ||
`SELECT headers.id, headers.block_number FROM headers | ||
LEFT JOIN maker.drip_drip on headers.id = header_id | ||
WHERE header_id ISNULL | ||
AND headers.block_number >= $1 | ||
AND headers.block_number <= $2 | ||
AND headers.eth_node_fingerprint = $3`, | ||
startingBlockNumber, | ||
endingBlockNumber, | ||
repository.db.Node.ID, | ||
) | ||
return result, err | ||
} |
Oops, something went wrong.