Address comments.
This commit is contained in:
parent
885d934c90
commit
77d28264f7
@ -321,7 +321,7 @@ func (ecr *CIDRetriever) RetrieveFilteredGQLLogs(tx *sqlx.Tx, rctFilter ReceiptF
|
|||||||
WHERE eth.log_cids.receipt_id = receipt_cids.id
|
WHERE eth.log_cids.receipt_id = receipt_cids.id
|
||||||
AND receipt_cids.tx_id = transaction_cids.id
|
AND receipt_cids.tx_id = transaction_cids.id
|
||||||
AND transaction_cids.header_id = header_cids.id
|
AND transaction_cids.header_id = header_cids.id
|
||||||
AND receipt_cids.leaf_mh_key = blocks.key AND header_cids.block_hash = $1`
|
AND log_cids.leaf_mh_key = blocks.key AND header_cids.block_hash = $1`
|
||||||
|
|
||||||
args = append(args, blockHash.String())
|
args = append(args, blockHash.String())
|
||||||
id++
|
id++
|
||||||
|
@ -165,7 +165,11 @@ func checkTransactionAddrs(wantedSrc, wantedDst []string, actualSrc, actualDst s
|
|||||||
func (s *ResponseFilterer) filerReceipts(receiptFilter ReceiptFilter, response *IPLDs, payload ConvertedPayload, trxHashes []common.Hash) error {
|
func (s *ResponseFilterer) filerReceipts(receiptFilter ReceiptFilter, response *IPLDs, payload ConvertedPayload, trxHashes []common.Hash) error {
|
||||||
if !receiptFilter.Off {
|
if !receiptFilter.Off {
|
||||||
response.Receipts = make([]ipfs.BlockModel, 0, len(payload.Receipts))
|
response.Receipts = make([]ipfs.BlockModel, 0, len(payload.Receipts))
|
||||||
rctLeafCID, rctIPLDData := FetchRctLeafNodeData(payload.Receipts)
|
rctLeafCID, rctIPLDData, err := GetRctLeafNodeData(payload.Receipts)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
for idx, receipt := range payload.Receipts {
|
for idx, receipt := range payload.Receipts {
|
||||||
// topics is always length 4
|
// topics is always length 4
|
||||||
topics := make([][]string, 4)
|
topics := make([][]string, 4)
|
||||||
@ -323,27 +327,23 @@ func checkNodeKeys(wantedKeys []common.Hash, actualKey []byte) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// FetchRctLeafNodeData fetches receipt leaf node IPLD data and CIDs
|
// GetRctLeafNodeData converts the receipts to receipt trie and returns the receipt leaf node IPLD data and
|
||||||
func FetchRctLeafNodeData(rcts types.Receipts) ([]cid.Cid, [][]byte) {
|
// corresponding CIDs
|
||||||
|
func GetRctLeafNodeData(rcts types.Receipts) ([]cid.Cid, [][]byte, error) {
|
||||||
receiptTrie := ipld.NewRctTrie()
|
receiptTrie := ipld.NewRctTrie()
|
||||||
for idx, rct := range rcts {
|
for idx, rct := range rcts {
|
||||||
ethRct, err := ipld.NewReceipt(rct)
|
ethRct, err := ipld.NewReceipt(rct)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
if err = receiptTrie.Add(idx, ethRct.RawData()); err != nil {
|
if err = receiptTrie.Add(idx, ethRct.RawData()); err != nil {
|
||||||
return nil, nil
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := receiptTrie.GetNodes()
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
rctLeafNodes, keys, err := receiptTrie.GetLeafNodes()
|
rctLeafNodes, keys, err := receiptTrie.GetLeafNodes()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
ethRctleafNodeCids := make([]cid.Cid, len(rctLeafNodes))
|
ethRctleafNodeCids := make([]cid.Cid, len(rctLeafNodes))
|
||||||
@ -354,12 +354,12 @@ func FetchRctLeafNodeData(rcts types.Receipts) ([]cid.Cid, [][]byte) {
|
|||||||
r := bytes.NewReader(keys[i].TrieKey)
|
r := bytes.NewReader(keys[i].TrieKey)
|
||||||
err = rlp.Decode(r, &idx)
|
err = rlp.Decode(r, &idx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
ethRctleafNodeCids[idx] = rln.Cid()
|
ethRctleafNodeCids[idx] = rln.Cid()
|
||||||
ethRctleafNodeData[idx] = rln.RawData()
|
ethRctleafNodeData[idx] = rln.RawData()
|
||||||
}
|
}
|
||||||
|
|
||||||
return ethRctleafNodeCids, ethRctleafNodeData
|
return ethRctleafNodeCids, ethRctleafNodeData, nil
|
||||||
}
|
}
|
||||||
|
@ -361,12 +361,12 @@ func (r *IPLDRetriever) RetrieveReceiptsByTxHashes(hashes []common.Hash) ([]stri
|
|||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
rcts[i] = nodeVal
|
rcts[i] = nodeVal
|
||||||
//rcts[i] = res.Data
|
|
||||||
}
|
}
|
||||||
return cids, rcts, nil
|
return cids, rcts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RetrieveReceiptsByBlockHash returns the cids and rlp bytes for the receipts corresponding to the provided block hash
|
// RetrieveReceiptsByBlockHash returns the cids and rlp bytes for the receipts corresponding to the provided block hash.
|
||||||
|
// cid returned corresponds to the leaf node data which contains the receipt.
|
||||||
func (r *IPLDRetriever) RetrieveReceiptsByBlockHash(hash common.Hash) ([]string, [][]byte, []common.Hash, error) {
|
func (r *IPLDRetriever) RetrieveReceiptsByBlockHash(hash common.Hash) ([]string, [][]byte, []common.Hash, error) {
|
||||||
rctResults := make([]rctIpldResult, 0)
|
rctResults := make([]rctIpldResult, 0)
|
||||||
if err := r.db.Select(&rctResults, RetrieveReceiptsByBlockHashPgStr, hash.Hex()); err != nil {
|
if err := r.db.Select(&rctResults, RetrieveReceiptsByBlockHashPgStr, hash.Hex()); err != nil {
|
||||||
@ -383,14 +383,14 @@ func (r *IPLDRetriever) RetrieveReceiptsByBlockHash(hash common.Hash) ([]string,
|
|||||||
return nil, nil, nil, err
|
return nil, nil, nil, err
|
||||||
}
|
}
|
||||||
rcts[i] = nodeVal
|
rcts[i] = nodeVal
|
||||||
//rcts[i] = res.Data
|
|
||||||
txs[i] = common.HexToHash(res.TxHash)
|
txs[i] = common.HexToHash(res.TxHash)
|
||||||
}
|
}
|
||||||
|
|
||||||
return cids, rcts, txs, nil
|
return cids, rcts, txs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RetrieveReceiptsByBlockNumber returns the cids and rlp bytes for the receipts corresponding to the provided block hash
|
// RetrieveReceiptsByBlockNumber returns the cids and rlp bytes for the receipts corresponding to the provided block hash.
|
||||||
|
// cid returned corresponds to the leaf node data which contains the receipt.
|
||||||
func (r *IPLDRetriever) RetrieveReceiptsByBlockNumber(number uint64) ([]string, [][]byte, error) {
|
func (r *IPLDRetriever) RetrieveReceiptsByBlockNumber(number uint64) ([]string, [][]byte, error) {
|
||||||
rctResults := make([]rctIpldResult, 0)
|
rctResults := make([]rctIpldResult, 0)
|
||||||
if err := r.db.Select(&rctResults, RetrieveReceiptsByBlockNumberPgStr, number); err != nil {
|
if err := r.db.Select(&rctResults, RetrieveReceiptsByBlockNumberPgStr, number); err != nil {
|
||||||
@ -405,15 +405,23 @@ func (r *IPLDRetriever) RetrieveReceiptsByBlockNumber(number uint64) ([]string,
|
|||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
rcts[i] = nodeVal
|
rcts[i] = nodeVal
|
||||||
//rcts[i] = res.Data
|
|
||||||
}
|
}
|
||||||
return cids, rcts, nil
|
return cids, rcts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RetrieveReceiptByHash returns the cid and rlp bytes for the receipt corresponding to the provided tx hash
|
// RetrieveReceiptByHash returns the cid and rlp bytes for the receipt corresponding to the provided tx hash.
|
||||||
|
// cid returned corresponds to the leaf node data which contains the receipt.
|
||||||
func (r *IPLDRetriever) RetrieveReceiptByHash(hash common.Hash) (string, []byte, error) {
|
func (r *IPLDRetriever) RetrieveReceiptByHash(hash common.Hash) (string, []byte, error) {
|
||||||
rctResult := new(rctIpldResult)
|
rctResult := new(rctIpldResult)
|
||||||
return rctResult.LeafCID, rctResult.Data, r.db.Get(rctResult, RetrieveReceiptByTxHashPgStr, hash.Hex())
|
if err := r.db.Select(&rctResult, RetrieveReceiptByTxHashPgStr, hash.Hex()); err != nil {
|
||||||
|
return "", nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
nodeVal, err := DecodeLeafNode(rctResult.Data)
|
||||||
|
if err != nil {
|
||||||
|
return "", nil, err
|
||||||
|
}
|
||||||
|
return rctResult.LeafCID, nodeVal, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type nodeInfo struct {
|
type nodeInfo struct {
|
||||||
|
@ -56,7 +56,7 @@ func TxModelsContainsCID(txs []models.TxModel, cid string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListContainsBytes used to check if a list of byte arrays contains a particular byte array
|
// ReceiptModelsContainsCID used to check if a list of ReceiptModel contains a specific cid string
|
||||||
func ReceiptModelsContainsCID(rcts []models.ReceiptModel, cid string) bool {
|
func ReceiptModelsContainsCID(rcts []models.ReceiptModel, cid string) bool {
|
||||||
for _, rct := range rcts {
|
for _, rct := range rcts {
|
||||||
if rct.LeafCID == cid {
|
if rct.LeafCID == cid {
|
||||||
|
@ -167,36 +167,36 @@ var (
|
|||||||
Tx3 = GetTxnRlp(2, MockTransactions)
|
Tx3 = GetTxnRlp(2, MockTransactions)
|
||||||
Tx4 = GetTxnRlp(3, MockTransactions)
|
Tx4 = GetTxnRlp(3, MockTransactions)
|
||||||
|
|
||||||
rctCIDs, rctIPLDData = eth.FetchRctLeafNodeData(MockReceipts)
|
rctCIDs, rctIPLDData, _ = eth.GetRctLeafNodeData(MockReceipts)
|
||||||
HeaderCID, _ = ipld.RawdataToCid(ipld.MEthHeader, MockHeaderRlp, multihash.KECCAK_256)
|
HeaderCID, _ = ipld.RawdataToCid(ipld.MEthHeader, MockHeaderRlp, multihash.KECCAK_256)
|
||||||
HeaderMhKey = shared.MultihashKeyFromCID(HeaderCID)
|
HeaderMhKey = shared.MultihashKeyFromCID(HeaderCID)
|
||||||
Trx1CID, _ = ipld.RawdataToCid(ipld.MEthTx, Tx1, multihash.KECCAK_256)
|
Trx1CID, _ = ipld.RawdataToCid(ipld.MEthTx, Tx1, multihash.KECCAK_256)
|
||||||
Trx1MhKey = shared.MultihashKeyFromCID(Trx1CID)
|
Trx1MhKey = shared.MultihashKeyFromCID(Trx1CID)
|
||||||
Trx2CID, _ = ipld.RawdataToCid(ipld.MEthTx, Tx2, multihash.KECCAK_256)
|
Trx2CID, _ = ipld.RawdataToCid(ipld.MEthTx, Tx2, multihash.KECCAK_256)
|
||||||
Trx2MhKey = shared.MultihashKeyFromCID(Trx2CID)
|
Trx2MhKey = shared.MultihashKeyFromCID(Trx2CID)
|
||||||
Trx3CID, _ = ipld.RawdataToCid(ipld.MEthTx, Tx3, multihash.KECCAK_256)
|
Trx3CID, _ = ipld.RawdataToCid(ipld.MEthTx, Tx3, multihash.KECCAK_256)
|
||||||
Trx3MhKey = shared.MultihashKeyFromCID(Trx3CID)
|
Trx3MhKey = shared.MultihashKeyFromCID(Trx3CID)
|
||||||
Trx4CID, _ = ipld.RawdataToCid(ipld.MEthTx, Tx4, multihash.KECCAK_256)
|
Trx4CID, _ = ipld.RawdataToCid(ipld.MEthTx, Tx4, multihash.KECCAK_256)
|
||||||
Trx4MhKey = shared.MultihashKeyFromCID(Trx4CID)
|
Trx4MhKey = shared.MultihashKeyFromCID(Trx4CID)
|
||||||
Rct1CID = rctCIDs[0]
|
Rct1CID = rctCIDs[0]
|
||||||
Rct1MhKey = shared.MultihashKeyFromCID(Rct1CID)
|
Rct1MhKey = shared.MultihashKeyFromCID(Rct1CID)
|
||||||
Rct2CID = rctCIDs[1]
|
Rct2CID = rctCIDs[1]
|
||||||
Rct2MhKey = shared.MultihashKeyFromCID(Rct2CID)
|
Rct2MhKey = shared.MultihashKeyFromCID(Rct2CID)
|
||||||
Rct3CID = rctCIDs[2]
|
Rct3CID = rctCIDs[2]
|
||||||
Rct3MhKey = shared.MultihashKeyFromCID(Rct3CID)
|
Rct3MhKey = shared.MultihashKeyFromCID(Rct3CID)
|
||||||
Rct4CID = rctCIDs[3]
|
Rct4CID = rctCIDs[3]
|
||||||
Rct4MhKey = shared.MultihashKeyFromCID(Rct4CID)
|
Rct4MhKey = shared.MultihashKeyFromCID(Rct4CID)
|
||||||
State1CID, _ = ipld.RawdataToCid(ipld.MEthStateTrie, ContractLeafNode, multihash.KECCAK_256)
|
State1CID, _ = ipld.RawdataToCid(ipld.MEthStateTrie, ContractLeafNode, multihash.KECCAK_256)
|
||||||
State1MhKey = shared.MultihashKeyFromCID(State1CID)
|
State1MhKey = shared.MultihashKeyFromCID(State1CID)
|
||||||
State2CID, _ = ipld.RawdataToCid(ipld.MEthStateTrie, AccountLeafNode, multihash.KECCAK_256)
|
State2CID, _ = ipld.RawdataToCid(ipld.MEthStateTrie, AccountLeafNode, multihash.KECCAK_256)
|
||||||
State2MhKey = shared.MultihashKeyFromCID(State2CID)
|
State2MhKey = shared.MultihashKeyFromCID(State2CID)
|
||||||
StorageCID, _ = ipld.RawdataToCid(ipld.MEthStorageTrie, StorageLeafNode, multihash.KECCAK_256)
|
StorageCID, _ = ipld.RawdataToCid(ipld.MEthStorageTrie, StorageLeafNode, multihash.KECCAK_256)
|
||||||
StorageMhKey = shared.MultihashKeyFromCID(StorageCID)
|
StorageMhKey = shared.MultihashKeyFromCID(StorageCID)
|
||||||
Rct1IPLD = rctIPLDData[0]
|
Rct1IPLD = rctIPLDData[0]
|
||||||
Rct2IPLD = rctIPLDData[1]
|
Rct2IPLD = rctIPLDData[1]
|
||||||
Rct3IPLD = rctIPLDData[2]
|
Rct3IPLD = rctIPLDData[2]
|
||||||
Rct4IPLD = rctIPLDData[3]
|
Rct4IPLD = rctIPLDData[3]
|
||||||
MockTrxMeta = []models.TxModel{
|
MockTrxMeta = []models.TxModel{
|
||||||
{
|
{
|
||||||
CID: "", // This is empty until we go to publish to ipfs
|
CID: "", // This is empty until we go to publish to ipfs
|
||||||
MhKey: "",
|
MhKey: "",
|
||||||
|
Loading…
Reference in New Issue
Block a user