forked from cerc-io/ipld-eth-server
Rename Cid to CID
This commit is contained in:
parent
31e9a7dc5e
commit
1fc53ccab1
@ -54,7 +54,7 @@ func (IPLDModelRecord) TableName() string {
|
|||||||
return "public.blocks"
|
return "public.blocks"
|
||||||
}
|
}
|
||||||
|
|
||||||
type HeaderCidRecord struct {
|
type HeaderCIDRecord struct {
|
||||||
CID string `gorm:"column:cid"`
|
CID string `gorm:"column:cid"`
|
||||||
BlockHash string `gorm:"primaryKey"`
|
BlockHash string `gorm:"primaryKey"`
|
||||||
BlockNumber string
|
BlockNumber string
|
||||||
@ -70,16 +70,16 @@ type HeaderCidRecord struct {
|
|||||||
|
|
||||||
// gorm doesn't check if foreign key exists in database.
|
// gorm doesn't check if foreign key exists in database.
|
||||||
// It is required to eager load relations using preload.
|
// It is required to eager load relations using preload.
|
||||||
TransactionCids []TransactionCidRecord `gorm:"foreignKey:HeaderID;references:BlockHash"`
|
TransactionCIDs []TransactionCIDRecord `gorm:"foreignKey:HeaderID;references:BlockHash"`
|
||||||
IPLD IPLDModelRecord `gorm:"foreignKey:MhKey;references:Key"`
|
IPLD IPLDModelRecord `gorm:"foreignKey:MhKey;references:Key"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableName overrides the table name used by HeaderCid
|
// TableName overrides the table name used by HeaderCIDRecord
|
||||||
func (HeaderCidRecord) TableName() string {
|
func (HeaderCIDRecord) TableName() string {
|
||||||
return "eth.header_cids"
|
return "eth.header_cids"
|
||||||
}
|
}
|
||||||
|
|
||||||
type TransactionCidRecord struct {
|
type TransactionCIDRecord struct {
|
||||||
CID string `gorm:"column:cid"`
|
CID string `gorm:"column:cid"`
|
||||||
TxHash string `gorm:"primaryKey"`
|
TxHash string `gorm:"primaryKey"`
|
||||||
HeaderID string `gorm:"column:header_id"`
|
HeaderID string `gorm:"column:header_id"`
|
||||||
@ -90,8 +90,8 @@ type TransactionCidRecord struct {
|
|||||||
IPLD IPLDModelRecord `gorm:"foreignKey:MhKey;references:Key"`
|
IPLD IPLDModelRecord `gorm:"foreignKey:MhKey;references:Key"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableName overrides the table name used by TransactionCid
|
// TableName overrides the table name used by TransactionCIDRecord
|
||||||
func (TransactionCidRecord) TableName() string {
|
func (TransactionCIDRecord) TableName() string {
|
||||||
return "eth.transaction_cids"
|
return "eth.transaction_cids"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -367,8 +367,8 @@ func (ecr *CIDRetriever) RetrieveRctCIDsByHeaderID(tx *sqlx.Tx, rctFilter Receip
|
|||||||
pgStr, args = receiptFilterConditions(&id, pgStr, args, rctFilter, trxHashes)
|
pgStr, args = receiptFilterConditions(&id, pgStr, args, rctFilter, trxHashes)
|
||||||
|
|
||||||
pgStr += ` ORDER BY transaction_cids.index`
|
pgStr += ` ORDER BY transaction_cids.index`
|
||||||
receiptCids := make([]models.ReceiptModel, 0)
|
receiptCIDs := make([]models.ReceiptModel, 0)
|
||||||
return receiptCids, tx.Select(&receiptCids, pgStr, args...)
|
return receiptCIDs, tx.Select(&receiptCIDs, pgStr, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RetrieveFilteredGQLLogs retrieves and returns all the log cIDs provided blockHash that conform to the provided
|
// RetrieveFilteredGQLLogs retrieves and returns all the log cIDs provided blockHash that conform to the provided
|
||||||
@ -462,8 +462,8 @@ func (ecr *CIDRetriever) RetrieveRctCIDs(tx *sqlx.Tx, rctFilter ReceiptFilter, b
|
|||||||
pgStr, args = receiptFilterConditions(&id, pgStr, args, rctFilter, txHashes)
|
pgStr, args = receiptFilterConditions(&id, pgStr, args, rctFilter, txHashes)
|
||||||
|
|
||||||
pgStr += ` ORDER BY transaction_cids.index`
|
pgStr += ` ORDER BY transaction_cids.index`
|
||||||
receiptCids := make([]models.ReceiptModel, 0)
|
receiptCIDs := make([]models.ReceiptModel, 0)
|
||||||
return receiptCids, tx.Select(&receiptCids, pgStr, args...)
|
return receiptCIDs, tx.Select(&receiptCIDs, pgStr, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func hasTopics(topics [][]string) bool {
|
func hasTopics(topics [][]string) bool {
|
||||||
@ -670,14 +670,14 @@ func (ecr *CIDRetriever) RetrieveReceiptCIDsByTxIDs(tx *sqlx.Tx, txHashes []stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RetrieveHeaderAndTxCIDsByBlockNumber retrieves header CIDs and their associated tx CIDs by block number
|
// RetrieveHeaderAndTxCIDsByBlockNumber retrieves header CIDs and their associated tx CIDs by block number
|
||||||
func (ecr *CIDRetriever) RetrieveHeaderAndTxCIDsByBlockNumber(blockNumber int64) ([]HeaderCidRecord, error) {
|
func (ecr *CIDRetriever) RetrieveHeaderAndTxCIDsByBlockNumber(blockNumber int64) ([]HeaderCIDRecord, error) {
|
||||||
log.Debug("retrieving header cids and tx cids for block number ", blockNumber)
|
log.Debug("retrieving header cids and tx cids for block number ", blockNumber)
|
||||||
|
|
||||||
var headerCIDs []HeaderCidRecord
|
var headerCIDs []HeaderCIDRecord
|
||||||
|
|
||||||
// https://github.com/go-gorm/gorm/issues/4083#issuecomment-778883283
|
// https://github.com/go-gorm/gorm/issues/4083#issuecomment-778883283
|
||||||
// Will use join for TransactionCids once preload for 1:N is supported.
|
// Will use join for TransactionCIDs once preload for 1:N is supported.
|
||||||
err := ecr.gormDB.Preload("TransactionCids", func(tx *gorm.DB) *gorm.DB {
|
err := ecr.gormDB.Preload("TransactionCIDs", func(tx *gorm.DB) *gorm.DB {
|
||||||
return tx.Select("cid", "tx_hash", "index", "src", "dst", "header_id")
|
return tx.Select("cid", "tx_hash", "index", "src", "dst", "header_id")
|
||||||
}).Joins("IPLD").Find(&headerCIDs, "block_number = ?", blockNumber).Error
|
}).Joins("IPLD").Find(&headerCIDs, "block_number = ?", blockNumber).Error
|
||||||
|
|
||||||
@ -690,14 +690,14 @@ func (ecr *CIDRetriever) RetrieveHeaderAndTxCIDsByBlockNumber(blockNumber int64)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RetrieveHeaderAndTxCIDsByBlockHash retrieves header CID and their associated tx CIDs by block hash
|
// RetrieveHeaderAndTxCIDsByBlockHash retrieves header CID and their associated tx CIDs by block hash
|
||||||
func (ecr *CIDRetriever) RetrieveHeaderAndTxCIDsByBlockHash(blockHash common.Hash) (HeaderCidRecord, error) {
|
func (ecr *CIDRetriever) RetrieveHeaderAndTxCIDsByBlockHash(blockHash common.Hash) (HeaderCIDRecord, error) {
|
||||||
log.Debug("retrieving header cid and tx cids for block hash ", blockHash.String())
|
log.Debug("retrieving header cid and tx cids for block hash ", blockHash.String())
|
||||||
|
|
||||||
var headerCID HeaderCidRecord
|
var headerCID HeaderCIDRecord
|
||||||
|
|
||||||
// https://github.com/go-gorm/gorm/issues/4083#issuecomment-778883283
|
// https://github.com/go-gorm/gorm/issues/4083#issuecomment-778883283
|
||||||
// Will use join for TransactionCids once preload for 1:N is supported.
|
// Will use join for TransactionCIDs once preload for 1:N is supported.
|
||||||
err := ecr.gormDB.Preload("TransactionCids", func(tx *gorm.DB) *gorm.DB {
|
err := ecr.gormDB.Preload("TransactionCIDs", func(tx *gorm.DB) *gorm.DB {
|
||||||
return tx.Select("cid", "tx_hash", "index", "src", "dst", "header_id")
|
return tx.Select("cid", "tx_hash", "index", "src", "dst", "header_id")
|
||||||
}).Joins("IPLD").First(&headerCID, "block_hash = ?", blockHash.String()).Error
|
}).Joins("IPLD").First(&headerCID, "block_hash = ?", blockHash.String()).Error
|
||||||
|
|
||||||
@ -710,10 +710,10 @@ func (ecr *CIDRetriever) RetrieveHeaderAndTxCIDsByBlockHash(blockHash common.Has
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RetrieveTxCIDByHash returns the tx for the given tx hash
|
// RetrieveTxCIDByHash returns the tx for the given tx hash
|
||||||
func (ecr *CIDRetriever) RetrieveTxCIDByHash(txHash string) (TransactionCidRecord, error) {
|
func (ecr *CIDRetriever) RetrieveTxCIDByHash(txHash string) (TransactionCIDRecord, error) {
|
||||||
log.Debug("retrieving tx cid for tx hash ", txHash)
|
log.Debug("retrieving tx cid for tx hash ", txHash)
|
||||||
|
|
||||||
var txCID TransactionCidRecord
|
var txCID TransactionCIDRecord
|
||||||
|
|
||||||
err := ecr.gormDB.Joins("IPLD").First(&txCID, "tx_hash = ?", txHash).Error
|
err := ecr.gormDB.Joins("IPLD").First(&txCID, "tx_hash = ?", txHash).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type StorageResponse struct {
|
type StorageResponse struct {
|
||||||
Cid string `json:"cid"`
|
CID string `json:"cid"`
|
||||||
Value common.Hash `json:"value"`
|
Value common.Hash `json:"value"`
|
||||||
IpldBlock hexutil.Bytes `json:"ipldBlock"`
|
IpldBlock hexutil.Bytes `json:"ipldBlock"`
|
||||||
}
|
}
|
||||||
@ -41,8 +41,8 @@ type IPFSBlockResponse struct {
|
|||||||
Data string `json:"data"`
|
Data string `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type EthTransactionCidResponse struct {
|
type EthTransactionCIDResponse struct {
|
||||||
Cid string `json:"cid"`
|
CID string `json:"cid"`
|
||||||
TxHash string `json:"txHash"`
|
TxHash string `json:"txHash"`
|
||||||
Index int32 `json:"index"`
|
Index int32 `json:"index"`
|
||||||
Src string `json:"src"`
|
Src string `json:"src"`
|
||||||
@ -50,16 +50,16 @@ type EthTransactionCidResponse struct {
|
|||||||
BlockByMhKey IPFSBlockResponse `json:"blockByMhKey"`
|
BlockByMhKey IPFSBlockResponse `json:"blockByMhKey"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type EthTransactionCidByTxHash struct {
|
type EthTransactionCIDByTxHash struct {
|
||||||
Response EthTransactionCidResponse `json:"ethTransactionCidByTxHash"`
|
Response EthTransactionCIDResponse `json:"ethTransactionCidByTxHash"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type EthTransactionCidsByHeaderIdResponse struct {
|
type EthTransactionCIDsByHeaderIdResponse struct {
|
||||||
Nodes []EthTransactionCidResponse `json:"nodes"`
|
Nodes []EthTransactionCIDResponse `json:"nodes"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type EthHeaderCidResponse struct {
|
type EthHeaderCIDResponse struct {
|
||||||
Cid string `json:"cid"`
|
CID string `json:"cid"`
|
||||||
BlockNumber BigInt `json:"blockNumber"`
|
BlockNumber BigInt `json:"blockNumber"`
|
||||||
BlockHash string `json:"blockHash"`
|
BlockHash string `json:"blockHash"`
|
||||||
ParentHash string `json:"parentHash"`
|
ParentHash string `json:"parentHash"`
|
||||||
@ -70,16 +70,16 @@ type EthHeaderCidResponse struct {
|
|||||||
ReceiptRoot string `json:"receiptRoot"`
|
ReceiptRoot string `json:"receiptRoot"`
|
||||||
UncleRoot string `json:"uncleRoot"`
|
UncleRoot string `json:"uncleRoot"`
|
||||||
Bloom string `json:"bloom"`
|
Bloom string `json:"bloom"`
|
||||||
EthTransactionCidsByHeaderId EthTransactionCidsByHeaderIdResponse `json:"ethTransactionCidsByHeaderId"`
|
EthTransactionCIDsByHeaderId EthTransactionCIDsByHeaderIdResponse `json:"ethTransactionCidsByHeaderId"`
|
||||||
BlockByMhKey IPFSBlockResponse `json:"blockByMhKey"`
|
BlockByMhKey IPFSBlockResponse `json:"blockByMhKey"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AllEthHeaderCidsResponse struct {
|
type AllEthHeaderCIDsResponse struct {
|
||||||
Nodes []EthHeaderCidResponse `json:"nodes"`
|
Nodes []EthHeaderCIDResponse `json:"nodes"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AllEthHeaderCids struct {
|
type AllEthHeaderCIDs struct {
|
||||||
Response AllEthHeaderCidsResponse `json:"allEthHeaderCids"`
|
Response AllEthHeaderCIDsResponse `json:"allEthHeaderCids"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
@ -164,7 +164,7 @@ func (c *Client) GetStorageAt(ctx context.Context, hash common.Hash, address com
|
|||||||
return &storageAt.Response, nil
|
return &storageAt.Response, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) AllEthHeaderCids(ctx context.Context, condition EthHeaderCidCondition) (*AllEthHeaderCidsResponse, error) {
|
func (c *Client) AllEthHeaderCIDs(ctx context.Context, condition EthHeaderCIDCondition) (*AllEthHeaderCIDsResponse, error) {
|
||||||
var params string
|
var params string
|
||||||
if condition.BlockHash != nil {
|
if condition.BlockHash != nil {
|
||||||
params = fmt.Sprintf(`blockHash: "%s"`, *condition.BlockHash)
|
params = fmt.Sprintf(`blockHash: "%s"`, *condition.BlockHash)
|
||||||
@ -220,15 +220,15 @@ func (c *Client) AllEthHeaderCids(ctx context.Context, condition EthHeaderCidCon
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var allEthHeaderCids AllEthHeaderCids
|
var allEthHeaderCIDs AllEthHeaderCIDs
|
||||||
err = json.Unmarshal(jsonStr, &allEthHeaderCids)
|
err = json.Unmarshal(jsonStr, &allEthHeaderCIDs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &allEthHeaderCids.Response, nil
|
return &allEthHeaderCIDs.Response, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) EthTransactionCidByTxHash(ctx context.Context, txHash string) (*EthTransactionCidResponse, error) {
|
func (c *Client) EthTransactionCIDByTxHash(ctx context.Context, txHash string) (*EthTransactionCIDResponse, error) {
|
||||||
getTxQuery := fmt.Sprintf(`
|
getTxQuery := fmt.Sprintf(`
|
||||||
query{
|
query{
|
||||||
ethTransactionCidByTxHash(txHash: "%s") {
|
ethTransactionCidByTxHash(txHash: "%s") {
|
||||||
@ -258,10 +258,10 @@ func (c *Client) EthTransactionCidByTxHash(ctx context.Context, txHash string) (
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var ethTxCid EthTransactionCidByTxHash
|
var ethTxCID EthTransactionCIDByTxHash
|
||||||
err = json.Unmarshal(jsonStr, ðTxCid)
|
err = json.Unmarshal(jsonStr, ðTxCID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return ðTxCid.Response, nil
|
return ðTxCID.Response, nil
|
||||||
}
|
}
|
||||||
|
@ -1125,7 +1125,7 @@ func decomposeGQLLogs(logCIDs []eth.LogResult) []logsCID {
|
|||||||
return logs
|
return logs
|
||||||
}
|
}
|
||||||
|
|
||||||
type EthTransactionCid struct {
|
type EthTransactionCID struct {
|
||||||
cid string
|
cid string
|
||||||
txHash string
|
txHash string
|
||||||
index int32
|
index int32
|
||||||
@ -1134,35 +1134,35 @@ type EthTransactionCid struct {
|
|||||||
ipfsBlock IPFSBlock
|
ipfsBlock IPFSBlock
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t EthTransactionCid) Cid(ctx context.Context) string {
|
func (t EthTransactionCID) Cid(ctx context.Context) string {
|
||||||
return t.cid
|
return t.cid
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t EthTransactionCid) TxHash(ctx context.Context) string {
|
func (t EthTransactionCID) TxHash(ctx context.Context) string {
|
||||||
return t.txHash
|
return t.txHash
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t EthTransactionCid) Index(ctx context.Context) int32 {
|
func (t EthTransactionCID) Index(ctx context.Context) int32 {
|
||||||
return t.index
|
return t.index
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t EthTransactionCid) Src(ctx context.Context) string {
|
func (t EthTransactionCID) Src(ctx context.Context) string {
|
||||||
return t.src
|
return t.src
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t EthTransactionCid) Dst(ctx context.Context) string {
|
func (t EthTransactionCID) Dst(ctx context.Context) string {
|
||||||
return t.dst
|
return t.dst
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t EthTransactionCid) BlockByMhKey(ctx context.Context) IPFSBlock {
|
func (t EthTransactionCID) BlockByMhKey(ctx context.Context) IPFSBlock {
|
||||||
return t.ipfsBlock
|
return t.ipfsBlock
|
||||||
}
|
}
|
||||||
|
|
||||||
type EthTransactionCidsConnection struct {
|
type EthTransactionCIDsConnection struct {
|
||||||
nodes []*EthTransactionCid
|
nodes []*EthTransactionCID
|
||||||
}
|
}
|
||||||
|
|
||||||
func (transactionCIDResult EthTransactionCidsConnection) Nodes(ctx context.Context) []*EthTransactionCid {
|
func (transactionCIDResult EthTransactionCIDsConnection) Nodes(ctx context.Context) []*EthTransactionCID {
|
||||||
return transactionCIDResult.nodes
|
return transactionCIDResult.nodes
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1179,7 +1179,7 @@ func (b IPFSBlock) Data(ctx context.Context) string {
|
|||||||
return b.data
|
return b.data
|
||||||
}
|
}
|
||||||
|
|
||||||
type EthHeaderCid struct {
|
type EthHeaderCID struct {
|
||||||
cid string
|
cid string
|
||||||
blockNumber BigInt
|
blockNumber BigInt
|
||||||
blockHash string
|
blockHash string
|
||||||
@ -1191,79 +1191,79 @@ type EthHeaderCid struct {
|
|||||||
receiptRoot string
|
receiptRoot string
|
||||||
uncleRoot string
|
uncleRoot string
|
||||||
bloom string
|
bloom string
|
||||||
transactions []*EthTransactionCid
|
transactions []*EthTransactionCID
|
||||||
ipfsBlock IPFSBlock
|
ipfsBlock IPFSBlock
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h EthHeaderCid) Cid(ctx context.Context) string {
|
func (h EthHeaderCID) Cid(ctx context.Context) string {
|
||||||
return h.cid
|
return h.cid
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h EthHeaderCid) BlockNumber(ctx context.Context) BigInt {
|
func (h EthHeaderCID) BlockNumber(ctx context.Context) BigInt {
|
||||||
return h.blockNumber
|
return h.blockNumber
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h EthHeaderCid) BlockHash(ctx context.Context) string {
|
func (h EthHeaderCID) BlockHash(ctx context.Context) string {
|
||||||
return h.blockHash
|
return h.blockHash
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h EthHeaderCid) ParentHash(ctx context.Context) string {
|
func (h EthHeaderCID) ParentHash(ctx context.Context) string {
|
||||||
return h.parentHash
|
return h.parentHash
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h EthHeaderCid) Timestamp(ctx context.Context) BigInt {
|
func (h EthHeaderCID) Timestamp(ctx context.Context) BigInt {
|
||||||
return h.timestamp
|
return h.timestamp
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h EthHeaderCid) StateRoot(ctx context.Context) string {
|
func (h EthHeaderCID) StateRoot(ctx context.Context) string {
|
||||||
return h.stateRoot
|
return h.stateRoot
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h EthHeaderCid) Td(ctx context.Context) BigInt {
|
func (h EthHeaderCID) Td(ctx context.Context) BigInt {
|
||||||
return h.td
|
return h.td
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h EthHeaderCid) TxRoot(ctx context.Context) string {
|
func (h EthHeaderCID) TxRoot(ctx context.Context) string {
|
||||||
return h.txRoot
|
return h.txRoot
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h EthHeaderCid) ReceiptRoot(ctx context.Context) string {
|
func (h EthHeaderCID) ReceiptRoot(ctx context.Context) string {
|
||||||
return h.receiptRoot
|
return h.receiptRoot
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h EthHeaderCid) UncleRoot(ctx context.Context) string {
|
func (h EthHeaderCID) UncleRoot(ctx context.Context) string {
|
||||||
return h.uncleRoot
|
return h.uncleRoot
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h EthHeaderCid) Bloom(ctx context.Context) string {
|
func (h EthHeaderCID) Bloom(ctx context.Context) string {
|
||||||
return h.bloom
|
return h.bloom
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h EthHeaderCid) EthTransactionCidsByHeaderId(ctx context.Context) EthTransactionCidsConnection {
|
func (h EthHeaderCID) EthTransactionCidsByHeaderId(ctx context.Context) EthTransactionCIDsConnection {
|
||||||
return EthTransactionCidsConnection{nodes: h.transactions}
|
return EthTransactionCIDsConnection{nodes: h.transactions}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h EthHeaderCid) BlockByMhKey(ctx context.Context) IPFSBlock {
|
func (h EthHeaderCID) BlockByMhKey(ctx context.Context) IPFSBlock {
|
||||||
return h.ipfsBlock
|
return h.ipfsBlock
|
||||||
}
|
}
|
||||||
|
|
||||||
type EthHeaderCidsConnection struct {
|
type EthHeaderCIDsConnection struct {
|
||||||
nodes []*EthHeaderCid
|
nodes []*EthHeaderCID
|
||||||
}
|
}
|
||||||
|
|
||||||
func (headerCIDResult EthHeaderCidsConnection) Nodes(ctx context.Context) []*EthHeaderCid {
|
func (headerCIDResult EthHeaderCIDsConnection) Nodes(ctx context.Context) []*EthHeaderCID {
|
||||||
return headerCIDResult.nodes
|
return headerCIDResult.nodes
|
||||||
}
|
}
|
||||||
|
|
||||||
type EthHeaderCidCondition struct {
|
type EthHeaderCIDCondition struct {
|
||||||
BlockNumber *BigInt
|
BlockNumber *BigInt
|
||||||
BlockHash *string
|
BlockHash *string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Resolver) AllEthHeaderCids(ctx context.Context, args struct {
|
func (r *Resolver) AllEthHeaderCids(ctx context.Context, args struct {
|
||||||
Condition *EthHeaderCidCondition
|
Condition *EthHeaderCIDCondition
|
||||||
}) (*EthHeaderCidsConnection, error) {
|
}) (*EthHeaderCIDsConnection, error) {
|
||||||
var headerCIDs []eth.HeaderCidRecord
|
var headerCIDs []eth.HeaderCIDRecord
|
||||||
var err error
|
var err error
|
||||||
if args.Condition.BlockHash != nil {
|
if args.Condition.BlockHash != nil {
|
||||||
headerCID, err := r.backend.Retriever.RetrieveHeaderAndTxCIDsByBlockHash(common.HexToHash(*args.Condition.BlockHash))
|
headerCID, err := r.backend.Retriever.RetrieveHeaderAndTxCIDsByBlockHash(common.HexToHash(*args.Condition.BlockHash))
|
||||||
@ -1297,7 +1297,7 @@ func (r *Resolver) AllEthHeaderCids(ctx context.Context, args struct {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var resultNodes []*EthHeaderCid
|
var resultNodes []*EthHeaderCID
|
||||||
for _, headerCID := range headerCIDs {
|
for _, headerCID := range headerCIDs {
|
||||||
var blockNumber BigInt
|
var blockNumber BigInt
|
||||||
blockNumber.UnmarshalText([]byte(headerCID.BlockNumber))
|
blockNumber.UnmarshalText([]byte(headerCID.BlockNumber))
|
||||||
@ -1308,7 +1308,7 @@ func (r *Resolver) AllEthHeaderCids(ctx context.Context, args struct {
|
|||||||
var td BigInt
|
var td BigInt
|
||||||
td.UnmarshalText([]byte(headerCID.TotalDifficulty))
|
td.UnmarshalText([]byte(headerCID.TotalDifficulty))
|
||||||
|
|
||||||
ethHeaderCidNode := EthHeaderCid{
|
ethHeaderCIDNode := EthHeaderCID{
|
||||||
cid: headerCID.CID,
|
cid: headerCID.CID,
|
||||||
blockNumber: blockNumber,
|
blockNumber: blockNumber,
|
||||||
blockHash: headerCID.BlockHash,
|
blockHash: headerCID.BlockHash,
|
||||||
@ -1326,8 +1326,8 @@ func (r *Resolver) AllEthHeaderCids(ctx context.Context, args struct {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, txCID := range headerCID.TransactionCids {
|
for _, txCID := range headerCID.TransactionCIDs {
|
||||||
ethHeaderCidNode.transactions = append(ethHeaderCidNode.transactions, &EthTransactionCid{
|
ethHeaderCIDNode.transactions = append(ethHeaderCIDNode.transactions, &EthTransactionCID{
|
||||||
cid: txCID.CID,
|
cid: txCID.CID,
|
||||||
txHash: txCID.TxHash,
|
txHash: txCID.TxHash,
|
||||||
index: int32(txCID.Index),
|
index: int32(txCID.Index),
|
||||||
@ -1336,24 +1336,24 @@ func (r *Resolver) AllEthHeaderCids(ctx context.Context, args struct {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
resultNodes = append(resultNodes, ðHeaderCidNode)
|
resultNodes = append(resultNodes, ðHeaderCIDNode)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &EthHeaderCidsConnection{
|
return &EthHeaderCIDsConnection{
|
||||||
nodes: resultNodes,
|
nodes: resultNodes,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Resolver) EthTransactionCidByTxHash(ctx context.Context, args struct {
|
func (r *Resolver) EthTransactionCidByTxHash(ctx context.Context, args struct {
|
||||||
TxHash string
|
TxHash string
|
||||||
}) (*EthTransactionCid, error) {
|
}) (*EthTransactionCID, error) {
|
||||||
txCID, err := r.backend.Retriever.RetrieveTxCIDByHash(args.TxHash)
|
txCID, err := r.backend.Retriever.RetrieveTxCIDByHash(args.TxHash)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &EthTransactionCid{
|
return &EthTransactionCID{
|
||||||
cid: txCID.CID,
|
cid: txCID.CID,
|
||||||
txHash: txCID.TxHash,
|
txHash: txCID.TxHash,
|
||||||
index: int32(txCID.Index),
|
index: int32(txCID.Index),
|
||||||
|
@ -254,81 +254,81 @@ var _ = Describe("GraphQL", func() {
|
|||||||
|
|
||||||
Describe("allEthHeaderCids", func() {
|
Describe("allEthHeaderCids", func() {
|
||||||
It("Retrieves header_cids that matches the provided blockNumber", func() {
|
It("Retrieves header_cids that matches the provided blockNumber", func() {
|
||||||
allEthHeaderCidsResp, err := client.AllEthHeaderCids(ctx, graphql.EthHeaderCidCondition{BlockNumber: new(graphql.BigInt).SetUint64(2)})
|
allEthHeaderCIDsResp, err := client.AllEthHeaderCIDs(ctx, graphql.EthHeaderCIDCondition{BlockNumber: new(graphql.BigInt).SetUint64(2)})
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
headerCIDs, err := backend.Retriever.RetrieveHeaderAndTxCIDsByBlockNumber(2)
|
headerCIDs, err := backend.Retriever.RetrieveHeaderAndTxCIDsByBlockNumber(2)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
for idx, headerCID := range headerCIDs {
|
for idx, headerCID := range headerCIDs {
|
||||||
ethHeaderCid := allEthHeaderCidsResp.Nodes[idx]
|
ethHeaderCID := allEthHeaderCIDsResp.Nodes[idx]
|
||||||
|
|
||||||
compareEthHeaderCid(ethHeaderCid, headerCID)
|
compareEthHeaderCID(ethHeaderCID, headerCID)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
It("Retrieves header_cids that matches the provided blockHash", func() {
|
It("Retrieves header_cids that matches the provided blockHash", func() {
|
||||||
blockHash := blocks[1].Hash().String()
|
blockHash := blocks[1].Hash().String()
|
||||||
allEthHeaderCidsResp, err := client.AllEthHeaderCids(ctx, graphql.EthHeaderCidCondition{BlockHash: &blockHash})
|
allEthHeaderCIDsResp, err := client.AllEthHeaderCIDs(ctx, graphql.EthHeaderCIDCondition{BlockHash: &blockHash})
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
headerCID, err := backend.Retriever.RetrieveHeaderAndTxCIDsByBlockHash(blocks[1].Hash())
|
headerCID, err := backend.Retriever.RetrieveHeaderAndTxCIDsByBlockHash(blocks[1].Hash())
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
Expect(len(allEthHeaderCidsResp.Nodes)).To(Equal(1))
|
Expect(len(allEthHeaderCIDsResp.Nodes)).To(Equal(1))
|
||||||
ethHeaderCid := allEthHeaderCidsResp.Nodes[0]
|
ethHeaderCID := allEthHeaderCIDsResp.Nodes[0]
|
||||||
compareEthHeaderCid(ethHeaderCid, headerCID)
|
compareEthHeaderCID(ethHeaderCID, headerCID)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
Describe("ethTransactionCidByTxHash", func() {
|
Describe("ethTransactionCidByTxHash", func() {
|
||||||
It("Retrieves tx_cid that matches the provided txHash", func() {
|
It("Retrieves tx_cid that matches the provided txHash", func() {
|
||||||
txHash := blocks[2].Transactions()[0].Hash().String()
|
txHash := blocks[2].Transactions()[0].Hash().String()
|
||||||
ethTransactionCidResp, err := client.EthTransactionCidByTxHash(ctx, txHash)
|
ethTransactionCIDResp, err := client.EthTransactionCIDByTxHash(ctx, txHash)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
txCID, err := backend.Retriever.RetrieveTxCIDByHash(txHash)
|
txCID, err := backend.Retriever.RetrieveTxCIDByHash(txHash)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
compareEthTxCid(*ethTransactionCidResp, txCID)
|
compareEthTxCID(*ethTransactionCIDResp, txCID)
|
||||||
|
|
||||||
Expect(ethTransactionCidResp.BlockByMhKey.Data).To(Equal(graphql.Bytes(txCID.IPLD.Data).String()))
|
Expect(ethTransactionCIDResp.BlockByMhKey.Data).To(Equal(graphql.Bytes(txCID.IPLD.Data).String()))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
func compareEthHeaderCid(ethHeaderCid graphql.EthHeaderCidResponse, headerCID eth.HeaderCidRecord) {
|
func compareEthHeaderCID(ethHeaderCID graphql.EthHeaderCIDResponse, headerCID eth.HeaderCIDRecord) {
|
||||||
blockNumber, err := strconv.ParseInt(headerCID.BlockNumber, 10, 64)
|
blockNumber, err := strconv.ParseInt(headerCID.BlockNumber, 10, 64)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
td, err := strconv.ParseInt(headerCID.TotalDifficulty, 10, 64)
|
td, err := strconv.ParseInt(headerCID.TotalDifficulty, 10, 64)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
Expect(ethHeaderCid.Cid).To(Equal(headerCID.CID))
|
Expect(ethHeaderCID.CID).To(Equal(headerCID.CID))
|
||||||
Expect(ethHeaderCid.BlockNumber).To(Equal(*new(graphql.BigInt).SetUint64(uint64(blockNumber))))
|
Expect(ethHeaderCID.BlockNumber).To(Equal(*new(graphql.BigInt).SetUint64(uint64(blockNumber))))
|
||||||
Expect(ethHeaderCid.BlockHash).To(Equal(headerCID.BlockHash))
|
Expect(ethHeaderCID.BlockHash).To(Equal(headerCID.BlockHash))
|
||||||
Expect(ethHeaderCid.ParentHash).To(Equal(headerCID.ParentHash))
|
Expect(ethHeaderCID.ParentHash).To(Equal(headerCID.ParentHash))
|
||||||
Expect(ethHeaderCid.Timestamp).To(Equal(*new(graphql.BigInt).SetUint64(headerCID.Timestamp)))
|
Expect(ethHeaderCID.Timestamp).To(Equal(*new(graphql.BigInt).SetUint64(headerCID.Timestamp)))
|
||||||
Expect(ethHeaderCid.StateRoot).To(Equal(headerCID.StateRoot))
|
Expect(ethHeaderCID.StateRoot).To(Equal(headerCID.StateRoot))
|
||||||
Expect(ethHeaderCid.Td).To(Equal(*new(graphql.BigInt).SetUint64(uint64(td))))
|
Expect(ethHeaderCID.Td).To(Equal(*new(graphql.BigInt).SetUint64(uint64(td))))
|
||||||
Expect(ethHeaderCid.TxRoot).To(Equal(headerCID.TxRoot))
|
Expect(ethHeaderCID.TxRoot).To(Equal(headerCID.TxRoot))
|
||||||
Expect(ethHeaderCid.ReceiptRoot).To(Equal(headerCID.RctRoot))
|
Expect(ethHeaderCID.ReceiptRoot).To(Equal(headerCID.RctRoot))
|
||||||
Expect(ethHeaderCid.UncleRoot).To(Equal(headerCID.UncleRoot))
|
Expect(ethHeaderCID.UncleRoot).To(Equal(headerCID.UncleRoot))
|
||||||
Expect(ethHeaderCid.Bloom).To(Equal(graphql.Bytes(headerCID.Bloom).String()))
|
Expect(ethHeaderCID.Bloom).To(Equal(graphql.Bytes(headerCID.Bloom).String()))
|
||||||
|
|
||||||
for tIdx, txCID := range headerCID.TransactionCids {
|
for tIdx, txCID := range headerCID.TransactionCIDs {
|
||||||
ethTxCid := ethHeaderCid.EthTransactionCidsByHeaderId.Nodes[tIdx]
|
ethTxCID := ethHeaderCID.EthTransactionCIDsByHeaderId.Nodes[tIdx]
|
||||||
compareEthTxCid(ethTxCid, txCID)
|
compareEthTxCID(ethTxCID, txCID)
|
||||||
}
|
}
|
||||||
|
|
||||||
Expect(ethHeaderCid.BlockByMhKey.Data).To(Equal(graphql.Bytes(headerCID.IPLD.Data).String()))
|
Expect(ethHeaderCID.BlockByMhKey.Data).To(Equal(graphql.Bytes(headerCID.IPLD.Data).String()))
|
||||||
Expect(ethHeaderCid.BlockByMhKey.Key).To(Equal(headerCID.IPLD.Key))
|
Expect(ethHeaderCID.BlockByMhKey.Key).To(Equal(headerCID.IPLD.Key))
|
||||||
}
|
}
|
||||||
|
|
||||||
func compareEthTxCid(ethTxCid graphql.EthTransactionCidResponse, txCID eth.TransactionCidRecord) {
|
func compareEthTxCID(ethTxCID graphql.EthTransactionCIDResponse, txCID eth.TransactionCIDRecord) {
|
||||||
Expect(ethTxCid.Cid).To(Equal(txCID.CID))
|
Expect(ethTxCID.CID).To(Equal(txCID.CID))
|
||||||
Expect(ethTxCid.TxHash).To(Equal(txCID.TxHash))
|
Expect(ethTxCID.TxHash).To(Equal(txCID.TxHash))
|
||||||
Expect(ethTxCid.Index).To(Equal(int32(txCID.Index)))
|
Expect(ethTxCID.Index).To(Equal(int32(txCID.Index)))
|
||||||
Expect(ethTxCid.Src).To(Equal(txCID.Src))
|
Expect(ethTxCID.Src).To(Equal(txCID.Src))
|
||||||
Expect(ethTxCid.Dst).To(Equal(txCID.Dst))
|
Expect(ethTxCID.Dst).To(Equal(txCID.Dst))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user