Handle diffs in apiReturn

This commit is contained in:
Sosthene 2024-12-17 12:09:19 +01:00
parent 93c2ea1d23
commit d64efbd6a0

View File

@ -307,30 +307,22 @@ export default class Services {
// Save process to storage
try {
await this.saveProcess(updatedProcess.commitment_tx, updatedProcess.current_process);
await this.saveDiffs(updatedProcess.new_diffs);
} catch (e) {
throw e;
}
if ((updatedProcess as any).new_state) {
this.currentProcess = updatedProcess.commitment_tx;
this.getUpdateProposals(this.currentProcess!);
await this.evaluatePendingUpdates();
} else if (updatedProcess.modified_state) {
// We added validation tokens
// We check if the state is now valid
// If enough validation tokens we shoot a commit msg to the relay
const [previous_state, new_state] = updatedProcess.modified_state;
const init_commitment = updatedProcess.commitment_tx;
if (updatedProcess.new_diffs.length != 0) {
try {
const apiReturn = this.sdkClient.evaluate_state(init_commitment, null, JSON.stringify(new_state));
await this.handleApiReturn(apiReturn);
this.saveDiffs(updatedProcess.new_diffs);
} catch (e) {
throw e
throw e;
}
}
if (updatedProcess.modified_state) {
// For now it can only mean we added a validation token to an existing state
// Not sure what action to take
}
}
if (apiReturn.commit_to_send) {