ipld-eth-server/pkg/watcher/constructors.go

54 lines
2.1 KiB
Go
Raw Normal View History

2020-02-19 22:32:59 +00:00
// VulcanizeDB
// Copyright © 2019 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 watcher
import (
"fmt"
"github.com/vulcanize/vulcanizedb/libraries/shared/streamer"
"github.com/vulcanize/vulcanizedb/pkg/eth/core"
"github.com/vulcanize/vulcanizedb/pkg/postgres"
shared2 "github.com/vulcanize/vulcanizedb/pkg/super_node/shared"
2020-02-23 23:14:29 +00:00
"github.com/vulcanize/vulcanizedb/pkg/watcher/eth"
"github.com/vulcanize/vulcanizedb/pkg/watcher/shared"
2020-02-19 22:32:59 +00:00
)
// NewSuperNodeStreamer returns a new shared.SuperNodeStreamer
func NewSuperNodeStreamer(source shared.SourceType, client interface{}) (shared.SuperNodeStreamer, error) {
switch source {
case shared.VulcanizeDB:
cli, ok := client.(core.RPCClient)
if !ok {
var expectedClientType core.RPCClient
return nil, fmt.Errorf("vulcanizedb NewSuperNodeStreamer construct expects client type %T got %T", expectedClientType, client)
}
return streamer.NewSuperNodeStreamer(cli), nil
default:
return nil, fmt.Errorf("NewSuperNodeStreamer constructor unexpected souce type %s", source.String())
}
2020-02-19 22:32:59 +00:00
}
// NewRepository constructs and returns a new Repository that satisfies the shared.Repository interface for the specified chain
func NewRepository(chain shared2.ChainType, db *postgres.DB, triggerFuncs []string) (shared.Repository, error) {
2020-02-19 22:32:59 +00:00
switch chain {
case shared2.Ethereum:
return eth.NewRepository(db, triggerFuncs), nil
default:
return nil, fmt.Errorf("NewRepository constructor unexpected chain type %s", chain.String())
}
}