Fix transaction deletion

This commit is contained in:
Garrett Mills 2021-04-10 22:36:26 -05:00
parent b8bf02bc12
commit 327d1a6ebd
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246

View File

@ -63,15 +63,17 @@ export class Transaction extends Unit {
*/ */
public async up() { public async up() {
this.firebase.ref('transaction').on('value', snapshot => { this.firebase.ref('transaction').on('value', snapshot => {
if ( !Array.isArray(snapshot.val()) || snapshot.val().length < 2 ) return; for ( const leftKey in snapshot.val() ) {
let newSnapshot = [...snapshot.val()] const left = snapshot.val()[leftKey]
for ( const left of snapshot.val() ) {
for ( const right of snapshot.val() ) { for ( const rightKey in snapshot.val() ) {
const right = snapshot.val()[rightKey]
this.compare(left, right).then(match => { this.compare(left, right).then(match => {
if ( match ) { if ( match ) {
this.blockchain.submitTransactions([left, right]) this.blockchain.submitTransactions([left, right])
this.firebase.ref('transaction').child(left.key).remove() this.firebase.ref('transaction').child(leftKey).remove()
this.firebase.ref('transaction').child(right.key).remove() this.firebase.ref('transaction').child(rightKey).remove()
} }
}) })
} }