Skip to content

Commit

Permalink
Adds CIP67/68 asset metadata support to asset_info endpoint (#239)
Browse files Browse the repository at this point in the history
TODO:

[x] - Add schema definition for the new field in response.

---------

Co-authored-by: Priyank <[email protected]>
  • Loading branch information
Scitz0 and rdlrt authored Oct 9, 2023
1 parent b8d4f52 commit 4c4da66
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 134 deletions.
2 changes: 1 addition & 1 deletion files/grest/rpc/02_indexes/13_1_00.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CREATE UNIQUE INDEX IF NOT EXISTS unique_col_txout ON public.collateral_tx_out U
CREATE UNIQUE INDEX IF NOT EXISTS unique_delegation ON public.delegation USING btree (tx_id, cert_index);
CREATE UNIQUE INDEX IF NOT EXISTS unique_epoch_param ON public.epoch_param USING btree (epoch_no, block_id);
CREATE UNIQUE INDEX IF NOT EXISTS unique_ma_tx_mint ON public.ma_tx_mint USING btree (ident, tx_id);
CREATE UNIQUE INDEX IF NOT EXISTS unique_ma_tx_out ON public.ma_tx_out USING btree (ident, tx_out_id);
CREATE UNIQUE INDEX IF NOT EXISTS unique_ma_tx_out ON public.ma_tx_out USING btree (ident, tx_out_id DESC);
CREATE UNIQUE INDEX IF NOT EXISTS unique_param_proposal ON public.param_proposal USING btree (key, registered_tx_id);
CREATE UNIQUE INDEX IF NOT EXISTS unique_pool_owner ON public.pool_owner USING btree (addr_id, pool_update_id);
CREATE UNIQUE INDEX IF NOT EXISTS unique_pool_relay ON public.pool_relay USING btree (update_id, ipv4, ipv6, dns_name);
Expand Down
52 changes: 50 additions & 2 deletions files/grest/rpc/assets/asset_info_bulk.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ RETURNS TABLE (
burn_cnt bigint,
creation_time integer,
minting_tx_metadata jsonb,
token_registry_metadata jsonb
token_registry_metadata jsonb,
cip68_metadata jsonb
)
LANGUAGE plpgsql
AS $$
Expand Down Expand Up @@ -52,7 +53,8 @@ BEGIN
'logo', arc.logo,
'decimals', arc.decimals
)
END
END,
cip68.metadata
FROM
multi_asset AS ma
INNER JOIN grest.asset_info_cache AS aic ON aic.asset_id = ma.id
Expand All @@ -69,6 +71,52 @@ BEGIN
WHERE
tm.tx_id = tx.id
) metadata ON TRUE
LEFT JOIN LATERAL (
-- CIP-68 supported labels
-- 100 = 000643b0 (ref, metadata)
-- 222 = 000de140 (NFT)
-- 333 = 0014df10 (FT)
-- 444 = 001bc280 (RFT)
SELECT
CASE
WHEN datum.value IS NULL THEN NULL
ELSE
JSONB_BUILD_OBJECT(
CASE
WHEN STARTS_WITH(ENCODE(ma.name, 'hex'), '000de140') THEN '222'
WHEN STARTS_WITH(ENCODE(ma.name, 'hex'), '0014df10') THEN '333'
WHEN STARTS_WITH(ENCODE(ma.name, 'hex'), '001bc280') THEN '444'
ELSE '0'
END,
datum.value
)
END AS metadata
FROM
tx_out
INNER JOIN datum ON datum.hash = tx_out.data_hash
WHERE
tx_out.id = (
SELECT
(SELECT MAX(tx_out_id) FROM ma_tx_out WHERE ident = _ma.id) as tx_id
FROM
multi_asset _ma
WHERE
_ma.policy = MA.policy
AND
_ma.name = (
SELECT
CASE WHEN
STARTS_WITH(ENCODE(ma.name, 'hex'), '000de140')
OR
STARTS_WITH(ENCODE(ma.name, 'hex'), '0014df10')
OR
STARTS_WITH(ENCODE(ma.name, 'hex'), '001bc280')
THEN CONCAT('\x000643b0', SUBSTRING(ENCODE(ma.name, 'hex'), 9))::bytea
ELSE null
END
)
)
) cip68 ON TRUE
WHERE
ma.id = ANY(_asset_id_list);

