From 7068daa52ecfaf2bd50e8b7fe703e11396be9a4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Dan?= Date: Mon, 27 Nov 2023 11:47:41 +0100 Subject: [PATCH 1/2] feat: regenerate graphql code to adapt to new subnetId field --- codegen.ts | 2 +- src/__generated__/gql.ts | 8 ++--- src/__generated__/graphql.ts | 33 ++++++++++++++++--- src/hooks/useSubnetGetCertificateById.tsx | 6 ++-- src/hooks/useSubnetGetCertificates.tsx | 4 ++- .../useSubnetSubscribeToCertificates.tsx | 16 ++++++--- 6 files changed, 52 insertions(+), 17 deletions(-) diff --git a/codegen.ts b/codegen.ts index 5824878..2e5b6f3 100644 --- a/codegen.ts +++ b/codegen.ts @@ -1,7 +1,7 @@ import { CodegenConfig } from '@graphql-codegen/cli' const config: CodegenConfig = { - schema: 'http://localhost:4000', + schema: 'http://localhost:4030', documents: ['src/**/*.tsx'], generates: { './src/__generated__/': { diff --git a/src/__generated__/gql.ts b/src/__generated__/gql.ts index 4cbf173..04f6060 100644 --- a/src/__generated__/gql.ts +++ b/src/__generated__/gql.ts @@ -13,8 +13,8 @@ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/ * Therefore it is highly recommended to use the babel or swc plugin for production. */ const documents = { - "\n query Certificate($certificateId: CertificateId!) {\n certificate(certificateId: $certificateId) {\n prevId\n id\n proof\n signature\n sourceSubnetId\n stateRoot\n targetSubnets {\n value\n }\n receiptsRootHash\n txRootHash\n verifier\n }\n }\n": types.CertificateDocument, - "\n query Certificates($fromSourceCheckpoint: SourceCheckpoint!, $limit: Int!) {\n certificates(fromSourceCheckpoint: $fromSourceCheckpoint, first: $limit) {\n prevId\n id\n proof\n signature\n sourceSubnetId\n stateRoot\n targetSubnets {\n value\n }\n receiptsRootHash\n txRootHash\n verifier\n }\n }\n": types.CertificatesDocument, + "\n query Certificate($certificateId: CertificateId!) {\n certificate(certificateId: $certificateId) {\n prevId\n id\n proof\n signature\n sourceSubnetId {\n value\n }\n stateRoot\n targetSubnets {\n value\n }\n receiptsRootHash\n txRootHash\n verifier\n }\n }\n": types.CertificateDocument, + "\n query Certificates($fromSourceCheckpoint: SourceCheckpoint!, $limit: Int!) {\n certificates(fromSourceCheckpoint: $fromSourceCheckpoint, first: $limit) {\n prevId\n id\n proof\n signature\n sourceSubnetId {\n value\n }\n stateRoot\n targetSubnets {\n value\n }\n receiptsRootHash\n txRootHash\n verifier\n }\n }\n": types.CertificatesDocument, }; /** @@ -34,11 +34,11 @@ export function graphql(source: string): unknown; /** * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ -export function graphql(source: "\n query Certificate($certificateId: CertificateId!) {\n certificate(certificateId: $certificateId) {\n prevId\n id\n proof\n signature\n sourceSubnetId\n stateRoot\n targetSubnets {\n value\n }\n receiptsRootHash\n txRootHash\n verifier\n }\n }\n"): (typeof documents)["\n query Certificate($certificateId: CertificateId!) {\n certificate(certificateId: $certificateId) {\n prevId\n id\n proof\n signature\n sourceSubnetId\n stateRoot\n targetSubnets {\n value\n }\n receiptsRootHash\n txRootHash\n verifier\n }\n }\n"]; +export function graphql(source: "\n query Certificate($certificateId: CertificateId!) {\n certificate(certificateId: $certificateId) {\n prevId\n id\n proof\n signature\n sourceSubnetId {\n value\n }\n stateRoot\n targetSubnets {\n value\n }\n receiptsRootHash\n txRootHash\n verifier\n }\n }\n"): (typeof documents)["\n query Certificate($certificateId: CertificateId!) {\n certificate(certificateId: $certificateId) {\n prevId\n id\n proof\n signature\n sourceSubnetId {\n value\n }\n stateRoot\n targetSubnets {\n value\n }\n receiptsRootHash\n txRootHash\n verifier\n }\n }\n"]; /** * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ -export function graphql(source: "\n query Certificates($fromSourceCheckpoint: SourceCheckpoint!, $limit: Int!) {\n certificates(fromSourceCheckpoint: $fromSourceCheckpoint, first: $limit) {\n prevId\n id\n proof\n signature\n sourceSubnetId\n stateRoot\n targetSubnets {\n value\n }\n receiptsRootHash\n txRootHash\n verifier\n }\n }\n"): (typeof documents)["\n query Certificates($fromSourceCheckpoint: SourceCheckpoint!, $limit: Int!) {\n certificates(fromSourceCheckpoint: $fromSourceCheckpoint, first: $limit) {\n prevId\n id\n proof\n signature\n sourceSubnetId\n stateRoot\n targetSubnets {\n value\n }\n receiptsRootHash\n txRootHash\n verifier\n }\n }\n"]; +export function graphql(source: "\n query Certificates($fromSourceCheckpoint: SourceCheckpoint!, $limit: Int!) {\n certificates(fromSourceCheckpoint: $fromSourceCheckpoint, first: $limit) {\n prevId\n id\n proof\n signature\n sourceSubnetId {\n value\n }\n stateRoot\n targetSubnets {\n value\n }\n receiptsRootHash\n txRootHash\n verifier\n }\n }\n"): (typeof documents)["\n query Certificates($fromSourceCheckpoint: SourceCheckpoint!, $limit: Int!) {\n certificates(fromSourceCheckpoint: $fromSourceCheckpoint, first: $limit) {\n prevId\n id\n proof\n signature\n sourceSubnetId {\n value\n }\n stateRoot\n targetSubnets {\n value\n }\n receiptsRootHash\n txRootHash\n verifier\n }\n }\n"]; export function graphql(source: string) { return (documents as any)[source] ?? {}; diff --git a/src/__generated__/graphql.ts b/src/__generated__/graphql.ts index 75d4a7a..36d0305 100644 --- a/src/__generated__/graphql.ts +++ b/src/__generated__/graphql.ts @@ -23,7 +23,7 @@ export type Certificate = { proof: Scalars['String']['output']; receiptsRootHash: Scalars['String']['output']; signature: Scalars['String']['output']; - sourceSubnetId: Scalars['String']['output']; + sourceSubnetId: SubnetId; stateRoot: Scalars['String']['output']; targetSubnets: Array; txRootHash: Scalars['String']['output']; @@ -63,6 +63,11 @@ export type SourceStreamPosition = { sourceSubnetId: SubnetIdInput; }; +export type SubnetFilter = { + source?: InputMaybe; + target?: InputMaybe; +}; + export type SubnetId = { __typename?: 'SubnetId'; value: Scalars['String']['output']; @@ -72,12 +77,30 @@ export type SubnetIdInput = { value: Scalars['String']['input']; }; +export type SubscriptionRoot = { + __typename?: 'SubscriptionRoot'; + /** + * This endpoint is used to received delivered certificates. + * It uses a transient stream, which is a stream that is only valid for the current connection. + * + * Closing the connection will close the stream. + * Starting a new connection will start a new stream and the client will not receive + * any certificates that were delivered before the connection was started. + */ + watchDeliveredCertificates: Certificate; +}; + + +export type SubscriptionRootWatchDeliveredCertificatesArgs = { + filter?: InputMaybe; +}; + export type CertificateQueryVariables = Exact<{ certificateId: CertificateId; }>; -export type CertificateQuery = { __typename?: 'QueryRoot', certificate: { __typename?: 'Certificate', prevId: string, id: string, proof: string, signature: string, sourceSubnetId: string, stateRoot: string, receiptsRootHash: string, txRootHash: string, verifier: number, targetSubnets: Array<{ __typename?: 'SubnetId', value: string }> } }; +export type CertificateQuery = { __typename?: 'QueryRoot', certificate: { __typename?: 'Certificate', prevId: string, id: string, proof: string, signature: string, stateRoot: string, receiptsRootHash: string, txRootHash: string, verifier: number, sourceSubnetId: { __typename?: 'SubnetId', value: string }, targetSubnets: Array<{ __typename?: 'SubnetId', value: string }> } }; export type CertificatesQueryVariables = Exact<{ fromSourceCheckpoint: SourceCheckpoint; @@ -85,8 +108,8 @@ export type CertificatesQueryVariables = Exact<{ }>; -export type CertificatesQuery = { __typename?: 'QueryRoot', certificates: Array<{ __typename?: 'Certificate', prevId: string, id: string, proof: string, signature: string, sourceSubnetId: string, stateRoot: string, receiptsRootHash: string, txRootHash: string, verifier: number, targetSubnets: Array<{ __typename?: 'SubnetId', value: string }> }> }; +export type CertificatesQuery = { __typename?: 'QueryRoot', certificates: Array<{ __typename?: 'Certificate', prevId: string, id: string, proof: string, signature: string, stateRoot: string, receiptsRootHash: string, txRootHash: string, verifier: number, sourceSubnetId: { __typename?: 'SubnetId', value: string }, targetSubnets: Array<{ __typename?: 'SubnetId', value: string }> }> }; -export const CertificateDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"Certificate"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"certificateId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"CertificateId"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"certificate"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"certificateId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"certificateId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"prevId"}},{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"proof"}},{"kind":"Field","name":{"kind":"Name","value":"signature"}},{"kind":"Field","name":{"kind":"Name","value":"sourceSubnetId"}},{"kind":"Field","name":{"kind":"Name","value":"stateRoot"}},{"kind":"Field","name":{"kind":"Name","value":"targetSubnets"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"value"}}]}},{"kind":"Field","name":{"kind":"Name","value":"receiptsRootHash"}},{"kind":"Field","name":{"kind":"Name","value":"txRootHash"}},{"kind":"Field","name":{"kind":"Name","value":"verifier"}}]}}]}}]} as unknown as DocumentNode; -export const CertificatesDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"Certificates"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"fromSourceCheckpoint"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"SourceCheckpoint"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"limit"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"certificates"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"fromSourceCheckpoint"},"value":{"kind":"Variable","name":{"kind":"Name","value":"fromSourceCheckpoint"}}},{"kind":"Argument","name":{"kind":"Name","value":"first"},"value":{"kind":"Variable","name":{"kind":"Name","value":"limit"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"prevId"}},{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"proof"}},{"kind":"Field","name":{"kind":"Name","value":"signature"}},{"kind":"Field","name":{"kind":"Name","value":"sourceSubnetId"}},{"kind":"Field","name":{"kind":"Name","value":"stateRoot"}},{"kind":"Field","name":{"kind":"Name","value":"targetSubnets"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"value"}}]}},{"kind":"Field","name":{"kind":"Name","value":"receiptsRootHash"}},{"kind":"Field","name":{"kind":"Name","value":"txRootHash"}},{"kind":"Field","name":{"kind":"Name","value":"verifier"}}]}}]}}]} as unknown as DocumentNode; \ No newline at end of file +export const CertificateDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"Certificate"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"certificateId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"CertificateId"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"certificate"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"certificateId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"certificateId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"prevId"}},{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"proof"}},{"kind":"Field","name":{"kind":"Name","value":"signature"}},{"kind":"Field","name":{"kind":"Name","value":"sourceSubnetId"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"value"}}]}},{"kind":"Field","name":{"kind":"Name","value":"stateRoot"}},{"kind":"Field","name":{"kind":"Name","value":"targetSubnets"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"value"}}]}},{"kind":"Field","name":{"kind":"Name","value":"receiptsRootHash"}},{"kind":"Field","name":{"kind":"Name","value":"txRootHash"}},{"kind":"Field","name":{"kind":"Name","value":"verifier"}}]}}]}}]} as unknown as DocumentNode; +export const CertificatesDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"Certificates"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"fromSourceCheckpoint"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"SourceCheckpoint"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"limit"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"certificates"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"fromSourceCheckpoint"},"value":{"kind":"Variable","name":{"kind":"Name","value":"fromSourceCheckpoint"}}},{"kind":"Argument","name":{"kind":"Name","value":"first"},"value":{"kind":"Variable","name":{"kind":"Name","value":"limit"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"prevId"}},{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"proof"}},{"kind":"Field","name":{"kind":"Name","value":"signature"}},{"kind":"Field","name":{"kind":"Name","value":"sourceSubnetId"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"value"}}]}},{"kind":"Field","name":{"kind":"Name","value":"stateRoot"}},{"kind":"Field","name":{"kind":"Name","value":"targetSubnets"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"value"}}]}},{"kind":"Field","name":{"kind":"Name","value":"receiptsRootHash"}},{"kind":"Field","name":{"kind":"Name","value":"txRootHash"}},{"kind":"Field","name":{"kind":"Name","value":"verifier"}}]}}]}}]} as unknown as DocumentNode; \ No newline at end of file diff --git a/src/hooks/useSubnetGetCertificateById.tsx b/src/hooks/useSubnetGetCertificateById.tsx index 706b10f..a66723f 100644 --- a/src/hooks/useSubnetGetCertificateById.tsx +++ b/src/hooks/useSubnetGetCertificateById.tsx @@ -14,7 +14,9 @@ const GET_CERTIFICATE = graphql(` id proof signature - sourceSubnetId + sourceSubnetId { + value + } stateRoot targetSubnets { value @@ -51,7 +53,7 @@ export default function useSubnetGetCertificateById({ if (data) { if ( !data?.certificate || - (data.certificate.sourceSubnetId !== selectedSubnet?.id && + (data.certificate.sourceSubnetId.value !== selectedSubnet?.id && selectedSubnet) ) { setErrors((e) => [ diff --git a/src/hooks/useSubnetGetCertificates.tsx b/src/hooks/useSubnetGetCertificates.tsx index 113a103..19f4fe3 100644 --- a/src/hooks/useSubnetGetCertificates.tsx +++ b/src/hooks/useSubnetGetCertificates.tsx @@ -14,7 +14,9 @@ const GET_CERTIFICATES = graphql(` id proof signature - sourceSubnetId + sourceSubnetId { + value + } stateRoot targetSubnets { value diff --git a/src/hooks/useSubnetSubscribeToCertificates.tsx b/src/hooks/useSubnetSubscribeToCertificates.tsx index 4961b3d..4cb2d23 100644 --- a/src/hooks/useSubnetSubscribeToCertificates.tsx +++ b/src/hooks/useSubnetSubscribeToCertificates.tsx @@ -15,7 +15,9 @@ const GET_CERTIFICATES = graphql(` id proof signature - sourceSubnetId + sourceSubnetId { + value + } stateRoot targetSubnets { value @@ -123,13 +125,18 @@ export default function useSubnetSubscribeToCertificates({ const newCertificates: Certificate[] = [] data.certificates.forEach((certificate) => { - const currentIndex = newCurrentIndexes.get(certificate.sourceSubnetId) + const currentIndex = newCurrentIndexes.get( + certificate.sourceSubnetId.value + ) if (currentIndex !== undefined) { - newCurrentIndexes.set(certificate.sourceSubnetId, currentIndex + 1) + newCurrentIndexes.set( + certificate.sourceSubnetId.value, + currentIndex + 1 + ) const sourcePosition = storedPositions.get( - certificate.sourceSubnetId + certificate.sourceSubnetId.value ) newCertificates.push({ ...certificate, @@ -146,6 +153,7 @@ export default function useSubnetSubscribeToCertificates({ }, [data?.certificates] ) + console.log(certificates) return { certificates, error, loading } } From 879ddf315e5f9f06e4b2ae7c5cefe06c32c1e2dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Dan?= Date: Mon, 27 Nov 2023 12:09:27 +0100 Subject: [PATCH 2/2] ci: add missing build workflow --- .github/workflows/build.yml | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..90d2b7d --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,37 @@ +name: Run build + +on: + pull_request: + branches: + - main + +jobs: + build: + name: Build + runs-on: ubuntu-latest-16-core + strategy: + matrix: + environment: [devnet-1, testnet-1] + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Set up NodeJS + uses: actions/setup-node@v3 + with: + node-version: 18 + cache: 'npm' + + - name: Install npm packages + run: npm ci + + - name: Run build + run: npm run build + env: + VITE_ERC20_MESSAGING_CONTRACT_ADDRESS: ${{ vars.ERC20_MESSAGING_CONTRACT_ADDRESS }} + VITE_SUBNET_REGISTRATOR_CONTRACT_ADDRESS: ${{ vars.SUBNET_REGISTRATOR_CONTRACT_ADDRESS }} + VITE_TOPOS_CORE_PROXY_CONTRACT_ADDRESS: ${{ vars.TOPOS_CORE_PROXY_CONTRACT_ADDRESS }} + VITE_TOPOS_SUBNET_ENDPOINT_REMOTE_DEFAULT: ${{ vars.TOPOS_SUBNET_ENDPOINT_REMOTE_DEFAULT }} + VITE_TOPOS_SUBNET_ENDPOINT_CUSTOM_DEFAULT: ${{ vars.TOPOS_SUBNET_ENDPOINT_CUSTOM_DEFAULT }} + VITE_TCE_ENDPOINT_REMOTE_DEFAULT: ${{ vars.TCE_ENDPOINT_REMOTE_DEFAULT }} + VITE_TCE_ENDPOINT_CUSTOM_DEFAULT: ${{ vars.TCE_ENDPOINT_CUSTOM_DEFAULT }}