diff --git a/serverless.yml b/serverless.yml index ee1396e..ebe2969 100644 --- a/serverless.yml +++ b/serverless.yml @@ -204,6 +204,7 @@ resources: NonKeyAttributes: - "utxoId" - "finalized" + - "txHash" - "data" ProjectionType: "INCLUDE" ProvisionedThroughput: diff --git a/src/db.js b/src/db.js index 039f3ce..a5a840f 100644 --- a/src/db.js +++ b/src/db.js @@ -35,13 +35,14 @@ export default class Db extends DynamoDb { return this.add(params); } - setAsFinalized(utxoId) { + setAsFinalized(utxoId, txHash) { const params = { TableName: this.tableName, Key: { utxoId: utxoId.toLowerCase() }, - UpdateExpression: 'set finalized = :f', + UpdateExpression: 'set finalized = :f, txHash = :hash', ExpressionAttributeValues: { ':f': 1, + ':hash': txHash, }, }; return this.update(params); diff --git a/src/exitFinalizer/exitFinalizer.js b/src/exitFinalizer/exitFinalizer.js index 46e0a9a..fff260f 100644 --- a/src/exitFinalizer/exitFinalizer.js +++ b/src/exitFinalizer/exitFinalizer.js @@ -35,14 +35,15 @@ class ExitFinalizer { console.log('Sold exits to process:', exits.length); let done = 0; - // TODO: do not wait for tx's to mine - await Promise.all(exits.map(exit => - this.sellExit(exit).then((txHash) => { - console.log('Processed sold exit:', exit.utxoId, txHash); + + for (let i = 0; i < exits.length; i += 1) { + const exit = exits[i]; + await this.sellExit(exit).then((rsp) => { + console.log('Processed sold exit:', exit.utxoId, rsp); done += 1; - return this.db.setAsFinalized(exit.utxoId); - }), - )); + return this.db.setAsFinalized(exit.utxoId, rsp.hash); + }); + } return { statusCode: 200, diff --git a/src/exitManager/exitManager.js b/src/exitManager/exitManager.js index c05a8d7..6487aa5 100644 --- a/src/exitManager/exitManager.js +++ b/src/exitManager/exitManager.js @@ -22,7 +22,7 @@ class ExitManager { async registerExit({ body }) { const inputTx = Tx.fromRaw(body.inputTx.raw); const color = inputTx.outputs[0].color; - const value = inputTx.outputs[0].value.toString(); + const value = body.tx.value.toString(); const account = inputTx.inputs[0].signer; const tx = Tx.fromRaw(body.tx.raw);