Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(battlepass): return battlepass state #20

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/chain/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export async function listenNewEvents(api: ApiPromise, knownBlock: number, known
if (api.events.battlepass.BattlepassCreated.is(event)) {
let [orgId, bpId, season] = event.data
const chainBp: any = await api.query.battlepass.battlepasses(bpId.toString())
const bpState: any = await api.query.battlepass.battlepassStates(bpId.toString())
await Battlepass.create({
chainId: bpId.toString(),
startDate: null,
Expand All @@ -41,6 +42,8 @@ export async function listenNewEvents(api: ApiPromise, knownBlock: number, known
price: chainBp ? parseInt(chainBp.value.price?.toString()) : null,
season: parseInt(season.toString()),
active: false,
// correct?
state: bpState ? Buffer.from(bpState.value, 'hex').toString() : 'DRAFT',
finalized: false,
})
logger.info('Found new battlepass %s', bpId.toString())
Expand All @@ -58,12 +61,16 @@ export async function listenNewEvents(api: ApiPromise, knownBlock: number, known
name: chainBp ? Buffer.from(chainBp.value.name, 'hex').toString() : null,
cid: chainBp ? Buffer.from(chainBp.value.cid, 'hex').toString() : null,
active: true,
// correct? should be derived from chain...
state: 'DRAFT',
finalized: false,
},
})
if (!created) {
bp.startDate = calculateBlockDate(knownDate, knownBlock, header.number.toNumber())
bp.active = true
// correct? should be derived from chain...
bp.state = 'ACTIVE'
bp.finalized = false
await bp.save()
}
Expand All @@ -79,6 +86,8 @@ export async function listenNewEvents(api: ApiPromise, knownBlock: number, known
}
bp.endDate = calculateBlockDate(knownDate, knownBlock, header.number.toNumber())
bp.active = false
// correct? should be derived from chain...
bp.state = 'ENDED'
await bp.save()
logger.info('Found ended battlepass %s', bpId.toString())
} else if (api.events.battlepass.BattlepassClaimed.is(event)) {
Expand Down
5 changes: 5 additions & 0 deletions src/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class Battlepass extends Model<InferAttributes<Battlepass>, InferCreation
declare startDate: Date | null
declare endDate: Date | null
declare active: boolean
declare state: string
declare finalized: boolean
declare joinable: CreationOptional<boolean>
declare totalJoined: CreationOptional<number>
Expand Down Expand Up @@ -78,6 +79,10 @@ Battlepass.init(
type: DataTypes.BOOLEAN,
allowNull: false,
},
state: {
type: DataTypes.STRING(16),
allowNull: false,
},
finalized: {
type: DataTypes.BOOLEAN,
allowNull: false,
Expand Down