Skip to content

Commit 74c8583

Browse files
committed
Merge branch 'rpc-url' of https://github.com/MicahMaphet/bitcore
2 parents f268fcf + 3098cb0 commit 74c8583

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

packages/bitcore-node/src/providers/chain-state/internal/internal.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ export class InternalStateProvider implements IChainStateService {
5656
if (!RPC_PEER) {
5757
throw new Error(`RPC not configured for ${chain} ${network}`);
5858
}
59-
const { username, password, host, port } = RPC_PEER;
60-
return new RPC(username, password, host, port);
59+
const { username, password, host, port, protocol } = RPC_PEER;
60+
return new RPC(username, password, host, port, protocol);
6161
}
6262

6363
private getAddressQuery(params: StreamAddressUtxosParams) {

packages/bitcore-node/src/rpc.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@ export class RPC {
99
private username: string,
1010
private password: string,
1111
private host: string,
12-
private port: number | string
12+
private port: number | string,
13+
private protocol: string = 'http'
1314
) {}
1415

1516
public callMethod(method: string, params: any, callback: CallbackType, walletName?: string) {
17+
const authString = this.username ? `${this.username}:${this.password}@` : '';
18+
const walletString = walletName ? '/wallet/' + walletName : '';
1619
request(
1720
{
1821
method: 'POST',
19-
url: `http://${this.username}:${this.password}@${this.host}:${this.port}${walletName ? '/wallet/' + walletName : ''}`,
22+
url: `${this.protocol}://${authString}${this.host}:${this.port}${walletString}`,
2023
body: {
2124
jsonrpc: '1.0',
2225
id: Date.now(),
@@ -122,8 +125,8 @@ export class AsyncRPC {
122125
private rpc: RPC;
123126
private walletName: string | undefined;
124127

125-
constructor(username: string, password: string, host: string, port: number | string) {
126-
this.rpc = new RPC(username, password, host, port);
128+
constructor(username: string, password: string, host: string, port: number | string, protocol?: string) {
129+
this.rpc = new RPC(username, password, host, port, protocol);
127130
this.walletName = process.env.LOADED_MOCHA_OPTS === 'true' ? 'MOCHA_BITCORE_WALLET' : undefined;
128131
}
129132

packages/bitcore-node/src/types/Config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface IUtxoNetworkConfig extends INetworkConfig {
2323
port: number | string;
2424
username: string;
2525
password: string;
26+
protocol?: string;
2627
};
2728
defaultFeeMode?: FeeMode;
2829
syncStartHash?: string; // Start syncing from this block

0 commit comments

Comments
 (0)