Skip to content

Commit

Permalink
Update create node command
Browse files Browse the repository at this point in the history
  • Loading branch information
tsmith123 committed Jun 28, 2024
1 parent d2fe8bc commit 95056a1
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 32 deletions.
29 changes: 8 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,34 @@ This should display the commands available to you.

### Init

Get an API key. Keys are currently limited due to beta testing.
Get an API key.

```
nodana init
-y (auto accept Nodana's terms and conditions)
```

After calling `nodana init`, the CLI will save your API key in a local file. The key will automatically be included in future requests. You can override this by providing the API key manually using the `-k <key>` option.
After calling `nodana init`, the CLI will save your API key in a local file. The key will automatically be included in future requests.

### During Beta Testing

During our beta testing period, running `nodana init` will automatically enrol you on the program and you will get your free sats added to your API key automatically. These free sats should give you plenty of time to test out Nodana.
### Create Invoice

### After Beta Testing
Create a Lightning invoice to top up the credit on your API key.

If you have joined after our beta testing period you won't get any sats attached to your API key automatically. You will instead need to run `nodana invoice` to create an invoice, choosing how many sats you would like the invoice to be for. The response will include a url that you can visit to make payment. Don't forget your Lightning wallet.
```
nodana create invoice
-v <value> (Amount in sats, min: 1k, max: 1m)
```

### Create Node

Create and start a node.

```
nodana create node
-n <name>
-p <password>
-s <seed>
-a <autoLiquidity>
-w <webhook>
-x <webhookSecret>
```

### Start
Expand Down Expand Up @@ -85,16 +82,6 @@ Delete a node.
nodana delete <nodeId>
```

### Create Invoice

Create a Lightning invoice to top up the credit on your API key.

```
nodana create invoice
-v <value> (Amount in sats, min: 1k, max: 1m)
```

### Status

Check the credit balance for your API key.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nodana/nodana-cli",
"version": "0.3.1",
"version": "0.4.0",
"description": "Lightning node infrastructure as a service",
"repository": {
"type": "git",
Expand Down
20 changes: 18 additions & 2 deletions src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ export const getAuthHeader = (key: string) => {
};
};

export const cleanOptions = (options: any) => {
const optionsCopy = { ...options };

delete optionsCopy.key;
delete optionsCopy.yes;

return optionsCopy;
};

export const init = async () => {
try {
const response = await request._call("/keys", "POST", {}, {});
Expand All @@ -41,7 +50,9 @@ export const createNode = async (options: any) => {
const key = await getAuthKey(options);

try {
return request._call("/containers", "POST", getAuthHeader(key), options);
return request._call("/containers", "POST", getAuthHeader(key), {
config: cleanOptions(options),
});
} catch (e: any) {
throw e;
}
Expand Down Expand Up @@ -101,7 +112,12 @@ export const createInvoice = async (options: any) => {
const key = await getAuthKey(options);

try {
return request._call("/invoices", "POST", getAuthHeader(key), options);
return request._call(
"/invoices",
"POST",
getAuthHeader(key),
cleanOptions(options)
);
} catch (e: any) {
throw e;
}
Expand Down
2 changes: 0 additions & 2 deletions src/commands/node/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { error, info, success } from "../../helpers/output";

type Props = {
key?: string;
password?: string;
seed?: string;
autoLiquidity?: string;
webhook?: string;
yes?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/node/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const print = (nodes: any) => {
console.log(chalk.yellow("ID:"), node.id);
node.name && console.log(chalk.yellow("Name:"), node.name);
console.log(chalk.yellow("Connection Url:"), node.connectionUrl);
console.log(chalk.yellow("Age"), getDurationString(node.age));
console.log(chalk.yellow("Age"), node.age);
console.log(chalk.yellow("Fee"), `${node.fee.toLocaleString()} sats`);
console.log(chalk.yellow("Status"), node.status);
console.log(chalk.yellow("Version"), node.version);
Expand Down
6 changes: 3 additions & 3 deletions src/commands/node/stop.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
const chalk = require("chalk");
import * as client from "../../client";
import { error, info } from "../../helpers/output";
import { sleep } from "../../helpers/date";
// import { sleep } from "../../helpers/date";

type Options = {
key?: string;
};

const DELAY = 5000;
// const DELAY = 5000;

export default async (id: string, options: Options) => {
try {
info(`Stopping. Please wait...`);
const response = await client.stopNode(id, options);
await sleep(DELAY); // wait 5 seconds instead of blocking thread on api
// await sleep(DELAY); // wait 5 seconds instead of blocking thread on api

print(response);
} catch (e: any) {
Expand Down
11 changes: 9 additions & 2 deletions tests/client/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ describe("client", () => {
"/containers",
"POST",
authHeader,
options
{
config: {
password: "12345",
},
}
);
});
});
Expand Down Expand Up @@ -153,7 +157,10 @@ describe("client", () => {
"/invoices",
"POST",
authHeader,
options
{
value: 1000,
memo: "Test memo",
}
);
});
});
Expand Down

0 comments on commit 95056a1

Please sign in to comment.