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

feature(toSlpRegtestAddress): #37

Closed
Closed
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
6 changes: 5 additions & 1 deletion lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as Bchaddr from "bchaddrjs-slp";
import * as Bchaddr from "bchaddrjs-slp-2";
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this library being used? Afaict there isn't any difference other than the -2 version is behind by 1 commit.

Copy link
Author

Choose a reason for hiding this comment

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

Because the current bchaddrjs-slp don't have toSlpRegtestAddress.

npm run build                                                                                                    ⮂

> [email protected] build /Users/naach/dev/af/slpjs
> tsc && mkdirp dist && browserify index.js --standalone slpjs > dist/slpjs.js && uglifyjs dist/slpjs.js > dist/slpjs.min.js

lib/utils.ts:42:24 - error TS2339: Property 'toSlpRegtestAddress' does not exist on type 'typeof import("bchaddrjs-slp")'.

42         return Bchaddr.toSlpRegtestAddress(address);
                          ~~~~~~~~~~~~~~~~~~~


Found 1 error.

npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] build: `tsc && mkdirp dist && browserify index.js --standalone slpjs > dist/slpjs.js && uglifyjs dist/slpjs.js > dist/slpjs.min.js`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/naach/.npm/_logs/2021-03-01T09_39_56_001Z-debug.log

(base)  ~/dev/af/slpjs ⮀ feature/toSlpRegtestAddress● ⮀ 116d2h59m ⮀ node -v                                                                                                          ⮂
v12.21.0

but I was able to get toSlpRegtestAddress working here for some reason
https://repl.it/@SuperCipher/bchaddr-test#index.js

import BigNumber from "bignumber.js";
import { AddressUtxoResult } from "bitcoin-com-rest";
import { SlpAddressUtxoResult, SlpPaymentRequest, utxo } from "../index";
Expand Down Expand Up @@ -38,6 +38,10 @@ export class Utils {
return Bchaddr.toSlpAddress(address);
}

public static toSlpRegtestAddress(address: string) {
return Bchaddr.toSlpRegtestAddress(address);
}

public static toRegtestAddress(address: string) {
return Bchaddr.toRegtestAddress(address);
}
Expand Down
4 changes: 4 additions & 0 deletions test/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ describe("Utils", () => {
const addr = Utils.toCashAddress("simpleledger:qr5agtachyxvrwxu76vzszan5pnvuzy8duhv4lxrsk");
assert.equal(addr, "bitcoincash:qr5agtachyxvrwxu76vzszan5pnvuzy8dumh7ynrwg");
});
it("toSlpRegtestAddress()", () => {
const addr = Utils.toSlpRegtestAddress("simpleledger:qph5kuz78czq00e3t85ugpgd7xmer5kr7ccj3fcpsg");
assert.equal(addr, "slpreg:qph5kuz78czq00e3t85ugpgd7xmer5kr7ch8j98fn9");
});
it("isCashAddress()", () => {
const addr = Utils.isCashAddress("bitcoincash:qr5agtachyxvrwxu76vzszan5pnvuzy8dumh7ynrwg");
assert.equal(addr, true);
Expand Down
5 changes: 3 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@
"downlevelIteration": true,
"moduleResolution": "node",
"esModuleInterop": true,
"lib":[ "es2017" ],
"lib":[ "es2017","dom" ],
Copy link
Contributor

Choose a reason for hiding this comment

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

why is "dom" being included?

Copy link
Author

Choose a reason for hiding this comment

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

this is a fix for an error tsc can't find element
https://stackoverflow.com/questions/57999416/typescript-puppeteer-library-error-cannot-find-name-element

npm run build                                                                                                                             ⮂

> [email protected] build /Users/naach/dev/af/slpjs
> npx tsc && mkdirp dist && browserify index.js --standalone slpjs > dist/slpjs.js && uglifyjs dist/slpjs.js > dist/slpjs.min.js

../../node_modules/@types/sizzle/index.d.ts:14:35 - error TS2304: Cannot find name 'Element'.

14     <TArrayLike extends ArrayLike<Element>>(selector: string, context: Element | Document | DocumentFragment, results: TArrayLike): TArrayLike;
                                     ~~~~~~~

../../node_modules/@types/sizzle/index.d.ts:14:72 - error TS2304: Cannot find name 'Element'.

14     <TArrayLike extends ArrayLike<Element>>(selector: string, context: Element | Document | DocumentFragment, results: TArrayLike): TArrayLike;
                                                                          ~~~~~~~

../../node_modules/@types/sizzle/index.d.ts:14:82 - error TS2304: Cannot find name 'Document'.

14     <TArrayLike extends ArrayLike<Element>>(selector: string, context: Element | Document | DocumentFragment, results: TArrayLike): TArrayLike;
                                                                                    ~~~~~~~~

../../node_modules/@types/sizzle/index.d.ts:14:93 - error TS2304: Cannot find name 'DocumentFragment'.

14     <TArrayLike extends ArrayLike<Element>>(selector: string, context: Element | Document | DocumentFragment, results: TArrayLike): TArrayLike;
                                                                                               ~~~~~~~~~~~~~~~~

../../node_modules/@types/sizzle/index.d.ts:15:34 - error TS2304: Cannot find name 'Element'.

15     (selector: string, context?: Element | Document | DocumentFragment): Element[];
                                    ~~~~~~~

../../node_modules/@types/sizzle/index.d.ts:15:44 - error TS2304: Cannot find name 'Document'.

15     (selector: string, context?: Element | Document | DocumentFragment): Element[];
                                              ~~~~~~~~

../../node_modules/@types/sizzle/index.d.ts:15:55 - error TS2304: Cannot find name 'DocumentFragment'.

15     (selector: string, context?: Element | Document | DocumentFragment): Element[];
                                                         ~~~~~~~~~~~~~~~~

../../node_modules/@types/sizzle/index.d.ts:15:74 - error TS2304: Cannot find name 'Element'.

15     (selector: string, context?: Element | Document | DocumentFragment): Element[];
                                                                            ~~~~~~~

../../node_modules/@types/sizzle/index.d.ts:18:28 - error TS2304: Cannot find name 'Element'.

18     matchSelector(element: Element, selector: string): boolean;
                              ~~~~~~~

../../node_modules/@types/sizzle/index.d.ts:19:41 - error TS2304: Cannot find name 'Element'.

"declaration": true,
"sourceMap": true,
"plugins": [
{ "name": "typescript-tslint-plugin" }
]
},
"include": [
"lib/**/*.ts"
"lib/**/*.ts",
"./typings-custom/**/*.ts"
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not able to find any "typings-custom" files. Why is this needed?

Copy link
Author

Choose a reason for hiding this comment

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

Sorry, I forgot to remove that, it's actually not necessary.

],
"exclude": [
"node_modules",
Expand Down