don't throw error on duplicate key insert

This commit is contained in:
Ian Norden 2020-03-25 19:14:20 -05:00
parent eb9c49a3e9
commit 716cc3663f
10 changed files with 24 additions and 10 deletions

View File

@ -18,6 +18,7 @@ package dag_putters
import (
"fmt"
"strings"
node "github.com/ipfs/go-ipld-format"
@ -25,6 +26,10 @@ import (
"github.com/vulcanize/vulcanizedb/pkg/ipfs/ipld"
)
var (
duplicateKeyErrorString = "pq: duplicate key value violates unique constraint"
)
type BtcHeaderDagPutter struct {
adder *ipfs.IPFS
}
@ -38,7 +43,7 @@ func (bhdp *BtcHeaderDagPutter) DagPut(n node.Node) (string, error) {
if !ok {
return "", fmt.Errorf("BtcHeaderDagPutter expected input type %T got %T", &ipld.BtcHeader{}, n)
}
if err := bhdp.adder.Add(header); err != nil {
if err := bhdp.adder.Add(header); err != nil && !strings.Contains(err.Error(), duplicateKeyErrorString) {
return "", err
}
return header.Cid().String(), nil

View File

@ -18,6 +18,7 @@ package dag_putters
import (
"fmt"
"strings"
node "github.com/ipfs/go-ipld-format"
@ -38,7 +39,7 @@ func (etdp *BtcTxDagPutter) DagPut(n node.Node) (string, error) {
if !ok {
return "", fmt.Errorf("BtcTxDagPutter expected input type %T got %T", &ipld.BtcTx{}, n)
}
if err := etdp.adder.Add(transaction); err != nil {
if err := etdp.adder.Add(transaction); err != nil && !strings.Contains(err.Error(), duplicateKeyErrorString) {
return "", err
}
return transaction.Cid().String(), nil

View File

@ -18,6 +18,7 @@ package dag_putters
import (
"fmt"
"strings"
node "github.com/ipfs/go-ipld-format"
@ -38,7 +39,7 @@ func (etdp *BtcTxTrieDagPutter) DagPut(n node.Node) (string, error) {
if !ok {
return "", fmt.Errorf("BtcTxTrieDagPutter expected input type %T got %T", &ipld.BtcTxTrie{}, n)
}
if err := etdp.adder.Add(txTrieNode); err != nil {
if err := etdp.adder.Add(txTrieNode); err != nil && !strings.Contains(err.Error(), duplicateKeyErrorString) {
return "", err
}
return txTrieNode.Cid().String(), nil

View File

@ -18,6 +18,7 @@ package dag_putters
import (
"fmt"
"strings"
node "github.com/ipfs/go-ipld-format"
@ -38,7 +39,7 @@ func (bhdp *EthHeaderDagPutter) DagPut(n node.Node) (string, error) {
if !ok {
return "", fmt.Errorf("EthHeaderDagPutter expected input type %T got %T", &ipld.EthHeader{}, n)
}
if err := bhdp.adder.Add(header); err != nil {
if err := bhdp.adder.Add(header); err != nil && !strings.Contains(err.Error(), duplicateKeyErrorString) {
return "", err
}
return header.Cid().String(), nil

View File

@ -18,6 +18,7 @@ package dag_putters
import (
"fmt"
"strings"
node "github.com/ipfs/go-ipld-format"
@ -38,7 +39,7 @@ func (erdp *EthReceiptDagPutter) DagPut(n node.Node) (string, error) {
if !ok {
return "", fmt.Errorf("EthReceiptDagPutter expected input type %T got type %T", &ipld.EthReceipt{}, n)
}
if err := erdp.adder.Add(receipt); err != nil {
if err := erdp.adder.Add(receipt); err != nil && !strings.Contains(err.Error(), duplicateKeyErrorString) {
return "", err
}
return receipt.Cid().String(), nil

View File

@ -18,6 +18,7 @@ package dag_putters
import (
"fmt"
"strings"
node "github.com/ipfs/go-ipld-format"
@ -38,7 +39,7 @@ func (etdp *EthRctTrieDagPutter) DagPut(n node.Node) (string, error) {
if !ok {
return "", fmt.Errorf("EthRctTrieDagPutter expected input type %T got %T", &ipld.EthRctTrie{}, n)
}
if err := etdp.adder.Add(rctTrieNode); err != nil {
if err := etdp.adder.Add(rctTrieNode); err != nil && !strings.Contains(err.Error(), duplicateKeyErrorString) {
return "", err
}
return rctTrieNode.Cid().String(), nil

View File

@ -18,6 +18,7 @@ package dag_putters
import (
"fmt"
"strings"
node "github.com/ipfs/go-ipld-format"
@ -38,7 +39,7 @@ func (erdp *EthStateDagPutter) DagPut(n node.Node) (string, error) {
if !ok {
return "", fmt.Errorf("EthStateDagPutter expected input type %T got %T", &ipld.EthStateTrie{}, n)
}
if err := erdp.adder.Add(stateNode); err != nil {
if err := erdp.adder.Add(stateNode); err != nil && !strings.Contains(err.Error(), duplicateKeyErrorString) {
return "", err
}
return stateNode.Cid().String(), nil

View File

@ -18,6 +18,7 @@ package dag_putters
import (
"fmt"
"strings"
node "github.com/ipfs/go-ipld-format"
@ -38,7 +39,7 @@ func (erdp *EthStorageDagPutter) DagPut(n node.Node) (string, error) {
if !ok {
return "", fmt.Errorf("EthStorageDagPutter expected input type %T got %T", &ipld.EthStorageTrie{}, n)
}
if err := erdp.adder.Add(storageNode); err != nil {
if err := erdp.adder.Add(storageNode); err != nil && !strings.Contains(err.Error(), duplicateKeyErrorString) {
return "", err
}
return storageNode.Cid().String(), nil

View File

@ -18,6 +18,7 @@ package dag_putters
import (
"fmt"
"strings"
node "github.com/ipfs/go-ipld-format"
@ -38,7 +39,7 @@ func (etdp *EthTxsDagPutter) DagPut(n node.Node) (string, error) {
if !ok {
return "", fmt.Errorf("EthTxsDagPutter expected input type %T got %T", &ipld.EthTx{}, n)
}
if err := etdp.adder.Add(transaction); err != nil {
if err := etdp.adder.Add(transaction); err != nil && !strings.Contains(err.Error(), duplicateKeyErrorString) {
return "", err
}
return transaction.Cid().String(), nil

View File

@ -18,6 +18,7 @@ package dag_putters
import (
"fmt"
"strings"
node "github.com/ipfs/go-ipld-format"
@ -38,7 +39,7 @@ func (etdp *EthTxTrieDagPutter) DagPut(n node.Node) (string, error) {
if !ok {
return "", fmt.Errorf("EthTxTrieDagPutter expected input type %T got %T", &ipld.EthTxTrie{}, n)
}
if err := etdp.adder.Add(txTrieNode); err != nil {
if err := etdp.adder.Add(txTrieNode); err != nil && !strings.Contains(err.Error(), duplicateKeyErrorString) {
return "", err
}
return txTrieNode.Cid().String(), nil