Skip to content

Commit

Permalink
feature: Multi-asset support
Browse files Browse the repository at this point in the history
Adds support for the multi-asset ledger with the Token type, `tokens` and `tokens_aggregate` queries.
`TransactionOutput.tokens` is a nullable field since, at this stage, Ada will remain to be inferred via
`TransactionOutput.value`. `Transaction.mint` is also feature nullable field.
  • Loading branch information
rhyslbw committed Jan 13, 2021
1 parent 6c559f1 commit 31ae067
Show file tree
Hide file tree
Showing 7 changed files with 236 additions and 0 deletions.
66 changes: 66 additions & 0 deletions packages/api-cardano-db-hasura/hasura/project/metadata/tables.yaml
Expand Up @@ -219,6 +219,28 @@
filter: {}
limit: 2500
allow_aggregations: true
- table:
schema: public
name: Mint
object_relationships:
- name: transaction
using:
manual_configuration:
remote_table:
schema: public
name: Transaction
column_mapping:
tx_id: id
select_permissions:
- role: cardano-graphql
permission:
columns:
- assetName
- policyId
- quantity
filter: {}
limit: 2500
allow_aggregations: true
- table:
schema: public
name: Reward
Expand Down Expand Up @@ -451,6 +473,33 @@
filter: {}
limit: 2500
allow_aggregations: true
- table:
schema: public
name: Token
configuration:
custom_root_fields:
select_aggregate: tokens_aggregate
select: tokens
custom_column_names: {}
object_relationships:
- name: transaction
using:
manual_configuration:
remote_table:
schema: public
name: TransactionOutput
column_mapping:
tx_out_id: id
select_permissions:
- role: cardano-graphql
permission:
columns:
- assetName
- policyId
- quantity
filter: {}
limit: 2500
allow_aggregations: true
- table:
schema: public
name: Transaction
Expand Down Expand Up @@ -485,6 +534,14 @@
name: tx_metadata
column_mapping:
id: tx_id
- name: mint
using:
manual_configuration:
remote_table:
schema: public
name: Mint
column_mapping:
id: tx_id
- name: outputs
using:
manual_configuration:
Expand Down Expand Up @@ -562,6 +619,15 @@
name: Transaction
column_mapping:
txHash: hash
array_relationships:
- name: tokens
using:
manual_configuration:
remote_table:
schema: public
name: Token
column_mapping:
id: tx_out_id
select_permissions:
- role: cardano-graphql
permission:
Expand Down
Expand Up @@ -4,13 +4,15 @@ DROP VIEW IF EXISTS
"Cardano",
"Delegation",
"Epoch",
"Mint",
"ShelleyEpochProtocolParams",
"Reward",
"SlotLeader",
"StakeDeregistration",
"StakePool",
"StakeRegistration",
"StakePoolRetirement",
"Token",
"Transaction",
"TransactionInput",
"TransactionOutput",
Expand Down
Expand Up @@ -170,6 +170,22 @@ SELECT
( SELECT pool_hash.hash_raw FROM pool_hash WHERE pool_hash.id = pool_id ) AS "pool_hash"
FROM epoch_stake;

CREATE VIEW "Mint" AS
SELECT
convert_from(name, 'UTF8') as "assetName",
policy as "policyId",
quantity,
tx_id
FROM ma_tx_mint;

CREATE VIEW "Token" AS
SELECT
convert_from(name, 'UTF8') as "assetName",
policy as "policyId",
quantity,
tx_out_id
FROM ma_tx_out;

