Skip to content

Commit

Permalink
feat: support Plutus data
Browse files Browse the repository at this point in the history
- adds `Datum` and `RedeemerDatum` views and GraphQL types
  • Loading branch information
rhyslbw committed Jul 18, 2022
1 parent ed499ac commit 58f6c48
Show file tree
Hide file tree
Showing 10 changed files with 244 additions and 42 deletions.
156 changes: 118 additions & 38 deletions packages/api-cardano-db-hasura/hasura/project/metadata/tables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,26 @@
filter: {}
limit: 2500
allow_aggregations: true
- table:
schema: public
name: Datum
object_relationships:
- name: firstIncludedIn
using:
manual_configuration:
remote_table:
schema: public
name: Transaction
column_mapping:
tx_id: id
select_permissions:
- role: cardano-graphql
permission:
columns:
- bytes
- hash
- value
filter: {}
- table:
schema: public
name: Delegation
Expand Down Expand Up @@ -388,6 +408,44 @@
filter: {}
limit: 2500
allow_aggregations: true
- table:
schema: public
name: ProtocolParams
select_permissions:
- role: cardano-graphql
permission:
columns:
- a0
- coinsPerUtxoByte
- collateralPercent
- costModels
- decentralisationParam
- eMax
- epoch_no
- extraEntropy
- keyDeposit
- maxBlockBodySize
- maxBlockExMem
- maxBlockExSteps
- maxBlockHeaderSize
- maxCollateralInputs
- maxTxExMem
- maxTxExSteps
- maxTxSize
- maxValSize
- minFeeA
- minFeeB
- minPoolCost
- minUTxOValue
- nOpt
- poolDeposit
- priceMem
- priceStep
- protocolVersion
- rho
- tau
filter: {}
limit: 2500
- table:
schema: public
name: Redeemer
Expand All @@ -397,6 +455,14 @@
select: redeemers
custom_column_names: {}
object_relationships:
- name: datum
using:
manual_configuration:
remote_table:
schema: public
name: RedeemerDatum
column_mapping:
redeemer_datum_id: id
- name: transaction
using:
manual_configuration:
Expand All @@ -418,6 +484,26 @@
filter: {}
limit: 2500
allow_aggregations: true
- table:
schema: public
name: RedeemerDatum
object_relationships:
- name: firstIncludedIn
using:
manual_configuration:
remote_table:
schema: public
name: Transaction
column_mapping:
tx_id: id
select_permissions:
- role: cardano-graphql
permission:
columns:
- bytes
- hash
- value
filter: {}
- table:
schema: public
name: Reward
Expand Down Expand Up @@ -488,44 +574,6 @@
filter: {}
limit: 2500
allow_aggregations: true
- table:
schema: public
name: ProtocolParams
select_permissions:
- role: cardano-graphql
permission:
columns:
- a0
- coinsPerUtxoByte
- collateralPercent
- costModels
- decentralisationParam
- eMax
- epoch_no
- extraEntropy
- keyDeposit
- maxBlockBodySize
- maxBlockExMem
- maxBlockExSteps
- maxBlockHeaderSize
- maxCollateralInputs
- maxTxExMem
- maxTxExSteps
- maxTxSize
- maxValSize
- minFeeA
- minFeeB
- minPoolCost
- minUTxOValue
- nOpt
- poolDeposit
- priceMem
- priceStep
- protocolVersion
- rho
- tau
filter: {}
limit: 2500
- table:
schema: public
name: SlotLeader
Expand Down Expand Up @@ -971,6 +1019,22 @@
schema: public
name: TransactionOutput
object_relationships:
- name: datum
using:
manual_configuration:
remote_table:
schema: public
name: Datum
column_mapping:
inline_datum_id: id
- name: script
using:
manual_configuration:
remote_table:
schema: public
name: Script
column_mapping:
reference_script_id: id
- name: transaction
using:
manual_configuration:
Expand Down Expand Up @@ -1009,6 +1073,22 @@
select: utxos
custom_column_names: {}
object_relationships:
- name: datum
using:
manual_configuration:
remote_table:
schema: public
name: Datum
column_mapping:
inline_datum_id: id
- name: script
using:
manual_configuration:
remote_table:
schema: public
name: Script
column_mapping:
reference_script_id: id
- name: transaction
using:
manual_configuration:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ DROP VIEW IF EXISTS
"Block",
"Cardano",
"Collateral",
"Datum",
"Delegation",
"Epoch",
"ProtocolParams",
"Redeemer",
"RedeemerDatum",
"Reward",
"Script",
"SlotLeader",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,24 @@ SELECT
FROM epoch
LEFT JOIN epoch_param on epoch.no = epoch_param.epoch_no;

