-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from ixofoundation/develop
Develop
- Loading branch information
Showing
12 changed files
with
1,290 additions
and
1,675 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { dbQuery } from "./client"; | ||
|
||
export type BlockCore = { | ||
height: number; | ||
time: Date; | ||
transactions: TransactionCore[]; | ||
events: EventCore[]; | ||
}; | ||
|
||
export type TransactionCore = { | ||
hash: string; | ||
code: number; | ||
fee: any; // JSON | ||
gasUsed: string; | ||
gasWanted: string; | ||
memo: string; | ||
messages: MessageCore[]; | ||
}; | ||
|
||
export type MessageCore = { | ||
typeUrl: string; | ||
value: any; // JSON | ||
}; | ||
|
||
export type EventCore = { | ||
type: string; | ||
attributes: any[]; // JSON | ||
}; | ||
|
||
const sqlTransactions = ` | ||
SELECT | ||
t."hash", | ||
t."code", | ||
t."fee", | ||
t."gasUsed", | ||
t."gasWanted", | ||
t."memo", | ||
json_agg(json_build_object('typeUrl', "m"."typeUrl", 'value', m.value)) AS messages | ||
FROM "TransactionCore" as t | ||
LEFT OUTER JOIN "MessageCore" as m ON t.hash = m."transactionHash" | ||
WHERE t."blockHeight" = $1 | ||
Group By t.hash; | ||
`; | ||
const sqlEvents = ` | ||
SELECT | ||
b."height", | ||
b."time", | ||
json_agg(json_build_object('type', e.type, 'attributes', e.attributes)) AS events | ||
FROM "BlockCore" as b | ||
LEFT OUTER JOIN ( | ||
SELECT "type", attributes | ||
from "EventCore" | ||
where "blockHeight" = $1 | ||
order by id asc | ||
) as e on TRUE | ||
WHERE b.height = $1 | ||
GROUP BY b.height, b."time" | ||
`; | ||
export const getCoreBlock = async ( | ||
blockHeight: number | ||
): Promise<BlockCore | null> => { | ||
try { | ||
let blockAndEvents: any = await dbQuery(sqlEvents, [blockHeight]); | ||
// If no block is found, return null before querying transactions | ||
if (blockAndEvents.rows.length === 0) return null; | ||
let transactions: any = await dbQuery(sqlTransactions, [blockHeight]); | ||
|
||
blockAndEvents = blockAndEvents.rows[0]; | ||
transactions = transactions.rows.map((row: any) => ({ | ||
hash: row.hash, | ||
code: row.code, | ||
fee: row.fee, | ||
gasUsed: row.gasUsed, | ||
gasWanted: row.gasWanted, | ||
memo: row.memo, | ||
messages: row.messages, | ||
})); | ||
|
||
return { | ||
height: blockAndEvents.height, | ||
time: blockAndEvents.time, | ||
transactions, | ||
events: blockAndEvents.events, | ||
}; | ||
} catch (error) { | ||
throw error; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.