adjust btc and eth publishers and publisher tests
This commit is contained in:
@@ -19,6 +19,8 @@ package dag_putters
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
node "github.com/ipfs/go-ipld-format"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/pkg/ipfs"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/ipfs/ipld"
|
||||
)
|
||||
@@ -31,13 +33,13 @@ func NewBtcHeaderDagPutter(adder *ipfs.IPFS) *BtcHeaderDagPutter {
|
||||
return &BtcHeaderDagPutter{adder: adder}
|
||||
}
|
||||
|
||||
func (bhdp *BtcHeaderDagPutter) DagPut(raw interface{}) ([]string, error) {
|
||||
header, ok := raw.(*ipld.BtcHeader)
|
||||
func (bhdp *BtcHeaderDagPutter) DagPut(n node.Node) (string, error) {
|
||||
header, ok := n.(*ipld.BtcHeader)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("BtcHeaderDagPutter expected input type %T got %T", &ipld.BtcHeader{}, raw)
|
||||
return "", fmt.Errorf("BtcHeaderDagPutter expected input type %T got %T", &ipld.BtcHeader{}, n)
|
||||
}
|
||||
if err := bhdp.adder.Add(header); err != nil {
|
||||
return nil, err
|
||||
return "", err
|
||||
}
|
||||
return []string{header.Cid().String()}, nil
|
||||
return header.Cid().String(), nil
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@ package dag_putters
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
node "github.com/ipfs/go-ipld-format"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/pkg/ipfs"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/ipfs/ipld"
|
||||
)
|
||||
@@ -31,17 +33,13 @@ func NewBtcTxDagPutter(adder *ipfs.IPFS) *BtcTxDagPutter {
|
||||
return &BtcTxDagPutter{adder: adder}
|
||||
}
|
||||
|
||||
func (etdp *BtcTxDagPutter) DagPut(raw interface{}) ([]string, error) {
|
||||
transactions, ok := raw.([]*ipld.BtcTx)
|
||||
func (etdp *BtcTxDagPutter) DagPut(n node.Node) (string, error) {
|
||||
transaction, ok := n.(*ipld.BtcTx)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("BtcTxDagPutter expected input type %T got %T", []*ipld.BtcTx{}, raw)
|
||||
return "", fmt.Errorf("BtcTxDagPutter expected input type %T got %T", &ipld.BtcTx{}, n)
|
||||
}
|
||||
cids := make([]string, len(transactions))
|
||||
for i, transaction := range transactions {
|
||||
if err := etdp.adder.Add(transaction); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cids[i] = transaction.Cid().String()
|
||||
if err := etdp.adder.Add(transaction); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return cids, nil
|
||||
return transaction.Cid().String(), nil
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
// 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 dag_putters
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
node "github.com/ipfs/go-ipld-format"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/pkg/ipfs"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/ipfs/ipld"
|
||||
)
|
||||
|
||||
type BtcTxTrieDagPutter struct {
|
||||
adder *ipfs.IPFS
|
||||
}
|
||||
|
||||
func NewBtcTxTrieDagPutter(adder *ipfs.IPFS) *BtcTxTrieDagPutter {
|
||||
return &BtcTxTrieDagPutter{adder: adder}
|
||||
}
|
||||
|
||||
func (etdp *BtcTxTrieDagPutter) DagPut(n node.Node) (string, error) {
|
||||
txTrieNode, ok := n.(*ipld.BtcTxTrie)
|
||||
if !ok {
|
||||
return "", fmt.Errorf("BtcTxTrieDagPutter expected input type %T got %T", &ipld.BtcTxTrie{}, n)
|
||||
}
|
||||
if err := etdp.adder.Add(txTrieNode); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return txTrieNode.Cid().String(), nil
|
||||
}
|
||||
@@ -19,6 +19,8 @@ package dag_putters
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
node "github.com/ipfs/go-ipld-format"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/pkg/ipfs"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/ipfs/ipld"
|
||||
)
|
||||
@@ -31,13 +33,13 @@ func NewEthBlockHeaderDagPutter(adder *ipfs.IPFS) *EthHeaderDagPutter {
|
||||
return &EthHeaderDagPutter{adder: adder}
|
||||
}
|
||||
|
||||
func (bhdp *EthHeaderDagPutter) DagPut(raw interface{}) ([]string, error) {
|
||||
header, ok := raw.(*ipld.EthHeader)
|
||||
func (bhdp *EthHeaderDagPutter) DagPut(n node.Node) (string, error) {
|
||||
header, ok := n.(*ipld.EthHeader)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("EthHeaderDagPutter expected input type %T got %T", &ipld.EthHeader{}, raw)
|
||||
return "", fmt.Errorf("EthHeaderDagPutter expected input type %T got %T", &ipld.EthHeader{}, n)
|
||||
}
|
||||
if err := bhdp.adder.Add(header); err != nil {
|
||||
return nil, err
|
||||
return "", err
|
||||
}
|
||||
return []string{header.Cid().String()}, nil
|
||||
return header.Cid().String(), nil
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@ package dag_putters
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
node "github.com/ipfs/go-ipld-format"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/pkg/ipfs"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/ipfs/ipld"
|
||||
)
|
||||
@@ -31,17 +33,13 @@ func NewEthReceiptDagPutter(adder *ipfs.IPFS) *EthReceiptDagPutter {
|
||||
return &EthReceiptDagPutter{adder: adder}
|
||||
}
|
||||
|
||||
func (erdp *EthReceiptDagPutter) DagPut(raw interface{}) ([]string, error) {
|
||||
receipts, ok := raw.([]*ipld.EthReceipt)
|
||||
func (erdp *EthReceiptDagPutter) DagPut(n node.Node) (string, error) {
|
||||
receipt, ok := n.(*ipld.EthReceipt)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("EthReceiptDagPutter expected input type %T got type %T", []*ipld.EthReceipt{}, raw)
|
||||
return "", fmt.Errorf("EthReceiptDagPutter expected input type %T got type %T", &ipld.EthReceipt{}, n)
|
||||
}
|
||||
cids := make([]string, len(receipts))
|
||||
for i, receipt := range receipts {
|
||||
if err := erdp.adder.Add(receipt); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cids[i] = receipt.Cid().String()
|
||||
if err := erdp.adder.Add(receipt); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return cids, nil
|
||||
return receipt.Cid().String(), nil
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@ package dag_putters
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
node "github.com/ipfs/go-ipld-format"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/pkg/ipfs"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/ipfs/ipld"
|
||||
)
|
||||
@@ -31,17 +33,13 @@ func NewEthRctTrieDagPutter(adder *ipfs.IPFS) *EthRctTrieDagPutter {
|
||||
return &EthRctTrieDagPutter{adder: adder}
|
||||
}
|
||||
|
||||
func (etdp *EthRctTrieDagPutter) DagPut(raw interface{}) ([]string, error) {
|
||||
rctTrieNodes, ok := raw.([]*ipld.EthRctTrie)
|
||||
func (etdp *EthRctTrieDagPutter) DagPut(n node.Node) (string, error) {
|
||||
rctTrieNode, ok := n.(*ipld.EthRctTrie)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("EthRctTrieDagPutter expected input type %T got %T", []*ipld.EthRctTrie{}, raw)
|
||||
return "", fmt.Errorf("EthRctTrieDagPutter expected input type %T got %T", &ipld.EthRctTrie{}, n)
|
||||
}
|
||||
cids := make([]string, len(rctTrieNodes))
|
||||
for i, rctNode := range rctTrieNodes {
|
||||
if err := etdp.adder.Add(rctNode); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cids[i] = rctNode.Cid().String()
|
||||
if err := etdp.adder.Add(rctTrieNode); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return cids, nil
|
||||
return rctTrieNode.Cid().String(), nil
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@ package dag_putters
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
node "github.com/ipfs/go-ipld-format"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/pkg/ipfs"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/ipfs/ipld"
|
||||
)
|
||||
@@ -31,13 +33,13 @@ func NewEthStateDagPutter(adder *ipfs.IPFS) *EthStateDagPutter {
|
||||
return &EthStateDagPutter{adder: adder}
|
||||
}
|
||||
|
||||
func (erdp *EthStateDagPutter) DagPut(raw interface{}) ([]string, error) {
|
||||
stateNode, ok := raw.(*ipld.EthStateTrie)
|
||||
func (erdp *EthStateDagPutter) DagPut(n node.Node) (string, error) {
|
||||
stateNode, ok := n.(*ipld.EthStateTrie)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("EthStateDagPutter expected input type %T got %T", &ipld.EthStateTrie{}, raw)
|
||||
return "", fmt.Errorf("EthStateDagPutter expected input type %T got %T", &ipld.EthStateTrie{}, n)
|
||||
}
|
||||
if err := erdp.adder.Add(stateNode); err != nil {
|
||||
return nil, err
|
||||
return "", err
|
||||
}
|
||||
return []string{stateNode.Cid().String()}, nil
|
||||
return stateNode.Cid().String(), nil
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@ package dag_putters
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
node "github.com/ipfs/go-ipld-format"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/pkg/ipfs"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/ipfs/ipld"
|
||||
)
|
||||
@@ -31,13 +33,13 @@ func NewEthStorageDagPutter(adder *ipfs.IPFS) *EthStorageDagPutter {
|
||||
return &EthStorageDagPutter{adder: adder}
|
||||
}
|
||||
|
||||
func (erdp *EthStorageDagPutter) DagPut(raw interface{}) ([]string, error) {
|
||||
storageNode, ok := raw.(*ipld.EthStorageTrie)
|
||||
func (erdp *EthStorageDagPutter) DagPut(n node.Node) (string, error) {
|
||||
storageNode, ok := n.(*ipld.EthStorageTrie)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("EthStorageDagPutter expected input type %T got %T", &ipld.EthStorageTrie{}, raw)
|
||||
return "", fmt.Errorf("EthStorageDagPutter expected input type %T got %T", &ipld.EthStorageTrie{}, n)
|
||||
}
|
||||
if err := erdp.adder.Add(storageNode); err != nil {
|
||||
return nil, err
|
||||
return "", err
|
||||
}
|
||||
return []string{storageNode.Cid().String()}, nil
|
||||
return storageNode.Cid().String(), nil
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@ package dag_putters
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
node "github.com/ipfs/go-ipld-format"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/pkg/ipfs"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/ipfs/ipld"
|
||||
)
|
||||
@@ -31,17 +33,13 @@ func NewEthTxsDagPutter(adder *ipfs.IPFS) *EthTxsDagPutter {
|
||||
return &EthTxsDagPutter{adder: adder}
|
||||
}
|
||||
|
||||
func (etdp *EthTxsDagPutter) DagPut(raw interface{}) ([]string, error) {
|
||||
transactions, ok := raw.([]*ipld.EthTx)
|
||||
func (etdp *EthTxsDagPutter) DagPut(n node.Node) (string, error) {
|
||||
transaction, ok := n.(*ipld.EthTx)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("EthTxsDagPutter expected input type %T got %T", []*ipld.EthTx{}, raw)
|
||||
return "", fmt.Errorf("EthTxsDagPutter expected input type %T got %T", &ipld.EthTx{}, n)
|
||||
}
|
||||
cids := make([]string, len(transactions))
|
||||
for i, transaction := range transactions {
|
||||
if err := etdp.adder.Add(transaction); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cids[i] = transaction.Cid().String()
|
||||
if err := etdp.adder.Add(transaction); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return cids, nil
|
||||
return transaction.Cid().String(), nil
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@ package dag_putters
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
node "github.com/ipfs/go-ipld-format"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/pkg/ipfs"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/ipfs/ipld"
|
||||
)
|
||||
@@ -31,17 +33,13 @@ func NewEthTxTrieDagPutter(adder *ipfs.IPFS) *EthTxTrieDagPutter {
|
||||
return &EthTxTrieDagPutter{adder: adder}
|
||||
}
|
||||
|
||||
func (etdp *EthTxTrieDagPutter) DagPut(raw interface{}) ([]string, error) {
|
||||
txTrieNodes, ok := raw.([]*ipld.EthTxTrie)
|
||||
func (etdp *EthTxTrieDagPutter) DagPut(n node.Node) (string, error) {
|
||||
txTrieNode, ok := n.(*ipld.EthTxTrie)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("EthTxTrieDagPutter expected input type %T got %T", []*ipld.EthTxTrie{}, raw)
|
||||
return "", fmt.Errorf("EthTxTrieDagPutter expected input type %T got %T", &ipld.EthTxTrie{}, n)
|
||||
}
|
||||
cids := make([]string, len(txTrieNodes))
|
||||
for i, txNode := range txTrieNodes {
|
||||
if err := etdp.adder.Add(txNode); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cids[i] = txNode.Cid().String()
|
||||
if err := etdp.adder.Add(txTrieNode); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return cids, nil
|
||||
return txTrieNode.Cid().String(), nil
|
||||
}
|
||||
|
||||
@@ -21,35 +21,35 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
mh "github.com/multiformats/go-multihash"
|
||||
)
|
||||
|
||||
// FromBlock takes a block and processes it
|
||||
// FromBlockAndReceipts takes a block and processes it
|
||||
// to return it a set of IPLD nodes for further processing.
|
||||
func FromBlock(block *types.Block, receipts []*types.Receipt) (*EthHeader, []*EthTx, []*EthTxTrie, []*EthReceipt, []*EthRctTrie, error) {
|
||||
// process the eth-header object
|
||||
headerRawData := getRLP(block.Header())
|
||||
cid, err := RawdataToCid(MEthHeader, headerRawData, mh.KECCAK_256)
|
||||
func FromBlockAndReceipts(block *types.Block, receipts []*types.Receipt) (*EthHeader, []*EthHeader, []*EthTx, []*EthTxTrie, []*EthReceipt, []*EthRctTrie, error) {
|
||||
// Process the header
|
||||
headerNode, err := NewEthHeader(block.Header())
|
||||
if err != nil {
|
||||
return nil, nil, nil, nil, nil, err
|
||||
return nil, nil, nil, nil, nil, nil, err
|
||||
}
|
||||
ethHeader := &EthHeader{
|
||||
Header: block.Header(),
|
||||
cid: cid,
|
||||
rawdata: headerRawData,
|
||||
// Process the uncles
|
||||
uncleNodes := make([]*EthHeader, len(block.Uncles()))
|
||||
for i, uncle := range block.Uncles() {
|
||||
uncleNode, err := NewEthHeader(uncle)
|
||||
if err != nil {
|
||||
return nil, nil, nil, nil, nil, nil, err
|
||||
}
|
||||
uncleNodes[i] = uncleNode
|
||||
}
|
||||
|
||||
// Process the found eth-tx objects
|
||||
// Process the txs
|
||||
ethTxNodes, ethTxTrieNodes, err := processTransactions(block.Transactions(),
|
||||
block.Header().TxHash[:])
|
||||
if err != nil {
|
||||
return nil, nil, nil, nil, nil, err
|
||||
return nil, nil, nil, nil, nil, nil, err
|
||||
}
|
||||
// process the eth-rct objects
|
||||
// Process the receipts
|
||||
ethRctNodes, ethRctTrieNodes, err := processReceipts(receipts,
|
||||
block.Header().ReceiptHash[:])
|
||||
|
||||
return ethHeader, ethTxNodes, ethTxTrieNodes, ethRctNodes, ethRctTrieNodes, nil
|
||||
return headerNode, uncleNodes, ethTxNodes, ethTxTrieNodes, ethRctNodes, ethRctTrieNodes, err
|
||||
}
|
||||
|
||||
// processTransactions will take the found transactions in a parsed block body
|
||||
@@ -132,6 +132,9 @@ func (lt *localTrie) add(idx int, rawdata []byte) {
|
||||
panic(err)
|
||||
}
|
||||
lt.keys = append(lt.keys, key)
|
||||
if err := lt.db.Put(key, rawdata); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
lt.trie.Update(key, rawdata)
|
||||
}
|
||||
|
||||
|
||||
@@ -19,39 +19,35 @@ package mocks
|
||||
import (
|
||||
"errors"
|
||||
|
||||
node "github.com/ipfs/go-ipld-format"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
)
|
||||
|
||||
// DagPutter is a mock for testing the ipfs publisher
|
||||
type DagPutter struct {
|
||||
CIDsToReturn []string
|
||||
PassedRaw interface{}
|
||||
ErrToReturn error
|
||||
PassedNode node.Node
|
||||
ErrToReturn error
|
||||
}
|
||||
|
||||
// DagPut returns the pre-loaded CIDs or error
|
||||
func (dp *DagPutter) DagPut(raw interface{}) ([]string, error) {
|
||||
dp.PassedRaw = raw
|
||||
return dp.CIDsToReturn, dp.ErrToReturn
|
||||
func (dp *DagPutter) DagPut(n node.Node) (string, error) {
|
||||
dp.PassedNode = n
|
||||
return n.Cid().String(), dp.ErrToReturn
|
||||
}
|
||||
|
||||
// MappedDagPutter is a mock for testing the ipfs publisher
|
||||
type MappedDagPutter struct {
|
||||
CIDsToReturn map[common.Hash][]string
|
||||
PassedRaw interface{}
|
||||
CIDsToReturn map[common.Hash]string
|
||||
PassedNode node.Node
|
||||
ErrToReturn error
|
||||
}
|
||||
|
||||
// DagPut returns the pre-loaded CIDs or error
|
||||
func (mdp *MappedDagPutter) DagPut(raw interface{}) ([]string, error) {
|
||||
mdp.PassedRaw = raw
|
||||
func (mdp *MappedDagPutter) DagPut(n node.Node) (string, error) {
|
||||
if mdp.CIDsToReturn == nil {
|
||||
return nil, errors.New("mapped dag putter needs to be initialized with a map of cids to return")
|
||||
return "", errors.New("mapped dag putter needs to be initialized with a map of cids to return")
|
||||
}
|
||||
by, ok := raw.([]byte)
|
||||
if !ok {
|
||||
return nil, errors.New("mapped dag putters can only dag put []byte values")
|
||||
}
|
||||
hash := common.BytesToHash(by)
|
||||
hash := common.BytesToHash(n.RawData())
|
||||
return mdp.CIDsToReturn[hash], nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user