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:
- `Token` type
- `tokens` and `tokens_aggregate` queries.
- `TransactionOutput.tokens` and `TransactionInput.tokens` contains all non-ada assets being
transacted, with TransactionOutput.value` remaining as the single value required for ada.
- `Transaction.mint` is a nullable field.
- 'paymentAddresses' query returns a count of the assets
associated with the address/es provided
  • Loading branch information
rhyslbw committed Jan 25, 2021
1 parent ef884f3 commit 86e4206
Show file tree
Hide file tree
Showing 17 changed files with 622 additions and 35 deletions.
86 changes: 86 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 @@ -219,6 +219,29 @@
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:
- assetId
- assetName
- policyId
- quantity
filter: {}
limit: 2500
allow_aggregations: true
- table:
schema: public
name: Reward
Expand Down Expand Up @@ -451,6 +474,34 @@
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: transactionOutput
using:
manual_configuration:
remote_table:
schema: public
name: TransactionOutput
column_mapping:
tx_out_id: id
select_permissions:
- role: cardano-graphql
permission:
columns:
- assetId
- assetName
- policyId
- quantity
filter: {}
limit: 2500
allow_aggregations: true
- table:
schema: public
name: Transaction
Expand Down Expand Up @@ -485,6 +536,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 @@ -538,6 +597,15 @@
name: Transaction
column_mapping:
txHash: hash
array_relationships:
- name: tokens
using:
manual_configuration:
remote_table:
schema: public
name: Token
column_mapping:
source_tx_out_id: tx_out_id
select_permissions:
- role: cardano-graphql
permission:
Expand All @@ -562,6 +630,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 @@ -590,6 +667,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,24 @@ 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
CONCAT(policy,name) as "assetId",
name as "assetName",
policy as "policyId",
quantity,
tx_id
FROM ma_tx_mint;

CREATE VIEW "Token" AS
SELECT
CONCAT(policy,name) as "assetId",
name as "assetName",
policy as "policyId",
quantity,
tx_out_id
FROM ma_tx_out;

CREATE VIEW "Transaction" AS
SELECT
block.hash AS "blockHash",
Expand All @@ -194,7 +212,8 @@ SELECT
source_tx_out.value,
tx.hash AS "txHash",
source_tx.hash AS "sourceTxHash",
tx_in.tx_out_index AS "sourceTxIndex"
tx_in.tx_out_index AS "sourceTxIndex",
source_tx_out.id AS source_tx_out_id
FROM
tx
JOIN tx_in
Expand All @@ -210,6 +229,7 @@ SELECT
address,
value,
tx.hash AS "txHash",
tx_out.id,
index
FROM tx
JOIN tx_out
Expand All @@ -219,6 +239,7 @@ CREATE VIEW "Utxo" AS SELECT
address,
value,
tx.hash AS "txHash",
tx_out.id,
index
FROM tx
JOIN tx_out
Expand Down Expand Up @@ -246,8 +267,8 @@ CREATE INDEX idx_block_hash
CREATE INDEX idx_tx_hash
ON tx(hash);

CREATE INDEX idx_tx_in_consuming_tx
ON tx_in(tx_out_id);
CREATE INDEX idx_tx_in_consuming_tx
ON tx_in(tx_out_id);

CREATE INDEX idx_tx_out_tx
ON tx_out(tx_id);
Expand All @@ -258,6 +279,7 @@ RETURNS SETOF "TransactionOutput" AS $$
"TransactionOutput".address,
"TransactionOutput".value,
"TransactionOutput"."txHash",
"TransactionOutput"."id",
"TransactionOutput".index
FROM tx
JOIN tx_out
Expand Down
Loading

0 comments on commit 86e4206

Please sign in to comment.