diff --git a/src/app/FirebaseResource.ts b/src/app/FirebaseResource.ts index 715fb6d..c867cf6 100644 --- a/src/app/FirebaseResource.ts +++ b/src/app/FirebaseResource.ts @@ -71,7 +71,16 @@ export class FirebaseResource extends Iterable(collection).max('seqID') + 1 + + let maxSeq = -1 + for ( const item of collection ) { + if ( !item ) continue + if ( !isNaN(item.seqID) && item.seqID > maxSeq ) { + maxSeq = item.seqID + } + } + + return maxSeq + 1 } /** @@ -81,6 +90,7 @@ export class FirebaseResource extends Iterable { await this.ref().transaction((collection) => { if ( !collection ) collection = [] + if ( typeof collection === 'object' ) collection = Object.values(collection) item.seqID = this.findNextId(collection) // @ts-ignore @@ -96,7 +106,6 @@ export class FirebaseResource extends Iterable { - console.log('got push ID back', snapshot.val(), snapshot.key) res() }) }) diff --git a/src/app/units/Blockchain.ts b/src/app/units/Blockchain.ts index aa856a3..3967e2f 100644 --- a/src/app/units/Blockchain.ts +++ b/src/app/units/Blockchain.ts @@ -179,7 +179,6 @@ export class Blockchain extends Unit { const blocks: unknown = result.data?.data?.records if ( Array.isArray(blocks) && blocks.every(block => { const match = isBlockResourceItem(block) - console.log(match, block) return match }) ) { return blocks.map(x => new Block(x)) @@ -353,6 +352,7 @@ export class Blockchain extends Unit { } public async getSubmitChain(): Promise { + await this.firebase.trylock('block', 'Blockchain_getSubmitChain') const blocks = await this.read() const submit = await this.attemptSubmit() if ( submit ) { @@ -360,6 +360,7 @@ export class Blockchain extends Unit { blocks.push(submit.toItem()) } + await this.firebase.unlock('block') this.refresh() return blocks }