Skip to content

Commit

Permalink
[@kadena/graph] Feat: Update prisma schema to follow naming convention (
Browse files Browse the repository at this point in the history
#998)

* removed event parameters and added paramtext; adjusted the client pages accordingly

* fix fetching of events and eventpage

* change while statement on block so that subscription stops even if no result is fetched

* add empty changeset

* lint fix

* removed commentary

* fix lint

* applied naming convention on prisma fields and changed graphql queries and subscriptions accordingly

* add empty changeset

* apply naming convention to powhash field

* change graphql field accordingly

* changes in client to accomodate graphql schema changes

* changed paramText to new naming convention in client
  • Loading branch information
nil-amrutlal authored Oct 11, 2023
1 parent 7646f96 commit c2482c8
Show file tree
Hide file tree
Showing 18 changed files with 238 additions and 196 deletions.
2 changes: 2 additions & 0 deletions .changeset/lucky-flies-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
2 changes: 2 additions & 0 deletions .changeset/tasty-emus-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const ChainBlock = (props: IChainBlockProps): JSX.Element => {
let confirmationDepth = 0;

if (block) {
confirmationDepth = chainTree[block.chainid][block.hash].confirmationDepth;
confirmationDepth = chainTree[block.chainId][block.hash].confirmationDepth;
}

return (
Expand All @@ -46,14 +46,14 @@ export const ChainBlock = (props: IChainBlockProps): JSX.Element => {
}}
>
<TimerIcon />
<TimeTicker date={new Date(block.creationtime)} />
<TimeTicker date={new Date(block.creationTime)} />

<InfoCircledIcon />

<Text as="span">
{confirmationDepth >= env.MAX_CALCULATED_CONFIRMATION_DEPTH
? `>${chainTree[block.chainid][block.hash].confirmationDepth}`
: chainTree[block.chainid][block.hash].confirmationDepth}
? `>${chainTree[block.chainId][block.hash].confirmationDepth}`
: chainTree[block.chainId][block.hash].confirmationDepth}
</Text>

{/* {block.transactions.totalCount > 0 && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const ChainwebRow = ({
height,
}: IChainwebRowProps): JSX.Element => {
const row: Array<IBlock | undefined> = new Array(20).fill(undefined);
blocks.forEach((block) => (row[block.chainid] = block));
blocks.forEach((block) => (row[block.chainId] = block));

return (
<Box
Expand Down
12 changes: 6 additions & 6 deletions packages/apps/graph-client/src/context/chain-tree-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ export function addBlockToChainTree(
let currentBlock = block;

//Check if chain index exists, if not create it
if (chainTree[currentBlock.chainid] === undefined) {
chainTree[currentBlock.chainid] = {};
if (chainTree[currentBlock.chainId] === undefined) {
chainTree[currentBlock.chainId] = {};
}

//Add block to chain
chainTree[currentBlock.chainid][currentBlock.hash] = currentBlock;
chainTree[currentBlock.chainId][currentBlock.hash] = currentBlock;

//Check if parent block exists, if it does increment confirmation depth
while (
currentBlock.parentHash &&
chainTree[currentBlock.chainid][currentBlock.parentHash]
chainTree[currentBlock.chainId][currentBlock.parentHash]
) {
const childsConfirmationDepth = currentBlock.confirmationDepth;

//set current block to parent block
currentBlock = {
...chainTree[currentBlock.chainid][currentBlock.parentHash],
...chainTree[currentBlock.chainId][currentBlock.parentHash],
};

//before incrementing depth check if it is already 6
Expand All @@ -50,7 +50,7 @@ export function addBlockToChainTree(
}

//set the updated block in the chain
chainTree[currentBlock.chainid][currentBlock.hash] = currentBlock;
chainTree[currentBlock.chainId][currentBlock.hash] = currentBlock;
}

return chainTree;
Expand Down
26 changes: 13 additions & 13 deletions packages/apps/graph-client/src/graphql/queries.graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { gql } from '@apollo/client';
export const CORE_BLOCK_FIELDS: DocumentNode = gql`
fragment CoreBlockFields on Block {
id
chainid
creationtime
chainId
creationTime
epoch
# flags
hash
Expand All @@ -14,7 +14,7 @@ export const CORE_BLOCK_FIELDS: DocumentNode = gql`
# nonce
# parent
# payload
powhash
powHash
# predicate
# target
# weight
Expand Down Expand Up @@ -69,12 +69,12 @@ export const CORE_EVENT_FIELDS: DocumentNode = gql`
requestKey
chainId
height
#index
#orderindex
#module
#name
eventParameters
parameterText
#parameters
qualName
qualifiedName
}
`;

Expand Down Expand Up @@ -116,8 +116,8 @@ export const getTransactionByRequestKey: DocumentNode = gql`
id
}
events {
qualName
eventParameters
qualifiedName
parameterText
}
chainId
code
Expand All @@ -132,15 +132,15 @@ export const getTransactionByRequestKey: DocumentNode = gql`
logs
metadata
nonce
numEvents
eventCount
pactId
proof
requestKey
rollback
sender
step
ttl
txId
transactionId
}
}
`;
Expand All @@ -154,11 +154,11 @@ export const getEventByName: DocumentNode = gql`
}
chainId
height
index
orderIndex
# module
# name
eventParameters
qualName
parameterText
qualifiedName
transaction {
requestKey
}
Expand Down
48 changes: 42 additions & 6 deletions packages/apps/graph-client/src/pages/event/[key].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,51 @@ const Event: React.FC = () => {
key={index}
url={`${routes.TRANSACTION}/${event.transaction?.requestKey}`}
>
<Table.Td>{event.qualName}</Table.Td>
<Table.Td>{event.qualifiedName}</Table.Td>
<Table.Td>
<Table.Root>
<Table.Body>
{event.eventParameters.map((parameter, index) => (
<Table.Tr key={`arguments-${index}`}>
<Table.Td>{parameter}</Table.Td>
</Table.Tr>
))}
{JSON.parse(event.parameterText).map(
(parameter: any, index: number) => (
<Table.Tr key={`arguments-${index}`}>
<Table.Td>
{typeof parameter === 'string' ? (
parameter
) : typeof parameter === 'object' ? (
<Table.Root>
<Table.Body>
{parameter.map(
(
subparameter: any,
index: number,
) => (
<Table.Tr
key={`arguments-${index}`}
>
<Table.Td>
{typeof subparameter ===
'string' ? (
subparameter
) : (
<pre>
{JSON.stringify(
subparameter,
)}
</pre>
)}
</Table.Td>
</Table.Tr>
),
)}
</Table.Body>
</Table.Root>
) : (
JSON.stringify(parameter)
)}
</Table.Td>
</Table.Tr>
),
)}
</Table.Body>
</Table.Root>
</Table.Td>
Expand Down
11 changes: 8 additions & 3 deletions packages/apps/graph-client/src/pages/transaction/[key].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,10 @@ const RequestKey: React.FC = () => {
<strong>Transaction ID</strong>
</Table.Td>
<Table.Td>
{transactionSubscription?.transaction?.txId}
{
transactionSubscription?.transaction
?.transactionId
}
</Table.Td>
</Table.Tr>
</Table.Body>
Expand All @@ -206,15 +209,17 @@ const RequestKey: React.FC = () => {
<Table.Td>
<strong>Name</strong>
</Table.Td>
<Table.Td>{event.qualName}</Table.Td>
<Table.Td>{event.qualifiedName}</Table.Td>
</Table.Tr>
<Table.Tr>
<Table.Td>
<strong>Parameters</strong>
</Table.Td>
<Table.Td>
<pre>
{JSON.stringify(event.eventParameters)}
{JSON.stringify(
JSON.parse(event.parameterText),
)}
</pre>
</Table.Td>
</Table.Tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ export interface IBlock
NonNullable<GetBlocksSubscription['newBlocks']>[number],
// TODO: fix transactions from graphql
// 'transactions' |
| 'creationtime'
| 'creationTime'
| 'height'
| 'chainid'
| 'chainId'
| 'hash'
| 'powhash'
| 'powHash'
| 'epoch'
| 'confirmationDepth'
| 'parentHash'
Expand Down Expand Up @@ -52,7 +52,7 @@ export function useParsedBlocks(): IUseParseBlocksReturn {

if (index === blocks.length - 1) {
updatedBlocks[heightNum] = [...updatedBlocks[heightNum]].sort(
(a, b) => b.chainid - a.chainid,
(a, b) => b.chainId - a.chainId,
);
}
});
Expand Down
19 changes: 9 additions & 10 deletions packages/apps/graph/generated-schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ The `BigInt` scalar type represents non-fractional signed whole numeric values.
scalar BigInt

type Block implements Node {
chainid: BigInt!
chainId: BigInt!
confirmationDepth: Int!
creationtime: DateTime!
creationTime: DateTime!
epoch: DateTime!
hash: ID!
height: BigInt!
id: ID!
parent: Block
parentHash: String
parent_old: String!
powhash: String!
powHash: String!
transactions(after: String, before: String, events: [String!] = [], first: Int, last: Int): BlockTransactionsConnection!
}

Expand All @@ -37,13 +36,13 @@ scalar DateTime
type Event implements Node {
block: Block!
chainId: BigInt!
eventParameters: [String!]!
height: BigInt!
id: ID!
index: BigInt!
module: String!
moduleName: String!
name: String!
qualName: String!
orderIndex: BigInt!
parameterText: String!
qualifiedName: String!
requestKey: String!
transaction: Transaction
}
Expand Down Expand Up @@ -85,6 +84,7 @@ type Transaction implements Node {
continuation: String
creationTime: DateTime!
data: String
eventCount: BigInt
events: [Event!]
gas: BigInt!
gasLimit: BigInt!
Expand All @@ -95,13 +95,12 @@ type Transaction implements Node {
logs: String
metadata: String
nonce: String
numEvents: BigInt
pactId: String
proof: String
requestKey: String!
rollback: Boolean
sender: String
step: BigInt
transactionId: BigInt
ttl: BigInt!
txId: BigInt
}
Loading

0 comments on commit c2482c8

Please sign in to comment.