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
Show file tree
Hide file tree
Changes from all commits
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
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:
Expand Down
8 changes: 4 additions & 4 deletions packages/azimuth-watcher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@
"dependencies": {
"@apollo/client": "^3.3.19",
"@ethersproject/providers": "^5.4.4",
"@cerc-io/cli": "^0.2.39",
"@cerc-io/ipld-eth-client": "^0.2.39",
"@cerc-io/solidity-mapper": "^0.2.39",
"@cerc-io/util": "^0.2.39",
"@cerc-io/cli": "^0.2.40",
"@cerc-io/ipld-eth-client": "^0.2.40",
"@cerc-io/solidity-mapper": "^0.2.40",
"@cerc-io/util": "^0.2.40",
"apollo-type-bigint": "^0.1.3",
"debug": "^4.3.1",
"ethers": "^5.4.4",
Expand Down
9 changes: 9 additions & 0 deletions packages/azimuth-watcher/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
19 changes: 18 additions & 1 deletion packages/azimuth-watcher/src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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 });
Expand Down Expand Up @@ -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');
Expand Down
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
Expand Up @@ -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');
Expand Down
Loading