Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement queries for multiple return type eth_calls #12

Merged
merged 4 commits into from
Apr 26, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Generate azimuth watcher from codegen handling multiple return type
nikugogoi committed Apr 25, 2023
commit 81dc3a3c246a1646e977c20848d6963c9e788ac7
Empty file modified packages/azimuth-watcher/.husky/pre-commit
100644 → 100755
Empty file.
6 changes: 0 additions & 6 deletions packages/azimuth-watcher/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
# azimuth-watcher

## Currently unsupported queries

The watcher was generated in `eth_call` mode and does not support the following queries in its current state:

* `getKeys(uint32 _point) returns (bytes32 crypt, bytes32 auth, uint32 suite, uint32 revision)`

## Setup

* Run the following command to install required packages:
9 changes: 9 additions & 0 deletions packages/azimuth-watcher/src/client.ts
Original file line number Diff line number Diff line change
@@ -26,6 +26,15 @@ export class Client {
return isActive;
}

async getGetKeys (blockHash: string, contractAddress: string, _point: bigint): Promise<any> {
const { getKeys } = await this._client.query(
gql(queries.getKeys),
{ blockHash, contractAddress, _point }
);

return getKeys;
}

async getGetKeyRevisionNumber (blockHash: string, contractAddress: string, _point: bigint): Promise<any> {
const { getKeyRevisionNumber } = await this._client.query(
gql(queries.getKeyRevisionNumber),
19 changes: 18 additions & 1 deletion packages/azimuth-watcher/src/database.ts
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ import { StateSyncStatus } from './entity/StateSyncStatus';
import { BlockProgress } from './entity/BlockProgress';
import { State } from './entity/State';
import { IsActive } from './entity/IsActive';
import { GetKeys } from './entity/GetKeys';
import { GetKeyRevisionNumber } from './entity/GetKeyRevisionNumber';
import { HasBeenLinked } from './entity/HasBeenLinked';
import { IsLive } from './entity/IsLive';
@@ -56,7 +57,7 @@ import { CanTransfer } from './entity/CanTransfer';
import { GetTransferringForCount } from './entity/GetTransferringForCount';
import { IsOperator } from './entity/IsOperator';

export const ENTITIES = [IsActive, GetKeyRevisionNumber, HasBeenLinked, IsLive, GetContinuityNumber, GetSpawnCount, HasSponsor, GetSponsor, IsSponsor, GetSponsoringCount, IsEscaping, GetEscapeRequest, IsRequestingEscapeTo, GetEscapeRequestsCount, GetOwner, IsOwner, GetOwnedPointCount, GetOwnedPointAtIndex, GetManagementProxy, IsManagementProxy, CanManage, GetManagerForCount, GetSpawnProxy, IsSpawnProxy, CanSpawnAs, GetSpawningForCount, GetVotingProxy, IsVotingProxy, CanVoteAs, GetVotingForCount, GetTransferProxy, IsTransferProxy, CanTransfer, GetTransferringForCount, IsOperator];
export const ENTITIES = [IsActive, GetKeys, GetKeyRevisionNumber, HasBeenLinked, IsLive, GetContinuityNumber, GetSpawnCount, HasSponsor, GetSponsor, IsSponsor, GetSponsoringCount, IsEscaping, GetEscapeRequest, IsRequestingEscapeTo, GetEscapeRequestsCount, GetOwner, IsOwner, GetOwnedPointCount, GetOwnedPointAtIndex, GetManagementProxy, IsManagementProxy, CanManage, GetManagerForCount, GetSpawnProxy, IsSpawnProxy, CanSpawnAs, GetSpawningForCount, GetVotingProxy, IsVotingProxy, CanVoteAs, GetVotingForCount, GetTransferProxy, IsTransferProxy, CanTransfer, GetTransferringForCount, IsOperator];

export class Database implements DatabaseInterface {
_config: ConnectionOptions;
@@ -98,6 +99,15 @@ export class Database implements DatabaseInterface {
});
}

async getGetKeys ({ blockHash, contractAddress, _point }: { blockHash: string, contractAddress: string, _point: bigint }): Promise<GetKeys | undefined> {
return this._conn.getRepository(GetKeys)
.findOne({
blockHash,
contractAddress,
_point
});
}

async getGetKeyRevisionNumber ({ blockHash, contractAddress, _point }: { blockHash: string, contractAddress: string, _point: bigint }): Promise<GetKeyRevisionNumber | undefined> {
return this._conn.getRepository(GetKeyRevisionNumber)
.findOne({
@@ -423,6 +433,12 @@ export class Database implements DatabaseInterface {
return repo.save(entity);
}

async saveGetKeys ({ blockHash, blockNumber, contractAddress, _point, value, proof }: DeepPartial<GetKeys>): Promise<GetKeys> {
const repo = this._conn.getRepository(GetKeys);
const entity = repo.create({ blockHash, blockNumber, contractAddress, _point, value, proof });
return repo.save(entity);
}

async saveGetKeyRevisionNumber ({ blockHash, blockNumber, contractAddress, _point, value, proof }: DeepPartial<GetKeyRevisionNumber>): Promise<GetKeyRevisionNumber> {
const repo = this._conn.getRepository(GetKeyRevisionNumber);
const entity = repo.create({ blockHash, blockNumber, contractAddress, _point, value, proof });
@@ -833,6 +849,7 @@ export class Database implements DatabaseInterface {

_setPropColMaps (): void {
this._propColMaps.IsActive = this._getPropertyColumnMapForEntity('IsActive');
this._propColMaps.GetKeys = this._getPropertyColumnMapForEntity('GetKeys');
this._propColMaps.GetKeyRevisionNumber = this._getPropertyColumnMapForEntity('GetKeyRevisionNumber');
this._propColMaps.HasBeenLinked = this._getPropertyColumnMapForEntity('HasBeenLinked');
this._propColMaps.IsLive = this._getPropertyColumnMapForEntity('IsLive');
31 changes: 31 additions & 0 deletions packages/azimuth-watcher/src/entity/GetKeys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// Copyright 2021 Vulcanize, Inc.
//

import { Entity, PrimaryGeneratedColumn, Column, Index } from 'typeorm';
import { bigintTransformer } from '@cerc-io/util';

@Entity()
@Index(['blockHash', 'contractAddress', '_point'], { unique: true })
export class GetKeys {
@PrimaryGeneratedColumn()
id!: number;

@Column('varchar', { length: 66 })
blockHash!: string;

@Column('integer')
blockNumber!: number;

@Column('varchar', { length: 42 })
contractAddress!: string;

@Column('numeric', { transformer: bigintTransformer })
_point!: bigint;

@Column('varchar')
value!: string;

@Column('text', { nullable: true })
proof!: string;
}
13 changes: 13 additions & 0 deletions packages/azimuth-watcher/src/gql/queries/getKeys.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
query getKeys($blockHash: String!, $contractAddress: String!, $_point: BigInt!){
getKeys(blockHash: $blockHash, contractAddress: $contractAddress, _point: $_point){
value{
value0
value1
value2
value3
}
proof{
data
}
}
}
1 change: 1 addition & 0 deletions packages/azimuth-watcher/src/gql/queries/index.ts
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ import path from 'path';
export const events = fs.readFileSync(path.join(__dirname, 'events.gql'), 'utf8');
export const eventsInRange = fs.readFileSync(path.join(__dirname, 'eventsInRange.gql'), 'utf8');
export const isActive = fs.readFileSync(path.join(__dirname, 'isActive.gql'), 'utf8');
export const getKeys = fs.readFileSync(path.join(__dirname, 'getKeys.gql'), 'utf8');
export const getKeyRevisionNumber = fs.readFileSync(path.join(__dirname, 'getKeyRevisionNumber.gql'), 'utf8');
export const hasBeenLinked = fs.readFileSync(path.join(__dirname, 'hasBeenLinked.gql'), 'utf8');
export const isLive = fs.readFileSync(path.join(__dirname, 'isLive.gql'), 'utf8');
197 changes: 120 additions & 77 deletions packages/azimuth-watcher/src/indexer.ts

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions packages/azimuth-watcher/src/resolvers.ts
Original file line number Diff line number Diff line change
@@ -90,6 +90,24 @@ export const createResolvers = async (indexerArg: IndexerInterface, eventWatcher
return indexer.isActive(blockHash, contractAddress, _point);
},

getKeys: (
_: any,
{ blockHash, contractAddress, _point }: { blockHash: string, contractAddress: string, _point: bigint },
// eslint-disable-next-line @typescript-eslint/no-unused-vars
__: any,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
info: GraphQLResolveInfo
): Promise<ValueResult> => {
log('getKeys', blockHash, contractAddress, _point);
gqlTotalQueryCount.inc(1);
gqlQueryCount.labels('getKeys').inc(1);

// Set cache-control hints
// setGQLCacheHints(info, {}, gqlCacheConfig);

return indexer.getKeys(blockHash, contractAddress, _point);
},

getKeyRevisionNumber: (
_: any,
{ blockHash, contractAddress, _point }: { blockHash: string, contractAddress: string, _point: bigint },
13 changes: 13 additions & 0 deletions packages/azimuth-watcher/src/schema.gql
Original file line number Diff line number Diff line change
@@ -128,6 +128,18 @@ type ResultBoolean {
proof: Proof
}

type ResultGetKeysType {
value: GetKeysType!
proof: Proof
}

type GetKeysType {
value0: String!
value1: String!
value2: BigInt!
value3: BigInt!
}

type ResultBigInt {
value: BigInt!
proof: Proof
@@ -162,6 +174,7 @@ type Query {
events(blockHash: String!, contractAddress: String!, name: String): [ResultEvent!]
eventsInRange(fromBlockNumber: Int!, toBlockNumber: Int!): [ResultEvent!]
isActive(blockHash: String!, contractAddress: String!, _point: BigInt!): ResultBoolean!
getKeys(blockHash: String!, contractAddress: String!, _point: BigInt!): ResultGetKeysType!
getKeyRevisionNumber(blockHash: String!, contractAddress: String!, _point: BigInt!): ResultBigInt!
hasBeenLinked(blockHash: String!, contractAddress: String!, _point: BigInt!): ResultBoolean!
isLive(blockHash: String!, contractAddress: String!, _point: BigInt!): ResultBoolean!