mirror of
https://github.com/cerc-io/watcher-ts
synced 2024-11-19 20:36:19 +00:00
GQL mutation to start watching contract.
This commit is contained in:
parent
7035a513b1
commit
c916e61a9b
@ -268,7 +268,14 @@ export class Indexer {
|
|||||||
async isWatchedContract (address : string): Promise<boolean> {
|
async isWatchedContract (address : string): Promise<boolean> {
|
||||||
assert(address);
|
assert(address);
|
||||||
|
|
||||||
return this._db.isWatchedContract(address);
|
return this._db.isWatchedContract(ethers.utils.getAddress(address));
|
||||||
|
}
|
||||||
|
|
||||||
|
async watchContract (address: string, startingBlock: number): Promise<boolean> {
|
||||||
|
// Always use the checksum address (https://docs.ethers.io/v5/api/utils/address/#utils-getAddress).
|
||||||
|
await this._db.saveContract(ethers.utils.getAddress(address), startingBlock);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Move into base/class or framework package.
|
// TODO: Move into base/class or framework package.
|
||||||
|
@ -26,6 +26,13 @@ export const createResolvers = async (indexer: Indexer): Promise<any> => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Mutation: {
|
||||||
|
watchToken: (_: any, { token, startingBlock = 1 }: { token: string, startingBlock: number }): Promise<boolean> => {
|
||||||
|
log('watchToken', token, startingBlock);
|
||||||
|
return indexer.watchContract(token, startingBlock);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
Query: {
|
Query: {
|
||||||
|
|
||||||
totalSupply: (_: any, { blockHash, token }: { blockHash: string, token: string }): Promise<ValueResult> => {
|
totalSupply: (_: any, { blockHash, token }: { blockHash: string, token: string }): Promise<ValueResult> => {
|
||||||
|
@ -139,4 +139,16 @@ type Subscription {
|
|||||||
# Watch for token events (at head of chain).
|
# Watch for token events (at head of chain).
|
||||||
onTokenEvent: WatchedEvent!
|
onTokenEvent: WatchedEvent!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Mutations
|
||||||
|
#
|
||||||
|
type Mutation {
|
||||||
|
|
||||||
|
# Actively watch and index data for the token.
|
||||||
|
watchToken(
|
||||||
|
token: String!
|
||||||
|
startingBlock: Int
|
||||||
|
): Boolean!
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
|
Loading…
Reference in New Issue
Block a user