diff --git a/lib/flight-booking-manager.js b/lib/flight-booking-manager.js index dbaee68..5069b81 100644 --- a/lib/flight-booking-manager.js +++ b/lib/flight-booking-manager.js @@ -103,7 +103,7 @@ class FlightBookingManager extends Contract { async isSeatAvailable(ctx, txId, tm, seatNumber) { let seatOwner = await this._queryVariable(ctx, txId, 'seatOwner_' + seatNumber, null, tm); - return seatOwner === null; + return seatOwner === null || seatOwner === undefined || seatOwner.length === 0; } async queryNextAvailableSeat(ctx, txId, tm) { @@ -282,10 +282,10 @@ class FlightBookingManager extends Contract { } async endFlight(ctx, txId, tm) { - let reservations = await this.queryBookedSeatsCount(ctx, txId, tm); + let seats = await this.querySeatsCount(ctx, txId, tm); - for (let i = 0; i < reservations; i++) { - if (!await (new ResourceManager()).setValue(ctx, txId, 'seatOwner_' + i, null, tm)) { + for (let i = 0; i < seats; i++) { + if (!await (new ResourceManager()).setValue(ctx, txId, 'seatOwner_' + i, '', tm)) { throw new Error('Cannot change seat status. Data item is locked by another transaction!'); } } diff --git a/lib/resourceManager.js b/lib/resourceManager.js index 4f87ef4..af0ab49 100644 --- a/lib/resourceManager.js +++ b/lib/resourceManager.js @@ -82,8 +82,11 @@ class ResourceManager extends Contract { if (tx) { const tm = tx.getTm(); + const tmClientName = tm.split(',').filter(x => x[0] === 'C' && x[1] === 'N')[0].split('=')[1]; + const currentClientName = ctx.clientIdentity.getID().split('::')[1].split('/').filter(x => x[0] === 'C' && x[1] === 'N')[0].split('=')[1]; - if (tm !== ctx.clientIdentity.getID()) { + + if (tmClientName !== currentClientName) { throw new Error('Message sender (' + ctx.clientIdentity.getID() + ') is not the designated transaction manager of global transaction!'); } } else {