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

Commit 7caf0f7

Browse files
committed
Use comit-sdk.createActor in separate_apps
1 parent a881d2a commit 7caf0f7

File tree

5 files changed

+22
-45
lines changed

5 files changed

+22
-45
lines 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.1",
26+
"comit-sdk": "^0.7.2",
2727
"dotenv": "^8.1.0",
2828
"express": "^4.17.1",
2929
"moment": "^2.24.0",

new_project/examples/separate_apps/src/lib.ts

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
import { BitcoinWallet, Cnd, ComitClient, EthereumWallet } from "comit-sdk";
1+
import {
2+
Actor,
3+
BitcoinWallet,
4+
createActor as createActorSdk,
5+
EthereumWallet,
6+
} from "comit-sdk";
27
import fs from "fs";
38

4-
export async function startClient(index: number): Promise<Actor> {
9+
export async function createActor(index: number): Promise<Actor> {
510
checkEnvFile(process.env.DOTENV_CONFIG_PATH!);
611

712
const bitcoinWallet = await BitcoinWallet.newInstance(
@@ -17,29 +22,11 @@ export async function startClient(index: number): Promise<Actor> {
1722
process.env[`ETHEREUM_KEY_${index}`]!
1823
);
1924

20-
const cnd = new Cnd(process.env[`HTTP_URL_CND_${index}`]!);
21-
const peerId = await cnd.getPeerId();
22-
const addressHint = await cnd
23-
.getPeerListenAddresses()
24-
.then(addresses => addresses[0]);
25-
26-
const comitClient = new ComitClient(bitcoinWallet, ethereumWallet, cnd);
27-
28-
return {
29-
comitClient,
30-
peerId,
31-
addressHint,
25+
return await createActorSdk(
3226
bitcoinWallet,
3327
ethereumWallet,
34-
};
35-
}
36-
37-
export interface Actor {
38-
comitClient: ComitClient;
39-
peerId: string;
40-
addressHint: string;
41-
bitcoinWallet: BitcoinWallet;
42-
ethereumWallet: EthereumWallet;
28+
process.env[`HTTP_URL_CND_${index}`]!
29+
);
4330
}
4431

4532
export function checkEnvFile(path: string) {

new_project/examples/separate_apps/src/maker.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
import {
2-
MakerHttpApi,
3-
MakerNegotiator,
4-
} from "comit-sdk/dist/src/negotiation/maker_negotiator";
5-
import { Order } from "comit-sdk/dist/src/negotiation/order";
6-
import { TryParams } from "comit-sdk/dist/src/timeout_promise";
1+
import { MakerHttpApi, MakerNegotiator, Order, TryParams } from "comit-sdk";
72
import { formatEther } from "ethers/utils";
83
import moment from "moment";
94
import readLineSync from "readline-sync";
105
import { toBitcoin } from "satoshi-bitcoin-ts";
11-
import { startClient } from "./lib";
6+
import { createActor } from "./lib";
127

138
/**
149
* This executable function represents the maker side during a trade.
@@ -24,7 +19,7 @@ import { startClient } from "./lib";
2419
*/
2520
(async function main() {
2621
// Initialize the maker Actor
27-
const maker = await startClient(0);
22+
const maker = await createActor(0);
2823

2924
// print balances before swapping
3025
console.log(

new_project/examples/separate_apps/src/taker.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
import { Order } from "comit-sdk/dist/src/negotiation/order";
2-
import {
3-
MakerClient,
4-
TakerNegotiator,
5-
} from "comit-sdk/dist/src/negotiation/taker_negotiator";
6-
import { TryParams } from "comit-sdk/dist/src/timeout_promise";
1+
import { MakerClient, Order, TakerNegotiator, TryParams } from "comit-sdk";
72
import { formatEther } from "ethers/utils";
83
import readLineSync from "readline-sync";
94
import { toBitcoin } from "satoshi-bitcoin-ts";
10-
import { startClient } from "./lib";
5+
import { createActor } from "./lib";
116

127
/**
138
* This executable function represents the taker side during a trade.
@@ -24,7 +19,7 @@ import { startClient } from "./lib";
2419
*/
2520
(async function main() {
2621
// Initialize the taker Actor
27-
const taker = await startClient(1);
22+
const taker = await createActor(1);
2823

2924
// print balances before swapping
3025
console.log(
@@ -101,7 +96,7 @@ import { startClient } from "./lib";
10196
readLineSync.question("2. Continue funding the Ethereum HTLC?");
10297

10398
// Define how often and how long the comit-js-sdk should try to execute the fund and redeem action.
104-
const tryParams: TryParams = { maxTimeoutSecs: 100, tryIntervalSecs: 1 };
99+
const tryParams: TryParams = { maxTimeoutSecs: 100, tryIntervalSecs: 1 };
105100

106101
console.log(
107102
"Ethereum HTLC funded! TXID: ",

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.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==
541+
comit-sdk@^0.7.2:
542+
version "0.7.2"
543+
resolved "https://registry.yarnpkg.com/comit-sdk/-/comit-sdk-0.7.2.tgz#121f3fb7409fea4b695259f9c522fd4828b579a6"
544+
integrity sha512-9lUkYLvt9wP/B9gmfVbPS+71lUMLCqoWEh5AVe1KfDYRC3rv+Bt5V+/tso90zgeyD4LecbVoab0g737uycOB1Q==
545545
dependencies:
546546
axios "^0.19.0"
547547
bcoin "https://github.com/bcoin-org/bcoin#2496acc7a98a43f00a7b5728eb256877c1bbf001"

0 commit comments

Comments
 (0)