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

Commit 62198fe

Browse files
bors[bot]luckysori
andauthored
Merge #247
247: Use createActor function from comit-sdk r=mergify[bot] a=luckysori Fixes #199. Co-authored-by: Lucas Soriano del Pino <l.soriano.del.pino@gmail.com>
2 parents 6fd788b + 245a4ef commit 62198fe

File tree

11 files changed

+54
-127
lines changed

11 files changed

+54
-127
lines changed

new_project/examples/btc_eth/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"typescript": "^3.7.3"
2222
},
2323
"dependencies": {
24-
"comit-sdk": "^0.7.1",
24+
"comit-sdk": "^0.7.2",
2525
"dotenv": "^8.2.0",
2626
"moment": "^2.24.0",
2727
"satoshi-bitcoin-ts": "^0.2.4"

new_project/examples/btc_eth/src/index.ts

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {
2+
Actor,
23
BigNumber,
34
BitcoinWallet,
4-
Cnd,
5-
ComitClient,
5+
createActor as createActorSdk,
66
EthereumWallet,
77
SwapRequest,
88
} from "comit-sdk";
@@ -13,18 +13,12 @@ import { toBitcoin, toSatoshi } from "satoshi-bitcoin-ts";
1313
(async function main() {
1414
checkEnvFile(process.env.DOTENV_CONFIG_PATH!);
1515

16-
const maker = await startClient(0, "Maker");
17-
const taker = await startClient(1, "Taker");
16+
const maker = await createActor(0, "Maker");
17+
const taker = await createActor(1, "Taker");
1818

19-
console.log(
20-
"Maker Ethereum address: ",
21-
await maker.ethereumWallet.getAccount()
22-
);
19+
console.log("Maker Ethereum address: ", maker.ethereumWallet.getAccount());
2320

24-
console.log(
25-
"Taker Ethereum address: ",
26-
await taker.ethereumWallet.getAccount()
27-
);
21+
console.log("Taker Ethereum address: ", taker.ethereumWallet.getAccount());
2822

2923
await printBalances(maker);
3024
await printBalances(taker);
@@ -74,16 +68,7 @@ import { toBitcoin, toSatoshi } from "satoshi-bitcoin-ts";
7468
process.exit();
7569
})();
7670

77-
interface Actor {
78-
name: string;
79-
comitClient: ComitClient;
80-
peerId: string;
81-
addressHint: string;
82-
bitcoinWallet: BitcoinWallet;
83-
ethereumWallet: EthereumWallet;
84-
}
85-
86-
async function startClient(index: number, name: string): Promise<Actor> {
71+
async function createActor(index: number, name: string): Promise<Actor> {
8772
const bitcoinWallet = await BitcoinWallet.newInstance(
8873
"regtest",
8974
process.env.BITCOIN_P2P_URI!,
@@ -96,22 +81,12 @@ async function startClient(index: number, name: string): Promise<Actor> {
9681
process.env[`ETHEREUM_KEY_${index}`]!
9782
);
9883

99-
const cnd = new Cnd(process.env[`HTTP_URL_CND_${index}`]!);
100-
const peerId = await cnd.getPeerId();
101-
const addressHint = await cnd
102-
.getPeerListenAddresses()
103-
.then(addresses => addresses[0]);
104-
105-
const comitClient = new ComitClient(bitcoinWallet, ethereumWallet, cnd);
106-
107-
return {
108-
name,
109-
comitClient,
110-
peerId,
111-
addressHint,
84+
return createActorSdk(
11285
bitcoinWallet,
11386
ethereumWallet,
114-
};
87+
process.env[`HTTP_URL_CND_${index}`]!,
88+
name
89+
);
11590
}
11691

11792
function createSwap(maker: Actor, taker: Actor): SwapRequest {

new_project/examples/btc_eth/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,10 +1105,10 @@ combined-stream@^1.0.6, combined-stream@~1.0.6:
11051105
dependencies:
11061106
delayed-stream "~1.0.0"
11071107

1108-
comit-sdk@^0.7.1:
1109-
version "0.7.1"
1110-
resolved "https://registry.yarnpkg.com/comit-sdk/-/comit-sdk-0.7.1.tgz#1853baef36067214868b289d51af2be7aaaa6994"
1111-
integrity sha512-M8j6iUf8G9zf7we0aBXSZQz7dvYuUkSUtEPMxlAWinpW+Ll5vAGsAVGlVC7rDFW+k//wk1XmcnQYGQx7omNPdw==
1108+
comit-sdk@^0.7.2:
1109+
version "0.7.2"
1110+
resolved "https://registry.yarnpkg.com/comit-sdk/-/comit-sdk-0.7.2.tgz#121f3fb7409fea4b695259f9c522fd4828b579a6"
1111+
integrity sha512-9lUkYLvt9wP/B9gmfVbPS+71lUMLCqoWEh5AVe1KfDYRC3rv+Bt5V+/tso90zgeyD4LecbVoab0g737uycOB1Q==
11121112
dependencies:
11131113
axios "^0.19.0"
11141114
bcoin "https://github.com/bcoin-org/bcoin#2496acc7a98a43f00a7b5728eb256877c1bbf001"

new_project/examples/erc20_btc/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"typescript": "^3.7.3"
2121
},
2222
"dependencies": {
23-
"comit-sdk": "^0.7.1",
23+
"comit-sdk": "^0.7.2",
2424
"dotenv": "^8.1.0",
2525
"moment": "^2.24.0",
2626
"readline-sync": "^1.4.10",

new_project/examples/erc20_btc/src/index.ts

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {
2+
Actor,
23
BigNumber,
34
BitcoinWallet,
4-
Cnd,
5-
ComitClient,
5+
createActor as createActorSdk,
66
EthereumWallet,
77
SwapRequest,
88
} from "comit-sdk";
@@ -14,18 +14,12 @@ import { toBitcoin, toSatoshi } from "satoshi-bitcoin-ts";
1414
(async function main() {
1515
checkEnvFile(process.env.DOTENV_CONFIG_PATH!);
1616

17-
const maker = await startClient(0, "Maker");
18-
const taker = await startClient(1, "Taker");
17+
const maker = await createActor(0, "Maker");
18+
const taker = await createActor(1, "Taker");
1919

20-
console.log(
21-
"Maker Ethereum address: ",
22-
await maker.ethereumWallet.getAccount()
23-
);
20+
console.log("Maker Ethereum address: ", maker.ethereumWallet.getAccount());
2421

25-
console.log(
26-
"Taker Ethereum address: ",
27-
await taker.ethereumWallet.getAccount()
28-
);
22+
console.log("Taker Ethereum address: ", taker.ethereumWallet.getAccount());
2923

3024
await printBalances(maker);
3125
await printBalances(taker);
@@ -90,16 +84,7 @@ import { toBitcoin, toSatoshi } from "satoshi-bitcoin-ts";
9084
process.exit();
9185
})();
9286

93-
interface Actor {
94-
name: string;
95-
comitClient: ComitClient;
96-
peerId: string;
97-
addressHint: string;
98-
bitcoinWallet: BitcoinWallet;
99-
ethereumWallet: EthereumWallet;
100-
}
101-
102-
async function startClient(index: number, name: string): Promise<Actor> {
87+
async function createActor(index: number, name: string): Promise<Actor> {
10388
const bitcoinWallet = await BitcoinWallet.newInstance(
10489
"regtest",
10590
process.env.BITCOIN_P2P_URI!,
@@ -112,22 +97,12 @@ async function startClient(index: number, name: string): Promise<Actor> {
11297
process.env[`ETHEREUM_KEY_${index}`]!
11398
);
11499

115-
const cnd = new Cnd(process.env[`HTTP_URL_CND_${index}`]!);
116-
const peerId = await cnd.getPeerId();
117-
const addressHint = await cnd
118-
.getPeerListenAddresses()
119-
.then(addresses => addresses[0]);
120-
121-
const comitClient = new ComitClient(bitcoinWallet, ethereumWallet, cnd);
122-
123-
return {
124-
name,
125-
comitClient,
126-
peerId,
127-
addressHint,
100+
return createActorSdk(
128101
bitcoinWallet,
129102
ethereumWallet,
130-
};
103+
process.env[`HTTP_URL_CND_${index}`]!,
104+
name
105+
);
131106
}
132107

133108
function createSwap(maker: Actor, taker: Actor): SwapRequest {

new_project/examples/erc20_btc/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -483,10 +483,10 @@ combined-stream@^1.0.6, combined-stream@~1.0.6:
483483
dependencies:
484484
delayed-stream "~1.0.0"
485485

486-
comit-sdk@^0.7.1:
487-
version "0.7.1"
488-
resolved "https://registry.yarnpkg.com/comit-sdk/-/comit-sdk-0.7.1.tgz#1853baef36067214868b289d51af2be7aaaa6994"
489-
integrity sha512-M8j6iUf8G9zf7we0aBXSZQz7dvYuUkSUtEPMxlAWinpW+Ll5vAGsAVGlVC7rDFW+k//wk1XmcnQYGQx7omNPdw==
486+
comit-sdk@^0.7.2:
487+
version "0.7.2"
488+
resolved "https://registry.yarnpkg.com/comit-sdk/-/comit-sdk-0.7.2.tgz#121f3fb7409fea4b695259f9c522fd4828b579a6"
489+
integrity sha512-9lUkYLvt9wP/B9gmfVbPS+71lUMLCqoWEh5AVe1KfDYRC3rv+Bt5V+/tso90zgeyD4LecbVoab0g737uycOB1Q==
490490
dependencies:
491491
axios "^0.19.0"
492492
bcoin "https://github.com/bcoin-org/bcoin#2496acc7a98a43f00a7b5728eb256877c1bbf001"

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: ",

0 commit comments

Comments
 (0)