CREATE VIEW "Transaction" AS
SELECT
block.hash AS "blockHash",
Expand Down Expand Up @@ -210,6 +226,7 @@ SELECT
address,
value,
tx.hash AS "txHash",
tx_out.id,
index
FROM tx
JOIN tx_out
Expand Down Expand Up @@ -258,6 +275,7 @@ RETURNS SETOF "TransactionOutput" AS $$
"TransactionOutput".address,
"TransactionOutput".value,
"TransactionOutput"."txHash",
"TransactionOutput"."id",
"TransactionOutput".index
FROM tx
JOIN tx_out
Expand Down
89 changes: 89 additions & 0 deletions packages/api-cardano-db-hasura/schema.graphql
Expand Up @@ -117,6 +117,20 @@ type Query {
offset: Int
where: StakeRegistration_bool_exp
): StakeRegistration_aggregate
tokens (
distinct_on: [Token_distinct_on!]
limit: Int
order_by: [Token_order_by!]
offset: Int
where: Token_bool_exp
): [Token]!
tokens_aggregate (
distinct_on: [Token_distinct_on!]
limit: Int
order_by: [Token_order_by!]
offset: Int
where: Token_bool_exp
): Token_aggregate!
transactions (
limit: Int
order_by: [Transaction_order_by!]
Expand Down Expand Up @@ -632,6 +646,62 @@ type StakeRegistration_aggregate_fields {
count: String
}

type Token {
assetName: String!
policyId: Hash28Hex!
quantity: String!
}

input Token_order_by {
assetName: order_by
policyId: order_by
quantity: order_by
}

input Token_bool_exp {
_and: [Token_bool_exp]
_not: Token_bool_exp
_or: [Token_bool_exp]
assetName: text_comparison_exp
policyId: Hash28Hex_comparison_exp
quantity: text_comparison_exp
}

type Token_aggregate {
aggregate: Token_aggregate_fields
nodes: [Token!]!
}

type Token_aggregate_fields {
avg: Token_avg_fields!
count: String!
max: Token_max_fields!
min: Token_min_fields!
sum: Token_sum_fields!
}

type Token_avg_fields {
quantity: String
}

enum Token_distinct_on {
policyId
assetName
}

type Token_max_fields {
quantity: String
}

type Token_min_fields {
quantity: String
}

type Token_sum_fields {
quantity: String
}


type Transaction {
block: Block
blockIndex: Int!
Expand All @@ -653,6 +723,13 @@ type Transaction {
invalidBefore: String
invalidHereafter: String
metadata: [TransactionMetadata]
mint: [Token!]
mint_aggregate(
limit: Int
order_by: [Token_order_by]
offset: Int
where: Token_bool_exp
): Token_aggregate!
outputs (
limit: Int
order_by: [TransactionOutput_order_by]
Expand Down Expand Up @@ -705,6 +782,7 @@ input Transaction_bool_exp {
invalidBefore: text_comparison_exp
invalidHereafter: text_comparison_exp
metadata: TransactionMetadata_bool_exp
mint: Token_bool_exp
outputs: TransactionOutput_bool_exp
size: BigInt_comparison_exp
totalOutput: text_comparison_exp
Expand All @@ -726,6 +804,7 @@ type Transaction_aggregate_fields {
type Transaction_avg_fields {
deposit: Float
fee: Float
mint: Token_avg_fields
size: Float
totalOutput: Float
withdrawals: Withdrawal_ave_fields
Expand All @@ -736,6 +815,7 @@ type Transaction_max_fields {
fee: String
invalidBefore: String
invalidHereafter: String
mint: Token_max_fields
size: String
totalOutput: String
withdrawals: Withdrawal_max_fields
Expand All @@ -746,6 +826,7 @@ type Transaction_min_fields {
fee: String
invalidBefore: String
invalidHereafter: String
mint: Token_min_fields
size: String
totalOutput: String
withdrawals: Withdrawal_min_fields
Expand All @@ -754,6 +835,7 @@ type Transaction_min_fields {
type Transaction_sum_fields {
deposit: String
fee: String
mint: Token_sum_fields
size: String
totalOutput: String
withdrawals: Withdrawal_sum_fields
Expand Down Expand Up @@ -828,6 +910,8 @@ type TransactionOutput {
index: Int!
transaction: Transaction!
txHash: Hash32Hex!
tokens: [Token!]
tokens_aggregate: Token_aggregate
value: String!
}

Expand All @@ -847,6 +931,7 @@ input TransactionOutput_bool_exp {
_not: TransactionOutput_bool_exp
_or: [TransactionOutput_bool_exp]
address: text_comparison_exp
tokens: Token_bool_exp
transaction: Transaction_bool_exp
value: text_comparison_exp
}
Expand All @@ -864,18 +949,22 @@ type TransactionOutput_aggregate_fields {
}

type TransactionOutput_avg_fields {
tokens: Token_avg_fields
value: String
}

type TransactionOutput_max_fields {
tokens: Token_max_fields
value: String
}

type TransactionOutput_min_fields {
tokens: Token_min_fields
value: String
}

type TransactionOutput_sum_fields {
tokens: Token_sum_fields
value: String
}

Expand Down
@@ -0,0 +1,20 @@
query distinctTokens {
tokens_aggregate(distinct_on: policyId) {
aggregate {
count
avg {
quantity
}
min {
quantity
}
max {
quantity
}
}
nodes {
assetName
policyId
}
}
}
@@ -0,0 +1,21 @@
query transactionsWithTokens (
$limit: Int
) {
transactions(
limit: $limit
where: { outputs: { tokens: {}} }
) {
outputs {
tokens {
assetName
policyId
quantity
}
}
mint {
assetName
policyId
quantity
}
}
}
20 changes: 20 additions & 0 deletions packages/api-cardano-db-hasura/src/executableSchema.ts
Expand Up @@ -240,6 +240,26 @@ export async function buildSchema (
schema: hasuraClient.schema
})
},
tokens: (_root, args, context, info) => {
return delegateToSchema({
args,
context,
fieldName: 'tokens',
info,
operation: 'query',
schema: hasuraClient.schema
})
},
tokens_aggregate: (_root, args, context, info) => {
return delegateToSchema({
args,
context,
fieldName: 'tokens_aggregate',
info,
operation: 'query',
schema: hasuraClient.schema
})
},
transactions: (_root, args, context, info) => {
return delegateToSchema({
args,
Expand Down

0 comments on commit 31ae067

Please sign in to comment.