-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from dkackman/https
add Https support to daemon library
- Loading branch information
Showing
12 changed files
with
3,189 additions
and
1,998 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,4 @@ | |
"packages/*" | ||
], | ||
"version": "0.0.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import chai from "chai"; | ||
import { createHttpsService, createConnection } from "chia-daemon"; | ||
import _utils from "chia-utils"; | ||
|
||
const expect = chai.expect; | ||
|
||
describe("chia-https", () => { | ||
describe("invocation", () => { | ||
it("should get all the way to the rpc endpoint", async function () { | ||
const connection = createConnection( | ||
"full_node", | ||
"localhost", | ||
"e:/chia/mainnet", | ||
60 | ||
); | ||
this.timeout(connection.timeout_seconds * 1000); | ||
|
||
const full_node = createHttpsService(connection); | ||
|
||
const state = await full_node.get_blockchain_state(); | ||
expect(state).to.not.equal(undefined); | ||
expect(state).to.not.equal(null); | ||
}); | ||
it("should pass arguments _DEBUG_", async function () { | ||
const connection = createConnection( | ||
"wallet", | ||
"localhost", | ||
"e:/chia/mainnet", | ||
60 | ||
); | ||
this.timeout(connection.timeout_seconds * 1000); | ||
|
||
const wallet = createHttpsService(connection); | ||
|
||
const response = await wallet.get_wallets({ include_data: true }); | ||
expect(response).to.not.equal(undefined); | ||
expect(response.wallets[1].data).to.not.equal(undefined); | ||
expect(response.wallets[1].data.length).to.be.greaterThan(0); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import _ from "lodash"; | ||
import Connection from "./connection.js"; | ||
import axios from "axios"; | ||
import https from "https"; | ||
import createRpcProxy from "./rpc_proxy.js"; | ||
|
||
export function createHttpsService(connection) { | ||
if (connection === undefined) { | ||
throw new Error("Connection meta data must be provided"); | ||
} | ||
|
||
return createRpcProxy(new ChiaHttps(connection), connection.service); | ||
} | ||
|
||
export class ChiaHttps { | ||
constructor(connection) { | ||
if (connection === undefined) { | ||
throw new Error("Connection meta data must be provided"); | ||
} | ||
|
||
this.connection = new Connection( | ||
connection.service, | ||
connection.host, | ||
connection.port, | ||
connection.key_path, | ||
connection.cert_path, | ||
connection.timeout_seconds | ||
); | ||
} | ||
|
||
get chiaServiceName() { | ||
return this.connection.service; | ||
} | ||
|
||
async sendCommand(destination, command, data = {}) { | ||
if (destination !== this.connection.service) { | ||
// if this happens something is seriously wrong | ||
throw new Error( | ||
`Invalid destination ${destination} for service ${this.connection.service}` | ||
); | ||
} | ||
|
||
// lazily create an axios instance | ||
if (this.axios === undefined) { | ||
const clientOptions = this.connection.createClientOptions(); | ||
this.axios = axios.create({ | ||
baseURL: this.connection.serviceAddress, | ||
timeout: this.connection.timeout_seconds * 1000, | ||
headers: { | ||
accepts: "application/json", | ||
"content-type": "application/json", | ||
}, | ||
httpsAgent: new https.Agent(clientOptions), | ||
}); | ||
} | ||
|
||
const response = await this.axios.post(`/${command}`, data); | ||
if (!response.data.success) { | ||
throw new Error(response.data.error); | ||
} | ||
return response.data; | ||
} | ||
} |
Oops, something went wrong.