ipld-eth-server/pkg/btc/types.go

77 lines
2.3 KiB
Go
Raw Normal View History

2020-01-29 20:37:20 +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
2020-01-29 21:49:13 +00:00
// along with this program. If not, see <http://www.gnu.org/licenses/>.
2020-01-29 20:37:20 +00:00
package btc
import (
2020-01-29 21:49:13 +00:00
"math/big"
2020-05-30 03:02:47 +00:00
"github.com/vulcanize/ipfs-chain-watcher/pkg/ipfs"
2020-01-29 20:37:20 +00:00
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil"
)
// BlockPayload packages the block and tx data received from block connection notifications
type BlockPayload struct {
2020-02-19 22:09:33 +00:00
BlockHeight int64
Header *wire.BlockHeader
Txs []*btcutil.Tx
2020-01-29 21:49:13 +00:00
}
// ConvertedPayload is a custom type which packages raw BTC data for publishing to IPFS and filtering to subscribers
2020-01-29 21:49:13 +00:00
// Returned by PayloadConverter
// Passed to IPLDPublisher and ResponseFilterer
type ConvertedPayload struct {
BlockPayload
2020-02-02 21:58:07 +00:00
TxMetaData []TxModelWithInsAndOuts
2020-01-29 21:49:13 +00:00
}
2020-02-19 22:09:33 +00:00
// Height satisfies the StreamedIPLDs interface
2020-02-27 21:07:33 +00:00
func (cp ConvertedPayload) Height() int64 {
return cp.BlockPayload.BlockHeight
2020-02-19 22:09:33 +00:00
}
2020-01-29 21:49:13 +00:00
// CIDPayload is a struct to hold all the CIDs and their associated meta data for indexing in Postgres
// Returned by IPLDPublisher
// Passed to CIDIndexer
type CIDPayload struct {
HeaderCID HeaderModel
2020-02-02 21:58:07 +00:00
TransactionCIDs []TxModelWithInsAndOuts
2020-01-29 21:49:13 +00:00
}
// CIDWrapper is used to direct fetching of IPLDs from IPFS
// Returned by CIDRetriever
// Passed to IPLDFetcher
type CIDWrapper struct {
BlockNumber *big.Int
2020-02-23 23:14:29 +00:00
Header HeaderModel
2020-01-29 21:49:13 +00:00
Transactions []TxModel
}
// IPLDs is used to package raw IPLD block data fetched from IPFS and returned by the server
// Returned by IPLDFetcher and ResponseFilterer
type IPLDs struct {
2020-01-29 21:49:13 +00:00
BlockNumber *big.Int
2020-02-23 23:14:29 +00:00
Header ipfs.BlockModel
Transactions []ipfs.BlockModel
2020-01-29 21:49:13 +00:00
}
// Height satisfies the StreamedIPLDs interface
func (i IPLDs) Height() int64 {
return i.BlockNumber.Int64()
2020-01-29 21:49:13 +00:00
}