forked from cerc-io/ipld-eth-server
remove pkg/transformers; extract shared files needed to
libraries/shared; work on automated db migration management
This commit is contained in:
@@ -1,35 +0,0 @@
|
||||
// VulcanizeDB
|
||||
// Copyright © 2018 Vulcanize
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package bite_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
func TestBite(t *testing.T) {
|
||||
RegisterFailHandler(Fail)
|
||||
RunSpecs(t, "Bite Suite")
|
||||
}
|
||||
|
||||
var _ = BeforeSuite(func() {
|
||||
log.SetOutput(ioutil.Discard)
|
||||
})
|
||||
@@ -1,33 +0,0 @@
|
||||
// VulcanizeDB
|
||||
// Copyright © 2018 Vulcanize
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package bite
|
||||
|
||||
import (
|
||||
shared_t "github.com/vulcanize/vulcanizedb/libraries/shared/transformer"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
|
||||
)
|
||||
|
||||
func GetBiteConfig() shared_t.TransformerConfig {
|
||||
return shared_t.TransformerConfig{
|
||||
TransformerName: constants.BiteLabel,
|
||||
ContractAddresses: []string{constants.CatContractAddress()},
|
||||
ContractAbi: constants.CatABI(),
|
||||
Topic: constants.GetBiteSignature(),
|
||||
StartingBlockNumber: constants.CatDeploymentBlock(),
|
||||
EndingBlockNumber: -1,
|
||||
}
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
// VulcanizeDB
|
||||
// Copyright © 2018 Vulcanize
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package bite
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/geth"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||
)
|
||||
|
||||
type BiteConverter struct{}
|
||||
|
||||
func (BiteConverter) ToEntities(contractAbi string, ethLogs []types.Log) ([]interface{}, error) {
|
||||
var entities []interface{}
|
||||
for _, ethLog := range ethLogs {
|
||||
entity := &BiteEntity{}
|
||||
address := ethLog.Address
|
||||
abi, err := geth.ParseAbi(contractAbi)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
contract := bind.NewBoundContract(address, abi, nil, nil, nil)
|
||||
|
||||
err = contract.UnpackLog(entity, "Bite", ethLog)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
entity.Raw = ethLog
|
||||
entity.LogIndex = ethLog.Index
|
||||
entity.TransactionIndex = ethLog.TxIndex
|
||||
|
||||
entities = append(entities, *entity)
|
||||
}
|
||||
|
||||
return entities, nil
|
||||
}
|
||||
|
||||
func (converter BiteConverter) ToModels(entities []interface{}) ([]interface{}, error) {
|
||||
var models []interface{}
|
||||
for _, entity := range entities {
|
||||
biteEntity, ok := entity.(BiteEntity)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("entity of type %T, not %T", entity, BiteEntity{})
|
||||
}
|
||||
|
||||
ilk := shared.GetHexWithoutPrefix(biteEntity.Ilk[:])
|
||||
urn := shared.GetHexWithoutPrefix(biteEntity.Urn[:])
|
||||
ink := biteEntity.Ink
|
||||
art := biteEntity.Art
|
||||
iArt := biteEntity.IArt
|
||||
tab := biteEntity.Tab
|
||||
flip := biteEntity.Flip
|
||||
logIdx := biteEntity.LogIndex
|
||||
txIdx := biteEntity.TransactionIndex
|
||||
rawLog, err := json.Marshal(biteEntity.Raw)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
model := BiteModel{
|
||||
Ilk: ilk,
|
||||
Urn: urn,
|
||||
Ink: shared.BigIntToString(ink),
|
||||
Art: shared.BigIntToString(art),
|
||||
IArt: shared.BigIntToString(iArt),
|
||||
Tab: shared.BigIntToString(tab),
|
||||
NFlip: shared.BigIntToString(flip),
|
||||
LogIndex: logIdx,
|
||||
TransactionIndex: txIdx,
|
||||
Raw: rawLog,
|
||||
}
|
||||
models = append(models, model)
|
||||
}
|
||||
return models, nil
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
// VulcanizeDB
|
||||
// Copyright © 2018 Vulcanize
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package bite_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/bite"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
|
||||
)
|
||||
|
||||
var _ = Describe("Bite Converter", func() {
|
||||
var converter = bite.BiteConverter{}
|
||||
|
||||
Describe("ToEntity", func() {
|
||||
It("converts an eth log to a bite entity", func() {
|
||||
entities, err := converter.ToEntities(test_data.KovanCatABI, []types.Log{test_data.EthBiteLog})
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(len(entities)).To(Equal(1))
|
||||
entity := entities[0]
|
||||
Expect(entity).To(Equal(test_data.BiteEntity))
|
||||
})
|
||||
|
||||
It("returns an error if converting log to entity fails", func() {
|
||||
_, err := converter.ToEntities("error abi", []types.Log{test_data.EthBiteLog})
|
||||
|
||||
Expect(err).To(HaveOccurred())
|
||||
})
|
||||
})
|
||||
|
||||
Describe("ToModel", func() {
|
||||
var emptyEntity = bite.BiteEntity{}
|
||||
|
||||
It("converts an Entity to a Model", func() {
|
||||
models, err := converter.ToModels([]interface{}{test_data.BiteEntity})
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(len(models)).To(Equal(1))
|
||||
model := models[0]
|
||||
Expect(model).To(Equal(test_data.BiteModel))
|
||||
})
|
||||
|
||||
It("returns an error if the entity type is wrong", func() {
|
||||
_, err := converter.ToModels([]interface{}{test_data.WrongEntity{}})
|
||||
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(ContainSubstring("entity of type test_data.WrongEntity, not bite.BiteEntity"))
|
||||
})
|
||||
|
||||
It("handles nil values", func() {
|
||||
emptyLog, err := json.Marshal(types.Log{})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
expectedModel := bite.BiteModel{
|
||||
Ilk: "0000000000000000000000000000000000000000000000000000000000000000",
|
||||
Urn: "0000000000000000000000000000000000000000000000000000000000000000",
|
||||
Ink: "",
|
||||
Art: "",
|
||||
IArt: "",
|
||||
Tab: "",
|
||||
NFlip: "",
|
||||
TransactionIndex: 0,
|
||||
Raw: emptyLog,
|
||||
}
|
||||
models, err := converter.ToModels([]interface{}{emptyEntity})
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(len(models)).To(Equal(1))
|
||||
model := models[0]
|
||||
Expect(model).To(Equal(expectedModel))
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,35 +0,0 @@
|
||||
// VulcanizeDB
|
||||
// Copyright © 2018 Vulcanize
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package bite
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
type BiteEntity struct {
|
||||
Ilk [32]byte
|
||||
Urn [32]byte
|
||||
Ink *big.Int
|
||||
Art *big.Int
|
||||
Tab *big.Int
|
||||
Flip *big.Int
|
||||
IArt *big.Int
|
||||
LogIndex uint
|
||||
TransactionIndex uint
|
||||
Raw types.Log
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
// VulcanizeDB
|
||||
// Copyright © 2018 Vulcanize
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package bite
|
||||
|
||||
type BiteModel struct {
|
||||
Ilk string
|
||||
Urn string
|
||||
Ink string
|
||||
Art string
|
||||
IArt string
|
||||
Tab string
|
||||
NFlip string
|
||||
LogIndex uint `db:"log_idx"`
|
||||
TransactionIndex uint `db:"tx_idx"`
|
||||
Raw []byte `db:"raw_log"`
|
||||
}
|
||||
Reference in New Issue
Block a user