Skip to content

Commit

Permalink
Add hex field to output where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
rdlrt committed Jul 30, 2024
1 parent e6066a3 commit 0d7d42e
Show file tree
Hide file tree
Showing 11 changed files with 551 additions and 21 deletions.
4 changes: 3 additions & 1 deletion files/grest/rpc/governance/drep_metadata.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
CREATE OR REPLACE FUNCTION grest.drep_metadata(_drep_ids text [])
RETURNS TABLE (
drep_id character varying,
hex text,
url text,
hash text,
json jsonb,
Expand All @@ -14,14 +15,15 @@ LANGUAGE sql STABLE
AS $$
SELECT
DISTINCT ON (dh.view) dh.view AS drep_id,
ENCODE(dh.raw, 'hex')::text AS hex,
va.url,
ENCODE(va.data_hash, 'hex') AS hash,
ocvd.json,
ENCODE(ocvd.bytes,'hex')::text AS bytes,
ocvd.warning AS warning,
ocvd.language AS language,
ocvd.comment AS comment,
is_valid AS is_valid
COALESCE(is_valid, true) AS is_valid
FROM public.drep_hash AS dh
INNER JOIN public.drep_registration AS dr ON dh.id = dr.drep_hash_id
LEFT JOIN public.voting_anchor AS va ON dr.voting_anchor_id = va.id
Expand Down
2 changes: 2 additions & 0 deletions files/grest/rpc/governance/drep_updates.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
CREATE OR REPLACE FUNCTION grest.drep_updates(_drep_id text DEFAULT NULL)
RETURNS TABLE (
drep_id character varying,
hex text,
tx_hash text,
cert_index integer,
block_time integer,
Expand All @@ -14,6 +15,7 @@ LANGUAGE sql STABLE
AS $$
SELECT
dh.view AS drep_id,
ENCODE(dh.raw, 'hex')::text AS hex,
ENCODE(tx.hash, 'hex')::text AS tx_hash,
dr.cert_index,
EXTRACT(EPOCH FROM b.time)::integer AS block_time,
Expand Down
49 changes: 29 additions & 20 deletions files/grest/rpc/governance/proposal_votes.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,39 @@ RETURNS TABLE (
block_time integer,
voter_role text,
voter text,
voter_hex text,
vote text
)
LANGUAGE sql STABLE
AS $$
SELECT z.* from (
SELECT
distinct on (COALESCE(ENCODE(ch.raw, 'hex'), dh.view, ph.view))
EXTRACT(EPOCH FROM vote_block.time)::integer AS block_time,
vp.voter_role,
COALESCE(ENCODE(ch.raw, 'hex'), dh.view, ph.view) as voter,
vp.vote
FROM public.voting_procedure AS vp
INNER JOIN public.gov_action_proposal AS gap ON vp.gov_action_proposal_id = gap.id
INNER JOIN public.tx ON gap.tx_id = tx.id
INNER JOIN public.tx AS vote_tx ON vp.tx_id = vote_tx.id
INNER JOIN public.block AS vote_block ON vote_tx.block_id = vote_block.id
LEFT JOIN public.drep_hash AS dh ON vp.drep_voter = dh.id
LEFT JOIN public.pool_hash AS ph ON vp.pool_voter = ph.id
LEFT JOIN public.committee_hash AS ch ON vp.committee_voter = ch.id
WHERE tx.hash = DECODE(_tx_hash, 'hex')
-- will we need a similar filters to the one below for pool and committee member retirements?
AND (case when dh.view is not null then ((select coalesce(dreg.deposit, 0) from drep_registration dreg where dreg.drep_hash_id = dh.id order by id desc limit 1) >= 0) else true end)
ORDER by COALESCE(ENCODE(ch.raw, 'hex'), dh.view, ph.view), block_time DESC
) z ORDER BY block_time desc;
SELECT z.*
FROM (
SELECT
distinct on (COALESCE(ENCODE(ch.raw, 'hex'), dh.view, ph.view))
EXTRACT(EPOCH FROM vote_block.time)::integer AS block_time,
vp.voter_role,
COALESCE(ENCODE(ch.raw, 'hex'), dh.view, ph.view) as voter,
COALESCE(ENCODE(ch.raw, 'hex'), ENCODE(dh.raw, 'hex'), ENCODE(ph.hash_raw, 'hex')) as voter_hex,
vp.vote
FROM public.voting_procedure AS vp
INNER JOIN public.gov_action_proposal AS gap ON vp.gov_action_proposal_id = gap.id
INNER JOIN public.tx ON gap.tx_id = tx.id
INNER JOIN public.tx AS vote_tx ON vp.tx_id = vote_tx.id
INNER JOIN public.block AS vote_block ON vote_tx.block_id = vote_block.id
LEFT JOIN public.drep_hash AS dh ON vp.drep_voter = dh.id
LEFT JOIN public.pool_hash AS ph ON vp.pool_voter = ph.id
LEFT JOIN public.committee_hash AS ch ON vp.committee_voter = ch.id
WHERE tx.hash = DECODE(_tx_hash, 'hex')
-- will we need a similar filters to the one below for pool and committee member retirements?
AND (
CASE
WHEN dh.view IS NOT NULL THEN ((SELECT coalesce(dreg.deposit, 0) FROM drep_registration AS dreg WHERE dreg.drep_hash_id = dh.id ORDER BY id DESC LIMIT 1) >= 0)
ELSE true
END)
ORDER by
COALESCE(ENCODE(ch.raw, 'hex'), dh.view, ph.view),
block_time DESC
) z ORDER BY block_time desc;
$$;

COMMENT ON FUNCTION grest.proposal_votes IS 'Get all votes cast on specified governance action'; -- noqa: LT01
File renamed without changes.
101 changes: 101 additions & 0 deletions specs/results/koiosapi-guild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2546,6 +2546,24 @@ components:
- ['313534a537bc476c86ff7c57ec511bd7f24a9d15654091b24e9c606e','41484c636f696e']
_extended: true
description: Array of array of policyID and asset names (hex) alongwith extended flag to return additional columns
drep_id_bulk:
content:
application/json:
schema:
required:
- _drep_ids
type: object
properties:
_drep_ids:
format: text
type: array
descriptions: Array of DRep IDs in bech32 format
items:
type: string
example:
_drep_ids:
- drep1s9qaseg7qyum807fcv0hdky9gv0c89tn98t4urjn5ewz57dml0r
- drep13p45vxysc2s6vp6ez2ng7lynlsheh64zxexpcennn68cuc05yps
utxo_refs_with_extended:
content:
application/json:
Expand Down Expand Up @@ -4894,6 +4912,89 @@ components:
$ref: "#/components/schemas/asset_info/items/properties/total_supply"
decimals:
$ref: "#/components/schemas/asset_info/items/properties/token_registry_metadata/properties/decimals"
drep_info:
description: Get detailed information about requested delegated representatives (DReps)
type: array
items:
properties:
drep_id:
type: string
description: DRep ID in bech32 format
example: drep1l9y2naagv0vqvft9szdt5wf94fqnxn5hdsgusdl7rf6vq4djqck
hex:
type: string
description: DRep ID in hex format
example: f948a9f7a863d8062565809aba3925aa41334e976c11c837fe1a74c0
has_script:
type: boolean
description: Flag which shows if this DRep credentials are a script hash
example: false
registered:
type: boolean
description: Flag to show if the DRep is currently registered
example: false
deposit:
type: string
description: DRep's registration deposit in lovelace
example: 500000000
active:
type: boolean
description: Flag to show if the DRep is (i.e. not expired)
example: true
amount:
type: string
description: The total amount of voting power this DRep is delegated.
example: 599496769641
drep_list:
description: List of all active delegated representatives (DReps)
type: array
items:
properties:
drep_id:
$ref: "#/components/schemas/drep_info/drep_id"
hex:
$ref: "#/components/schemas/drep_info/hex"
has_script:
$ref: "#/components/schemas/drep_info/has_script"
registered:
$ref: "#/components/schemas/drep_info/registered"
drep_metadata:
description: List metadata for requested delegated representatives (DReps)
type: array
items:
properties:
drep_id:
$ref: "#/components/schemas/drep_info/drep_id"
hex:
$ref: "#/components/schemas/drep_info/drep_metadata"
url:
type: string
description: A URL to a JSON payload of metadata
example: "https://hornan7.github.io/Vote_Context.jsonld"
hash:
type: string
description: A hash of the contents of the metadata URL
example: dc208474e195442d07a5b6d42af19bb2db02229427dfb53ab23122e6b0e2487d
json:
type: object
description: The payload as JSON
example:
{"body": {"title": "...", "...": "...", "references": [{"uri": "...", "@type": "Other", "label": "Hardfork to PV10"}]}, "authors": [{"name": "...", "witness": {"publicKey": "...", "signature": "...", "witnessAlgorithm": "ed25519"}}], "@context": {"body": {"@id": "CIP108:body", "@context": {"title": "CIP108:title", "abstract": "CIP108:abstract", "rationale": "CIP108:rationale", "motivation": "CIP108:motivation", "references": {"@id": "CIP108:references", "@context": {"uri": "CIP100:reference-uri", "Other": "CIP100:OtherReference", "label": "CIP100:reference-label", "referenceHash": {"@id": "CIP108:referenceHash", "@context": {"hashDigest": "CIP108:hashDigest", "hashAlgorithm": "CIP100:hashAlgorithm"}}, "GovernanceMetadata": "CIP100:GovernanceMetadataReference"}, "@container": "@set"}}}, "CIP100": "https://github.com/cardano-foundation/CIPs/blob/master/CIP-0100/README.md#", "CIP108": "https://github.com/cardano-foundation/CIPs/blob/master/CIP-0108/README.md#", "authors": {"@id": "CIP100:authors", "@context": {"name": "http://xmlns.com/foaf/0.1/name", "witness": {"@id": "CIP100:witness", "@context": {"publicKey": "CIP100:publicKey", "signature": "CIP100:signature", "witnessAlgorithm": "CIP100:witnessAlgorithm"}}}, "@container": "@set"}, "@language": "en-us", "hashAlgorithm": "CIP100:hashAlgorithm"}, "hashAlgorithm": "blake2b-256"}
bytes:
type: text
description: The raw bytes of the payload
example: 7b0a20202240636f6e74657874223a207b0a2020202022406c616e6775616765223a2022656e2d7573222c0a2020202022434950313030223a202268747470733a2f2f6769746875622e636f6d2f63617264616e6f2d666f756e646174696f6e2f434950732f626c6f622f6d61737465722f4349502d303130302f524541444d452e6d6423222c0a2020202022434950313038223a202268747470733a2f2f6769746875622e636f6d2f63617264616e6f2d666f756e646174696f6e2f434950732f626c6f622f6d61737465722f4349502d303130382f524541444d452e6d6423222c0a202020202268617368416c676f726974686d223a20224349503130303a68617368416c676f726974686d222c0a2020202022626f6479223a207b0a20202020202022406964223a20224349503130383a626f6479222c0a2020202020202240636f6e74657874223a207b0a2020202020202020227265666572656e636573223a207b0a2020202020202020202022406964223a20224349503130383a7265666572656e636573222c0a202020202020202020202240636f6e7461696e6572223a202240736574222c0a202020202020202020202240636f6e74657874223a207b0a20202020202020202020202022476f7665726e616e63654d65746164617461223a20224349503130303a476f7665726e616e63654d657461646174615265666572656e6365222c0a202020202020202020202020224f74686572223a20224349503130303a4f746865725265666572656e6365222c0a202020202020202020202020226c6162656c223a20224349503130303a7265666572656e63652d6c6162656c222c0a20202020202020202020202022757269223a20224349503130303a7265666572656e63652d757269222c0a202020202020202020202020227265666572656e636548617368223a207b0a202020202020202020202020202022406964223a20224349503130383a7265666572656e636548617368222c0a20202020202020202020202020202240636f6e74657874223a207b0a202020202020202020202020202020202268617368446967657374223a20224349503130383a68617368446967657374222c0a202020202020202020202020202020202268617368416c676f726974686d223a20224349503130303a68617368416c676f726974686d220a20202020202020202020202020207d0a2020202020202020202020207d0a202020202020202020207d0a20202020202020207d2c0a2020202020202020227469746c65223a20224349503130383a7469746c65222c0a2020202020202020226162737472616374223a20224349503130383a6162737472616374222c0a2020202020202020226d6f7469766174696f6e223a20224349503130383a6d6f7469766174696f6e222c0a202020202020202022726174696f6e616c65223a20224349503130383a726174696f6e616c65220a2020202020207d0a202020207d2c0a2020202022617574686f7273223a207b0a20202020202022406964223a20224349503130303a617574686f7273222c0a2020202020202240636f6e7461696e6572223a202240736574222c0a2020202020202240636f6e74657874223a207b0a2020202020202020226e616d65223a2022687474703a2f2f786d6c6e732e636f6d2f666f61662f302e312f6e616d65222c0a2020202020202020227769746e657373223a207b0a2020202020202020202022406964223a20224349503130303a7769746e657373222c0a202020202020202020202240636f6e74657874223a207b0a202020202020202020202020227769746e657373416c676f726974686d223a20224349503130303a7769746e657373416c676f726974686d222c0a202020202020202020202020227075626c69634b6579223a20224349503130303a7075626c69634b6579222c0a202020202020202020202020227369676e6174757265223a20224349503130303a7369676e6174757265220a202020202020202020207d0a20202020202020207d0a2020202020207d0a202020207d0a20207d2c0a20202268617368416c676f726974686d223a2022626c616b6532622d323536222c0a202022626f6479223a207b0a20202020227469746c65223a202248617264666f726b20746f2050726f746f636f6c2076657273696f6e203130222c0a20202020226162737472616374223a20224c6574277320686176652073616e63686f4e657420696e2066756c6c20676f7665726e616e636520617320736f6f6e20617320706f737369626c65222c0a20202020226d6f7469766174696f6e223a2022505639206973206e6f742061732066756e2061732050563130222c0a2020202022726174696f6e616c65223a20224c65742773206b6565702074657374696e67207374756666222c0a20202020227265666572656e636573223a205b0a2020202020207b0a2020202020202020224074797065223a20224f74686572222c0a2020202020202020226c6162656c223a202248617264666f726b20746f2050563130222c0a202020202020202022757269223a2022220a2020202020207d0a202020205d0a20207d2c0a202022617574686f7273223a205b0a202020207b0a202020202020226e616d65223a20224361726c6f73222c0a202020202020227769746e657373223a207b0a2020202020202020227769746e657373416c676f726974686d223a202265643235353139222c0a2020202020202020227075626c69634b6579223a202237656130396133346165626231336339383431633731333937623163616266656335646466393530343035323933646565343936636163326634333734383061222c0a2020202020202020227369676e6174757265223a20226134373639383562346363306434353766323437373937363131373939613666366138306663386362376563396463623561383232333838386430363138653330646531363566336438363963346130643931303764386135623631326164376335653432343431393037663562393137393666306437313837643634613031220a2020202020207d0a202020207d0a20205d0a7d
warning:
type: text
description: A warning that occured while validating the metadata
comment:
type: text
description: Comment attached to the metadata
is_valid:
type: boolean
description: Indicate whether data is invalid
example: true

script_info:
type: array
items:
Expand Down
Loading

0 comments on commit 0d7d42e

Please sign in to comment.