Skip to content
Open
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
15 changes: 10 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@
"prettier": "^1.16.4",
"rimraf": "^2.6.3",
"tslint": "^5.15.0",
"typescript": "^3.4.2"
"typescript": "4.1.2"
}
}
5 changes: 4 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
exports.RegtestUtils = void 0;
const assert = require('assert');
const rng = require('randombytes');
const bs58check = require('bs58check');
Expand All @@ -10,6 +11,8 @@ class RegtestUtils {
this._APIURL =
(_opts || {}).APIURL || process.env.APIURL || 'http://127.0.0.1:8080/1';
this._APIPASS = (_opts || {}).APIPASS || process.env.APIPASS || 'satoshi';
this._PRIVATE_KEY =
(_opts || {}).PRIVATE_KEY || process.env.PRIVATE_KEY || '';
// regtest network parameters
this.network = {
messagePrefix: '\x18Tapyrus Signed Message:\n',
Expand Down Expand Up @@ -50,7 +53,7 @@ class RegtestUtils {
async mine(count) {
return this.dhttp({
method: 'POST',
url: `${this._APIURL}/r/generate?count=${count}&key=${this._APIPASS}`,
url: `${this._APIURL}/r/generate?count=${count}&key=${this._APIPASS}&priv=${this._PRIVATE_KEY}`,
});
}
async height() {
Expand Down
6 changes: 5 additions & 1 deletion ts_src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ interface Transaction {
interface RegUtilOpts {
APIPASS?: string;
APIURL?: string;
PRIVATE_KEY?: string;
}

const dhttpCallback = require('dhttp/200');
Expand All @@ -70,11 +71,14 @@ export class RegtestUtils {
network: Network;
private _APIURL: string;
private _APIPASS: string;
private _PRIVATE_KEY: string;

constructor(_opts?: RegUtilOpts) {
this._APIURL =
(_opts || {}).APIURL || process.env.APIURL || 'http://127.0.0.1:8080/1';
this._APIPASS = (_opts || {}).APIPASS || process.env.APIPASS || 'satoshi';
this._PRIVATE_KEY =
(_opts || {}).PRIVATE_KEY || process.env.PRIVATE_KEY || '';
// regtest network parameters
this.network = {
messagePrefix: '\x18Tapyrus Signed Message:\n',
Expand Down Expand Up @@ -119,7 +123,7 @@ export class RegtestUtils {
async mine(count: number): Promise<string[]> {
return this.dhttp({
method: 'POST',
url: `${this._APIURL}/r/generate?count=${count}&key=${this._APIPASS}`,
url: `${this._APIURL}/r/generate?count=${count}&key=${this._APIPASS}&priv=${this._PRIVATE_KEY}`,
}) as Promise<string[]>;
}

Expand Down
4 changes: 3 additions & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ interface Transaction {
interface RegUtilOpts {
APIPASS?: string;
APIURL?: string;
PRIVATE_KEY?: string;
}
export declare class RegtestUtils {
network: Network;
private _APIURL;
private _APIPASS;
private _PRIVATE_KEY;
constructor(_opts?: RegUtilOpts);
readonly RANDOM_ADDRESS: string;
get RANDOM_ADDRESS(): string;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why need this change?

dhttp(options: Request): Promise<DhttpResponse>;
broadcast(txHex: string): Promise<null>;
mine(count: number): Promise<string[]>;
Expand Down