Add query ethTransactionCidByTxHash

This commit is contained in:
2022-06-03 15:05:46 +05:30
parent da1c8b2332
commit 9550d60467
3 changed files with 79 additions and 5 deletions
+43 -5
View File
@@ -1126,11 +1126,12 @@ func decomposeGQLLogs(logCIDs []eth.LogResult) []logsCID {
}
type EthTransactionCid struct {
cid string
txHash string
index int32
src string
dst string
cid string
txHash string
index int32
src string
dst string
ipfsBlock IPFSBlock
}
func (t EthTransactionCid) Cid(ctx context.Context) string {
@@ -1153,6 +1154,10 @@ func (t EthTransactionCid) Dst(ctx context.Context) string {
return t.dst
}
func (t EthTransactionCid) BlockByMhKey(ctx context.Context) IPFSBlock {
return t.ipfsBlock
}
type EthTransactionCidsConnection struct {
nodes []*EthTransactionCid
}
@@ -1337,3 +1342,36 @@ func (r *Resolver) AllEthHeaderCids(ctx context.Context, args struct {
nodes: resultNodes,
}, nil
}
func (r *Resolver) EthTransactionCidByTxHash(ctx context.Context, args struct {
TxHash string
}) (*EthTransactionCid, error) {
txCID, err := r.backend.Retriever.RetrieveTxCIDByHash(args.TxHash)
if err != nil {
return nil, err
}
// Begin tx
tx, err := r.backend.DB.Beginx()
if err != nil {
return nil, err
}
txIPLDs, err := r.backend.Fetcher.FetchTrxs(tx, []models.TxModel{txCID})
if err != nil {
return nil, err
}
return &EthTransactionCid{
cid: txCID.CID,
txHash: txCID.TxHash,
index: int32(txCID.Index),
src: txCID.Src,
dst: txCID.Dst,
ipfsBlock: IPFSBlock{
key: txIPLDs[0].Key,
data: hexutil.Bytes(txIPLDs[0].Data).String(),
},
}, nil
}
+4
View File
@@ -294,6 +294,7 @@ const schema string = `
index: Int!
src: String!
dst: String!
blockByMhKey: IPFSBlock!
}
type EthTransactionCidsConnection {
@@ -351,5 +352,8 @@ const schema string = `
# PostGraphile alternative to get headers with transactions using block number or block hash.
allEthHeaderCids(condition: EthHeaderCidCondition): EthHeaderCidsConnection
# PostGraphile alternative to get transactions using transaction hash.
ethTransactionCidByTxHash(txHash: String!): EthTransactionCid
}
`