Skip to content

Commit

Permalink
Merge pull request #385 from BibliothecaDAO/feat/cont-updates
Browse files Browse the repository at this point in the history
Feat/cont updates
  • Loading branch information
starknetdev authored Oct 9, 2023
2 parents a225323 + eb10df5 commit 164e699
Show file tree
Hide file tree
Showing 24 changed files with 127 additions and 230 deletions.
2 changes: 1 addition & 1 deletion indexer/env-goerli
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
GAME="0x01263ecbc05e28d1e99f531894838db10b90cfcdd39d020642da1747a733a37a"
GAME="0x03f2ac2c55abbf633123ddb72adc3472feefc4e962c4cedc16dda11a2ac8d1d4"
START=873000
MONGO_CONNECTION_STRING="mongodb://mongo:[email protected]:27017"
12 changes: 4 additions & 8 deletions indexer/graphql/src/indexer/graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,8 +621,6 @@ class AdventurersFilter:
id: Optional[FeltValueFilter] = None
lastAction: Optional[FeltValueFilter] = None
owner: Optional[HexValueFilter] = None
classType: Optional[ClassFilter] = None
homeRealm: Optional[FeltValueFilter] = None
name: Optional[StringFilter] = None
health: Optional[FeltValueFilter] = None
strength: Optional[FeltValueFilter] = None
Expand All @@ -643,6 +641,7 @@ class AdventurersFilter:
ring: Optional[FeltValueFilter] = None
beastHealth: Optional[FeltValueFilter] = None
statUpgrades: Optional[FeltValueFilter] = None
actionsPerBlock: Optional[FeltValueFilter] = None
gold: Optional[FeltValueFilter] = None
createdTime: Optional[OrderByInput] = None
lastUpdatedTime: Optional[DateTimeFilter] = None
Expand Down Expand Up @@ -750,8 +749,6 @@ class AdventurersOrderByInput:
id: Optional[OrderByInput] = None
lastAction: Optional[OrderByInput] = None
owner: Optional[OrderByInput] = None
classType: Optional[OrderByInput] = None
homeRealm: Optional[OrderByInput] = None
name: Optional[OrderByInput] = None
health: Optional[OrderByInput] = None
level: Optional[OrderByInput] = None
Expand All @@ -773,6 +770,7 @@ class AdventurersOrderByInput:
ring: Optional[OrderByInput] = None
beastHealth: Optional[OrderByInput] = None
statUpgrades: Optional[OrderByInput] = None
actionsPerBlock: Optional[OrderByInput] = None
gold: Optional[OrderByInput] = None
createdTime: Optional[OrderByInput] = None
lastUpdatedTime: Optional[OrderByInput] = None
Expand Down Expand Up @@ -881,8 +879,6 @@ class Adventurer:
id: Optional[FeltValue]
lastAction: Optional[FeltValue]
owner: Optional[HexValue]
classType: Optional[ClassValue]
homeRealm: Optional[FeltValue]
name: Optional[StringValue]
health: Optional[FeltValue]
strength: Optional[FeltValue]
Expand All @@ -903,6 +899,7 @@ class Adventurer:
ring: Optional[ItemValue]
beastHealth: Optional[FeltValue]
statUpgrades: Optional[FeltValue]
actionsPerBlock: Optional[FeltValue]
gold: Optional[FeltValue]
createdTime: Optional[str]
lastUpdatedTime: Optional[str]
Expand All @@ -914,8 +911,6 @@ def from_mongo(cls, data):
id=data["id"],
lastAction=data["lastAction"],
owner=data["owner"],
classType=data["classType"],
homeRealm=data["homeRealm"],
name=data["name"],
health=data["health"],
strength=data["strength"],
Expand All @@ -936,6 +931,7 @@ def from_mongo(cls, data):
ring=data["ring"],
beastHealth=data["beastHealth"],
statUpgrades=data["statUpgrades"],
actionsPerBlock=data["actionsPerBlock"],
gold=data["gold"],
createdTime=data["createdTime"],
lastUpdatedTime=data["lastUpdatedTime"],
Expand Down
47 changes: 23 additions & 24 deletions indexer/src/adventurers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ export default function transform({ header, events }: Block) {
return events.flatMap(({ event }) => {
switch (event.keys[0]) {
case START_GAME: {
console.log("START_GAME", "->", "ADVENTURER UPDATES");
const { value } = parseStartGame(event.data, 0);
const as = value.adventurerState;
const am = value.adventurerMeta;
console.log("START_GAME", "->", "ADVENTURER UPDATES");
return [
insertAdventurer({
id: as.adventurerId,
owner: as.owner,
lastAction: as.adventurer.lastAction,
lastAction: as.adventurer.lastActionBlock,
health: as.adventurer.health,
xp: as.adventurer.xp,
strength: as.adventurer.stats.strength,
Expand All @@ -126,9 +126,8 @@ export default function transform({ header, events }: Block) {
ring: as.adventurer.ring.id,
beastHealth: as.adventurer.beastHealth,
statUpgrades: as.adventurer.statsPointsAvailable,
actionsPerBlock: as.adventurer.actionsPerBlock,
name: am.name,
homeRealm: am.homeRealm,
classType: am.class,
entropy: am.entropy,
createdTime: new Date().toISOString(),
lastUpdatedTime: new Date().toISOString(),
Expand All @@ -137,8 +136,8 @@ export default function transform({ header, events }: Block) {
];
}
case ADVENTURER_UPGRADED: {
const { value } = parseAdventurerUpgraded(event.data, 0);
console.log("ADVENTURER_UPGRADED", "->", "ADVENTURER UPDATES");
const { value } = parseAdventurerUpgraded(event.data, 0);
return [
updateAdventurer({
adventurerState: value.adventurerStateWithBag.adventurerState,
Expand All @@ -147,8 +146,8 @@ export default function transform({ header, events }: Block) {
];
}
case DISCOVERED_HEALTH: {
const { value } = parseDiscoveredHealth(event.data, 0);
console.log("DISCOVERED_HEALTH", "->", "ADVENTURER UPDATES");
const { value } = parseDiscoveredHealth(event.data, 0);
return [
updateAdventurer({
timestamp: new Date().toISOString(),
Expand All @@ -157,8 +156,8 @@ export default function transform({ header, events }: Block) {
];
}
case DISCOVERED_GOLD: {
const { value } = parseDiscoveredGold(event.data, 0);
console.log("DISCOVERED_GOLD", "->", "ADVENTURER UPDATES");
const { value } = parseDiscoveredGold(event.data, 0);
return [
updateAdventurer({
timestamp: new Date().toISOString(),
Expand All @@ -167,8 +166,8 @@ export default function transform({ header, events }: Block) {
];
}
case DISCOVERED_XP: {
const { value } = parseDiscoveredXp(event.data, 0);
console.log("DISCOVERED_XP", "->", "ADVENTURER UPDATES");
const { value } = parseDiscoveredXp(event.data, 0);
return [
updateAdventurer({
timestamp: new Date().toISOString(),
Expand All @@ -177,8 +176,8 @@ export default function transform({ header, events }: Block) {
];
}
case DODGED_OBSTACLE: {
const { value } = parseDodgedObstacle(event.data, 0);
console.log("DODGED_OBSTACLE", "->", "ADVENTURER UPDATES");
const { value } = parseDodgedObstacle(event.data, 0);
return [
updateAdventurer({
timestamp: new Date().toISOString(),
Expand All @@ -187,8 +186,8 @@ export default function transform({ header, events }: Block) {
];
}
case HIT_BY_OBSTACLE: {
const { value } = parseHitByObstacle(event.data, 0);
console.log("HIT_BY_OBSTACLE", "->", "ADVENTURER UPDATES");
const { value } = parseHitByObstacle(event.data, 0);
return [
updateAdventurer({
timestamp: new Date().toISOString(),
Expand All @@ -197,8 +196,8 @@ export default function transform({ header, events }: Block) {
];
}
case DISCOVERED_BEAST: {
const { value } = parseDiscoveredBeast(event.data, 0);
console.log("DISCOVERED_BEAST", "->", "ADVENTURER UPDATES");
const { value } = parseDiscoveredBeast(event.data, 0);
return [
updateAdventurer({
timestamp: new Date().toISOString(),
Expand All @@ -207,8 +206,8 @@ export default function transform({ header, events }: Block) {
];
}
case PURCHASED_POTIONS: {
const { value } = parseDiscoveredXp(event.data, 0);
console.log("PURCHASED_POTIONS", "->", "ADVENTURER UPDATES");
const { value } = parseDiscoveredXp(event.data, 0);
return [
updateAdventurer({
timestamp: new Date().toISOString(),
Expand All @@ -217,8 +216,8 @@ export default function transform({ header, events }: Block) {
];
}
case PURCHASED_ITEMS: {
const { value } = parsePurchasedItems(event.data, 0);
console.log("PURCHASED_ITEMS", "->", "ADVENTURER UPDATES");
const { value } = parsePurchasedItems(event.data, 0);
return [
updateAdventurer({
timestamp: new Date().toISOString(),
Expand All @@ -227,8 +226,8 @@ export default function transform({ header, events }: Block) {
];
}
case EQUIPPED_ITEMS: {
const { value } = parseEquippedItems(event.data, 0);
console.log("EQUIPPED_ITEMS", "->", "ADVENTURER UPDATES");
const { value } = parseEquippedItems(event.data, 0);
return [
updateAdventurer({
timestamp: new Date().toISOString(),
Expand All @@ -237,8 +236,8 @@ export default function transform({ header, events }: Block) {
];
}
case DROPPED_ITEMS: {
const { value } = parseDroppedItems(event.data, 0);
console.log("DROPPED_ITEMS", "->", "ADVENTURER UPDATES");
const { value } = parseDroppedItems(event.data, 0);
return [
updateAdventurer({
timestamp: new Date().toISOString(),
Expand All @@ -247,8 +246,8 @@ export default function transform({ header, events }: Block) {
];
}
case ATTACKED_BEAST: {
const { value } = parseAttackedByBeast(event.data, 0);
console.log("ATTACKED_BEAST", "->", "ADVENTURER UPDATES");
const { value } = parseAttackedByBeast(event.data, 0);
return [
updateAdventurer({
timestamp: new Date().toISOString(),
Expand All @@ -257,8 +256,8 @@ export default function transform({ header, events }: Block) {
];
}
case ATTACKED_BY_BEAST: {
const { value } = parseAttackedByBeast(event.data, 0);
console.log("ATTACKED_BY_BEAST", "->", "ADVENTURER UPDATES");
const { value } = parseAttackedByBeast(event.data, 0);
return [
updateAdventurer({
timestamp: new Date().toISOString(),
Expand All @@ -267,8 +266,8 @@ export default function transform({ header, events }: Block) {
];
}
case AMBUSHED_BY_BEAST: {
const { value } = parseAmbushedByBeast(event.data, 0);
console.log("AMBUSHED_BY_BEAST", "->", "ADVENTURER UPDATES");
const { value } = parseAmbushedByBeast(event.data, 0);
return [
updateAdventurer({
timestamp: new Date().toISOString(),
Expand All @@ -277,8 +276,8 @@ export default function transform({ header, events }: Block) {
];
}
case SLAYED_BEAST: {
const { value } = parseSlayedBeast(event.data, 0);
console.log("SLAYED_BEAST", "->", "ADVENTURER UPDATES");
const { value } = parseSlayedBeast(event.data, 0);
return [
updateAdventurer({
timestamp: new Date().toISOString(),
Expand All @@ -287,8 +286,8 @@ export default function transform({ header, events }: Block) {
];
}
case ADVENTURER_DIED: {
const { value } = parseAdventurerDied(event.data, 0);
console.log("ADVENTURER_DIED", "->", "ADVENTURER UPDATES");
const { value } = parseAdventurerDied(event.data, 0);
return [
updateAdventurer({
timestamp: new Date().toISOString(),
Expand All @@ -297,8 +296,8 @@ export default function transform({ header, events }: Block) {
];
}
case FLEE_FAILED: {
const { value } = parseFleeFailed(event.data, 0);
console.log("FLEE_FAILED", "->", "ADVENTURER UPDATES");
const { value } = parseFleeFailed(event.data, 0);
return [
updateAdventurer({
timestamp: new Date().toISOString(),
Expand All @@ -307,8 +306,8 @@ export default function transform({ header, events }: Block) {
];
}
case FLEE_SUCCEEDED: {
const { value } = parseFleeSucceeded(event.data, 0);
console.log("FLEE_SUCCEEDED", "->", "ADVENTURER UPDATES");
const { value } = parseFleeSucceeded(event.data, 0);
return [
updateAdventurer({
timestamp: new Date().toISOString(),
Expand All @@ -317,8 +316,8 @@ export default function transform({ header, events }: Block) {
];
}
case ITEMS_LEVELED_UP: {
const { value } = parseItemsLeveledUp(event.data, 0);
console.log("ITEMS_LEVELED_UP", "->", "ADVENTURER UPDATES");
const { value } = parseItemsLeveledUp(event.data, 0);
return [
updateAdventurer({
timestamp: new Date().toISOString(),
Expand All @@ -327,8 +326,8 @@ export default function transform({ header, events }: Block) {
];
}
case UPGRADES_AVAILABLE: {
const { value } = parseUpgradesAvailable(event.data, 0);
console.log("UPGRADES_AVAILABLE", "->", "ADVENTURER UPDATES");
const { value } = parseUpgradesAvailable(event.data, 0);
return [
updateAdventurer({
timestamp: new Date().toISOString(),
Expand Down
3 changes: 0 additions & 3 deletions indexer/src/scores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ export default function transform({ header, events }: Block) {
updateTotalPayout({
adventurerId: fp.adventurerId,
owner: fp.address,
rank: fp.rank,
timestamp: new Date().toISOString(),
newPayout: fp.amount,
})
Expand All @@ -83,7 +82,6 @@ export default function transform({ header, events }: Block) {
updateTotalPayout({
adventurerId: sp.adventurerId,
owner: sp.address,
rank: sp.rank,
timestamp: new Date().toISOString(),
newPayout: sp.amount,
})
Expand All @@ -94,7 +92,6 @@ export default function transform({ header, events }: Block) {
updateTotalPayout({
adventurerId: tp.adventurerId,
owner: tp.address,
rank: tp.rank,
timestamp: new Date().toISOString(),
newPayout: tp.amount,
})
Expand Down
11 changes: 5 additions & 6 deletions indexer/src/utils/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const parseLootWithPrice = combineParsers({
});

export const parseAdventurer = combineParsers({
lastAction: { index: 0, parser: parseU16 },
lastActionBlock: { index: 0, parser: parseU16 },
health: { index: 1, parser: parseU16 },
xp: { index: 2, parser: parseU16 },
stats: { index: 3, parser: parseStats },
Expand All @@ -90,12 +90,13 @@ export const parseAdventurer = combineParsers({
ring: { index: 12, parser: parseLootStatistics },
beastHealth: { index: 13, parser: parseU16 },
statsPointsAvailable: { index: 14, parser: parseU8 },
mutated: { index: 15, parser: parseBoolean },
actionsPerBlock: { index: 15, parser: parseU8 },
mutated: { index: 16, parser: parseBoolean },
});

export const parseAdventurerState = combineParsers({
owner: { index: 0, parser: parseFelt252 },
adventurerId: { index: 1, parser: parseU256 },
adventurerId: { index: 1, parser: parseFelt252 },
adventurer: { index: 2, parser: parseAdventurer },
});

Expand Down Expand Up @@ -170,9 +171,7 @@ export const parseAdventurerDied = combineParsers({

export const parseAdventurerMetadata = combineParsers({
name: { index: 0, parser: parseU128 },
homeRealm: { index: 1, parser: parseU16 },
class: { index: 2, parser: parseU8 },
entropy: { index: 3, parser: parseU128 },
entropy: { index: 1, parser: parseU128 },
});

export const parseStartGame = combineParsers({
Expand Down
Loading

1 comment on commit 164e699

@vercel
Copy link

@vercel vercel bot commented on 164e699 Oct 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.