Expand Down
36 changes: 9 additions & 27 deletions specs/results/koiosapi-guild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -957,28 +957,6 @@ paths:
summary: Asset Token Registry
description: Get a list of assets registered via token registry on github
/asset_info: #RPC
get:
deprecated: true
tags:
- Asset
parameters:
- $ref: "#/components/parameters/_asset_policy"
- $ref: "#/components/parameters/_asset_name"
responses:
"200":
description: Array of detailed asset information
content:
application/json:
schema:
$ref: "#/components/schemas/asset_info"
"400":
$ref: "#/components/responses/BadRequest"
"401":
$ref: "#/components/responses/Unauthorized"
"404":
$ref: "#/components/responses/NotFound"
summary: Asset Information
description: Get the information of an asset including first minting & token registry metadata
post:
tags:
- Asset
Expand Down Expand Up @@ -1018,7 +996,7 @@ paths:
$ref: "#/components/responses/Unauthorized"
"404":
$ref: "#/components/responses/NotFound"
summary: Asset UTXO Information (Bulk)
summary: Asset UTXOs
description: Get the UTXO information of a list of assets including
/asset_history: #RPC
get:
Expand Down Expand Up @@ -1631,18 +1609,17 @@ paths:
x-code-samples:
- lang: "Shell"
source: |
# Assuming ${data} is a raw binary serialized transaction on the file-system.
# If using a CLI-generated tx file, please ensure to deserialise (using `xxd -p -r <<< $(jq .cborHex ${tx.signed}) > ${data}`) first before submitting.
# Assuming ${data} contains a CBOR-serialized signed transaction (base16-encoded) as documented on Ogmios v6 site.
curl -X POST \
--header "Content-Type: application/cbor" \
--data-binary @${data} https://api.koios.rest/api/ogmios/?EvaluateTransaction
--data-binary ${data} https://api.koios.rest/api/ogmios/?SubmitTransaction
responses:
"200":
description: OK
"400":
description: An error occured while querying transaction.
summary: Submit Transaction
description: Submit a signed and serialized transaction to the network.
description: Submit a signed and serialized transaction to the network. Please refer to Ogmios documentation [here](https://ogmios.dev/api/#operation-publish-/?SubmitTransaction) for complete spec

components:
parameters:
Expand Down Expand Up @@ -3976,6 +3953,11 @@ components:
decimals:
type: integer
example: 0
cip68_metadata:
type: object
description: CIP 68 metadata if present for asset
nullable: true
example: {"222": {"fields": [{"map": [{"k": {"bytes": "6e616d65"}, "v": {"bytes": "74657374"}}]}], "constructor": 0}}
asset_history:
type: array
items:
Expand Down
36 changes: 9 additions & 27 deletions specs/results/koiosapi-mainnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -957,28 +957,6 @@ paths:
summary: Asset Token Registry
description: Get a list of assets registered via token registry on github
/asset_info: #RPC
get:
deprecated: true
tags:
- Asset
parameters:
- $ref: "#/components/parameters/_asset_policy"
- $ref: "#/components/parameters/_asset_name"
responses:
"200":
description: Array of detailed asset information
content:
application/json:
schema:
$ref: "#/components/schemas/asset_info"
"400":
$ref: "#/components/responses/BadRequest"
"401":
$ref: "#/components/responses/Unauthorized"
"404":
$ref: "#/components/responses/NotFound"
summary: Asset Information
description: Get the information of an asset including first minting & token registry metadata
post:
tags:
- Asset
Expand Down Expand Up @@ -1018,7 +996,7 @@ paths:
$ref: "#/components/responses/Unauthorized"
"404":
$ref: "#/components/responses/NotFound"
summary: Asset UTXO Information (Bulk)
summary: Asset UTXOs
description: Get the UTXO information of a list of assets including
/asset_history: #RPC
get:
Expand Down Expand Up @@ -1631,18 +1609,17 @@ paths:
x-code-samples:
- lang: "Shell"
source: |
# Assuming ${data} is a raw binary serialized transaction on the file-system.
# If using a CLI-generated tx file, please ensure to deserialise (using `xxd -p -r <<< $(jq .cborHex ${tx.signed}) > ${data}`) first before submitting.
# Assuming ${data} contains a CBOR-serialized signed transaction (base16-encoded) as documented on Ogmios v6 site.
curl -X POST \
--header "Content-Type: application/cbor" \
--data-binary @${data} https://api.koios.rest/api/ogmios/?EvaluateTransaction
--data-binary ${data} https://api.koios.rest/api/ogmios/?SubmitTransaction
responses:
"200":
description: OK
"400":
description: An error occured while querying transaction.
summary: Submit Transaction
description: Submit a signed and serialized transaction to the network.
description: Submit a signed and serialized transaction to the network. Please refer to Ogmios documentation [here](https://ogmios.dev/api/#operation-publish-/?SubmitTransaction) for complete spec

components:
parameters:
Expand Down Expand Up @@ -3976,6 +3953,11 @@ components:
decimals:
type: integer
example: 0
cip68_metadata:
type: object
description: CIP 68 metadata if present for asset
nullable: true
example: {"222": {"fields": [{"map": [{"k": {"bytes": "6e616d65"}, "v": {"bytes": "74657374"}}]}], "constructor": 0}}
asset_history:
type: array
items:
Expand Down
36 changes: 9 additions & 27 deletions specs/results/koiosapi-preprod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -957,28 +957,6 @@ paths:
summary: Asset Token Registry
description: Get a list of assets registered via token registry on github
/asset_info: #RPC
get:
deprecated: true
tags:
- Asset
parameters:
- $ref: "#/components/parameters/_asset_policy"
- $ref: "#/components/parameters/_asset_name"
responses:
"200":
description: Array of detailed asset information
content:
application/json:
schema:
$ref: "#/components/schemas/asset_info"
"400":
$ref: "#/components/responses/BadRequest"
"401":
$ref: "#/components/responses/Unauthorized"
"404":
$ref: "#/components/responses/NotFound"
summary: Asset Information
description: Get the information of an asset including first minting & token registry metadata
post:
tags:
- Asset
Expand Down Expand Up @@ -1018,7 +996,7 @@ paths:
$ref: "#/components/responses/Unauthorized"
"404":
$ref: "#/components/responses/NotFound"
summary: Asset UTXO Information (Bulk)
summary: Asset UTXOs
description: Get the UTXO information of a list of assets including
/asset_history: #RPC
get:
Expand Down Expand Up @@ -1631,18 +1609,17 @@ paths:
x-code-samples:
- lang: "Shell"
source: |
# Assuming ${data} is a raw binary serialized transaction on the file-system.
# If using a CLI-generated tx file, please ensure to deserialise (using `xxd -p -r <<< $(jq .cborHex ${tx.signed}) > ${data}`) first before submitting.
# Assuming ${data} contains a CBOR-serialized signed transaction (base16-encoded) as documented on Ogmios v6 site.
curl -X POST \
--header "Content-Type: application/cbor" \
--data-binary @${data} https://api.koios.rest/api/ogmios/?EvaluateTransaction
--data-binary ${data} https://api.koios.rest/api/ogmios/?SubmitTransaction
responses:
"200":
description: OK
"400":
description: An error occured while querying transaction.
summary: Submit Transaction
description: Submit a signed and serialized transaction to the network.
description: Submit a signed and serialized transaction to the network. Please refer to Ogmios documentation [here](https://ogmios.dev/api/#operation-publish-/?SubmitTransaction) for complete spec

components:
parameters:
Expand Down Expand Up @@ -3976,6 +3953,11 @@ components:
decimals:
type: integer
example: 0
cip68_metadata:
type: object
description: CIP 68 metadata if present for asset
nullable: true
example: {"222": {"fields": [{"map": [{"k": {"bytes": "6e616d65"}, "v": {"bytes": "74657374"}}]}], "constructor": 0}}
asset_history:
type: array
items:
Expand Down
36 changes: 9 additions & 27 deletions specs/results/koiosapi-preview.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -957,28 +957,6 @@ paths:
summary: Asset Token Registry
description: Get a list of assets registered via token registry on github
/asset_info: #RPC
get:
deprecated: true
tags:
- Asset
parameters:
- $ref: "#/components/parameters/_asset_policy"
- $ref: "#/components/parameters/_asset_name"
responses:
"200":
description: Array of detailed asset information
content:
application/json:
schema:
$ref: "#/components/schemas/asset_info"
"400":
$ref: "#/components/responses/BadRequest"
"401":
$ref: "#/components/responses/Unauthorized"
"404":
$ref: "#/components/responses/NotFound"
summary: Asset Information
description: Get the information of an asset including first minting & token registry metadata
post:
tags:
- Asset
Expand Down Expand Up @@ -1018,7 +996,7 @@ paths:
$ref: "#/components/responses/Unauthorized"
"404":
$ref: "#/components/responses/NotFound"
summary: Asset UTXO Information (Bulk)
summary: Asset UTXOs
description: Get the UTXO information of a list of assets including
/asset_history: #RPC
get:
Expand Down Expand Up @@ -1631,18 +1609,17 @@ paths:
x-code-samples:
- lang: "Shell"
source: |
# Assuming ${data} is a raw binary serialized transaction on the file-system.
# If using a CLI-generated tx file, please ensure to deserialise (using `xxd -p -r <<< $(jq .cborHex ${tx.signed}) > ${data}`) first before submitting.
# Assuming ${data} contains a CBOR-serialized signed transaction (base16-encoded) as documented on Ogmios v6 site.
curl -X POST \
--header "Content-Type: application/cbor" \
--data-binary @${data} https://api.koios.rest/api/ogmios/?EvaluateTransaction
--data-binary ${data} https://api.koios.rest/api/ogmios/?SubmitTransaction
responses:
"200":
description: OK
"400":
description: An error occured while querying transaction.
summary: Submit Transaction
description: Submit a signed and serialized transaction to the network.
description: Submit a signed and serialized transaction to the network. Please refer to Ogmios documentation [here](https://ogmios.dev/api/#operation-publish-/?SubmitTransaction) for complete spec

components:
parameters:
Expand Down Expand Up @@ -3976,6 +3953,11 @@ components:
decimals:
type: integer
example: 0
cip68_metadata:
type: object
description: CIP 68 metadata if present for asset
nullable: true
example: {"222": {"fields": [{"map": [{"k": {"bytes": "6e616d65"}, "v": {"bytes": "74657374"}}]}], "constructor": 0}}
asset_history:
type: array
items:
Expand Down
5 changes: 5 additions & 0 deletions specs/templates/4-api-schemas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1689,6 +1689,11 @@ schemas:
decimals:
type: integer
example: 0
cip68_metadata:
type: object
description: CIP 68 metadata if present for asset
nullable: true
example: {"222": {"fields": [{"map": [{"k": {"bytes": "6e616d65"}, "v": {"bytes": "74657374"}}]}], "constructor": 0}}
asset_history:
type: array
items:
Expand Down
Loading

0 comments on commit 4c4da66

Please sign in to comment.