Skip to content
This repository was archived by the owner on Mar 23, 2021. It is now read-only.

Commit b29f495

Browse files
bors[bot]Franck Royer
andauthored
Merge #233
233: Fix auto-accept r=D4nte a=D4nte Upgrade to comit-sdk 0.7.1 to: - Fix auto-accept issue - Use swap search by id in negotiation protocol Co-authored-by: Franck Royer <franck@coblox.tech>
2 parents 78d6a60 + 622edc6 commit b29f495

File tree

4 files changed

+12
-26
lines changed

4 files changed

+12
-26
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## Fixed
10+
- Upgrade `separate_apps` example to comit-sdk 0.7.0 to fix maker auto-accept.
11+
912
## [0.5.0] - 2019-11-28
1013

1114
## Changed

new_project/examples/separate_apps/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"dependencies": {
2424
"@types/express": "^4.17.2",
2525
"axios": "^0.19.0",
26-
"comit-sdk": "^0.7.0",
26+
"comit-sdk": "^0.7.1",
2727
"dotenv": "^8.1.0",
2828
"express": "^4.17.1",
2929
"moment": "^2.24.0",

new_project/examples/separate_apps/src/maker.ts

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ function createOrder(): Order {
4949
console.log("[Maker] peer id:", peerId);
5050
console.log("[Maker] address hint:", addressHint);
5151

52-
const tryParams: TryParams = { maxTimeoutSecs: 100, tryIntervalSecs: 1 };
53-
5452
// start negotiation protocol handler so that a taker can take the order and receives the latest rate
5553

5654
const makerNegotiator = new MakerNegotiator(
@@ -68,7 +66,7 @@ function createOrder(): Order {
6866
ethereum: { network: "regtest" },
6967
},
7068
},
71-
tryParams
69+
{ maxTimeoutSecs: 1000, tryIntervalSecs: 0.1 }
7270
);
7371

7472
const makerHttpApi = new MakerHttpApi(makerNegotiator);
@@ -83,7 +81,7 @@ function createOrder(): Order {
8381
let swapHandle;
8482
while (!swapHandle) {
8583
await new Promise(r => setTimeout(r, 1000));
86-
swapHandle = await maker.comitClient.getNewSwaps().then(swaps => {
84+
swapHandle = await maker.comitClient.getOngoingSwaps().then(swaps => {
8785
if (swaps) {
8886
return swaps[0];
8987
} else {
@@ -95,15 +93,6 @@ function createOrder(): Order {
9593
const swap = await swapHandle.fetchDetails();
9694
const swapParams = swap.properties!.parameters;
9795

98-
// only accept a request if it fits to the created order above
99-
if (isValid(swapParams, order)) {
100-
console.log("Requested order is invalid");
101-
await swapHandle.decline(tryParams);
102-
process.exit();
103-
}
104-
console.log("Requested order is still valid");
105-
await swapHandle.accept(tryParams);
106-
10796
console.log(
10897
"Swap started! Swapping %d Ether for %d %s",
10998
formatEther(swapParams.alpha_asset.quantity),
@@ -113,6 +102,8 @@ function createOrder(): Order {
113102

114103
readLineSync.question("2. Continue?");
115104

105+
const tryParams: TryParams = { maxTimeoutSecs: 100, tryIntervalSecs: 1 };
106+
116107
console.log(
117108
"Bitcoin HTLC funded! TXID: ",
118109
await swapHandle.fund(tryParams)
@@ -132,11 +123,3 @@ function createOrder(): Order {
132123
);
133124
process.exit();
134125
})();
135-
136-
function isValid(swapParams: any, order: Order) {
137-
return (
138-
swapParams.alpha_asset.name !== order.ask.asset ||
139-
swapParams.beta_asset.name !== order.bid.asset ||
140-
order.validUntil < moment().unix()
141-
);
142-
}

new_project/examples/separate_apps/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -538,10 +538,10 @@ combined-stream@^1.0.6, combined-stream@~1.0.6:
538538
dependencies:
539539
delayed-stream "~1.0.0"
540540

541-
comit-sdk@^0.7.0:
542-
version "0.7.0"
543-
resolved "https://registry.yarnpkg.com/comit-sdk/-/comit-sdk-0.7.0.tgz#08cef516247e130a4eb310698a372635f584e08e"
544-
integrity sha512-KTf6H4xJ2cpRh3UwgJFSSE8AGad1cwV6MR8rrYix9Xhr9w600+ShkHMpESk0diIRXdWttRSZkbaBlNXe5fODpg==
541+
comit-sdk@^0.7.1:
542+
version "0.7.1"
543+
resolved "https://registry.yarnpkg.com/comit-sdk/-/comit-sdk-0.7.1.tgz#1853baef36067214868b289d51af2be7aaaa6994"
544+
integrity sha512-M8j6iUf8G9zf7we0aBXSZQz7dvYuUkSUtEPMxlAWinpW+Ll5vAGsAVGlVC7rDFW+k//wk1XmcnQYGQx7omNPdw==
545545
dependencies:
546546
axios "^0.19.0"
547547
bcoin "https://github.com/bcoin-org/bcoin#2496acc7a98a43f00a7b5728eb256877c1bbf001"

0 commit comments

Comments
 (0)