2019-04-30 17:48:31 +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 ipfs
|
|
|
|
|
|
|
|
import (
|
2019-05-17 04:08:53 +00:00
|
|
|
"math/big"
|
|
|
|
|
2019-04-30 17:48:31 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
"github.com/ethereum/go-ethereum/core/types"
|
2019-06-18 17:28:57 +00:00
|
|
|
"github.com/ipfs/go-block-format"
|
2019-04-30 17:48:31 +00:00
|
|
|
)
|
|
|
|
|
2019-08-23 21:34:54 +00:00
|
|
|
// CIDWrapper is used to package CIDs retrieved from the local Postgres cache and direct fetching of IPLDs
|
2019-08-05 17:56:15 +00:00
|
|
|
type CIDWrapper struct {
|
2019-06-18 17:28:57 +00:00
|
|
|
BlockNumber *big.Int
|
2019-05-21 19:27:24 +00:00
|
|
|
Headers []string
|
2019-06-18 17:28:57 +00:00
|
|
|
Uncles []string
|
2019-05-21 19:27:24 +00:00
|
|
|
Transactions []string
|
|
|
|
Receipts []string
|
|
|
|
StateNodes []StateNodeCID
|
|
|
|
StorageNodes []StorageNodeCID
|
|
|
|
}
|
|
|
|
|
2019-08-23 21:34:54 +00:00
|
|
|
// IPLDWrapper is used to package raw IPLD block data fetched from IPFS
|
2019-08-05 17:56:15 +00:00
|
|
|
type IPLDWrapper struct {
|
2019-06-18 17:28:57 +00:00
|
|
|
BlockNumber *big.Int
|
2019-05-21 19:27:24 +00:00
|
|
|
Headers []blocks.Block
|
2019-06-18 17:28:57 +00:00
|
|
|
Uncles []blocks.Block
|
2019-05-21 19:27:24 +00:00
|
|
|
Transactions []blocks.Block
|
|
|
|
Receipts []blocks.Block
|
|
|
|
StateNodes map[common.Hash]blocks.Block
|
|
|
|
StorageNodes map[common.Hash]map[common.Hash]blocks.Block
|
|
|
|
}
|
|
|
|
|
2019-08-23 21:34:54 +00:00
|
|
|
// IPLDPayload is a custom type which packages raw ETH data for the IPFS publisher
|
2019-04-30 17:48:31 +00:00
|
|
|
type IPLDPayload struct {
|
|
|
|
HeaderRLP []byte
|
|
|
|
BlockNumber *big.Int
|
|
|
|
BlockHash common.Hash
|
|
|
|
BlockBody *types.Body
|
|
|
|
TrxMetaData []*TrxMetaData
|
|
|
|
Receipts types.Receipts
|
|
|
|
ReceiptMetaData []*ReceiptMetaData
|
2019-05-17 04:08:53 +00:00
|
|
|
StateNodes map[common.Hash]StateNode
|
|
|
|
StorageNodes map[common.Hash][]StorageNode
|
|
|
|
}
|
|
|
|
|
2019-05-21 19:27:24 +00:00
|
|
|
// StateNode struct used to flag node as leaf or not
|
2019-05-17 04:08:53 +00:00
|
|
|
type StateNode struct {
|
|
|
|
Value []byte
|
|
|
|
Leaf bool
|
|
|
|
}
|
|
|
|
|
2019-05-21 19:27:24 +00:00
|
|
|
// StorageNode struct used to flag node as leaf or not
|
2019-05-17 04:08:53 +00:00
|
|
|
type StorageNode struct {
|
|
|
|
Key common.Hash
|
|
|
|
Value []byte
|
|
|
|
Leaf bool
|
2019-04-30 17:48:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// CIDPayload is a struct to hold all the CIDs and their meta data
|
|
|
|
type CIDPayload struct {
|
|
|
|
BlockNumber string
|
2019-05-17 04:08:53 +00:00
|
|
|
BlockHash common.Hash
|
2019-04-30 17:48:31 +00:00
|
|
|
HeaderCID string
|
|
|
|
UncleCIDS map[common.Hash]string
|
|
|
|
TransactionCIDs map[common.Hash]*TrxMetaData
|
|
|
|
ReceiptCIDs map[common.Hash]*ReceiptMetaData
|
2019-05-17 04:08:53 +00:00
|
|
|
StateNodeCIDs map[common.Hash]StateNodeCID
|
|
|
|
StorageNodeCIDs map[common.Hash][]StorageNodeCID
|
|
|
|
}
|
|
|
|
|
2019-05-21 19:27:24 +00:00
|
|
|
// StateNodeCID is used to associate a leaf flag with a state node cid
|
2019-05-17 04:08:53 +00:00
|
|
|
type StateNodeCID struct {
|
|
|
|
CID string
|
|
|
|
Leaf bool
|
2019-05-21 19:27:24 +00:00
|
|
|
Key string `db:"state_key"`
|
2019-05-17 04:08:53 +00:00
|
|
|
}
|
|
|
|
|
2019-05-21 19:27:24 +00:00
|
|
|
// StorageNodeCID is used to associate a leaf flag with a storage node cid
|
2019-05-17 04:08:53 +00:00
|
|
|
type StorageNodeCID struct {
|
2019-05-21 19:27:24 +00:00
|
|
|
Key string `db:"storage_key"`
|
|
|
|
CID string
|
|
|
|
Leaf bool
|
|
|
|
StateKey string `db:"state_key"`
|
2019-04-30 17:48:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ReceiptMetaData wraps some additional data around our receipt CIDs for indexing
|
|
|
|
type ReceiptMetaData struct {
|
2019-06-20 15:59:10 +00:00
|
|
|
CID string
|
|
|
|
Topic0s []string
|
|
|
|
ContractAddress string
|
2019-04-30 17:48:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TrxMetaData wraps some additional data around our transaction CID for indexing
|
|
|
|
type TrxMetaData struct {
|
2019-05-21 19:27:24 +00:00
|
|
|
CID string
|
|
|
|
Src string
|
|
|
|
Dst string
|
2019-04-30 17:48:31 +00:00
|
|
|
}
|