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

Commit 24f7acf

Browse files
bors[bot]luckysori
andauthored
Merge #257
257: Improve template project experience r=luckysori a=luckysori Fixes #205. Co-authored-by: Lucas Soriano del Pino <l.soriano.del.pino@gmail.com>
2 parents 38f86a7 + 6c4fe92 commit 24f7acf

File tree

7 files changed

+83
-5
lines changed

7 files changed

+83
-5
lines changed

new_project/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
yarn-error.log
2+
node_modules/

new_project/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
This project was bootstrapped with [Create Comit App](https://github.com/comit-network/create-comit-app).
2+
3+
## Available Scripts
4+
5+
In the project directory, you can run:
6+
7+
### `yarn create comit-app start-env`
8+
9+
Sets up the development environment, starting blockchain nodes and COMIT nodes.
10+
11+
This command will take hold of your terminal; to run an application using the environment you will have to use a separate terminal.
12+
To clean up the environment, press `CTRL-C`.
13+
14+
### `yarn start`
15+
16+
Displays the environment variables created during environment set-up.
17+
18+
## Example Projects
19+
20+
There are 3 example projects included in the `examples` directory which may guide you when developing your COMIT application:
21+
22+
- [Simple Bitcoin for Ether atomic swap using COMIT](./examples/btc_eth/README.md).
23+
- [Simple ERC20 token for Bitcoin atomic swap using COMIT](./examples/erc20_btc/README.md).
24+
- [Two applications interacting to negotiate and execute an atomic swap](./examples/separate_apps/README.md).

new_project/examples/btc_eth/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ function createSwap(maker: Actor, taker: Actor): SwapRequest {
123123
function checkEnvFile(path: string) {
124124
if (!fs.existsSync(path)) {
125125
console.log(
126-
"Could not find %s file. Did you run \\`create-comit-app start-env\\`?",
126+
"Could not find file %s. Did you run `yarn create comit-app start-env`?",
127127
path
128128
);
129129
process.exit(1);

new_project/examples/erc20_btc/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ function createSwap(maker: Actor, taker: Actor): SwapRequest {
140140
function checkEnvFile(path: string) {
141141
if (!fs.existsSync(path)) {
142142
console.log(
143-
"Could not find %s file. Did you run \\`create-comit-app start-env\\`?",
143+
"Could not find file %s. Did you run `yarn create comit-app start-env`?",
144144
path
145145
);
146146
process.exit(1);

new_project/examples/separate_apps/src/lib.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export async function createActor(index: number): Promise<Actor> {
3232
export function checkEnvFile(path: string) {
3333
if (!fs.existsSync(path)) {
3434
console.log(
35-
"Could not find %s file. Did you run \\`create-comit-app start-env\\`?",
35+
"Could not find file %s. Did you run `yarn create comit-app start-env`?",
3636
path
3737
);
3838
process.exit(1);

new_project/package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
{
22
"name": "new_project",
3-
"version": "1.0.0",
3+
"version": "0.1.0",
4+
"private": true,
5+
"main": "index.js",
6+
"scripts": {
7+
"start": "DOTENV_CONFIG_PATH=$HOME/.create-comit-app/env node -r dotenv/config ./src/index.js"
8+
},
49
"dependencies": {
5-
"comit-sdk": "^0.7.0"
10+
"comit-sdk": "^0.7.1",
11+
"dotenv": "^8.2.0",
12+
"readline-sync": "^1.4.10"
613
}
714
}

new_project/src/index.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const fs = require("fs");
2+
3+
const configPath = process.env.DOTENV_CONFIG_PATH;
4+
5+
if (fs.existsSync(configPath)) {
6+
console.log("Environment configuration:");
7+
8+
// Bitcoin HD keys with address funded during environment set-up.
9+
// Used to initialize Bitcoin wallets with funds.
10+
console.log("Bitcoin HD keys:");
11+
console.log("1. ", process.env.BITCOIN_HD_KEY_0);
12+
console.log("2. ", process.env.BITCOIN_HD_KEY_1);
13+
14+
// The URI of the regtest Bitcoin node created during environment set-up.
15+
// Used to initialize Bitcoin wallets connected to the correct local network.
16+
console.log("Bitcoin node P2P URI: ", process.env.BITCOIN_P2P_URI);
17+
18+
// Ethereum private keys with address funded during environment set-up.
19+
// Used to initialize Ethereum wallets with funds.
20+
console.log("Ethereum private keys:");
21+
console.log("1. ", process.env.ETHEREUM_KEY_0);
22+
console.log("2. ", process.env.ETHEREUM_KEY_1);
23+
24+
// The URL for the HTTP API of the regtest Ethereum node created during environment set-up.
25+
// Used to initialize Ethereum wallets connected to the correct local network.
26+
console.log("Ethereum node HTTP URL: ", process.env.ETHEREUM_NODE_HTTP_URL);
27+
28+
// The contract address of the ERC20 token deployed on the regtest network during environment set-up.
29+
// Used to identify the ERC20 token when performing swaps.
30+
console.log(
31+
"ERC20 token contract address: ",
32+
process.env.ERC20_CONTRACT_ADDRESS
33+
);
34+
35+
// HTTP API URLs for the instances of cnd created during environment set-up.
36+
// Used to interact with said instances of cnd. In particular, it allows for
37+
// instantiating `ComitClient`s when using `comit-sdk`.
38+
console.log("cnd HTTP API URLs:");
39+
console.log("1. ", process.env.HTTP_URL_CND_0);
40+
console.log("2. ", process.env.HTTP_URL_CND_1);
41+
} else {
42+
console.log(
43+
"Could not find file %s. Did you run `yarn create comit-app start-env`?",
44+
configPath
45+
);
46+
}

0 commit comments

Comments
 (0)