forked from cerc-io/ipld-eth-server
move interface_getter.go from ens_watcher to vDB pkging- used to construct a custom ABI based on results from calls to supportsInterface; also moved fetcher.go from examples to pkg
This commit is contained in:
1 parent
59cdaa05e6
commit
aa4e698240
10 files changed
+342
-12
No files matched your search
@@ -19,8 +19,8 @@ package every_block
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/examples/generic"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/core"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/omni/shared/fetcher"
|
||||
)
|
||||
|
||||
// Getter serves as a higher level data fetcher that invokes its underlying Fetcher methods for a given contract method
|
||||
@@ -35,13 +35,13 @@ type ERC20GetterInterface interface {
|
||||
|
||||
// Getter struct
|
||||
type ERC20Getter struct {
|
||||
generic.Fetcher
|
||||
fetcher.Fetcher
|
||||
}
|
||||
|
||||
// Initializes and returns a Getter with the given blockchain
|
||||
func NewGetter(blockChain core.BlockChain) ERC20Getter {
|
||||
return ERC20Getter{
|
||||
Fetcher: generic.Fetcher{
|
||||
Fetcher: fetcher.Fetcher{
|
||||
BlockChain: blockChain,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -17,12 +17,12 @@
|
||||
package every_block
|
||||
|
||||
import (
|
||||
"github.com/vulcanize/vulcanizedb/examples/generic"
|
||||
"math/big"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/pkg/core"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/omni/shared/fetcher"
|
||||
)
|
||||
|
||||
// Getter serves as a higher level data fetcher that invokes its underlying Fetcher methods for a given contract method
|
||||
@@ -41,13 +41,13 @@ type GenericGetterInterface interface {
|
||||
|
||||
// Getter struct
|
||||
type GenericGetter struct {
|
||||
generic.Fetcher // Underlying Fetcher
|
||||
fetcher.Fetcher // Underlying Fetcher
|
||||
}
|
||||
|
||||
// Initializes and returns a Getter with the given blockchain
|
||||
func NewGetter(blockChain core.BlockChain) GenericGetter {
|
||||
return GenericGetter{
|
||||
Fetcher: generic.Fetcher{
|
||||
Fetcher: fetcher.Fetcher{
|
||||
BlockChain: blockChain,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1,122 +0,0 @@
|
||||
// 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 generic
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"math/big"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/pkg/core"
|
||||
)
|
||||
|
||||
// Fetcher serves as the lower level data fetcher that calls the underlying
|
||||
// blockchain's FetchConctractData method for a given return type
|
||||
|
||||
// Interface definition for a Fetcher
|
||||
type FetcherInterface interface {
|
||||
FetchBigInt(method, contractAbi, contractAddress string, blockNumber int64, methodArgs []interface{}) (big.Int, error)
|
||||
FetchBool(method, contractAbi, contractAddress string, blockNumber int64, methodArgs []interface{}) (bool, error)
|
||||
FetchAddress(method, contractAbi, contractAddress string, blockNumber int64, methodArgs []interface{}) (common.Address, error)
|
||||
FetchString(method, contractAbi, contractAddress string, blockNumber int64, methodArgs []interface{}) (string, error)
|
||||
FetchHash(method, contractAbi, contractAddress string, blockNumber int64, methodArgs []interface{}) (common.Hash, error)
|
||||
}
|
||||
|
||||
// Used to create a new Fetcher error for a given error and fetch method
|
||||
func newFetcherError(err error, fetchMethod string) *fetcherError {
|
||||
e := fetcherError{err.Error(), fetchMethod}
|
||||
log.Println(e.Error())
|
||||
return &e
|
||||
}
|
||||
|
||||
// Fetcher struct
|
||||
type Fetcher struct {
|
||||
BlockChain core.BlockChain // Underyling Blockchain
|
||||
}
|
||||
|
||||
// Fetcher error
|
||||
type fetcherError struct {
|
||||
err string
|
||||
fetchMethod string
|
||||
}
|
||||
|
||||
// Fetcher error method
|
||||
func (fe *fetcherError) Error() string {
|
||||
return fmt.Sprintf("Error fetching %s: %s", fe.fetchMethod, fe.err)
|
||||
}
|
||||
|
||||
// Generic Fetcher methods used by Getters to call contract methods
|
||||
|
||||
// Method used to fetch big.Int value from contract
|
||||
func (f Fetcher) FetchBigInt(method, contractAbi, contractAddress string, blockNumber int64, methodArgs []interface{}) (big.Int, error) {
|
||||
var result = new(big.Int)
|
||||
err := f.BlockChain.FetchContractData(contractAbi, contractAddress, method, methodArgs, &result, blockNumber)
|
||||
|
||||
if err != nil {
|
||||
return *result, newFetcherError(err, method)
|
||||
}
|
||||
|
||||
return *result, nil
|
||||
}
|
||||
|
||||
// Method used to fetch bool value from contract
|
||||
func (f Fetcher) FetchBool(method, contractAbi, contractAddress string, blockNumber int64, methodArgs []interface{}) (bool, error) {
|
||||
var result = new(bool)
|
||||
err := f.BlockChain.FetchContractData(contractAbi, contractAddress, method, methodArgs, &result, blockNumber)
|
||||
|
||||
if err != nil {
|
||||
return *result, newFetcherError(err, method)
|
||||
}
|
||||
|
||||
return *result, nil
|
||||
}
|
||||
|
||||
// Method used to fetch address value from contract
|
||||
func (f Fetcher) FetchAddress(method, contractAbi, contractAddress string, blockNumber int64, methodArgs []interface{}) (common.Address, error) {
|
||||
var result = new(common.Address)
|
||||
err := f.BlockChain.FetchContractData(contractAbi, contractAddress, method, methodArgs, &result, blockNumber)
|
||||
|
||||
if err != nil {
|
||||
return *result, newFetcherError(err, method)
|
||||
}
|
||||
|
||||
return *result, nil
|
||||
}
|
||||
|
||||
// Method used to fetch string value from contract
|
||||
func (f Fetcher) FetchString(method, contractAbi, contractAddress string, blockNumber int64, methodArgs []interface{}) (string, error) {
|
||||
var result = new(string)
|
||||
err := f.BlockChain.FetchContractData(contractAbi, contractAddress, method, methodArgs, &result, blockNumber)
|
||||
|
||||
if err != nil {
|
||||
return *result, newFetcherError(err, method)
|
||||
}
|
||||
|
||||
return *result, nil
|
||||
}
|
||||
|
||||
// Method used to fetch hash value from contract
|
||||
func (f Fetcher) FetchHash(method, contractAbi, contractAddress string, blockNumber int64, methodArgs []interface{}) (common.Hash, error) {
|
||||
var result = new(common.Hash)
|
||||
err := f.BlockChain.FetchContractData(contractAbi, contractAddress, method, methodArgs, &result, blockNumber)
|
||||
|
||||
if err != nil {
|
||||
return *result, newFetcherError(err, method)
|
||||
}
|
||||
|
||||
return *result, nil
|
||||
}
|
||||
Reference in new issue
Block a user