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

Commit

Permalink
Merge #407
Browse files Browse the repository at this point in the history
407: Use MakerNegotiator.getUrl(), remove steps for `TakerNegotiator` r=mergify[bot] a=D4nte

Resolves #371 and comit-network/comit-js-sdk#90.

Co-authored-by: Franck Royer <franck@coblox.tech>
  • Loading branch information
bors[bot] and Franck Royer authored Feb 1, 2020
2 parents a301dba + 3bfdb67 commit 56c7ebc
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 16 deletions.
3 changes: 3 additions & 0 deletions create/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## Changed
- Upgrade `examples/btc_eth` to `comit-sdk@0.10.0`

## [0.8.2] - 2020-01-17

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion create/new_project/examples/btc_eth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"dependencies": {
"@types/express": "^4.17.2",
"axios": "^0.19.2",
"comit-sdk": "^0.9.1",
"comit-sdk": "^0.10.0",
"dotenv": "^8.1.0",
"express": "^4.17.1",
"moment": "^2.24.0",
Expand Down
15 changes: 7 additions & 8 deletions create/new_project/examples/btc_eth/src/maker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MakerHttpApi, MakerNegotiator, Order, TryParams } from "comit-sdk";
import { MakerNegotiator, Order, TryParams } from "comit-sdk";
import { formatEther } from "ethers/utils";
import moment from "moment";
import readLineSync from "readline-sync";
Expand Down Expand Up @@ -59,9 +59,8 @@ import { createActor, sleep } from "./lib";
);

// Start the HTTP service used to publish orders.
const makerHttpApi = new MakerHttpApi(makerNegotiator);
// The maker's HTTP service will be served at port 2318.
makerHttpApi.listen(2318);
// The maker's HTTP service will be served at http://localhost:2318/
await makerNegotiator.listen(2318, "localhost");
// Create an order to be published.
const order: Order = {
id: "123",
Expand All @@ -82,10 +81,10 @@ import { createActor, sleep } from "./lib";
// Publish the order so the taker can take it.
makerNegotiator.addOrder(order);

// Let the world know that there is an order available.
// In a real-world application this information could be shared publicly, e.g. on social medias.
const invitationDetails = `http://localhost:2318/orders/ETH-BTC`;
console.log(`Waiting for someone taking my order at: ${invitationDetails}`);
// Let the world know that you are a maker.
// Your app could publish this link on a forum or social media so takers can connect to you.
const link = makerNegotiator.getUrl();
console.log(`Waiting for someone to take my order at: ${link}`);

// Wait for a taker to accept the order and send a swap request through the comit network daemon (cnd).
let swapHandle;
Expand Down
13 changes: 10 additions & 3 deletions create/new_project/examples/btc_eth/src/taker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MakerClient, TakerNegotiator, TryParams } from "comit-sdk";
import { TakerNegotiator, TryParams } from "comit-sdk";
import { formatEther } from "ethers/utils";
import readLineSync from "readline-sync";
import { toBitcoin } from "satoshi-bitcoin-ts";
Expand Down Expand Up @@ -33,13 +33,20 @@ import { createActor, sleep } from "./lib";
// Wait for commandline input for demo purposes
readLineSync.question("1. Ready to accept and order from the maker?");

// This URL needs to be provided by the other party, the maker.
// `MakerNegotiator.getUrl()` on the Maker side returns this url.
// It is only hardcoded here for simplicity.
const makerNegotiatorUrl = "http://localhost:2318/";

// Initialize the taker negotiator that defines the negotiation phase of the trade.
// The taker negotiator manages retrieving orders from the maker and deciding if they are acceptable for the taker.
// Once an order was taken by a taker the negotiator hands over the order and execution parameters to the
// execution phase.

const makerClient = new MakerClient("http://localhost:2318/");
const takerNegotiator = new TakerNegotiator(taker.comitClient, makerClient);
const takerNegotiator = new TakerNegotiator(
taker.comitClient,
makerNegotiatorUrl
);

const order = await takerNegotiator.getOrderByTradingPair(
// Define the trading pair to request and order for.
Expand Down
8 changes: 4 additions & 4 deletions create/new_project/examples/btc_eth/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -576,10 +576,10 @@ comit-scripts@^0.8.2:
axios "^0.19.0"
targz "^1.0.1"

comit-sdk@^0.9.1:
version "0.9.1"
resolved "https://registry.yarnpkg.com/comit-sdk/-/comit-sdk-0.9.1.tgz#46cdfc8abe3c3b132cb91b1a688beee2ece1ce2e"
integrity sha512-RvecE3FFmiKGVXoUTXF0QIm56GIRXn9DlnS2SmI0kcsz/f0nhrPr5nQgdIt9juaGzNoCMMTqJgZmy4ATscMWDg==
comit-sdk@^0.10.0:
version "0.10.0"
resolved "https://registry.yarnpkg.com/comit-sdk/-/comit-sdk-0.10.0.tgz#ba24039612975e8006c7a235fd5165bb248f1ae1"
integrity sha512-4JMeIypj0kaMSGUYyNkkzDJeJlF4ktFH1Ss1BX/zRxzgLVoWgf0g5BTzGZ95HydqyWT+rorCgLqIuMAwmEy+7Q==
dependencies:
axios "^0.19.0"
bcoin "https://github.com/bcoin-org/bcoin#2496acc7a98a43f00a7b5728eb256877c1bbf001"
Expand Down

0 comments on commit 56c7ebc

Please sign in to comment.