mirror of
https://github.com/cerc-io/watcher-ts
synced 2026-09-08 16:54:08 +00:00
Implement method for storage based access in subgraph mapping code (#162)
* Implement storage call in subgraph mapping code * Add test for mapping type variable storage call * Use vulcanize graph-ts * Revert to graph-ts version 0.22.1
This commit is contained in:
@@ -4,12 +4,15 @@
|
||||
|
||||
import { BaseProvider } from '@ethersproject/providers';
|
||||
import { getCustomProvider } from '@vulcanize/util';
|
||||
import { EthClient } from '@vulcanize/ipld-eth-client';
|
||||
import { StorageLayout } from '@vulcanize/solidity-mapper';
|
||||
|
||||
import { EventData } from '../../src/utils';
|
||||
import { Database } from '../../src/database';
|
||||
import { Indexer } from './indexer';
|
||||
|
||||
const NETWORK_URL = 'http://127.0.0.1:8081';
|
||||
const IPLD_ETH_SERVER_GQL_URL = 'http://127.0.0.1:8082/graphql';
|
||||
|
||||
export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
|
||||
export const ZERO_HASH = '0x0000000000000000000000000000000000000000000000000000000000000000';
|
||||
@@ -71,8 +74,13 @@ export const getTestDatabase = (): Database => {
|
||||
return new Database({ type: 'postgres' }, '');
|
||||
};
|
||||
|
||||
export const getTestIndexer = (): Indexer => {
|
||||
return new Indexer();
|
||||
export const getTestIndexer = (storageLayout?: Map<string, StorageLayout>): Indexer => {
|
||||
const ethClient = new EthClient({
|
||||
gqlEndpoint: IPLD_ETH_SERVER_GQL_URL,
|
||||
cache: undefined
|
||||
});
|
||||
|
||||
return new Indexer(ethClient, storageLayout);
|
||||
};
|
||||
|
||||
export const getTestProvider = (): BaseProvider => {
|
||||
|
||||
@@ -6,14 +6,43 @@ import {
|
||||
BlockProgressInterface,
|
||||
EventInterface,
|
||||
SyncStatusInterface,
|
||||
ServerConfig as ServerConfigInterface
|
||||
ServerConfig as ServerConfigInterface,
|
||||
ValueResult
|
||||
} from '@vulcanize/util';
|
||||
import { EthClient } from '@vulcanize/ipld-eth-client';
|
||||
import { GetStorageAt, getStorageValue, MappingKey, StorageLayout } from '@vulcanize/solidity-mapper';
|
||||
|
||||
export class Indexer implements IndexerInterface {
|
||||
_getStorageAt: GetStorageAt;
|
||||
_storageLayoutMap: Map<string, StorageLayout> = new Map()
|
||||
|
||||
constructor (ethClient: EthClient, storageLayoutMap?: Map<string, StorageLayout>) {
|
||||
this._getStorageAt = ethClient.getStorageAt.bind(ethClient);
|
||||
|
||||
if (storageLayoutMap) {
|
||||
this._storageLayoutMap = storageLayoutMap;
|
||||
}
|
||||
}
|
||||
|
||||
get serverConfig () {
|
||||
return new ServerConfig();
|
||||
}
|
||||
|
||||
get storageLayoutMap (): Map<string, StorageLayout> {
|
||||
return this._storageLayoutMap;
|
||||
}
|
||||
|
||||
async getStorageValue (storageLayout: StorageLayout, blockHash: string, contractAddress: string, variable: string, ...mappingKeys: MappingKey[]): Promise<ValueResult> {
|
||||
return getStorageValue(
|
||||
storageLayout,
|
||||
this._getStorageAt,
|
||||
blockHash,
|
||||
contractAddress,
|
||||
variable,
|
||||
...mappingKeys
|
||||
);
|
||||
}
|
||||
|
||||
async getBlockProgress (blockHash: string): Promise<BlockProgressInterface | undefined> {
|
||||
assert(blockHash);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user