Generate watcher with deployed DelegatedSending contract (#15)

This commit is contained in:
Nabarun Gogoi 2023-04-27 10:04:15 +05:30 committed by GitHub
parent 787965737d
commit 0bce143a00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 37 additions and 491 deletions

View File

@ -1,16 +1,6 @@
# delegated-sending-watcher
## Currently unsupported queries
The watcher was generated in `eth_call` mode and does not support the following queries in its current state:
* `getPoolStars(uint32 _who) returns (uint16[] stars)`
* `getInviters() returns (uint32[] invs)`
* `getInvited(uint32 _who) returns (uint32[] invd)`
* `getPool(uint32 _point) returns (uint32 pool)`
This watcher has been generated based on the `DelegatedSending` contract deployed at [0xf6b461fe1ad4bd2ce25b23fe0aff2ac19b3dfa76](https://etherscan.io/address/0xf6b461fe1ad4bd2ce25b23fe0aff2ac19b3dfa76#code#L1)
## Setup

View File

@ -1,101 +1,17 @@
{
"abi": [
{
"constant": true,
"inputs": [],
"name": "getInviters",
"outputs": [
{
"name": "invs",
"type": "uint32[]"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"constant": false,
"inputs": [
{
"name": "",
"name": "_for",
"type": "uint32"
}
],
"name": "isInviter",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"name": "resetPool",
"outputs": [],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "",
"type": "uint32"
},
{
"name": "",
"type": "uint16"
}
],
"name": "poolStarsRegistered",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "",
"type": "uint32"
}
],
"name": "invitedBy",
"outputs": [
{
"name": "",
"type": "uint32"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "",
"type": "uint32"
},
{
"name": "",
"type": "uint16"
}
],
"name": "pools",
"outputs": [
{
"name": "",
"type": "uint16"
}
],
"payable": false,
"stateMutability": "view",
"stateMutability": "nonpayable",
"type": "function"
},
{
@ -132,7 +48,7 @@
"outputs": [
{
"name": "",
"type": "uint32"
"type": "uint64"
}
],
"payable": false,
@ -167,33 +83,10 @@
"inputs": [
{
"name": "",
"type": "uint256"
"type": "uint64"
}
],
"name": "inviters",
"outputs": [
{
"name": "",
"type": "uint32"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "",
"type": "uint32"
},
{
"name": "",
"type": "uint256"
}
],
"name": "poolStars",
"name": "pools",
"outputs": [
{
"name": "",
@ -228,60 +121,36 @@
"inputs": [
{
"name": "",
"type": "uint32"
"type": "uint16"
}
],
"name": "limits",
"outputs": [
{
"name": "",
"type": "uint16"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_prefix",
"type": "uint16"
},
{
"name": "",
"type": "uint256"
}
],
"name": "invited",
"outputs": [
{
"name": "",
"type": "uint32"
"name": "_limit",
"type": "uint16"
}
],
"name": "configureLimit",
"outputs": [],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "_point",
"type": "uint32"
}
],
"name": "getPool",
"outputs": [
{
"name": "pool",
"type": "uint32"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "_who",
"type": "uint32"
}
],
"name": "getPoolStars",
"outputs": [
{
"name": "stars",
"type": "uint16[]"
}
],
"payable": false,
"stateMutability": "view",
"stateMutability": "nonpayable",
"type": "function"
},
{
@ -298,47 +167,6 @@
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "_who",
"type": "uint32"
}
],
"name": "getInvited",
"outputs": [
{
"name": "invd",
"type": "uint32[]"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_as",
"type": "uint16"
},
{
"name": "_for",
"type": "uint32"
},
{
"name": "_size",
"type": "uint16"
}
],
"name": "setPoolSize",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
@ -350,28 +178,6 @@
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "prefix",
"type": "uint16"
},
{
"indexed": true,
"name": "who",
"type": "uint32"
},
{
"indexed": false,
"name": "size",
"type": "uint16"
}
],
"name": "Pool",
"type": "event"
},
{
"anonymous": false,
"inputs": [
@ -383,7 +189,7 @@
{
"indexed": true,
"name": "fromPool",
"type": "uint32"
"type": "uint64"
},
{
"indexed": false,

View File

@ -26,15 +26,6 @@ export class Client {
return canSend;
}
async getGetPool (blockHash: string, contractAddress: string, _point: bigint): Promise<any> {
const { getPool } = await this._client.query(
gql(queries.getPool),
{ blockHash, contractAddress, _point }
);
return getPool;
}
async getCanReceive (blockHash: string, contractAddress: string, _recipient: string): Promise<any> {
const { canReceive } = await this._client.query(
gql(queries.canReceive),

View File

@ -21,10 +21,9 @@ import { StateSyncStatus } from './entity/StateSyncStatus';
import { BlockProgress } from './entity/BlockProgress';
import { State } from './entity/State';
import { CanSend } from './entity/CanSend';
import { GetPool } from './entity/GetPool';
import { CanReceive } from './entity/CanReceive';
export const ENTITIES = [CanSend, GetPool, CanReceive];
export const ENTITIES = [CanSend, CanReceive];
export class Database implements DatabaseInterface {
_config: ConnectionOptions;
@ -67,15 +66,6 @@ export class Database implements DatabaseInterface {
});
}
async getGetPool ({ blockHash, contractAddress, _point }: { blockHash: string, contractAddress: string, _point: bigint }): Promise<GetPool | undefined> {
return this._conn.getRepository(GetPool)
.findOne({
blockHash,
contractAddress,
_point
});
}
async getCanReceive ({ blockHash, contractAddress, _recipient }: { blockHash: string, contractAddress: string, _recipient: string }): Promise<CanReceive | undefined> {
return this._conn.getRepository(CanReceive)
.findOne({
@ -91,12 +81,6 @@ export class Database implements DatabaseInterface {
return repo.save(entity);
}
async saveGetPool ({ blockHash, blockNumber, contractAddress, _point, value, proof }: DeepPartial<GetPool>): Promise<GetPool> {
const repo = this._conn.getRepository(GetPool);
const entity = repo.create({ blockHash, blockNumber, contractAddress, _point, value, proof });
return repo.save(entity);
}
async saveCanReceive ({ blockHash, blockNumber, contractAddress, _recipient, value, proof }: DeepPartial<CanReceive>): Promise<CanReceive> {
const repo = this._conn.getRepository(CanReceive);
const entity = repo.create({ blockHash, blockNumber, contractAddress, _recipient, value, proof });
@ -309,7 +293,6 @@ export class Database implements DatabaseInterface {
_setPropColMaps (): void {
this._propColMaps.CanSend = this._getPropertyColumnMapForEntity('CanSend');
this._propColMaps.GetPool = this._getPropertyColumnMapForEntity('GetPool');
this._propColMaps.CanReceive = this._getPropertyColumnMapForEntity('CanReceive');
}
}

View File

@ -16,11 +16,6 @@ query events($blockHash: String!, $contractAddress: String!, $name: String){
contract
eventIndex
event{
... on PoolEvent {
prefix
who
size
}
... on SentEvent {
prefix
fromPool

View File

@ -16,11 +16,6 @@ query eventsInRange($fromBlockNumber: Int!, $toBlockNumber: Int!){
contract
eventIndex
event{
... on PoolEvent {
prefix
who
size
}
... on SentEvent {
prefix
fromPool

View File

@ -1,8 +0,0 @@
query getInvited($blockHash: String!, $contractAddress: String!, $_who: BigInt!){
getInvited(blockHash: $blockHash, contractAddress: $contractAddress, _who: $_who){
value
proof{
data
}
}
}

View File

@ -1,8 +0,0 @@
query getInviters($blockHash: String!, $contractAddress: String!){
getInviters(blockHash: $blockHash, contractAddress: $contractAddress){
value
proof{
data
}
}
}

View File

@ -1,8 +0,0 @@
query getPool($blockHash: String!, $contractAddress: String!, $_point: BigInt!){
getPool(blockHash: $blockHash, contractAddress: $contractAddress, _point: $_point){
value
proof{
data
}
}
}

View File

@ -1,8 +0,0 @@
query getPoolStars($blockHash: String!, $contractAddress: String!, $_who: BigInt!){
getPoolStars(blockHash: $blockHash, contractAddress: $contractAddress, _who: $_who){
value
proof{
data
}
}
}

View File

@ -4,11 +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 canSend = fs.readFileSync(path.join(__dirname, 'canSend.gql'), 'utf8');
export const getPool = fs.readFileSync(path.join(__dirname, 'getPool.gql'), 'utf8');
export const canReceive = fs.readFileSync(path.join(__dirname, 'canReceive.gql'), 'utf8');
export const getPoolStars = fs.readFileSync(path.join(__dirname, 'getPoolStars.gql'), 'utf8');
export const getInviters = fs.readFileSync(path.join(__dirname, 'getInviters.gql'), 'utf8');
export const getInvited = fs.readFileSync(path.join(__dirname, 'getInvited.gql'), 'utf8');
export const getSyncStatus = fs.readFileSync(path.join(__dirname, 'getSyncStatus.gql'), 'utf8');
export const getStateByCID = fs.readFileSync(path.join(__dirname, 'getStateByCID.gql'), 'utf8');
export const getState = fs.readFileSync(path.join(__dirname, 'getState.gql'), 'utf8');

View File

@ -16,11 +16,6 @@ subscription onEvent{
contract
eventIndex
event{
... on PoolEvent {
prefix
who
size
}
... on SentEvent {
prefix
fromPool

View File

@ -123,37 +123,6 @@ export class Indexer implements IndexerInterface {
return result;
}
async getPool (blockHash: string, contractAddress: string, _point: bigint): Promise<ValueResult> {
const entity = await this._db.getGetPool({ blockHash, contractAddress, _point });
if (entity) {
log('getPool: db hit.');
return {
value: entity.value,
proof: JSON.parse(entity.proof)
};
}
const { block: { number } } = await this._ethClient.getBlockByHash(blockHash);
const blockNumber = ethers.BigNumber.from(number).toNumber();
log('getPool: db miss, fetching from upstream server');
const abi = this._abiMap.get(KIND_DELEGATEDSENDING);
assert(abi);
const contract = new ethers.Contract(contractAddress, abi, this._ethProvider);
const contractResult = await contract.getPool(_point, { blockTag: blockHash });
const value = ethers.BigNumber.from(contractResult).toBigInt();
const result: ValueResult = { value };
await this._db.saveGetPool({ blockHash, blockNumber, contractAddress, _point, value: result.value, proof: JSONbigNative.stringify(result.proof) });
return result;
}
async canReceive (blockHash: string, contractAddress: string, _recipient: string): Promise<ValueResult> {
const entity = await this._db.getCanReceive({ blockHash, contractAddress, _recipient });
if (entity) {
@ -184,51 +153,6 @@ export class Indexer implements IndexerInterface {
return result;
}
async getPoolStars (blockHash: string, contractAddress: string, _who: bigint): Promise<ValueResult> {
log('getPoolStars: db miss, fetching from upstream server');
const abi = this._abiMap.get(KIND_DELEGATEDSENDING);
assert(abi);
const contract = new ethers.Contract(contractAddress, abi, this._ethProvider);
const contractResult = await contract.getPoolStars(_who, { blockTag: blockHash });
const value = contractResult;
const result: ValueResult = { value };
return result;
}
async getInviters (blockHash: string, contractAddress: string): Promise<ValueResult> {
log('getInviters: db miss, fetching from upstream server');
const abi = this._abiMap.get(KIND_DELEGATEDSENDING);
assert(abi);
const contract = new ethers.Contract(contractAddress, abi, this._ethProvider);
const contractResult = await contract.getInviters({ blockTag: blockHash });
const value = contractResult.map((val: ethers.BigNumber | number) => ethers.BigNumber.from(val).toBigInt());
const result: ValueResult = { value };
return result;
}
async getInvited (blockHash: string, contractAddress: string, _who: bigint): Promise<ValueResult> {
log('getInvited: db miss, fetching from upstream server');
const abi = this._abiMap.get(KIND_DELEGATEDSENDING);
assert(abi);
const contract = new ethers.Contract(contractAddress, abi, this._ethProvider);
const contractResult = await contract.getInvited(_who, { blockTag: blockHash });
const value = contractResult.map((val: ethers.BigNumber | number) => ethers.BigNumber.from(val).toBigInt());
const result: ValueResult = { value };
return result;
}
async getStorageValue (storageLayout: StorageLayout, blockHash: string, contractAddress: string, variable: string, ...mappingKeys: MappingKey[]): Promise<ValueResult> {
return this._baseIndexer.getStorageValue(
storageLayout,

View File

@ -90,24 +90,6 @@ export const createResolvers = async (indexerArg: IndexerInterface, eventWatcher
return indexer.canSend(blockHash, contractAddress, _as, _point);
},
getPool: (
_: 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('getPool', blockHash, contractAddress, _point);
gqlTotalQueryCount.inc(1);
gqlQueryCount.labels('getPool').inc(1);
// Set cache-control hints
// setGQLCacheHints(info, {}, gqlCacheConfig);
return indexer.getPool(blockHash, contractAddress, _point);
},
canReceive: (
_: any,
{ blockHash, contractAddress, _recipient }: { blockHash: string, contractAddress: string, _recipient: string },
@ -126,60 +108,6 @@ export const createResolvers = async (indexerArg: IndexerInterface, eventWatcher
return indexer.canReceive(blockHash, contractAddress, _recipient);
},
getPoolStars: (
_: any,
{ blockHash, contractAddress, _who }: { blockHash: string, contractAddress: string, _who: 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('getPoolStars', blockHash, contractAddress, _who);
gqlTotalQueryCount.inc(1);
gqlQueryCount.labels('getPoolStars').inc(1);
// Set cache-control hints
// setGQLCacheHints(info, {}, gqlCacheConfig);
return indexer.getPoolStars(blockHash, contractAddress, _who);
},
getInviters: (
_: any,
{ blockHash, contractAddress }: { blockHash: string, contractAddress: string },
// eslint-disable-next-line @typescript-eslint/no-unused-vars
__: any,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
info: GraphQLResolveInfo
): Promise<ValueResult> => {
log('getInviters', blockHash, contractAddress);
gqlTotalQueryCount.inc(1);
gqlQueryCount.labels('getInviters').inc(1);
// Set cache-control hints
// setGQLCacheHints(info, {}, gqlCacheConfig);
return indexer.getInviters(blockHash, contractAddress);
},
getInvited: (
_: any,
{ blockHash, contractAddress, _who }: { blockHash: string, contractAddress: string, _who: 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('getInvited', blockHash, contractAddress, _who);
gqlTotalQueryCount.inc(1);
gqlQueryCount.labels('getInvited').inc(1);
// Set cache-control hints
// setGQLCacheHints(info, {}, gqlCacheConfig);
return indexer.getInvited(blockHash, contractAddress, _who);
},
events: async (_: any, { blockHash, contractAddress, name }: { blockHash: string, contractAddress: string, name?: string }) => {
log('events', blockHash, contractAddress, name);
gqlTotalQueryCount.inc(1);

View File

@ -39,13 +39,7 @@ type ResultEvent {
proof: Proof
}
union Event = PoolEvent | SentEvent
type PoolEvent {
prefix: Int!
who: BigInt!
size: Int!
}
union Event = SentEvent
type SentEvent {
prefix: Int!
@ -60,21 +54,6 @@ type ResultBoolean {
proof: Proof
}
type ResultBigInt {
value: BigInt!
proof: Proof
}
type ResultIntArray {
value: [Int!]!
proof: Proof
}
type ResultBigIntArray {
value: [BigInt!]!
proof: Proof
}
type SyncStatus {
latestIndexedBlockHash: String!
latestIndexedBlockNumber: Int!
@ -94,11 +73,7 @@ type Query {
events(blockHash: String!, contractAddress: String!, name: String): [ResultEvent!]
eventsInRange(fromBlockNumber: Int!, toBlockNumber: Int!): [ResultEvent!]
canSend(blockHash: String!, contractAddress: String!, _as: BigInt!, _point: BigInt!): ResultBoolean!
getPool(blockHash: String!, contractAddress: String!, _point: BigInt!): ResultBigInt!
canReceive(blockHash: String!, contractAddress: String!, _recipient: String!): ResultBoolean!
getPoolStars(blockHash: String!, contractAddress: String!, _who: BigInt!): ResultIntArray!
getInviters(blockHash: String!, contractAddress: String!): ResultBigIntArray!
getInvited(blockHash: String!, contractAddress: String!, _who: BigInt!): ResultBigIntArray!
getSyncStatus: SyncStatus
getStateByCID(cid: String!): ResultState
getState(blockHash: String!, contractAddress: String!, kind: String): ResultState