Add query ethTransactionCidByTxHash
This commit is contained in:
+43
-5
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
`
|
||||
|
||||
Reference in New Issue
Block a user