forked from subquery/cosmos-subql-starter
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6379b3e
commit 8e55180
Showing
4 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./registrations"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import {attemptHandling, messageId, unprocessedEventHandler} from "../utils"; | ||
import {CosmosEvent} from "@subql/types-cosmos"; | ||
import {AlmanacRecord, AlmanacRegistration} from "../../types"; | ||
|
||
export async function handleAlmanacRegistration(event: CosmosEvent): Promise<void> { | ||
await attemptHandling(event, _handleAlmanacRegistration, unprocessedEventHandler); | ||
} | ||
|
||
async function _handleAlmanacRegistration(event: CosmosEvent): Promise<void> { | ||
const id = messageId(event); | ||
logger.info(`[handleAlmanacRegistration] (tx ${event.tx.hash}): indexing AlmanacRegistration ${id}`); | ||
logger.debug(`[handleAlmanacRegistration] (event.log.log): ${JSON.stringify(event.log.log, null, 2)}`); | ||
|
||
const attributes = event.event.attributes.reduce((acc, curr) => { | ||
acc[curr.key] = curr.value; | ||
return acc; | ||
}, {}); | ||
|
||
const {address, record: recordStr, expiry_height} = attributes as unknown as any; | ||
if (!address) { | ||
logger.warn("[handleAlmanacRegistration]: missing address"); | ||
return; | ||
} | ||
|
||
if (!expiry_height) { | ||
logger.warn("[handleAlmanacRegistration]: missing expiry_height"); | ||
return; | ||
} | ||
|
||
if (!recordStr) { | ||
logger.warn("[handleAlmanacRegistration]: missing record"); | ||
return; | ||
} | ||
|
||
const record = JSON.parse(recordStr); | ||
if (!record || !record.Service) { | ||
logger.warn("[handleAlmanacRegistration]: missing record service"); | ||
return; | ||
} | ||
|
||
const recordEntity = AlmanacRecord.create({ | ||
id, | ||
service: record.service, | ||
// eventId: id, | ||
transactionId: event.tx.hash, | ||
blockId: event.block.block.id, | ||
}); | ||
await recordEntity.save(); | ||
|
||
const registrationEntity = AlmanacRegistration.create({ | ||
id, | ||
expiryHeight: expiry_height, | ||
accountId: address, | ||
recordId: id, | ||
// eventId: id, | ||
transactionId: event.tx.hash, | ||
blockId: event.block.block.id, | ||
}); | ||
await registrationEntity.save(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters