mirror of
https://github.com/cerc-io/watcher-ts
synced 2025-01-09 04:48:05 +00:00
Get block size using JSON RPC API from ipld-eth-server (#68)
This commit is contained in:
parent
86dcee12f7
commit
c75be57146
@ -48,7 +48,7 @@ const main = async (): Promise<void> => {
|
|||||||
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
||||||
await graphDb.init();
|
await graphDb.init();
|
||||||
|
|
||||||
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, config.server.subgraphPath);
|
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server.subgraphPath);
|
||||||
|
|
||||||
const indexer = new Indexer(config.server, db, ethClient, postgraphileClient, ethProvider, graphWatcher);
|
const indexer = new Indexer(config.server, db, ethClient, postgraphileClient, ethProvider, graphWatcher);
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ const main = async (): Promise<void> => {
|
|||||||
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
||||||
await graphDb.init();
|
await graphDb.init();
|
||||||
|
|
||||||
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, config.server.subgraphPath);
|
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server.subgraphPath);
|
||||||
|
|
||||||
const indexer = new Indexer(config.server, db, ethClient, postgraphileClient, ethProvider, graphWatcher);
|
const indexer = new Indexer(config.server, db, ethClient, postgraphileClient, ethProvider, graphWatcher);
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ export const main = async (): Promise<any> => {
|
|||||||
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
||||||
await graphDb.init();
|
await graphDb.init();
|
||||||
|
|
||||||
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, config.server.subgraphPath);
|
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server.subgraphPath);
|
||||||
|
|
||||||
// Note: In-memory pubsub works fine for now, as each watcher is a single process anyway.
|
// Note: In-memory pubsub works fine for now, as each watcher is a single process anyway.
|
||||||
// Later: https://www.apollographql.com/docs/apollo-server/data/subscriptions/#production-pubsub-libraries
|
// Later: https://www.apollographql.com/docs/apollo-server/data/subscriptions/#production-pubsub-libraries
|
||||||
|
@ -50,7 +50,7 @@ export const main = async (): Promise<any> => {
|
|||||||
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
||||||
await graphDb.init();
|
await graphDb.init();
|
||||||
|
|
||||||
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, config.server.subgraphPath);
|
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server.subgraphPath);
|
||||||
|
|
||||||
// Note: In-memory pubsub works fine for now, as each watcher is a single process anyway.
|
// Note: In-memory pubsub works fine for now, as each watcher is a single process anyway.
|
||||||
// Later: https://www.apollographql.com/docs/apollo-server/data/subscriptions/#production-pubsub-libraries
|
// Later: https://www.apollographql.com/docs/apollo-server/data/subscriptions/#production-pubsub-libraries
|
||||||
|
@ -46,7 +46,7 @@ const main = async (): Promise<void> => {
|
|||||||
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
||||||
await graphDb.init();
|
await graphDb.init();
|
||||||
|
|
||||||
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, config.server.subgraphPath);
|
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server.subgraphPath);
|
||||||
|
|
||||||
const indexer = new Indexer(config.server, db, ethClient, postgraphileClient, ethProvider, graphWatcher);
|
const indexer = new Indexer(config.server, db, ethClient, postgraphileClient, ethProvider, graphWatcher);
|
||||||
|
|
||||||
|
@ -133,7 +133,7 @@ export const main = async (): Promise<any> => {
|
|||||||
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
||||||
await graphDb.init();
|
await graphDb.init();
|
||||||
|
|
||||||
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, config.server.subgraphPath);
|
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server.subgraphPath);
|
||||||
|
|
||||||
const indexer = new Indexer(config.server, db, ethClient, postgraphileClient, ethProvider, graphWatcher);
|
const indexer = new Indexer(config.server, db, ethClient, postgraphileClient, ethProvider, graphWatcher);
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ export const handler = async (argv: any): Promise<void> => {
|
|||||||
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
||||||
await graphDb.init();
|
await graphDb.init();
|
||||||
|
|
||||||
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, config.server.subgraphPath);
|
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server.subgraphPath);
|
||||||
|
|
||||||
const indexer = new Indexer(config.server, db, ethClient, postgraphileClient, ethProvider, graphWatcher);
|
const indexer = new Indexer(config.server, db, ethClient, postgraphileClient, ethProvider, graphWatcher);
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ export const main = async (): Promise<any> => {
|
|||||||
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
||||||
await graphDb.init();
|
await graphDb.init();
|
||||||
|
|
||||||
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, config.server.subgraphPath);
|
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server.subgraphPath);
|
||||||
|
|
||||||
// Note: In-memory pubsub works fine for now, as each watcher is a single process anyway.
|
// Note: In-memory pubsub works fine for now, as each watcher is a single process anyway.
|
||||||
// Later: https://www.apollographql.com/docs/apollo-server/data/subscriptions/#production-pubsub-libraries
|
// Later: https://www.apollographql.com/docs/apollo-server/data/subscriptions/#production-pubsub-libraries
|
||||||
|
@ -60,7 +60,7 @@ const main = async (): Promise<void> => {
|
|||||||
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
||||||
await graphDb.init();
|
await graphDb.init();
|
||||||
|
|
||||||
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, config.server.subgraphPath);
|
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server.subgraphPath);
|
||||||
|
|
||||||
const indexer = new Indexer(config.server, db, ethClient, postgraphileClient, ethProvider, graphWatcher);
|
const indexer = new Indexer(config.server, db, ethClient, postgraphileClient, ethProvider, graphWatcher);
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ const main = async (): Promise<void> => {
|
|||||||
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
||||||
await graphDb.init();
|
await graphDb.init();
|
||||||
|
|
||||||
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, config.server.subgraphPath);
|
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server.subgraphPath);
|
||||||
|
|
||||||
const jobQueueConfig = config.jobQueue;
|
const jobQueueConfig = config.jobQueue;
|
||||||
assert(jobQueueConfig, 'Missing job queue config');
|
assert(jobQueueConfig, 'Missing job queue config');
|
||||||
|
@ -46,7 +46,7 @@ const main = async (): Promise<void> => {
|
|||||||
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
||||||
await graphDb.init();
|
await graphDb.init();
|
||||||
|
|
||||||
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, config.server.subgraphPath);
|
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server.subgraphPath);
|
||||||
|
|
||||||
const jobQueueConfig = config.jobQueue;
|
const jobQueueConfig = config.jobQueue;
|
||||||
assert(jobQueueConfig, 'Missing job queue config');
|
assert(jobQueueConfig, 'Missing job queue config');
|
||||||
|
@ -50,7 +50,7 @@ export const main = async (): Promise<any> => {
|
|||||||
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
||||||
await graphDb.init();
|
await graphDb.init();
|
||||||
|
|
||||||
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, config.server.subgraphPath);
|
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server.subgraphPath);
|
||||||
|
|
||||||
// Note: In-memory pubsub works fine for now, as each watcher is a single process anyway.
|
// Note: In-memory pubsub works fine for now, as each watcher is a single process anyway.
|
||||||
// Later: https://www.apollographql.com/docs/apollo-server/data/subscriptions/#production-pubsub-libraries
|
// Later: https://www.apollographql.com/docs/apollo-server/data/subscriptions/#production-pubsub-libraries
|
||||||
|
@ -46,7 +46,7 @@ const main = async (): Promise<void> => {
|
|||||||
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
||||||
await graphDb.init();
|
await graphDb.init();
|
||||||
|
|
||||||
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, config.server.subgraphPath);
|
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server.subgraphPath);
|
||||||
|
|
||||||
const jobQueueConfig = config.jobQueue;
|
const jobQueueConfig = config.jobQueue;
|
||||||
assert(jobQueueConfig, 'Missing job queue config');
|
assert(jobQueueConfig, 'Missing job queue config');
|
||||||
|
@ -56,7 +56,7 @@ export const handler = async (argv: any): Promise<void> => {
|
|||||||
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
||||||
await graphDb.init();
|
await graphDb.init();
|
||||||
|
|
||||||
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, config.server.subgraphPath);
|
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server.subgraphPath);
|
||||||
|
|
||||||
const jobQueueConfig = config.jobQueue;
|
const jobQueueConfig = config.jobQueue;
|
||||||
assert(jobQueueConfig, 'Missing job queue config');
|
assert(jobQueueConfig, 'Missing job queue config');
|
||||||
|
@ -62,7 +62,7 @@ const main = async (): Promise<void> => {
|
|||||||
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
||||||
await graphDb.init();
|
await graphDb.init();
|
||||||
|
|
||||||
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, config.server.subgraphPath);
|
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server.subgraphPath);
|
||||||
|
|
||||||
const jobQueueConfig = config.jobQueue;
|
const jobQueueConfig = config.jobQueue;
|
||||||
assert(jobQueueConfig, 'Missing job queue config');
|
assert(jobQueueConfig, 'Missing job queue config');
|
||||||
|
@ -51,7 +51,7 @@ export const main = async (): Promise<any> => {
|
|||||||
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
||||||
await graphDb.init();
|
await graphDb.init();
|
||||||
|
|
||||||
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, config.server.subgraphPath);
|
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server.subgraphPath);
|
||||||
|
|
||||||
const jobQueueConfig = config.jobQueue;
|
const jobQueueConfig = config.jobQueue;
|
||||||
assert(jobQueueConfig, 'Missing job queue config');
|
assert(jobQueueConfig, 'Missing job queue config');
|
||||||
|
@ -130,7 +130,7 @@ export const main = async (): Promise<any> => {
|
|||||||
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
||||||
await graphDb.init();
|
await graphDb.init();
|
||||||
|
|
||||||
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, config.server.subgraphPath);
|
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server.subgraphPath);
|
||||||
|
|
||||||
const jobQueueConfig = config.jobQueue;
|
const jobQueueConfig = config.jobQueue;
|
||||||
assert(jobQueueConfig, 'Missing job queue config');
|
assert(jobQueueConfig, 'Missing job queue config');
|
||||||
|
@ -46,7 +46,7 @@ export const main = async (): Promise<any> => {
|
|||||||
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
||||||
await graphDb.init();
|
await graphDb.init();
|
||||||
|
|
||||||
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, config.server.subgraphPath);
|
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server.subgraphPath);
|
||||||
|
|
||||||
// Note: In-memory pubsub works fine for now, as each watcher is a single process anyway.
|
// Note: In-memory pubsub works fine for now, as each watcher is a single process anyway.
|
||||||
// Later: https://www.apollographql.com/docs/apollo-server/data/subscriptions/#production-pubsub-libraries
|
// Later: https://www.apollographql.com/docs/apollo-server/data/subscriptions/#production-pubsub-libraries
|
||||||
|
@ -39,6 +39,7 @@ export interface Block {
|
|||||||
gasLimit: string;
|
gasLimit: string;
|
||||||
gasUsed: string;
|
gasUsed: string;
|
||||||
author: string;
|
author: string;
|
||||||
|
size: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface EventData {
|
export interface EventData {
|
||||||
@ -333,7 +334,7 @@ export const createBlock = async (instanceExports: any, blockData: Block): Promi
|
|||||||
const authorStringPtr = await __newString(blockData.author);
|
const authorStringPtr = await __newString(blockData.author);
|
||||||
const authorPtr = await Address.fromString(authorStringPtr);
|
const authorPtr = await Address.fromString(authorStringPtr);
|
||||||
|
|
||||||
const sizePtr = await __newString('0');
|
const sizePtr = await __newString(blockData.size);
|
||||||
const size = await BigInt.fromString(sizePtr);
|
const size = await BigInt.fromString(sizePtr);
|
||||||
|
|
||||||
// Missing fields from watcher in block data:
|
// Missing fields from watcher in block data:
|
||||||
|
@ -7,7 +7,7 @@ import 'reflect-metadata';
|
|||||||
import debug from 'debug';
|
import debug from 'debug';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import { ContractInterface, utils } from 'ethers';
|
import { ContractInterface, utils, providers } from 'ethers';
|
||||||
|
|
||||||
import { ResultObject } from '@vulcanize/assemblyscript/lib/loader';
|
import { ResultObject } from '@vulcanize/assemblyscript/lib/loader';
|
||||||
import { EthClient } from '@vulcanize/ipld-eth-client';
|
import { EthClient } from '@vulcanize/ipld-eth-client';
|
||||||
@ -28,6 +28,7 @@ export class GraphWatcher {
|
|||||||
_database: Database;
|
_database: Database;
|
||||||
_indexer?: IndexerInterface;
|
_indexer?: IndexerInterface;
|
||||||
_postgraphileClient: EthClient;
|
_postgraphileClient: EthClient;
|
||||||
|
_ethProvider: providers.BaseProvider;
|
||||||
_subgraphPath: string;
|
_subgraphPath: string;
|
||||||
_dataSources: any[] = [];
|
_dataSources: any[] = [];
|
||||||
_dataSourceMap: { [key: string]: DataSource } = {};
|
_dataSourceMap: { [key: string]: DataSource } = {};
|
||||||
@ -36,9 +37,10 @@ export class GraphWatcher {
|
|||||||
event: {}
|
event: {}
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor (database: Database, postgraphileClient: EthClient, subgraphPath: string) {
|
constructor (database: Database, postgraphileClient: EthClient, ethProvider: providers.BaseProvider, subgraphPath: string) {
|
||||||
this._database = database;
|
this._database = database;
|
||||||
this._postgraphileClient = postgraphileClient;
|
this._postgraphileClient = postgraphileClient;
|
||||||
|
this._ethProvider = ethProvider;
|
||||||
this._subgraphPath = subgraphPath;
|
this._subgraphPath = subgraphPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +111,7 @@ export class GraphWatcher {
|
|||||||
const { contract, event, eventSignature, block, tx, eventIndex } = eventData;
|
const { contract, event, eventSignature, block, tx, eventIndex } = eventData;
|
||||||
|
|
||||||
// TODO: Use blockData fetched in handleBlock.
|
// TODO: Use blockData fetched in handleBlock.
|
||||||
const blockData = await getFullBlock(this._postgraphileClient, block.hash);
|
const blockData = await getFullBlock(this._postgraphileClient, this._ethProvider, block.hash);
|
||||||
|
|
||||||
this._context.event.block = blockData;
|
this._context.event.block = blockData;
|
||||||
|
|
||||||
@ -148,7 +150,7 @@ export class GraphWatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async handleBlock (blockHash: string) {
|
async handleBlock (blockHash: string) {
|
||||||
const blockData = await getFullBlock(this._postgraphileClient, blockHash);
|
const blockData = await getFullBlock(this._postgraphileClient, this._ethProvider, blockHash);
|
||||||
|
|
||||||
this._context.event.block = blockData;
|
this._context.event.block = blockData;
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ const main = async (): Promise<void> => {
|
|||||||
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
||||||
await graphDb.init();
|
await graphDb.init();
|
||||||
|
|
||||||
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, config.server.subgraphPath);
|
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server.subgraphPath);
|
||||||
|
|
||||||
const jobQueueConfig = config.jobQueue;
|
const jobQueueConfig = config.jobQueue;
|
||||||
assert(jobQueueConfig, 'Missing job queue config');
|
assert(jobQueueConfig, 'Missing job queue config');
|
||||||
|
@ -46,7 +46,7 @@ const main = async (): Promise<void> => {
|
|||||||
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
||||||
await graphDb.init();
|
await graphDb.init();
|
||||||
|
|
||||||
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, config.server.subgraphPath);
|
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server.subgraphPath);
|
||||||
|
|
||||||
const jobQueueConfig = config.jobQueue;
|
const jobQueueConfig = config.jobQueue;
|
||||||
assert(jobQueueConfig, 'Missing job queue config');
|
assert(jobQueueConfig, 'Missing job queue config');
|
||||||
|
@ -50,7 +50,7 @@ export const main = async (): Promise<any> => {
|
|||||||
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
||||||
await graphDb.init();
|
await graphDb.init();
|
||||||
|
|
||||||
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, config.server.subgraphPath);
|
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server.subgraphPath);
|
||||||
|
|
||||||
// Note: In-memory pubsub works fine for now, as each watcher is a single process anyway.
|
// Note: In-memory pubsub works fine for now, as each watcher is a single process anyway.
|
||||||
// Later: https://www.apollographql.com/docs/apollo-server/data/subscriptions/#production-pubsub-libraries
|
// Later: https://www.apollographql.com/docs/apollo-server/data/subscriptions/#production-pubsub-libraries
|
||||||
|
@ -46,7 +46,7 @@ const main = async (): Promise<void> => {
|
|||||||
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
||||||
await graphDb.init();
|
await graphDb.init();
|
||||||
|
|
||||||
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, config.server.subgraphPath);
|
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server.subgraphPath);
|
||||||
|
|
||||||
const jobQueueConfig = config.jobQueue;
|
const jobQueueConfig = config.jobQueue;
|
||||||
assert(jobQueueConfig, 'Missing job queue config');
|
assert(jobQueueConfig, 'Missing job queue config');
|
||||||
|
@ -44,7 +44,7 @@ export const handler = async (argv: any): Promise<void> => {
|
|||||||
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
||||||
await graphDb.init();
|
await graphDb.init();
|
||||||
|
|
||||||
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, config.server.subgraphPath);
|
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server.subgraphPath);
|
||||||
|
|
||||||
const jobQueueConfig = config.jobQueue;
|
const jobQueueConfig = config.jobQueue;
|
||||||
assert(jobQueueConfig, 'Missing job queue config');
|
assert(jobQueueConfig, 'Missing job queue config');
|
||||||
|
@ -62,7 +62,7 @@ const main = async (): Promise<void> => {
|
|||||||
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
||||||
await graphDb.init();
|
await graphDb.init();
|
||||||
|
|
||||||
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, config.server.subgraphPath);
|
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server.subgraphPath);
|
||||||
|
|
||||||
const jobQueueConfig = config.jobQueue;
|
const jobQueueConfig = config.jobQueue;
|
||||||
assert(jobQueueConfig, 'Missing job queue config');
|
assert(jobQueueConfig, 'Missing job queue config');
|
||||||
|
@ -51,7 +51,7 @@ export const main = async (): Promise<any> => {
|
|||||||
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
||||||
await graphDb.init();
|
await graphDb.init();
|
||||||
|
|
||||||
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, config.server.subgraphPath);
|
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server.subgraphPath);
|
||||||
|
|
||||||
const jobQueueConfig = config.jobQueue;
|
const jobQueueConfig = config.jobQueue;
|
||||||
assert(jobQueueConfig, 'Missing job queue config');
|
assert(jobQueueConfig, 'Missing job queue config');
|
||||||
|
@ -130,7 +130,7 @@ export const main = async (): Promise<any> => {
|
|||||||
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
||||||
await graphDb.init();
|
await graphDb.init();
|
||||||
|
|
||||||
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, config.server.subgraphPath);
|
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server.subgraphPath);
|
||||||
|
|
||||||
const jobQueueConfig = config.jobQueue;
|
const jobQueueConfig = config.jobQueue;
|
||||||
assert(jobQueueConfig, 'Missing job queue config');
|
assert(jobQueueConfig, 'Missing job queue config');
|
||||||
|
@ -46,7 +46,7 @@ export const main = async (): Promise<any> => {
|
|||||||
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
||||||
await graphDb.init();
|
await graphDb.init();
|
||||||
|
|
||||||
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, config.server.subgraphPath);
|
const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server.subgraphPath);
|
||||||
|
|
||||||
// Note: In-memory pubsub works fine for now, as each watcher is a single process anyway.
|
// Note: In-memory pubsub works fine for now, as each watcher is a single process anyway.
|
||||||
// Later: https://www.apollographql.com/docs/apollo-server/data/subscriptions/#production-pubsub-libraries
|
// Later: https://www.apollographql.com/docs/apollo-server/data/subscriptions/#production-pubsub-libraries
|
||||||
|
@ -173,7 +173,7 @@ class CustomFormatter extends providers.Formatter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getFullBlock = async (ethClient: EthClient, blockHash: string): Promise<any> => {
|
export const getFullBlock = async (ethClient: EthClient, ethProvider: providers.BaseProvider, blockHash: string): Promise<any> => {
|
||||||
const {
|
const {
|
||||||
allEthHeaderCids: {
|
allEthHeaderCids: {
|
||||||
nodes: [
|
nodes: [
|
||||||
@ -188,8 +188,11 @@ export const getFullBlock = async (ethClient: EthClient, blockHash: string): Pro
|
|||||||
const header = EthDecoder.decodeHeader(EthDecoder.decodeData(fullBlock.blockByMhKey.data));
|
const header = EthDecoder.decodeHeader(EthDecoder.decodeData(fullBlock.blockByMhKey.data));
|
||||||
assert(header);
|
assert(header);
|
||||||
|
|
||||||
// TODO:
|
// TODO: Calculate size from rlp encoded data provided by postgraphile.
|
||||||
// 1. Calculate size
|
// Get block info from JSON RPC API provided by ipld-eth-server.
|
||||||
|
const provider = ethProvider as providers.JsonRpcProvider;
|
||||||
|
const { size } = await provider.send('eth_getBlockByHash', [blockHash, false]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
cid: fullBlock.cid,
|
cid: fullBlock.cid,
|
||||||
blockNumber: fullBlock.blockNumber,
|
blockNumber: fullBlock.blockNumber,
|
||||||
@ -204,6 +207,7 @@ export const getFullBlock = async (ethClient: EthClient, blockHash: string): Pro
|
|||||||
difficulty: header.Difficulty.toString(),
|
difficulty: header.Difficulty.toString(),
|
||||||
gasLimit: header.GasLimit.toString(),
|
gasLimit: header.GasLimit.toString(),
|
||||||
gasUsed: header.GasUsed.toString(),
|
gasUsed: header.GasUsed.toString(),
|
||||||
author: header.Beneficiary
|
author: header.Beneficiary,
|
||||||
|
size: BigInt(size).toString()
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user