Skip to content

Commit

Permalink
feat: add Transaction.referenceInputs
Browse files Browse the repository at this point in the history
  • Loading branch information
rhyslbw committed Jul 18, 2022
1 parent e6e2d45 commit 2c5e0b5
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 0 deletions.
48 changes: 48 additions & 0 deletions packages/api-cardano-db-hasura/hasura/project/metadata/tables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,46 @@
- hash
- value
filter: {}
- table:
schema: public
name: ReferenceInput
object_relationships:
- name: sourceTransaction
using:
manual_configuration:
remote_table:
schema: public
name: Transaction
column_mapping:
sourceTxHash: hash
- name: transaction
using:
manual_configuration:
remote_table:
schema: public
name: Transaction
column_mapping:
txHash: hash
array_relationships:
- name: tokens
using:
manual_configuration:
remote_table:
schema: public
name: TokenInOutput
column_mapping:
source_tx_out_id: tx_out_id
select_permissions:
- role: cardano-graphql
permission:
columns:
- address
- sourceTxHash
- sourceTxIndex
- txHash
- value
filter: {}
allow_aggregations: true
- table:
schema: public
name: Reward
Expand Down Expand Up @@ -984,6 +1024,14 @@
name: Redeemer
column_mapping:
id: txId
- name: referenceInputs
using:
manual_configuration:
remote_table:
schema: public
name: ReferenceInput
column_mapping:
hash: txHash
- name: scripts
using:
manual_configuration:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ DROP VIEW IF EXISTS
"ProtocolParams",
"Redeemer",
"RedeemerDatum",
"ReferenceInput",
"Reward",
"Script",
"SlotLeader",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,24 @@ SELECT
redeemer.redeemer_data_id AS "redeemer_datum_id"
FROM redeemer;

CREATE OR REPLACE VIEW "ReferenceInput" AS
SELECT
source_tx_out.address,
source_tx_out.value,
tx.hash AS "txHash",
source_tx.hash AS "sourceTxHash",
reference_tx_in.tx_out_index AS "sourceTxIndex",
source_tx_out.id AS source_tx_out_id
FROM
tx
JOIN reference_tx_in
ON reference_tx_in.tx_in_id = tx.id
JOIN tx_out AS source_tx_out
ON reference_tx_in.tx_out_id = source_tx_out.tx_id
AND reference_tx_in.tx_out_index = source_tx_out.index
JOIN tx AS source_tx
ON source_tx_out.tx_id = source_tx.id;

CREATE OR REPLACE VIEW "Reward" AS
SELECT
reward.amount,
Expand Down
12 changes: 12 additions & 0 deletions packages/api-cardano-db-hasura/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1354,6 +1354,18 @@ type Transaction {
where: TransactionOutput_bool_exp
): TransactionOutput_aggregate!
redeemers: [Redeemer]
referenceInputs (
limit: Int
order_by: [TransactionInput_order_by]
offset: Int
where: TransactionInput_bool_exp
): [TransactionInput!]!
referenceInputs_aggregate (
limit: Int
order_by: [TransactionInput_order_by]
offset: Int
where: TransactionInput_bool_exp
): TransactionInput_aggregate!
scripts: [Script]
scriptSize: Int!
size: BigInt!
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
query transactionsByHashesWithReferenceInputs(
$hashes: [Hash32Hex]!
) {
transactions(
where: { hash: { _in: $hashes }},
order_by: { hash: desc }
) {
hash
referenceInputs(order_by: { sourceTxHash: asc }) {
address
sourceTransaction {
hash
}
sourceTxHash
sourceTxIndex
}
referenceInputs_aggregate(order_by: { sourceTxHash: asc }) {
aggregate {
avg {
value
}
count
max {
value
}
min {
value
}
sum {
value
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,43 @@ Object {
}
`;

exports[`transactions transactions with reference inputs shows the reference inputs 1`] = `
Object {
"transactions": Array [
Object {
"hash": "067e84ddc353faefcbd29f11586d854146b3df43f89b3c1a64a3ff9fbb3c05bd",
"referenceInputs": Array [
Object {
"address": "addr_test1wqag3rt979nep9g2wtdwu8mr4gz6m4kjdpp5zp705km8wys6t2kla",
"sourceTransaction": Object {
"hash": "62a8a3c215d1241e6407ec7422ec0878ea533b2db436e4d099bdd226a08fe7e1",
},
"sourceTxHash": "62a8a3c215d1241e6407ec7422ec0878ea533b2db436e4d099bdd226a08fe7e1",
"sourceTxIndex": 1,
},
],
"referenceInputs_aggregate": Object {
"aggregate": Object {
"avg": Object {
"value": "1094740",
},
"count": "1",
"max": Object {
"value": "1094740",
},
"min": Object {
"value": "1094740",
},
"sum": Object {
"value": "1094740",
},
},
},
},
],
}
`;

exports[`transactions transactions with tokens shows the tokens minted and output 1`] = `
Object {
"transactions": Array [
Expand Down
10 changes: 10 additions & 0 deletions packages/api-cardano-db-hasura/test/transactions.query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,14 @@ describe('transactions', () => {
expect(result.data).toMatchSnapshot()
})
})

describe('transactions with reference inputs', () => {
it('shows the reference inputs', async () => {
const result = await client.query({
query: await loadQueryNode('transactionsByHashesWithReferenceInputs'),
variables: { hashes: ['067e84ddc353faefcbd29f11586d854146b3df43f89b3c1a64a3ff9fbb3c05bd'] }
})
expect(result.data).toMatchSnapshot()
})
})
})

0 comments on commit 2c5e0b5

Please sign in to comment.