Skip to content

Commit

Permalink
demux adjusts
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo Ribeiro committed Sep 28, 2018
1 parent 3fe9716 commit 41a083d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
6 changes: 3 additions & 3 deletions services/demux/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ console.info("==== Starting demux ====")

const INITIAL_BLOCK = Number(process.env.CHAIN_INIT_BLOCK || 100)

const MONGO_URI = process.env.MONGO_URI || "mongodb://127.0.0.1:5901"
const MONGO_DB = process.env.MONGO_DB || "EOSMN"
const MONGO_URI = process.env.MONGO_URI || "mongodb://127.0.0.1:27017"
const MONGO_DB = process.env.MONGO_DB || "EOSFN"

console.info("Initial Block to sync >>>> ", INITIAL_BLOCK)

const dbConfig = {
user: process.env.DB_USER || "user",
password: process.env.DB_PASSWORD || "pass",
host: process.env.DB_HOST || "localhost",
port: Number(process.env.DB_PORT) || 5932,
port: Number(process.env.DB_PORT) || 5432,
database: process.env.DB_NAME || "monstereosio",
schema: process.env.DB_SCHEMA || "pets",
}
Expand Down
12 changes: 6 additions & 6 deletions services/demux/src/services/data-cleaner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import fetch from "node-fetch"

const BLOCK_SYNC_TOLERANCE = process.env.BLOCK_SYNC_TOLERANCE || 10

const NODEOS = process.env.CHAIN_HOST || "http://localhost:5988"
const NODEOS = process.env.CHAIN_HOST || "http://localhost:8830"
const rpc = new Rpc.JsonRpc(NODEOS, { fetch })

const dbConfig = {
user: process.env.DB_USER || "user",
password: process.env.DB_PASSWORD || "pass",
host: process.env.DB_HOST || "localhost",
port: Number(process.env.DB_PORT) || 5932,
port: Number(process.env.DB_PORT) || 5432,
database: process.env.DB_NAME || "monstereosio",
schema: process.env.DB_SCHEMA || "pets",
}
Expand Down Expand Up @@ -83,7 +83,7 @@ const killMonsters = async (db: any, dbFull: any) => {

const query = `
SELECT pet_id, MAX(created_at) as last_feed_at FROM "pets"."pet_actions"
WHERE pet_id IN (${pendingPetsIds}) AND action = 'feedpet'
WHERE pet_id IN (${pendingPetsIds}) AND action = 'feedpet' AND is_invalid = FALSE
GROUP BY pet_id
`

Expand All @@ -100,12 +100,12 @@ const killMonsters = async (db: any, dbFull: any) => {

const isDead = Date.now() - deathTime > 0

const death_at = isDead ? moment(deathTime).toISOString() : pet.death_at
const deathAt = isDead ? moment(deathTime).toISOString() : pet.death_at

return {id: pet.id, isDead, death_at }
return {id: pet.id, isDead, deathAt }
}).filter((pet: any) => pet.isDead)

const updatedDeadPets = deadPets.map((pet: any) => (db.pets.save({id: pet.id, death_at: pet.death_at})))
const updatedDeadPets = deadPets.map((pet: any) => (db.pets.save({id: pet.id, death_at: pet.deathAt})))
if (updatedDeadPets.length) {
console.info("Dead pets: ", deadPets)
await Promise.all(updatedDeadPets)
Expand Down
2 changes: 1 addition & 1 deletion services/demux/src/services/postgraphile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const dbConfig = {
user: process.env.DB_USER || "user",
password: process.env.DB_PASSWORD || "pass",
host: process.env.DB_HOST || "localhost",
port: Number(process.env.DB_PORT) || 5932,
port: Number(process.env.DB_PORT) || 5432,
database: process.env.DB_NAME || "monstereosio",
schema: process.env.DB_SCHEMA || "pets",
}
Expand Down
13 changes: 10 additions & 3 deletions services/demux/src/updaters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ const quickbattle = async (db: any, payload: any, blockInfo: BlockInfo) => {
await battleJoin(db, res.id, payload.data.picks.pets, payload.authorization[0].actor, blockInfo, true)

} else { // join in the current battle
await battleJoin(db, lastBattle, payload.data.picks.pets, payload.authorization[0].actor, blockInfo, false)
await battleJoin(db, lastBattle.id, payload.data.picks.pets, payload.authorization[0].actor, blockInfo, false)
}
}

Expand Down Expand Up @@ -214,14 +214,21 @@ const battlestart = async (db: any, payload: any, blockInfo: BlockInfo) => {
battle_id: battle.id,
})

battleJoin(db, battle, payload.data.picks.pets, payload.authorization[0].actor, blockInfo, !existentPicks)
battleJoin(db, battle.id, payload.data.picks.pets, payload.authorization[0].actor, blockInfo, !existentPicks)
} else { // ignoring old battles
console.info("Ignoring old battle pick")
}

}

const battleJoin = async(db: any, battleId: any, pickPets: any, picker: any, blockInfo: BlockInfo, firstPick: boolean) => {
const battleJoin = async (
db: any,
battleId: any,
pickPets: any,
picker: any,
blockInfo: BlockInfo,
firstPick: boolean,
) => {

// insert new picks
const picks = pickPets.map((petId: number) =>
Expand Down

0 comments on commit 41a083d

Please sign in to comment.