Skip to content

Commit

Permalink
fix(graph): introduce RawGuard type as fallthrough for IGuard non K…
Browse files Browse the repository at this point in the history
…eysetGuard types
  • Loading branch information
alber70g committed Jan 15, 2025
1 parent 64cf5e1 commit d24bad7
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 29 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -216,25 +216,25 @@ jobs:
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
id: docker_build
uses: docker/build-push-action@v6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export const ExtendedTransactionsTable = (
</Cell>
<Cell>
{edge.node.result.__typename === 'TransactionResult' ? (
edge.node.result.height
edge.node.result.block.height
) : (
<span style={{ color: 'lightgray' }}>N/A</span>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ const RequestKey: React.FC = () => {
<Cell>
{transaction.result.__typename ===
'TransactionResult' ? (
transaction.result.height
transaction.result.block.height
) : (
<span style={{ color: 'lightgray' }}>N/A</span>
)}
Expand Down
10 changes: 9 additions & 1 deletion packages/apps/graph/generated-schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ type Event implements Node {
The order index of this event, in the case that there are multiple events in one transaction.
"""
orderIndex: BigInt!
parameterText: String!
parameters: String

"""
Expand Down Expand Up @@ -431,7 +432,7 @@ type Query {
"""
Retrieve an account by its name and fungible, such as coin, on a specific chain.
"""
fungibleChainAccount(accountName: String!, chainIds: [String!]! = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"], fungibleName: String = "coin"): [FungibleChainAccount!]
fungibleChainAccount(accountName: String!, chainIds: [String!] = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"], fungibleName: String = "coin"): [FungibleChainAccount!]

"""Retrieve a chain account by public key."""
fungibleChainAccountsByPublicKey(chainId: String!, fungibleName: String, publicKey: String!): [FungibleChainAccount!]!
Expand Down Expand Up @@ -566,6 +567,13 @@ type QueryTransfersConnectionEdge {
node: Transfer!
}

"""DEPRECATED: a fallthrough IGuard type to cover non-KeysetGuard types."""
type RawGuard implements IGuard {
keys: [String!]! @deprecated(reason: "deprecated, use KeysetGuard.keys")
predicate: String! @deprecated(reason: "deprecated, use KeysetGuard.predicate")
raw: String!
}

"""A signer for a specific transaction."""
type Signer implements Node {
"""The signer for the gas."""
Expand Down
4 changes: 2 additions & 2 deletions packages/apps/graph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
"pactjs:generate:contract:faucet": "pactjs contract-generate --contract user.coin-faucet --api https://api.testnet.chainweb.com/chainweb/0.0/testnet04/chain/0/pact;",
"pactjs:generate:contract:marmalade": "pactjs contract-generate --contract marmalade.ledger --api https://api.testnet.chainweb.com/chainweb/0.0/testnet04/chain/1/pact;",
"pactjs:generate:contract:marmalade-v2": "pactjs contract-generate --contract marmalade-v2.ledger --api https://api.testnet.chainweb.com/chainweb/0.0/testnet04/chain/1/pact;",
"pactjs:generate:contracts": "npm run pactjs:generate:contract:coin & npm run pactjs:generate:contract:marmalade & npm run pactjs:generate:contract:marmalade-v2",
"prisma:generate": "prisma generate",
"pactjs:generate:contracts": "cache-sh -i \"node_modules/.kadena/**\" -- \"npm run pactjs:generate:contract:coin & npm run pactjs:generate:contract:marmalade & npm run pactjs:generate:contract:marmalade-v2\"",
"prisma:generate": "cache-sh -i \"prisma/*\" -- prisma generate",
"prisma:pull": "prisma db pull",
"prisma:studio": "prisma studio",
"simulate:all": "pnpm run simulate:coin & pnpm run simulate:marmalade",
Expand Down
2 changes: 2 additions & 0 deletions packages/apps/graph/src/graph/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import type {
INonFungibleToken,
INonFungibleTokenBalance,
IPactQueryResponse,
IRawGuard,
ITransactionCapability,
ITransactionCommand,
ITransactionMempoolInfo,
Expand Down Expand Up @@ -103,6 +104,7 @@ export const builder = new SchemaBuilder<
NetworkInfo: INetworkInfo;
BlockNeighbor: IBlockNeighbor;
KeysetGuard: IKeysetGuard;
RawGuard: IRawGuard;
};
Interfaces: {
IGuard: IGuard;
Expand Down
1 change: 1 addition & 0 deletions packages/apps/graph/src/graph/objects/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default builder.prismaNode(Prisma.ModelName.Event, {
}),
moduleName: t.exposeString('moduleName'),
name: t.exposeString('name'),
parameterText: t.exposeString('parameterText'),
parameters: t.string({
nullable: true,
select: {
Expand Down
47 changes: 31 additions & 16 deletions packages/apps/graph/src/graph/objects/keyset-guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ async function tryParseJson<T>(json: string): Promise<T> {
}
});
}

export class GuardInterfaceClass implements IGuard {
public raw: string;
public keys: string[] = [];
public predicate: '' | 'keys-all' | 'keys-any' | 'keys-two' = '';

public constructor(raw: string) {
this.raw = raw;
Expand All @@ -35,22 +38,22 @@ export const InterfaceGuard = builder.interfaceType(GuardInterfaceClass, {
switch (true) {
case parsed && 'keys' in parsed:
return 'KeysetGuard';
case parsed && 'keysetref' in parsed:
return 'KeysetRefGuard';
case parsed && 'fun' in parsed:
return 'UserGuard';
case parsed && 'cgName' in parsed:
return 'CapabilityGuard';
case parsed && 'moduleName' in parsed:
return 'ModuleGuard';
case parsed && 'pactId' in parsed:
return 'PactGuard';
// case parsed && 'keysetref' in parsed:
// return 'KeysetRefGuard';
// case parsed && 'fun' in parsed:
// return 'UserGuard';
// case parsed && 'cgName' in parsed:
// return 'CapabilityGuard';
// case parsed && 'moduleName' in parsed:
// return 'ModuleGuard';
// case parsed && 'pactId' in parsed:
// return 'PactGuard';
default:
throw new Error('not supported guard');
return 'RawGuard';
}
},
fields: (t) => ({
raw: t.string(),
raw: t.string({ resolve: (parent) => parent.raw }),
predicate: t.string({
deprecationReason: 'deprecated, use KeysetGuard.predicate',
resolve: () =>
Expand All @@ -69,7 +72,10 @@ builder.objectType('KeysetGuard', {
interfaces: [InterfaceGuard],
description: 'A keyset guard.',
fields: (t) => ({
raw: t.expose('raw', { type: 'String' }),
raw: t.field({
type: 'String',
resolve: (parent) => parent.raw,
}),
predicate: t.field({
type: 'String',
resolve: async (parent) => ((await tryParseJson(parent.raw)) as any).pred,
Expand All @@ -81,6 +87,13 @@ builder.objectType('KeysetGuard', {
}),
});

// Temporary RawGuard
builder.objectType('RawGuard', {
interfaces: [InterfaceGuard],
description:
'DEPRECATED: a fallthrough IGuard type to cover non-KeysetGuard types.',
});

// // KeysetRef:
// // { "keysetref": { "ns":String?, "ksn":String } }
// export class KeysetRefGuard {
Expand All @@ -104,12 +117,14 @@ type PactValue = string;

// // UserGuard:
// // { "fun":String, "args":Array[PactValue] }
export class UserGuard {
constructor(
export class UserGuard extends GuardInterfaceClass {
public constructor(
public raw: string,
public fun: string,
public args: PactValue[],
) {}
) {
super(raw);
}
}

builder.objectType(UserGuard, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ builder.queryField('fungibleChainAccount', (t) =>
}),
chainIds: t.arg.stringList({
defaultValue: [...CHAINS],
required: true,
validate: {
minLength: 1,
items: {
Expand All @@ -42,7 +41,7 @@ builder.queryField('fungibleChainAccount', (t) =>
try {
return (
await Promise.all(
args.chainIds.map((chainId) =>
args.chainIds!.map((chainId) =>
getFungibleChainAccount({
chainId: chainId,
fungibleName: args.fungibleName as string,
Expand Down
11 changes: 11 additions & 0 deletions packages/apps/graph/src/graph/types/graphql-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import type { Signer, Transaction, Transfer } from '@prisma/client';

export interface IGuard {
raw: string;

/** @deprecated */
keys?: string[];
/** @deprecated */
predicate?: 'keys-all' | 'keys-any' | 'keys-two' | '';
}

export interface IKeysetGuard extends IGuard {
Expand All @@ -10,6 +15,12 @@ export interface IKeysetGuard extends IGuard {
raw: string;
}

export interface IRawGuard extends IGuard {
keys: string[];
predicate: 'keys-all' | 'keys-any' | 'keys-two' | '';
raw: string;
}

export interface IGasLimitEstimation {
amount: number;
inputType: string;
Expand Down
2 changes: 0 additions & 2 deletions packages/apps/graph/src/services/account-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ export async function getFungibleChainAccount({
accountName,
fungibleName,
guard: {
keys: accountDetails.guard.keys,
predicate: accountDetails.guard.pred,
raw: JSON.stringify(accountDetails.guard),
},
balance: accountDetails.balance,
Expand Down

0 comments on commit d24bad7

Please sign in to comment.