This commit is contained in:
aozhiwei 2022-02-15 18:00:53 +08:00
parent c43e99268a
commit d0c65ebd98
2 changed files with 28 additions and 31 deletions

View File

@ -15,19 +15,19 @@ class ContractExecutor {
this.getLogData = null;
this.getPrepareBlockNumber = null;
this.getSuccessBlockNumber = null;
this.getSyncCount = null;
this.searchLogClass = '';
this.eventName = '';
this.eventFilter = null;
this.onSearchSuccess = null;
this.syncLogClass = '';
this.methodName = '';
this.methodArgs = [];
this.syncDbLogClass = '';
this.syncResetState = null;
this.syncGetSyncCount = null;
this.onSyncPrepare = null;
this.onSearchSuccess = null;
this.onSyncSuccess = null;
this.onSyncFailed = null;
}
@ -48,7 +48,7 @@ class ContractExecutor {
await this.syncResetState();
await utils.sleep(utils.randRange(1500, 4000));
}
} while (tryCount < 3 && !confirmed && this.syncGetSyncCount() < 3);
} while (tryCount < 3 && !confirmed && this.getSyncCount() < 3);
return confirmed;
}
@ -124,9 +124,6 @@ class ContractExecutor {
'prepare',
this.getLogKey(),
utils.jsonEncode(this.getLogData()));
if (this.onSyncPrepare) {
await this.onSyncPrepare();
}
result = await this.method(this.methodArgs).send({gas: 1000000});
await dblog.addLog(
this.syncDbLogClass,

View File

@ -54,19 +54,6 @@ class BoxOrder {
const eventFilter = {
boxId: this.getOrderId()
};
const onSearchSuccess = async (event) => {
const blockNumber = event['blockNumber'];
await this.updateDbMustBeSuccess(
logClass,
[
['bc_paid', 1],
['bc_pay_result', 1],
['bc_pay_success_block_number', blockNumber],
]);
this.orderDb['bc_paid'] = 1;
this.orderDb['bc_pay_result'] = 1;
this.orderDb['bc_pay_success_block_number'] = blockNumber;
};
const methodArgs = [
this.orderDb['order_id'],
this.orderDb['type'],
@ -82,18 +69,30 @@ class BoxOrder {
[
['bc_paid', 0],
['bc_pay_result', 0],
['bc_block_number', 0],
['bc_sync_block_number', 0],
['bc_pay_prepare_block_number', 0],
['bc_pay_success_block_number', 0],
]);
this.orderDb['bc_paid'] = 0;
this.orderDb['bc_pay_result'] = 0;
this.orderDb['bc_block_number'] = 0;
this.orderDb['bc_sync_block_number'] = 0;
this.orderDb['bc_pay_prepare_block_number'] = 0;
this.orderDb['bc_pay_success_block_number'] = 0;
};
const syncGetSyncCount = () => {
const getSyncCount = () => {
return this.orderDb['bc_pay_count'];
};
const onSyncPrepare = async () => {
const onSearchSuccess = async (event) => {
const blockNumber = event['blockNumber'];
await this.updateDbMustBeSuccess(
logClass,
[
['bc_paid', 1],
['bc_pay_result', 1],
['bc_pay_success_block_number', blockNumber],
]);
this.orderDb['bc_paid'] = 1;
this.orderDb['bc_pay_result'] = 1;
this.orderDb['bc_pay_success_block_number'] = blockNumber;
};
const onSyncSuccess = async () => {
};
@ -106,20 +105,21 @@ class BoxOrder {
exec.getLogKey = this.getOrderId.bind(this);
exec.getLogData = this.getOrderDb.bind(this);
exec.getPrepareBlockNumber = getPrepareBlockNumber;
exec.getSuccessBlockNumber = getSuccessBlockNumber;
exec.getSyncCount = getSyncCount;
exec.searchLogClass = 'order.search';
exec.eventName = 'BEBoxPaid';
exec.eventFilter = eventFilter;
exec.onSearchSuccess = onSearchSuccess;
exec.getPrepareBlockNumber = getPrepareBlockNumber;
exec.syncLogClass = 'order.sync';
exec.methodName = 'payForBoxWithSignature';
exec.methodArgs = methodArgs;
exec.syncDbLogClass = 'order.sync';
exec.syncResetState = syncResetState;
exec.getSuccessBlockNumber = getSuccessBlockNumber;
exec.syncGetSyncCount = syncGetSyncCount;
exec.onSyncPrepare = onSyncPrepare;
exec.onSearchSuccess = onSearchSuccess;
exec.onSyncSuccess = onSyncSuccess;
exec.onSyncFailed = onSyncFailed;
const ok = await exec.execute();