Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to pass hostname in nitro-rpc-client cli #13

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
node-version: "18.15.0"
- name: "Install dependencies and build packages"
run: |
cd ./nitro-protocol
cd ./packages/nitro-protocol
npm ci --legacy-peer-deps
- name: Configure git.vdb.to npm registry
run: |
Expand Down
44 changes: 31 additions & 13 deletions packages/nitro-rpc-client/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import yargs from "yargs/yargs";
import { hideBin } from "yargs/helpers";

import { NitroRpcClient } from "./rpc-client";
import { compactJson, getLocalRPCUrl, logOutChannelUpdates } from "./utils";
import { compactJson, getCustomRPCUrl, logOutChannelUpdates } from "./utils";

yargs(hideBin(process.argv))
.scriptName("nitro-rpc-client")
Expand All @@ -18,16 +18,23 @@ yargs(hideBin(process.argv))
type: "boolean",
description: "Whether channel notifications are printed to the console",
},
h: {
alias: "host",
default: "127.0.0.1",
type: "string",
description: "Custom hostname",
},
})
.command(
"version",
"Get the version of the Nitro RPC server",
async () => {},
async (yargs) => {
const rpcPort = yargs.p;
const rpcHost = yargs.h;

const rpcClient = await NitroRpcClient.CreateHttpNitroClient(
getLocalRPCUrl(rpcPort)
getCustomRPCUrl(rpcHost, rpcPort)
);
const version = await rpcClient.GetVersion();
console.log(version);
Expand All @@ -41,9 +48,10 @@ yargs(hideBin(process.argv))
async () => {},
async (yargs) => {
const rpcPort = yargs.p;
const rpcHost = yargs.h;

const rpcClient = await NitroRpcClient.CreateHttpNitroClient(
getLocalRPCUrl(rpcPort)
getCustomRPCUrl(rpcHost, rpcPort)
);
const address = await rpcClient.GetAddress();
console.log(address);
Expand All @@ -57,9 +65,10 @@ yargs(hideBin(process.argv))
async () => {},
async (yargs) => {
const rpcPort = yargs.p;
const rpcHost = yargs.h;

const rpcClient = await NitroRpcClient.CreateHttpNitroClient(
getLocalRPCUrl(rpcPort)
getCustomRPCUrl(rpcHost, rpcPort)
);
const ledgers = await rpcClient.GetAllLedgerChannels();
for (const ledger of ledgers) {
Expand All @@ -82,9 +91,10 @@ yargs(hideBin(process.argv))

async (yargs) => {
const rpcPort = yargs.p;
const rpcHost = yargs.h;

const rpcClient = await NitroRpcClient.CreateHttpNitroClient(
getLocalRPCUrl(rpcPort)
getCustomRPCUrl(rpcHost, rpcPort)
);
const paymentChans = await rpcClient.GetPaymentChannelsByLedger(
yargs.ledgerId
Expand Down Expand Up @@ -115,9 +125,10 @@ yargs(hideBin(process.argv))
},
async (yargs) => {
const rpcPort = yargs.p;
const rpcHost = yargs.h;

const rpcClient = await NitroRpcClient.CreateHttpNitroClient(
getLocalRPCUrl(rpcPort)
getCustomRPCUrl(rpcHost, rpcPort)
);
if (yargs.n) logOutChannelUpdates(rpcClient);

Expand Down Expand Up @@ -146,9 +157,10 @@ yargs(hideBin(process.argv))
},
async (yargs) => {
const rpcPort = yargs.p;
const rpcHost = yargs.h;

const rpcClient = await NitroRpcClient.CreateHttpNitroClient(
getLocalRPCUrl(rpcPort)
getCustomRPCUrl(rpcHost, rpcPort)
);
if (yargs.n) logOutChannelUpdates(rpcClient);

Expand Down Expand Up @@ -179,9 +191,10 @@ yargs(hideBin(process.argv))
},
async (yargs) => {
const rpcPort = yargs.p;
const rpcHost = yargs.h;

const rpcClient = await NitroRpcClient.CreateHttpNitroClient(
getLocalRPCUrl(rpcPort)
getCustomRPCUrl(rpcHost, rpcPort)
);
if (yargs.n) logOutChannelUpdates(rpcClient);

Expand Down Expand Up @@ -220,9 +233,10 @@ yargs(hideBin(process.argv))
},
async (yargs) => {
const rpcPort = yargs.p;
const rpcHost = yargs.h;

const rpcClient = await NitroRpcClient.CreateHttpNitroClient(
getLocalRPCUrl(rpcPort)
getCustomRPCUrl(rpcHost, rpcPort)
);

if (yargs.n) logOutChannelUpdates(rpcClient);
Expand All @@ -248,9 +262,10 @@ yargs(hideBin(process.argv))
},
async (yargs) => {
const rpcPort = yargs.p;
const rpcHost = yargs.h;

const rpcClient = await NitroRpcClient.CreateHttpNitroClient(
getLocalRPCUrl(rpcPort)
getCustomRPCUrl(rpcHost, rpcPort)
);

const ledgerInfo = await rpcClient.GetLedgerChannel(yargs.channelId);
Expand All @@ -271,9 +286,10 @@ yargs(hideBin(process.argv))
},
async (yargs) => {
const rpcPort = yargs.p;
const rpcHost = yargs.h;

const rpcClient = await NitroRpcClient.CreateHttpNitroClient(
getLocalRPCUrl(rpcPort)
getCustomRPCUrl(rpcHost, rpcPort)
);
const paymentChannelInfo = await rpcClient.GetPaymentChannel(
yargs.channelId
Expand Down Expand Up @@ -301,9 +317,10 @@ yargs(hideBin(process.argv))
},
async (yargs) => {
const rpcPort = yargs.p;
const rpcHost = yargs.h;

const rpcClient = await NitroRpcClient.CreateHttpNitroClient(
getLocalRPCUrl(rpcPort)
getCustomRPCUrl(rpcHost, rpcPort)
);
if (yargs.n) logOutChannelUpdates(rpcClient);

Expand Down Expand Up @@ -334,9 +351,10 @@ yargs(hideBin(process.argv))
},
async (yargs) => {
const rpcPort = yargs.p;
const rpcHost = yargs.h;

const rpcClient = await NitroRpcClient.CreateHttpNitroClient(
getLocalRPCUrl(rpcPort)
getCustomRPCUrl(rpcHost, rpcPort)
);
if (yargs.n) logOutChannelUpdates(rpcClient);

Expand Down
4 changes: 4 additions & 0 deletions packages/nitro-rpc-client/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ export function getLocalRPCUrl(port: number): string {
return `127.0.0.1:${port}/${RPC_PATH}`;
}

export function getCustomRPCUrl(host: string, port: number): string {
return `${host}:${port}/${RPC_PATH}`;
}

export async function logOutChannelUpdates(rpcClient: NitroRpcClient) {
const shortAddress = (await rpcClient.GetAddress()).slice(0, 8);

Expand Down
100 changes: 50 additions & 50 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1876,6 +1876,56 @@ __metadata:
languageName: node
linkType: hard

"@cerc-io/nitro-protocol@workspace:packages/nitro-protocol":
version: 0.0.0-use.local
resolution: "@cerc-io/nitro-protocol@workspace:packages/nitro-protocol"
dependencies:
"@nomicfoundation/hardhat-network-helpers": ^1.0.3
"@nomiclabs/hardhat-ethers": ^2.1.1
"@nomiclabs/hardhat-etherscan": ^3.0.0
"@nomiclabs/hardhat-waffle": ^2.0.2
"@openzeppelin/contracts": ^4.7.3
"@statechannels/devtools": ^0.5.7
"@statechannels/exit-format": ^0.2.0
"@typechain/ethers-v5": ^9.0.0
"@typechain/hardhat": ^4.0.0
"@types/jest": 29.5.0
"@types/lodash.isequal": ^4.5.5
"@types/lodash.shuffle": ^4.2.6
"@types/mocha": ^9.1.0
"@types/node": ^18.11.3
"@types/wait-on": ^5.3.1
"@typescript-eslint/eslint-plugin": ^5.59.0
"@typescript-eslint/parser": ^5.59.0
axios: 0.25.0
chai: ^4.3.6
dotenv: ^14.3.2
eslint: 7.17.0
eslint-config-prettier: ^8.5.0
eslint-plugin-import: ^2.26.0
eslint-plugin-prettier: 3.3.1
ethereum-waffle: ^3.4.0
ethers: ^5.5.4
hardhat: ^2.17.2
hardhat-deploy: ^0.10.4
hardhat-deploy-ethers: ^0.3.0-beta.13
hardhat-gas-reporter: ^1.0.7
hardhat-watcher: ^2.3.0
jest: 29.5.0
lodash.isequal: ^4.5.0
lodash.shuffle: ^4.2.0
prettier: ^2.6.2
prettier-plugin-solidity: ^1.0.0-beta.19
solhint: ^3.3.7
solidity-coverage: ^0.8.4
ts-jest: 29.1.0
ts-node: ^10.4.0
typechain: ^8.0.0
typescript: ^4.6.3
wait-on: ^6.0.1
languageName: unknown
linkType: soft

"@chainsafe/as-sha256@npm:^0.3.1":
version: 0.3.1
resolution: "@chainsafe/as-sha256@npm:0.3.1"
Expand Down Expand Up @@ -4479,56 +4529,6 @@ __metadata:
languageName: node
linkType: hard

"@statechannels/nitro-protocol@workspace:packages/nitro-protocol":
version: 0.0.0-use.local
resolution: "@statechannels/nitro-protocol@workspace:packages/nitro-protocol"
dependencies:
"@nomicfoundation/hardhat-network-helpers": ^1.0.3
"@nomiclabs/hardhat-ethers": ^2.1.1
"@nomiclabs/hardhat-etherscan": ^3.0.0
"@nomiclabs/hardhat-waffle": ^2.0.2
"@openzeppelin/contracts": ^4.7.3
"@statechannels/devtools": ^0.5.7
"@statechannels/exit-format": ^0.2.0
"@typechain/ethers-v5": ^9.0.0
"@typechain/hardhat": ^4.0.0
"@types/jest": 29.5.0
"@types/lodash.isequal": ^4.5.5
"@types/lodash.shuffle": ^4.2.6
"@types/mocha": ^9.1.0
"@types/node": ^18.11.3
"@types/wait-on": ^5.3.1
"@typescript-eslint/eslint-plugin": ^5.59.0
"@typescript-eslint/parser": ^5.59.0
axios: 0.25.0
chai: ^4.3.6
dotenv: ^14.3.2
eslint: 7.17.0
eslint-config-prettier: ^8.5.0
eslint-plugin-import: ^2.26.0
eslint-plugin-prettier: 3.3.1
ethereum-waffle: ^3.4.0
ethers: ^5.5.4
hardhat: ^2.17.2
hardhat-deploy: ^0.10.4
hardhat-deploy-ethers: ^0.3.0-beta.13
hardhat-gas-reporter: ^1.0.7
hardhat-watcher: ^2.3.0
jest: 29.5.0
lodash.isequal: ^4.5.0
lodash.shuffle: ^4.2.0
prettier: ^2.6.2
prettier-plugin-solidity: ^1.0.0-beta.19
solhint: ^3.3.7
solidity-coverage: ^0.8.4
ts-jest: 29.1.0
ts-node: ^10.4.0
typechain: ^8.0.0
typescript: ^4.6.3
wait-on: ^6.0.1
languageName: unknown
linkType: soft

"@statechannels/nitro-rpc-client@workspace:*, @statechannels/nitro-rpc-client@workspace:packages/nitro-rpc-client":
version: 0.0.0-use.local
resolution: "@statechannels/nitro-rpc-client@workspace:packages/nitro-rpc-client"
Expand Down
Loading