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

FABN-1492: Add isValid() convenience method to transaction events #165

Merged
merged 1 commit into from
Mar 11, 2020
Merged
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
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