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

Commit 016394d

Browse files
da-kamiluckysori
authored andcommitted
maker sleeps before retrieving Ethereum balance after swap
1 parent 62198fe commit 016394d

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

new_project/examples/separate_apps/src/lib.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,7 @@ export function checkEnvFile(path: string) {
3838
process.exit(1);
3939
}
4040
}
41+
42+
export async function sleep(ms: number) {
43+
return new Promise(resolve => setTimeout(resolve, ms));
44+
}

new_project/examples/separate_apps/src/maker.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { formatEther } from "ethers/utils";
33
import moment from "moment";
44
import readLineSync from "readline-sync";
55
import { toBitcoin } from "satoshi-bitcoin-ts";
6-
import { createActor } from "./lib";
6+
import { createActor, sleep } from "./lib";
77

88
/**
99
* This executable function represents the maker side during a trade.
@@ -23,7 +23,7 @@ import { createActor } from "./lib";
2323

2424
// print balances before swapping
2525
console.log(
26-
"[Maker] Bitcoin balance: %f. Ether balance: %f",
26+
"[Maker] Bitcoin balance: %f, Ether balance: %f",
2727
parseFloat(await maker.bitcoinWallet.getBalance()).toFixed(2),
2828
parseFloat(
2929
formatEther(await maker.ethereumWallet.getBalance())
@@ -164,9 +164,15 @@ import { createActor } from "./lib";
164164

165165
console.log("Swapped!");
166166

167+
// The comit network daemon (cnd) processes new incoming blocks faster than etherjs.
168+
// This results in the final balance not being printed correctly, even though the redeem transaction was already
169+
// noticed by cnd.
170+
// In order to make sure the final balance is printed correctly we thus sleep for 500ms here.
171+
await sleep(1000);
172+
167173
// print balances after swapping
168174
console.log(
169-
"[Maker] Bitcoin balance: %f. Ether balance: %f",
175+
"[Maker] Bitcoin balance: %f, Ether balance: %f",
170176
parseFloat(await maker.bitcoinWallet.getBalance()).toFixed(2),
171177
parseFloat(
172178
formatEther(await maker.ethereumWallet.getBalance())

new_project/examples/separate_apps/src/taker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { createActor } from "./lib";
2323

2424
// print balances before swapping
2525
console.log(
26-
"[Taker] Bitcoin balance: %f. Ether balance: %f",
26+
"[Taker] Bitcoin balance: %f, Ether balance: %f",
2727
parseFloat(await taker.bitcoinWallet.getBalance()).toFixed(2),
2828
parseFloat(
2929
formatEther(await taker.ethereumWallet.getBalance())
@@ -141,7 +141,7 @@ import { createActor } from "./lib";
141141

142142
// print balances after swapping
143143
console.log(
144-
"[Taker] Bitcoin balance: %f. Ether balance: %f",
144+
"[Taker] Bitcoin balance: %f, Ether balance: %f",
145145
parseFloat(await taker.bitcoinWallet.getBalance()).toFixed(2),
146146
parseFloat(
147147
formatEther(await taker.ethereumWallet.getBalance())

0 commit comments

Comments
 (0)