CREATE OR REPLACE VIEW "Datum" AS
SELECT
bytes,
hash,
id,
tx_id,
value
FROM datum;

CREATE OR REPLACE VIEW "RedeemerDatum" AS
SELECT
bytes,
hash,
id,
tx_id,
value
FROM redeemer_data;

CREATE OR REPLACE VIEW "ProtocolParams" AS
SELECT
epoch_param.influence AS "a0",
Expand Down Expand Up @@ -143,7 +161,8 @@ SELECT
redeemer.script_hash AS "scriptHash",
redeemer.tx_id AS "txId",
redeemer.unit_mem AS "unitMem",
redeemer.unit_steps AS "unitSteps"
redeemer.unit_steps AS "unitSteps",
redeemer.redeemer_data_id AS "redeemer_datum_id"
FROM redeemer;

CREATE OR REPLACE VIEW "Reward" AS
Expand All @@ -160,6 +179,7 @@ JOIN stake_address on reward.addr_id = stake_address.id;
CREATE OR REPLACE VIEW "Script" AS
SELECT
script.hash AS "hash",
script.id AS "id",
script.serialised_size AS "serialisedSize",
script.type AS "type",
script.tx_id AS "txId"
Expand Down Expand Up @@ -317,7 +337,9 @@ SELECT
value,
tx.hash AS "txHash",
tx_out.id,
index
index,
tx_out.inline_datum_id AS "inline_datum_id",
tx_out.reference_script_id AS "reference_script_id"
FROM tx
JOIN tx_out
ON tx.id = tx_out.tx_id;
Expand All @@ -328,7 +350,9 @@ CREATE OR REPLACE VIEW "Utxo" AS SELECT
value,
tx.hash AS "txHash",
tx_out.id,
index
index,
tx_out.inline_datum_id AS "inline_datum_id",
tx_out.reference_script_id AS "reference_script_id"
FROM tx
JOIN tx_out
ON tx.id = tx_out.tx_id
Expand Down
19 changes: 19 additions & 0 deletions packages/api-cardano-db-hasura/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,18 @@ type CardanoDbMeta {
syncPercentage: Percentage!
}

type Datum {
bytes: Hex!
hash: Hash32Hex!
firstIncludedIn: Transaction!
value: JSONObject!
}

input Datum_bool_exp {
firstIncludedIn: Transaction_bool_exp
hash: Hex_comparison_exp
}

type Delegation {
address: StakeAddress!
redeemer: Redeemer
Expand Down Expand Up @@ -522,6 +534,7 @@ type PaymentAddressSummary {
}

type Redeemer {
datum: Datum
fee: BigInt
index: Int!
purpose: String! # Todo: Make scalar
Expand Down Expand Up @@ -571,6 +584,7 @@ input Redeemer_bool_exp {
_and: [Redeemer_bool_exp]
_not: Redeemer_bool_exp
_or: [Redeemer_bool_exp]
datum: Datum_bool_exp
fee: BigInt_comparison_exp
index: Int_comparison_exp
purpose: text_comparison_exp
Expand Down Expand Up @@ -1364,7 +1378,9 @@ input TransactionMetadata_bool_exp {
type TransactionOutput {
address: String!
addressHasScript: Boolean!
datum: Datum
index: Int!
script: Script
transaction: Transaction!
txHash: Hash32Hex!
tokens: [Token!]!
Expand All @@ -1379,6 +1395,7 @@ enum TransactionOutput_distinct_on {
input TransactionOutput_order_by {
address: order_by
addressHasScript: order_by
datum: Transaction_order_by
index: order_by
txHash: order_by
value: order_by
Expand All @@ -1390,7 +1407,9 @@ input TransactionOutput_bool_exp {
_or: [TransactionOutput_bool_exp]
address: text_comparison_exp
addressHasScript: Boolean_comparison_exp
datum: Datum_bool_exp
index: Int_comparison_exp
script: Script_bool_exp
tokens: Token_bool_exp
transaction: Transaction_bool_exp
value: text_comparison_exp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ query redeemers (
redeemers(
limit: $limit
) {
datum {
bytes
hash
firstIncludedIn {
hash
}
value
}
fee
index
purpose
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ query utxoSetForAddress (
where: { address: { _eq: $address }}
) {
address
datum {
bytes
hash
firstIncludedIn {
hash
}
value
}
transaction {
block {
number
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
query getAnyUtxoAddress (
$qty: Int!
){
utxos (limit: $qty, where: { transaction: { block: { number: { _is_null: false }}}}) {
utxos (
limit: $qty,
where: {
_and: {
transaction: { block: { number: { _is_null: false }}},
datum: { firstIncludedIn: { block: { number: { _is_null: false }}}}
}}) {
address
transaction {
block {
Expand Down
Loading

0 comments on commit 58f6c48

Please sign in to comment.