@azpool/chia-client
Version:
TypeScript client for Chia node peer RPC interface
96 lines • 3.69 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FullNode = void 0;
const RpcClient_1 = require("./RpcClient");
// @ts-ignore
const chia_utils_1 = require("chia-utils");
const defaultProtocol = "https";
const defaultHostname = process.env.CHIA__HOSTNAME || "0.0.0.0";
const defaultPort = parseInt(process.env.CHIA__FULLNODE__PORT || '8555') || 8555;
const defaultCaCertPath = process.env.CHIA__CA_CERT_PATH || false;
const defaultCertPath = process.env.CHIA__FULLNODE__CERT_PATH || '';
const defaultKeyPath = process.env.CHIA__FULLNODE__KEY_PATH || '';
class FullNode extends RpcClient_1.RpcClient {
constructor(options) {
super({
protocol: (options === null || options === void 0 ? void 0 : options.protocol) || defaultProtocol,
hostname: (options === null || options === void 0 ? void 0 : options.hostname) || defaultHostname,
port: (options === null || options === void 0 ? void 0 : options.port) || defaultPort,
caCertPath: (options === null || options === void 0 ? void 0 : options.caCertPath) || defaultCaCertPath,
certPath: (options === null || options === void 0 ? void 0 : options.certPath) || defaultCertPath,
keyPath: (options === null || options === void 0 ? void 0 : options.keyPath) || defaultKeyPath
});
}
async getBlockchainState() {
return this.request("get_blockchain_state", {});
}
async getNetworkSpace(newerBlockHeaderHash, olderBlockHeaderHash) {
return this.request("get_network_space", {
newer_block_header_hash: newerBlockHeaderHash,
older_block_header_hash: olderBlockHeaderHash,
});
}
async getBlocks(start, end, excludeHeaderHash) {
return this.request("get_blocks", {
start,
end,
exclude_header_hash: excludeHeaderHash || false,
});
}
async getBlock(headerHash) {
return this.request("get_block", {
header_hash: headerHash,
});
}
async getBlockRecordByHeight(height) {
return this.request("get_block_record_by_height", {
height,
});
}
async getBlockRecord(hash) {
return this.request("get_block_record", {
header_hash: hash,
});
}
async getBlockRecords(start, end) {
return this.request("get_block_records", {
start: start,
end: end
});
}
async getUnfinishedBlockHeaders(height) {
return this.request("get_unfinished_block_headers", {
height,
});
}
async getUnspentCoins(puzzleHash, startHeight, endHeight) {
return this.request("get_coin_records_by_puzzle_hash", {
puzzle_hash: puzzleHash,
start_height: startHeight,
end_height: endHeight,
include_spent_coins: false,
});
}
async getCoinRecordByName(name) {
return this.request("get_coin_record_by_name", {
name,
});
}
async getAdditionsAndRemovals(hash) {
return this.request("get_additions_and_removals", {
header_hash: hash,
});
}
/* https://github.com/CMEONE/chia-utils */
addressToPuzzleHash(address) {
return chia_utils_1.address_to_puzzle_hash(address);
}
puzzleHashToAddress(puzzleHash) {
return chia_utils_1.puzzle_hash_to_address(puzzleHash);
}
getCoinInfo(parentCoinInfo, puzzleHash, amount) {
return chia_utils_1.get_coin_info(parentCoinInfo, puzzleHash, amount / 1000000000000);
}
}
exports.FullNode = FullNode;
//# sourceMappingURL=FullNode.js.map