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

Commit 38f86a7

Browse files
bors[bot]da-kamiluckysori
authored
Merge #246
246: maker sleeps before retrieving Ethereum balance after swap r=mergify[bot] a=da-kami This PR fixes the Ethers wallet balance printing after swapping. The problem of the initial Bcoin wallet balance is not solved through this, check the updated ticket for more infos: #140 Co-authored-by: Daniel Karzel <daniel.karzel@coblox.tech> Co-authored-by: Lucas Soriano del Pino <l.soriano.del.pino@gmail.com>
2 parents 62198fe + 257230b commit 38f86a7

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
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 1 second 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: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { MakerClient, Order, TakerNegotiator, TryParams } from "comit-sdk";
22
import { formatEther } from "ethers/utils";
33
import readLineSync from "readline-sync";
44
import { toBitcoin } from "satoshi-bitcoin-ts";
5-
import { createActor } from "./lib";
5+
import { createActor, sleep } from "./lib";
66

77
/**
88
* This executable function represents the taker side during a trade.
@@ -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())
@@ -139,9 +139,15 @@ import { createActor } from "./lib";
139139

140140
console.log("Swapped!");
141141

142+
// The comit network daemon (cnd) processes new incoming blocks faster than bcoin.
143+
// This results in the final balance not being printed correctly, even though the redeem transaction was already
144+
// noticed by cnd.
145+
// In order to make sure the final balance is printed correctly we thus sleep for 1 second here.
146+
await sleep(1000);
147+
142148
// print balances after swapping
143149
console.log(
144-
"[Taker] Bitcoin balance: %f. Ether balance: %f",
150+
"[Taker] Bitcoin balance: %f, Ether balance: %f",
145151
parseFloat(await taker.bitcoinWallet.getBalance()).toFixed(2),
146152
parseFloat(
147153
formatEther(await taker.ethereumWallet.getBalance())

0 commit comments

Comments
 (0)