Skip to content

Commit

Permalink
feat: store txHash of startBoughtExit for reference
Browse files Browse the repository at this point in the history
  • Loading branch information
troggy committed Apr 15, 2019
1 parent e457719 commit fb3e609
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
1 change: 1 addition & 0 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ resources:
NonKeyAttributes:
- "utxoId"
- "finalized"
- "txHash"
- "data"
ProjectionType: "INCLUDE"
ProvisionedThroughput:
Expand Down
5 changes: 3 additions & 2 deletions src/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 8 additions & 7 deletions src/exitFinalizer/exitFinalizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/exitManager/exitManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit fb3e609

Please sign in to comment.