Skip to content

Commit

Permalink
FABN-1492: Add isValid() convenience method to transaction events (#165)
Browse files Browse the repository at this point in the history
Signed-off-by: Mark S. Lewis <[email protected]>
  • Loading branch information
bestbeforetoday authored Mar 11, 2020
1 parent c332096 commit ac93f72
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions fabric-network/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface TransactionEvent {
getStatus(): string;
getBlockEvent(): BlockEvent;
getContractEvents(): ContractEvent[];
isValid(): boolean;
}

export interface FilteredTransactionEvent extends TransactionEvent {
Expand Down
7 changes: 5 additions & 2 deletions fabric-network/src/impl/event/filteredevents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function getCodeToStatusMap(): { [code: number]: string } {
}

const codeToStatusMap = getCodeToStatusMap();
const validStatus = 'VALID';

export function newFilteredBlockEvent(eventInfo: EventInfo): FilteredBlockEvent {
let transactionEvents: FilteredTransactionEvent[] | undefined;
Expand Down Expand Up @@ -63,7 +64,8 @@ export function newCommitEvent(peer: Endorser, eventInfo: EventInfo): CommitEven
getTransactionId: () => transactionId,
getStatus: () => eventInfo.status!,
getContractEvents: () => getTransactionEvent().getContractEvents(),
getTransactionData: () => getTransactionEvent().getTransactionData()
getTransactionData: () => getTransactionEvent().getTransactionData(),
isValid: () => eventInfo.status === validStatus
};
}

Expand All @@ -89,7 +91,8 @@ function newFilteredTransactionEvent(blockEvent: FilteredBlockEvent, filteredTra
getTransactionId: () => filteredTransaction.txid,
getStatus: () => status,
getContractEvents: () => getContractEvents(transactionEvent),
getTransactionData: () => filteredTransaction
getTransactionData: () => filteredTransaction,
isValid: () => status === validStatus
};

return transactionEvent;
Expand Down
2 changes: 1 addition & 1 deletion fabric-network/src/impl/event/transactioneventhandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export class TransactionEventHandler implements TxEventHandler {
}

private eventCallback(error?: CommitError, event?: CommitEvent) {
if (event && event.getStatus() !== 'VALID') {
if (event && !event.isValid()) {
const message = `Commit of transaction ${this.transactionId} failed on peer ${event.getPeer().name} with status ${event.getStatus()}`;
this.strategyFail(new Error(message));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class SampleTransactionEventHandler implements TxEventHandler {
}

private eventCallback(error?: CommitError, event?: CommitEvent) {
if (event && event.getStatus() !== 'VALID') {
if (event && !event.isValid()) {
return this.fail(new Error(event.getStatus()));
}

Expand Down

0 comments on commit ac93f72

Please sign in to comment.