Skip to content

Commit

Permalink
Update ethereum-gravatar.md
Browse files Browse the repository at this point in the history
  • Loading branch information
seandotau authored Aug 18, 2023
1 parent 0d14143 commit 3460d66
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions docs/quickstart/quickstart_chains/ethereum-gravatar.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,15 @@ import {
UpdatedGravatarLog,
} from "../types/abi-interfaces/Gravity";
import { Gravatar } from "../types";
import assert from "assert";
export async function handleNewGravatar(log: NewGravatarLog): Promise<void> {
logger.info("New Gravar at block " + log.blockNumber.toString());
assert(log.args, "Require args on the logs");
const gravatar = Gravatar.create({
id: log.args.id.toHexString(),
id: log.args.id.toHexString()!,
owner: log.args.owner,
displayName: log.args.displayName,
imageUrl: log.args.imageUrl,
Expand All @@ -152,20 +156,29 @@ export async function handleUpdatedGravatar(
log: UpdatedGravatarLog
): Promise<void> {
logger.info("Updated Gravar at block " + log.blockNumber.toString());
const id = log.args.id.toHexString();
assert(log.args, "Require args on the logs");
const id: string = log.args.id.toHexString()!;
// We first check if the Gravatar already exists, if not we create it
let gravatar = await Gravatar.get(id);
if (gravatar == null || gravatar == undefined) {
gravatar = new Gravatar(id);
gravatar.createdBlock = BigInt(log.blockNumber);
gravatar = Gravatar.create({
id,
createdBlock: BigInt(log.blockNumber),
owner: "",
displayName: "",
imageUrl: "",
});
}
// Update with new data
gravatar.owner = log.args.owner;
gravatar.displayName = log.args.displayName;
gravatar.imageUrl = log.args.imageUrl;
await gravatar.save();
}
```

Let’s understand how the above code works.
Expand Down

0 comments on commit 3460d66

Please sign in to comment.