Skip to content

Commit fdd5bcc

Browse files
author
wangchao
committed
fix(subscribe tx): unsubscribe tx when submit return
1 parent 4e5e9d9 commit fdd5bcc

File tree

2 files changed

+24
-29
lines changed

2 files changed

+24
-29
lines changed

chainsql/src/main/java/com/peersafe/chainsql/core/Submit.java

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -227,22 +227,25 @@ public void called(Response args) {
227227
}
228228
}
229229

230-
if(sync){
231-
if(submit_state == SubmitState.submit_error ||
232-
(submit_state == SubmitState.send_success && condition == SyncCond.send_success)){
230+
if (sync) {
231+
if (submit_state == SubmitState.submit_error) {
233232
return submitRes;
234-
}else{
233+
} else if (submit_state == SubmitState.send_success && condition == SyncCond.send_success) {
234+
unSubscribeTx(tx.hash.toString());
235+
return submitRes;
236+
} else {
235237
count = sync_maxtime / wait_milli;
236-
while(sync_state != SyncState.sync_response){
238+
while (sync_state != SyncState.sync_response) {
237239
Util.waiting();
238-
if(--count <= 0){
239-
syncRes = getError("waiting sync result timeout",tx.hash.toString());
240+
if (--count <= 0) {
241+
syncRes = getError("waiting sync result timeout", tx.hash.toString());
240242
break;
241243
}
242244
}
245+
unSubscribeTx(tx.hash.toString());
243246
return syncRes;
244247
}
245-
}else{
248+
} else {
246249
return submitRes;
247250
}
248251
}
@@ -279,14 +282,11 @@ public void called(JSONObject data) {
279282

280283
res.put("tx_hash", hash);
281284

282-
boolean bUnsubcribe = true;
283285
String status = obj.getString("status");
284286
switch (status) {
285287
case "validate_success":
286288
if (condition.compareTo(SyncCond.db_success) < 0) {
287289
res.put("status", condition.toString());
288-
} else {
289-
bUnsubcribe = false;
290290
}
291291
break;
292292
case "db_success":
@@ -309,12 +309,7 @@ public void called(JSONObject data) {
309309
break;
310310
}
311311

312-
//unsubscribe tx
313-
if(bUnsubcribe) {
314-
unSubscribeTx(hash);
315-
}
316-
317-
if(!res.isNull("status") && sync_state == SyncState.waiting_sync){
312+
if (!res.isNull("status") && sync_state == SyncState.waiting_sync) {
318313
syncRes = res;
319314
sync_state = SyncState.sync_response;
320315
submit_state = SubmitState.send_success;

chainsql/src/main/java/com/peersafe/chainsql/manager/EventManager.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -375,18 +375,18 @@ private void onTXMessage(JSONObject data){
375375
// makeCallback(key,data);
376376
// }
377377
makeCallback(key,data);
378-
if(data.has("transaction") && data.getJSONObject("transaction").has("TransactionType"))
379-
{
380-
JSONObject tx = data.getJSONObject("transaction");
381-
TransactionType type = TransactionType.valueOf(tx.getString("TransactionType"));
382-
if(Util.isChainsqlType(type)) {
383-
if(!("validate_success".equals(data.getString("status")))){
384-
mapCache.remove(key);
385-
}
386-
}else {
387-
mapCache.remove(key);
388-
}
389-
}
378+
// if(data.has("transaction") && data.getJSONObject("transaction").has("TransactionType"))
379+
// {
380+
// JSONObject tx = data.getJSONObject("transaction");
381+
// TransactionType type = TransactionType.valueOf(tx.getString("TransactionType"));
382+
// if(Util.isChainsqlType(type)) {
383+
// if(!("validate_success".equals(data.getString("status")))){
384+
// mapCache.remove(key);
385+
// }
386+
// }else {
387+
// mapCache.remove(key);
388+
// }
389+
// }
390390
}
391391

392392

0 commit comments

Comments
 (0)