Skip to content

Commit

Permalink
feat: adapt utxo query for ma balances
Browse files Browse the repository at this point in the history
  • Loading branch information
Juan Cruz authored and AlanVerbner committed Jan 18, 2021
1 parent 9ca1f65 commit 61243be
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
Expand Up @@ -489,7 +489,10 @@ export const configure = (databaseInstance: Pool): BlockchainRepository => ({
return result.rows.map(utxo => ({
value: utxo.value,
transactionHash: hexFormatter(utxo.txHash),
index: utxo.index
index: utxo.index,
maName: utxo.maName ? hexFormatter(utxo.maName) : utxo.maName,
maPolicy: utxo.maPolicy ? hexFormatter(utxo.maPolicy) : utxo.maPolicy,
quantity: utxo.quantity
}));
},
async findBalanceByAddressAndBlock(logger: Logger, address, blockHash): Promise<string> {
Expand Down
12 changes: 10 additions & 2 deletions cardano-rosetta-server/src/server/db/queries/blockchain-queries.ts
Expand Up @@ -228,6 +228,9 @@ export interface FindUtxo {
value: string;
txHash: Buffer;
index: number;
maPolicy: Buffer;
maName: Buffer;
quantity: number;
}

const findUtxoFieldsByAddressAndBlock = (selectFields: string): string => `
Expand All @@ -241,7 +244,9 @@ ${selectFields}
tx_in_tx.block_id <= (select id from block where hash = $2)
JOIN tx AS tx_out_tx ON
tx_out_tx.id = tx_out.tx_id AND
tx_out_tx.block_id <= (select id from block where hash = $2)
tx_out_tx.block_id <= (select id from block where hash = $2)
LEFT JOIN ma_tx_out ON
ma_tx_out.tx_out_id = tx_out.id
WHERE
tx_out.address = $1 AND
tx_in_tx.id IS NULL
Expand All @@ -250,7 +255,10 @@ ${selectFields}
const selectUtxoDetail = `SELECT
tx_out.value as value,
tx_out_tx.hash as "txHash",
tx_out.index as index`;
tx_out.index as index,
ma_tx_out.name as "maName",
ma_tx_out.policy as "maPolicy",
ma_tx_out.quantity`;

const findUtxoByAddressAndBlock = findUtxoFieldsByAddressAndBlock(selectUtxoDetail);

Expand Down
3 changes: 3 additions & 0 deletions cardano-rosetta-server/src/server/models.ts
Expand Up @@ -44,6 +44,9 @@ export interface Utxo {
value: string;
transactionHash: string;
index: number;
maName: string;
maPolicy: string;
quantity: number;
}

export interface TransactionInOut {
Expand Down

0 comments on commit 61243be

Please sign in to comment.