@@ -2435,25 +2435,7 @@ public CompletableFuture<TransactionEvent> sendTransaction(Collection<ProposalRe
24352435 String emsg = format ("Channel %s unsuccessful sendTransaction to orderer" , name );
24362436 if (resp != null ) {
24372437
2438- StringBuilder respdata = new StringBuilder (400 );
2439-
2440- Status status = resp .getStatus ();
2441- if (null != status ) {
2442- respdata .append (status .name ());
2443- respdata .append ("-" );
2444- respdata .append (status .getNumber ());
2445- }
2446-
2447- String info = resp .getInfo ();
2448- if (null != info && !info .isEmpty ()) {
2449- if (respdata .length () > 0 ) {
2450- respdata .append (", " );
2451- }
2452-
2453- respdata .append ("Additional information: " ).append (info );
2454-
2455- }
2456- emsg = format ("Channel %s unsuccessful sendTransaction to orderer. %s" , name , respdata .toString ());
2438+ emsg = format ("Channel %s unsuccessful sendTransaction to orderer. %s" , name , getRespData (resp ));
24572439 }
24582440
24592441 logger .error (emsg , e );
@@ -2466,28 +2448,12 @@ public CompletableFuture<TransactionEvent> sendTransaction(Collection<ProposalRe
24662448 logger .debug (format ("Channel %s successful sent to Orderer transaction id: %s" , name , proposalTransactionID ));
24672449 return sret ;
24682450 } else {
2469- StringBuilder respdata = new StringBuilder (400 );
2470- if (resp != null ) {
2471- Status status = resp .getStatus ();
2472- if (null != status ) {
2473- respdata .append (status .name ());
2474- respdata .append ("-" );
2475- respdata .append (status .getNumber ());
2476- }
2477-
2478- String info = resp .getInfo ();
2479- if (null != info && !info .isEmpty ()) {
2480- if (respdata .length () > 0 ) {
2481- respdata .append (", " );
2482- }
24832451
2484- respdata .append ("Additional information: " ).append (info );
2452+ String emsg = format ("Channel %s failed to place transaction %s on Orderer. Cause: UNSUCCESSFUL. %s" ,
2453+ name , proposalTransactionID , getRespData (resp ));
24852454
2486- }
2455+ unregisterTxListener ( proposalTransactionID );
24872456
2488- }
2489- String emsg = format ("Channel %s failed to place transaction %s on Orderer. Cause: UNSUCCESSFUL. %s" ,
2490- name , proposalTransactionID , respdata .toString ());
24912457 CompletableFuture <TransactionEvent > ret = new CompletableFuture <>();
24922458 ret .completeExceptionally (new Exception (emsg ));
24932459 return ret ;
@@ -2502,6 +2468,38 @@ public CompletableFuture<TransactionEvent> sendTransaction(Collection<ProposalRe
25022468
25032469 }
25042470
2471+ /**
2472+ * Build response details
2473+ * @param resp
2474+ * @return
2475+ */
2476+ private String getRespData (BroadcastResponse resp ) {
2477+
2478+ StringBuilder respdata = new StringBuilder (400 );
2479+ if (resp != null ) {
2480+ Status status = resp .getStatus ();
2481+ if (null != status ) {
2482+ respdata .append (status .name ());
2483+ respdata .append ("-" );
2484+ respdata .append (status .getNumber ());
2485+ }
2486+
2487+ String info = resp .getInfo ();
2488+ if (null != info && !info .isEmpty ()) {
2489+ if (respdata .length () > 0 ) {
2490+ respdata .append (", " );
2491+ }
2492+
2493+ respdata .append ("Additional information: " ).append (info );
2494+
2495+ }
2496+
2497+ }
2498+
2499+ return respdata .toString ();
2500+
2501+ }
2502+
25052503 private Envelope createTransactionEnvelope (Payload transactionPayload , User user ) throws CryptoException {
25062504
25072505 return Envelope .newBuilder ()
@@ -2892,6 +2890,20 @@ private CompletableFuture<TransactionEvent> registerTxListener(String txid) {
28922890
28932891 }
28942892
2893+ /**
2894+ * Unregister a transactionId
2895+ *
2896+ * @param txid
2897+ */
2898+ private void unregisterTxListener (String txid ) {
2899+
2900+ synchronized (txListeners ) {
2901+
2902+ txListeners .remove (txid );
2903+ }
2904+
2905+ }
2906+
28952907 ////////////////////////////////////////////////////////////////////////
28962908 //////////////// Chaincode Events.. //////////////////////////////////
28972909
0 commit comments