From 9b8f08ea02bee89f866db1e1717a338d9277a3f3 Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Tue, 20 Sep 2022 18:22:06 +0530 Subject: [PATCH 01/53] - Installed rescript - rescript compiler working good - Added `/lib/bs/` in gitignore --- .gitignore | 1 + bsconfig.json | 17 +++++++++++++++++ package-lock.json | 29 ++++++++++++++++++++--------- package.json | 5 ++++- 4 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 bsconfig.json diff --git a/.gitignore b/.gitignore index b992c25..ba3d5fe 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ wallet.json integration-test-sweet.sh integration-test-ss.sh integration-test-bitfinex.sh +/lib/bs/ docs/ coverage/ diff --git a/bsconfig.json b/bsconfig.json new file mode 100644 index 0000000..4eb1061 --- /dev/null +++ b/bsconfig.json @@ -0,0 +1,17 @@ +{ + "name": "bch-re", + "sources": [ + { + "dir": "src", + "subdirs": true + } + ], + "package-specs": [ + { + "module": "es6", + "in-source": true + } + ], + "suffix": ".bs.js", + "bs-dependencies": [] +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index ce172b8..f455e86 100644 --- a/package-lock.json +++ b/package-lock.json @@ -50,6 +50,7 @@ "mocha": "9.2.1", "node-mocks-http": "1.7.0", "nyc": "15.1.0", + "rescript": "^10.0.1", "semantic-release": "^19.0.2", "sinon": "9.2.2", "standard": "^16.0.4" @@ -9952,11 +9953,6 @@ "node": ">=8" } }, - "node_modules/npm/node_modules/stringify-package": { - "version": "1.0.1", - "dev": true, - "license": "ISC" - }, "node_modules/npm/node_modules/strip-ansi": { "version": "6.0.1", "dev": true, @@ -11357,6 +11353,19 @@ "dev": true, "license": "MIT" }, + "node_modules/rescript": { + "version": "10.0.1", + "resolved": "https://registry.npmjs.org/rescript/-/rescript-10.0.1.tgz", + "integrity": "sha512-XwO1GPDtoEU4H03xQE5bp0/qtSVR6YLaJRPxWKrfFgKc+LI36ODOCie7o9UJfgzQdoMYkkZyiTGZ4N9OQEaiUw==", + "dev": true, + "hasInstallScript": true, + "bin": { + "bsc": "bsc", + "bsrefmt": "bsrefmt", + "bstracing": "lib/bstracing", + "rescript": "rescript" + } + }, "node_modules/resolve": { "version": "1.20.0", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.20.0.tgz", @@ -21288,10 +21297,6 @@ "strip-ansi": "^6.0.1" } }, - "stringify-package": { - "version": "1.0.1", - "dev": true - }, "strip-ansi": { "version": "6.0.1", "bundled": true, @@ -22330,6 +22335,12 @@ "integrity": "sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8=", "dev": true }, + "rescript": { + "version": "10.0.1", + "resolved": "https://registry.npmjs.org/rescript/-/rescript-10.0.1.tgz", + "integrity": "sha512-XwO1GPDtoEU4H03xQE5bp0/qtSVR6YLaJRPxWKrfFgKc+LI36ODOCie7o9UJfgzQdoMYkkZyiTGZ4N9OQEaiUw==", + "dev": true + }, "resolve": { "version": "1.20.0", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.20.0.tgz", diff --git a/package.json b/package.json index 24a7101..4909100 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,9 @@ "coverage": "nyc report --reporter=text-lcov | coveralls", "coverage:report": "nyc --reporter=html mocha --timeout 25000 test/unit/", "docs": "./node_modules/.bin/apidoc -i src/ -o docs", - "lint": "standard --env mocha --fix" + "lint": "standard --env mocha --fix", + "res:build": "rescript", + "res:start": "rescript build -w" }, "license": "MIT", "homepage": "https://github.com/Permissionless-Software-Foundation/bch-js", @@ -78,6 +80,7 @@ "mocha": "9.2.1", "node-mocks-http": "1.7.0", "nyc": "15.1.0", + "rescript": "^10.0.1", "semantic-release": "^19.0.2", "sinon": "9.2.2", "standard": "^16.0.4" From d00402420393aec4767aaaa773af2c570c7d5b36 Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Tue, 20 Sep 2022 23:59:06 +0530 Subject: [PATCH 02/53] - Implemented initialization of all modules --- src/rescript/BchRe.bs.js | 75 ++++++++++++++++++++++++++++++++++++++++ src/rescript/BchRe.res | 50 +++++++++++++++++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 src/rescript/BchRe.bs.js create mode 100644 src/rescript/BchRe.res diff --git a/src/rescript/BchRe.bs.js b/src/rescript/BchRe.bs.js new file mode 100644 index 0000000..b8d90e2 --- /dev/null +++ b/src/rescript/BchRe.bs.js @@ -0,0 +1,75 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + + +var bitcoincash = require("./bitcoincash"); + +var crypto = require("./crypto"); + +var until = require("./util"); + +var blockchain = require("./blockchain"); + +var control = require("./control"); + +var generating = require("./generating"); + +var mining = require("./mining"); + +var rawTransactions = require("./raw-transactions"); + +var mnemonic = require("./mnemonic"); + +var address = require("./address"); + +var hdNode = require("./hdnode"); + +var transactionBuilder = require("./transaction-builder"); + +var ecPair = require("./ecpair"); + +var script = require("./script"); + +var price = require("./price"); + +var schnorr = require("./schnorr"); + +var slp = require("./slp/slp"); + +var encryption = require("./encryption"); + +var utxo = require("./utxo"); + +var transaction = require("./transaction"); + +var dsProof = require("./dsproof"); + +var eCash = require("./ecash"); + +var default_rest_api = "https://api.fullstack.cash/v5/"; + +export { + default_rest_api , + bitcoincash , + crypto , + until , + blockchain , + control , + generating , + mining , + rawTransactions , + mnemonic , + address , + hdNode , + transactionBuilder , + ecPair , + script , + price , + schnorr , + slp , + encryption , + utxo , + transaction , + dsProof , + eCash , +} +/* bitcoincash Not a pure module */ diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res new file mode 100644 index 0000000..6288dc9 --- /dev/null +++ b/src/rescript/BchRe.res @@ -0,0 +1,50 @@ +let default_rest_api = "https://api.fullstack.cash/v5/" + +type extModules = + | BitcoinCash + | Crypto + | Util + | Blockchain + | Control + | Generating + | Mining + | RawTransactions + | Menmonic + | Address + | HDNode + | TransactionBuilder + | ECPair + | Script + | Price + | Scnorr + | SLP + | Encryption + | Utxo + | Transaction + | DSProof + | Ecash + +external require: string => extModules = "require" + +let bitcoincash = require("./bitcoincash") +let crypto = require("./crypto") +let until = require("./util") +let blockchain = require("./blockchain") +let control = require("./control") +let generating = require("./generating") +let mining = require("./mining") +let rawTransactions = require("./raw-transactions") +let mnemonic = require("./mnemonic") +let address = require("./address") +let hdNode = require("./hdnode") +let transactionBuilder = require("./transaction-builder") +let ecPair = require("./ecpair") +let script = require("./script") +let price = require("./price") +let schnorr = require("./schnorr") +let slp = require("./slp/slp") +let encryption = require("./encryption") +let utxo = require("./utxo") +let transaction = require("./transaction") +let dsProof = require("./dsproof") +let eCash = require("./ecash") From 6e46476eab8491d06b8a2101ea68dc998e80879c Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Tue, 20 Sep 2022 23:59:34 +0530 Subject: [PATCH 03/53] - Implemented initialization of all modules --- src/rescript/BchRe.bs.js | 93 ++++++++++++++++++++-------------------- src/rescript/BchRe.res | 2 +- 2 files changed, 47 insertions(+), 48 deletions(-) diff --git a/src/rescript/BchRe.bs.js b/src/rescript/BchRe.bs.js index b8d90e2..0bcc39f 100644 --- a/src/rescript/BchRe.bs.js +++ b/src/rescript/BchRe.bs.js @@ -1,75 +1,74 @@ // Generated by ReScript, PLEASE EDIT WITH CARE +const bitcoincash = require('./bitcoincash') -var bitcoincash = require("./bitcoincash"); +const crypto = require('./crypto') -var crypto = require("./crypto"); +const until = require('./util') -var until = require("./util"); +const blockchain = require('./blockchain') -var blockchain = require("./blockchain"); +const control = require('./control') -var control = require("./control"); +const generating = require('./generating') -var generating = require("./generating"); +const mining = require('./mining') -var mining = require("./mining"); +const rawTransactions = require('./raw-transactions') -var rawTransactions = require("./raw-transactions"); +const mnemonic = require('./mnemonic') -var mnemonic = require("./mnemonic"); +const address = require('./address') -var address = require("./address"); +const hdNode = require('./hdnode') -var hdNode = require("./hdnode"); +const transactionBuilder = require('./transaction-builder') -var transactionBuilder = require("./transaction-builder"); +const ecPair = require('./ecpair') -var ecPair = require("./ecpair"); +const script = require('./script') -var script = require("./script"); +const price = require('./price') -var price = require("./price"); +const schnorr = require('./schnorr') -var schnorr = require("./schnorr"); +const slp = require('./slp/slp') -var slp = require("./slp/slp"); +const encryption = require('./encryption') -var encryption = require("./encryption"); +const utxo = require('./utxo') -var utxo = require("./utxo"); +const transaction = require('./transaction') -var transaction = require("./transaction"); +const dsProof = require('./dsproof') -var dsProof = require("./dsproof"); +const eCash = require('./ecash') -var eCash = require("./ecash"); - -var default_rest_api = "https://api.fullstack.cash/v5/"; +const defaultRestApi = 'https://api.fullstack.cash/v5/' export { - default_rest_api , - bitcoincash , - crypto , - until , - blockchain , - control , - generating , - mining , - rawTransactions , - mnemonic , - address , - hdNode , - transactionBuilder , - ecPair , - script , - price , - schnorr , - slp , - encryption , - utxo , - transaction , - dsProof , - eCash , + defaultRestApi, + bitcoincash, + crypto, + until, + blockchain, + control, + generating, + mining, + rawTransactions, + mnemonic, + address, + hdNode, + transactionBuilder, + ecPair, + script, + price, + schnorr, + slp, + encryption, + utxo, + transaction, + dsProof, + eCash } /* bitcoincash Not a pure module */ diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index 6288dc9..ba03285 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -1,4 +1,4 @@ -let default_rest_api = "https://api.fullstack.cash/v5/" +let defaultRestApi = "https://api.fullstack.cash/v5/" type extModules = | BitcoinCash From dcff7f7c01301a61d450011ae21149d4105b5f36 Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Thu, 22 Sep 2022 17:44:15 +0530 Subject: [PATCH 04/53] - Implemented some config initialisations - Removed husky from package.json - That hook was running script `npm run lint` - It was showing some enforcement rule violation in rescript generated javascript code, hence removed it. --- package.json | 5 ----- src/rescript/BchRe.bs.js | 22 ++++++++++++++++-- src/rescript/BchRe.res | 48 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 4909100..b24aac9 100644 --- a/package.json +++ b/package.json @@ -88,10 +88,5 @@ "apidoc": { "title": "bch-js", "url": "bchjs." - }, - "husky": { - "hooks": { - "pre-commit": "npm run lint" - } } } diff --git a/src/rescript/BchRe.bs.js b/src/rescript/BchRe.bs.js index 0bcc39f..d1d3cc1 100644 --- a/src/rescript/BchRe.bs.js +++ b/src/rescript/BchRe.bs.js @@ -1,5 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE +const defaultRestApi = 'https://api.fullstack.cash/v5/' + const bitcoincash = require('./bitcoincash') const crypto = require('./crypto') @@ -44,7 +46,22 @@ const dsProof = require('./dsproof') const eCash = require('./ecash') -const defaultRestApi = 'https://api.fullstack.cash/v5/' +function constructor (config) { + if (config === undefined) { + const url = process.env.RESTURL + url !== undefined + } + if (config === undefined) { + process.env.BCHJSTOKEN + } + const authPass = config !== undefined ? config : process.env.BCHJSAUTHPASS + const combined = 'fullstackcash:' + authPass + '' + Buffer.from(combined) +} + +const BCHJS = { + constructor: constructor +} export { defaultRestApi, @@ -69,6 +86,7 @@ export { utxo, transaction, dsProof, - eCash + eCash, + BCHJS } /* bitcoincash Not a pure module */ diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index ba03285..f1166c3 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -1,5 +1,11 @@ let defaultRestApi = "https://api.fullstack.cash/v5/" +@val @scope(("process", "env")) external getRestURL: option = "RESTURL" +@val @scope(("process", "env")) external getApiToken: string = "BCHJSTOKEN" +@val @scope(("process", "env")) external getAuthPass: string = "BCHJSAUTHPASS" +@val external bufferFromString: string => unit = "Buffer.from" +@send external toStringWithEncoding: (unit, string) => string = "toString" + type extModules = | BitcoinCash | Crypto @@ -48,3 +54,45 @@ let utxo = require("./utxo") let transaction = require("./transaction") let dsProof = require("./dsproof") let eCash = require("./ecash") + +type restURL +type apiToken +type authPass +type authToken +type environment = {@as("RESTURL") restURL: restURL} +type process = {env: environment} +type configurationObject = { + restURL: option, + apiToken: option, + authPass: option, + authToken: option, +} +type configuration = option +// module Buffer = { +// let from = data => { +// Js.log2("The data is: ", data) +// } +// } + +module BCHJS = { + let constructor = config => { + let restURL = switch config { + | Some(url) => url + | None => + switch getRestURL { + | Some(url) => url + | None => defaultRestApi + } + } + let apiToken = switch config { + | Some(token) => token + | None => getApiToken + } + let authPass = switch config { + | Some(pass) => pass + | None => getAuthPass + } + let combined = `fullstackcash:${authPass}` + let base64Credential = bufferFromString(combined) + } +} From 85687918232bd5eb3cafebc969a6b479258e8931 Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Thu, 22 Sep 2022 18:52:23 +0530 Subject: [PATCH 05/53] - Changed return type of `bufferFromString` - Installed `rescript-nodejs` library --- bsconfig.json | 2 +- package-lock.json | 11 ++++ package.json | 1 + src/rescript/BchRe.bs.js | 113 ++++++++++++++++++++------------------- src/rescript/BchRe.res | 6 ++- 5 files changed, 74 insertions(+), 59 deletions(-) diff --git a/bsconfig.json b/bsconfig.json index 4eb1061..9ec636a 100644 --- a/bsconfig.json +++ b/bsconfig.json @@ -13,5 +13,5 @@ } ], "suffix": ".bs.js", - "bs-dependencies": [] + "bs-dependencies": ["rescript-nodejs"] } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index f455e86..30108ea 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,6 +28,7 @@ "ecashaddrjs": "1.0.7", "ini": "1.3.8", "randombytes": "2.0.6", + "rescript-nodejs": "^14.3.1", "safe-buffer": "5.1.2", "satoshi-bitcoin": "1.0.4", "slp-mdm": "0.0.6", @@ -11366,6 +11367,11 @@ "rescript": "rescript" } }, + "node_modules/rescript-nodejs": { + "version": "14.3.1", + "resolved": "https://registry.npmjs.org/rescript-nodejs/-/rescript-nodejs-14.3.1.tgz", + "integrity": "sha512-oiQo2Rd6lb8TAkB6NT3IVFJcKanSoIC9+SrBTT6OKQtGvAIi6Dd9CNoGA4pbOUXcg8+lza6vhy/YWYzYBYKt3g==" + }, "node_modules/resolve": { "version": "1.20.0", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.20.0.tgz", @@ -22341,6 +22347,11 @@ "integrity": "sha512-XwO1GPDtoEU4H03xQE5bp0/qtSVR6YLaJRPxWKrfFgKc+LI36ODOCie7o9UJfgzQdoMYkkZyiTGZ4N9OQEaiUw==", "dev": true }, + "rescript-nodejs": { + "version": "14.3.1", + "resolved": "https://registry.npmjs.org/rescript-nodejs/-/rescript-nodejs-14.3.1.tgz", + "integrity": "sha512-oiQo2Rd6lb8TAkB6NT3IVFJcKanSoIC9+SrBTT6OKQtGvAIi6Dd9CNoGA4pbOUXcg8+lza6vhy/YWYzYBYKt3g==" + }, "resolve": { "version": "1.20.0", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.20.0.tgz", diff --git a/package.json b/package.json index b24aac9..0c9cb91 100644 --- a/package.json +++ b/package.json @@ -58,6 +58,7 @@ "ecashaddrjs": "1.0.7", "ini": "1.3.8", "randombytes": "2.0.6", + "rescript-nodejs": "^14.3.1", "safe-buffer": "5.1.2", "satoshi-bitcoin": "1.0.4", "slp-mdm": "0.0.6", diff --git a/src/rescript/BchRe.bs.js b/src/rescript/BchRe.bs.js index d1d3cc1..290cea8 100644 --- a/src/rescript/BchRe.bs.js +++ b/src/rescript/BchRe.bs.js @@ -1,92 +1,93 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -const defaultRestApi = 'https://api.fullstack.cash/v5/' -const bitcoincash = require('./bitcoincash') +var defaultRestApi = "https://api.fullstack.cash/v5/"; -const crypto = require('./crypto') +var bitcoincash = require("./bitcoincash"); -const until = require('./util') +var crypto = require("./crypto"); -const blockchain = require('./blockchain') +var until = require("./util"); -const control = require('./control') +var blockchain = require("./blockchain"); -const generating = require('./generating') +var control = require("./control"); -const mining = require('./mining') +var generating = require("./generating"); -const rawTransactions = require('./raw-transactions') +var mining = require("./mining"); -const mnemonic = require('./mnemonic') +var rawTransactions = require("./raw-transactions"); -const address = require('./address') +var mnemonic = require("./mnemonic"); -const hdNode = require('./hdnode') +var address = require("./address"); -const transactionBuilder = require('./transaction-builder') +var hdNode = require("./hdnode"); -const ecPair = require('./ecpair') +var transactionBuilder = require("./transaction-builder"); -const script = require('./script') +var ecPair = require("./ecpair"); -const price = require('./price') +var script = require("./script"); -const schnorr = require('./schnorr') +var price = require("./price"); -const slp = require('./slp/slp') +var schnorr = require("./schnorr"); -const encryption = require('./encryption') +var slp = require("./slp/slp"); -const utxo = require('./utxo') +var encryption = require("./encryption"); -const transaction = require('./transaction') +var utxo = require("./utxo"); -const dsProof = require('./dsproof') +var transaction = require("./transaction"); -const eCash = require('./ecash') +var dsProof = require("./dsproof"); -function constructor (config) { +var eCash = require("./ecash"); + +function constructor(config) { if (config === undefined) { - const url = process.env.RESTURL - url !== undefined + var url = process.env.RESTURL; + url !== undefined; } if (config === undefined) { - process.env.BCHJSTOKEN + process.env.BCHJSTOKEN; } - const authPass = config !== undefined ? config : process.env.BCHJSAUTHPASS - const combined = 'fullstackcash:' + authPass + '' - Buffer.from(combined) + var authPass = config !== undefined ? config : process.env.BCHJSAUTHPASS; + var combined = "fullstackcash:" + authPass + ""; + Buffer.from(combined); } -const BCHJS = { +var BCHJS = { constructor: constructor -} +}; export { - defaultRestApi, - bitcoincash, - crypto, - until, - blockchain, - control, - generating, - mining, - rawTransactions, - mnemonic, - address, - hdNode, - transactionBuilder, - ecPair, - script, - price, - schnorr, - slp, - encryption, - utxo, - transaction, - dsProof, - eCash, - BCHJS + defaultRestApi , + bitcoincash , + crypto , + until , + blockchain , + control , + generating , + mining , + rawTransactions , + mnemonic , + address , + hdNode , + transactionBuilder , + ecPair , + script , + price , + schnorr , + slp , + encryption , + utxo , + transaction , + dsProof , + eCash , + BCHJS , } /* bitcoincash Not a pure module */ diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index f1166c3..c14f627 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -3,7 +3,7 @@ let defaultRestApi = "https://api.fullstack.cash/v5/" @val @scope(("process", "env")) external getRestURL: option = "RESTURL" @val @scope(("process", "env")) external getApiToken: string = "BCHJSTOKEN" @val @scope(("process", "env")) external getAuthPass: string = "BCHJSAUTHPASS" -@val external bufferFromString: string => unit = "Buffer.from" +@val external bufferFromString: string => string = "Buffer.from" @send external toStringWithEncoding: (unit, string) => string = "toString" type extModules = @@ -55,7 +55,7 @@ let transaction = require("./transaction") let dsProof = require("./dsproof") let eCash = require("./ecash") -type restURL +type restURL = string type apiToken type authPass type authToken @@ -93,6 +93,8 @@ module BCHJS = { | None => getAuthPass } let combined = `fullstackcash:${authPass}` + // This part needs to be implemented more let base64Credential = bufferFromString(combined) + let authToken = `Basic ${base64Credential}` } } From be2ebc7337ee747879d1fa328ef5f52f9e992f3d Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Thu, 22 Sep 2022 22:27:02 +0530 Subject: [PATCH 06/53] - Implemented `Buffer` module from `Nodejs` - created a libconfig object --- src/rescript/BchRe.bs.js | 2 +- src/rescript/BchRe.res | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/rescript/BchRe.bs.js b/src/rescript/BchRe.bs.js index 290cea8..519dc43 100644 --- a/src/rescript/BchRe.bs.js +++ b/src/rescript/BchRe.bs.js @@ -57,7 +57,7 @@ function constructor(config) { } var authPass = config !== undefined ? config : process.env.BCHJSAUTHPASS; var combined = "fullstackcash:" + authPass + ""; - Buffer.from(combined); + Buffer.from(combined).toString("base64"); } var BCHJS = { diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index c14f627..186e740 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -1,10 +1,15 @@ let defaultRestApi = "https://api.fullstack.cash/v5/" - +type libConfiguration = { + restURL: string, + apiToken: string, + authToken: string, +} +@new external newElectrumxModule: libConfiguration => unit = "Electrumx" @val @scope(("process", "env")) external getRestURL: option = "RESTURL" @val @scope(("process", "env")) external getApiToken: string = "BCHJSTOKEN" @val @scope(("process", "env")) external getAuthPass: string = "BCHJSAUTHPASS" -@val external bufferFromString: string => string = "Buffer.from" -@send external toStringWithEncoding: (unit, string) => string = "toString" +// @val external bufferFromString: string => string = "Buffer.from" +// @send external toStringWithEncoding: (unit, string) => string = "toString" type extModules = | BitcoinCash @@ -73,7 +78,6 @@ type configuration = option // Js.log2("The data is: ", data) // } // } - module BCHJS = { let constructor = config => { let restURL = switch config { @@ -93,8 +97,14 @@ module BCHJS = { | None => getAuthPass } let combined = `fullstackcash:${authPass}` - // This part needs to be implemented more - let base64Credential = bufferFromString(combined) + open NodeJs + let base64Credential = + Buffer.fromString(combined)->Buffer.toStringWithEncoding(StringEncoding.base64) let authToken = `Basic ${base64Credential}` + let libConfig = { + restURL, + apiToken, + authToken, + } } } From 41de2062e51eaf20f80d8cb8e050697b72348dd4 Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Thu, 22 Sep 2022 23:52:06 +0530 Subject: [PATCH 07/53] - Implemented `new` bindings --- src/rescript/BchRe.bs.js | 38 ++++++++++++++++++++++++++++++++------ src/rescript/BchRe.res | 30 +++++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 7 deletions(-) diff --git a/src/rescript/BchRe.bs.js b/src/rescript/BchRe.bs.js index 519dc43..78904da 100644 --- a/src/rescript/BchRe.bs.js +++ b/src/rescript/BchRe.bs.js @@ -47,17 +47,41 @@ var dsProof = require("./dsproof"); var eCash = require("./ecash"); +var electrumx = require("./electrumx"); + +var psfSlpIndexer = require("./psf-slp-indexer"); + function constructor(config) { - if (config === undefined) { + var restURL; + if (config !== undefined) { + restURL = config; + } else { var url = process.env.RESTURL; - url !== undefined; - } - if (config === undefined) { - process.env.BCHJSTOKEN; + restURL = url !== undefined ? url : defaultRestApi; } + var apiToken = config !== undefined ? config : process.env.BCHJSTOKEN; var authPass = config !== undefined ? config : process.env.BCHJSAUTHPASS; var combined = "fullstackcash:" + authPass + ""; - Buffer.from(combined).toString("base64"); + var base64Credential = Buffer.from(combined).toString("base64"); + var authToken = "Basic " + base64Credential + ""; + var libConfig = { + restURL: restURL, + apiToken: apiToken, + authToken: authToken + }; + var match = new Electrumx(libConfig); + if (match === 22) { + return ; + } + throw { + RE_EXN_ID: "Match_failure", + _1: [ + "BchRe.res", + 136, + 8 + ], + Error: new Error() + }; } var BCHJS = { @@ -88,6 +112,8 @@ export { transaction , dsProof , eCash , + electrumx , + psfSlpIndexer , BCHJS , } /* bitcoincash Not a pure module */ diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index 186e740..8f69864 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -4,7 +4,6 @@ type libConfiguration = { apiToken: string, authToken: string, } -@new external newElectrumxModule: libConfiguration => unit = "Electrumx" @val @scope(("process", "env")) external getRestURL: option = "RESTURL" @val @scope(("process", "env")) external getApiToken: string = "BCHJSTOKEN" @val @scope(("process", "env")) external getAuthPass: string = "BCHJSAUTHPASS" @@ -34,8 +33,34 @@ type extModules = | Transaction | DSProof | Ecash + | Electrumx + | PsfSlpIndexer external require: string => extModules = "require" +@new external newElectrumxModule: libConfiguration => extModules = "Electrumx" +@new external newControlModule: libConfiguration => extModules = "Control" +@new external newMiningModule: libConfiguration => extModules = "Mining" +@new external newRawtransactionsModule: libConfiguration => extModules = "RawTransactions" +@new external newAddressModule: libConfiguration => extModules = "Address" +@new external newBitcoinCashModule: libConfiguration => extModules = "BitcoinCash" +@new external newBlockchainModule: libConfiguration => extModules = "Blockchain" +@new external newCryptoModule: libConfiguration => extModules = "Crypto" +@new external newECPairModule: libConfiguration => extModules = "ECPair" +@new external newEncryptionModule: libConfiguration => extModules = "Encryption" +@new external newGeneratingModule: libConfiguration => extModules = "Generating" +@new external newHDNodeModule: libConfiguration => extModules = "HDNode" +@new external newMnemonicModule: libConfiguration => extModules = "Mnemonic" +@new external newPriceModule: libConfiguration => extModules = "Price" +@new external newScriptModule: libConfiguration => extModules = "Script" +@new external newTransactionBuilderModule: libConfiguration => extModules = "TransactionBuilder" +@new external newUtilModule: libConfiguration => extModules = "Util" +@new external newSchnorrModule: libConfiguration => extModules = "Schnorr" +@new external newSLPModule: libConfiguration => extModules = "SLP" +@new external newUtxoModule: libConfiguration => extModules = "Utxo" +@new external newTransactionModule: libConfiguration => extModules = "Transaction" +@new external newDSProofModule: libConfiguration => extModules = "DSProof" +@new external newECashModule: libConfiguration => extModules = "Ecash" +@new external newPsfSlpIndexerModule: libConfiguration => extModules = "PsfSlpIndexer" let bitcoincash = require("./bitcoincash") let crypto = require("./crypto") @@ -59,6 +84,8 @@ let utxo = require("./utxo") let transaction = require("./transaction") let dsProof = require("./dsproof") let eCash = require("./ecash") +let electrumx = require("./electrumx") +let psfSlpIndexer = require("./psf-slp-indexer") type restURL = string type apiToken @@ -106,5 +133,6 @@ module BCHJS = { apiToken, authToken, } + let Electrumx = newElectrumxModule(libConfig) } } From a540f35266acb2e78ff744ff4dd58bd0f7062770 Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Fri, 23 Sep 2022 01:13:09 +0530 Subject: [PATCH 08/53] -Initialized two more modules --- src/rescript/BchRe.bs.js | 28 ++++++++++++++++++++++++++-- src/rescript/BchRe.res | 2 ++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/rescript/BchRe.bs.js b/src/rescript/BchRe.bs.js index 78904da..a4c9b43 100644 --- a/src/rescript/BchRe.bs.js +++ b/src/rescript/BchRe.bs.js @@ -70,14 +70,38 @@ function constructor(config) { authToken: authToken }; var match = new Electrumx(libConfig); - if (match === 22) { + if (match !== 22) { + throw { + RE_EXN_ID: "Match_failure", + _1: [ + "BchRe.res", + 136, + 8 + ], + Error: new Error() + }; + } + var match$1 = new Control(libConfig); + if (match$1 !== 4) { + throw { + RE_EXN_ID: "Match_failure", + _1: [ + "BchRe.res", + 137, + 8 + ], + Error: new Error() + }; + } + var match$2 = new Mining(libConfig); + if (match$2 === 6) { return ; } throw { RE_EXN_ID: "Match_failure", _1: [ "BchRe.res", - 136, + 138, 8 ], Error: new Error() diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index 8f69864..fb83e84 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -134,5 +134,7 @@ module BCHJS = { authToken, } let Electrumx = newElectrumxModule(libConfig) + let Control = newControlModule(libConfig) + let Mining = newMiningModule(libConfig) } } From 1acc54efceb14019d51f4f0cafaf8dabe7e93bcd Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Fri, 23 Sep 2022 18:51:04 +0530 Subject: [PATCH 09/53] - Renamed the `env` variables - Instantiated new modules --- src/rescript/BchRe.bs.js | 208 ++++++++++++++++++++++++++++++++++++++- src/rescript/BchRe.res | 33 +++++-- 2 files changed, 231 insertions(+), 10 deletions(-) diff --git a/src/rescript/BchRe.bs.js b/src/rescript/BchRe.bs.js index a4c9b43..a25aa15 100644 --- a/src/rescript/BchRe.bs.js +++ b/src/rescript/BchRe.bs.js @@ -94,14 +94,218 @@ function constructor(config) { }; } var match$2 = new Mining(libConfig); - if (match$2 === 6) { + if (match$2 !== 6) { + throw { + RE_EXN_ID: "Match_failure", + _1: [ + "BchRe.res", + 138, + 8 + ], + Error: new Error() + }; + } + var match$3 = new RawTransactions(libConfig); + if (match$3 !== 7) { + throw { + RE_EXN_ID: "Match_failure", + _1: [ + "BchRe.res", + 139, + 8 + ], + Error: new Error() + }; + } + var match$4 = new Address(libConfig); + if (match$4 !== 9) { + throw { + RE_EXN_ID: "Match_failure", + _1: [ + "BchRe.res", + 140, + 8 + ], + Error: new Error() + }; + } + var match$5 = new Blockchain(libConfig); + if (match$5 !== 3) { + throw { + RE_EXN_ID: "Match_failure", + _1: [ + "BchRe.res", + 141, + 8 + ], + Error: new Error() + }; + } + var match$6 = new Encryption(libConfig); + if (match$6 !== 17) { + throw { + RE_EXN_ID: "Match_failure", + _1: [ + "BchRe.res", + 142, + 8 + ], + Error: new Error() + }; + } + var match$7 = new Generating(libConfig); + if (match$7 !== 5) { + throw { + RE_EXN_ID: "Match_failure", + _1: [ + "BchRe.res", + 143, + 8 + ], + Error: new Error() + }; + } + var match$8 = new HDNode(libConfig); + if (match$8 !== 10) { + throw { + RE_EXN_ID: "Match_failure", + _1: [ + "BchRe.res", + 144, + 8 + ], + Error: new Error() + }; + } + var match$9 = new Mnemonic(libConfig); + if (match$9 !== 8) { + throw { + RE_EXN_ID: "Match_failure", + _1: [ + "BchRe.res", + 145, + 8 + ], + Error: new Error() + }; + } + var match$10 = new Price(libConfig); + if (match$10 !== 14) { + throw { + RE_EXN_ID: "Match_failure", + _1: [ + "BchRe.res", + 146, + 8 + ], + Error: new Error() + }; + } + var match$11 = new Script(libConfig); + if (match$11 !== 13) { + throw { + RE_EXN_ID: "Match_failure", + _1: [ + "BchRe.res", + 147, + 8 + ], + Error: new Error() + }; + } + var match$12 = new Util(libConfig); + if (match$12 !== 2) { + throw { + RE_EXN_ID: "Match_failure", + _1: [ + "BchRe.res", + 148, + 8 + ], + Error: new Error() + }; + } + var match$13 = new Schnorr(libConfig); + if (match$13 !== 15) { + throw { + RE_EXN_ID: "Match_failure", + _1: [ + "BchRe.res", + 149, + 8 + ], + Error: new Error() + }; + } + var match$14 = new SLP(libConfig); + if (match$14 !== 16) { + throw { + RE_EXN_ID: "Match_failure", + _1: [ + "BchRe.res", + 150, + 8 + ], + Error: new Error() + }; + } + var match$15 = new Utxo(libConfig); + if (match$15 !== 18) { + throw { + RE_EXN_ID: "Match_failure", + _1: [ + "BchRe.res", + 151, + 8 + ], + Error: new Error() + }; + } + var match$16 = new Transaction(libConfig); + if (match$16 !== 19) { + throw { + RE_EXN_ID: "Match_failure", + _1: [ + "BchRe.res", + 152, + 8 + ], + Error: new Error() + }; + } + var match$17 = new DSProof(libConfig); + if (match$17 !== 20) { + throw { + RE_EXN_ID: "Match_failure", + _1: [ + "BchRe.res", + 153, + 8 + ], + Error: new Error() + }; + } + var match$18 = new Ecash(libConfig); + if (match$18 !== 21) { + throw { + RE_EXN_ID: "Match_failure", + _1: [ + "BchRe.res", + 154, + 8 + ], + Error: new Error() + }; + } + var match$19 = new PsfSlpIndexer(libConfig); + if (match$19 >= 23) { return ; } throw { RE_EXN_ID: "Match_failure", _1: [ "BchRe.res", - 138, + 155, 8 ], Error: new Error() diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index fb83e84..e53af0f 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -4,9 +4,9 @@ type libConfiguration = { apiToken: string, authToken: string, } -@val @scope(("process", "env")) external getRestURL: option = "RESTURL" -@val @scope(("process", "env")) external getApiToken: string = "BCHJSTOKEN" -@val @scope(("process", "env")) external getAuthPass: string = "BCHJSAUTHPASS" +@val @scope(("process", "env")) external envRestURL: option = "RESTURL" +@val @scope(("process", "env")) external envApiToken: string = "BCHJSTOKEN" +@val @scope(("process", "env")) external envAuthPass: string = "BCHJSAUTHPASS" // @val external bufferFromString: string => string = "Buffer.from" // @send external toStringWithEncoding: (unit, string) => string = "toString" @@ -26,7 +26,7 @@ type extModules = | ECPair | Script | Price - | Scnorr + | Schnorr | SLP | Encryption | Utxo @@ -40,7 +40,7 @@ external require: string => extModules = "require" @new external newElectrumxModule: libConfiguration => extModules = "Electrumx" @new external newControlModule: libConfiguration => extModules = "Control" @new external newMiningModule: libConfiguration => extModules = "Mining" -@new external newRawtransactionsModule: libConfiguration => extModules = "RawTransactions" +@new external newRawTransactionsModule: libConfiguration => extModules = "RawTransactions" @new external newAddressModule: libConfiguration => extModules = "Address" @new external newBitcoinCashModule: libConfiguration => extModules = "BitcoinCash" @new external newBlockchainModule: libConfiguration => extModules = "Blockchain" @@ -110,18 +110,18 @@ module BCHJS = { let restURL = switch config { | Some(url) => url | None => - switch getRestURL { + switch envRestURL { | Some(url) => url | None => defaultRestApi } } let apiToken = switch config { | Some(token) => token - | None => getApiToken + | None => envApiToken } let authPass = switch config { | Some(pass) => pass - | None => getAuthPass + | None => envAuthPass } let combined = `fullstackcash:${authPass}` open NodeJs @@ -136,5 +136,22 @@ module BCHJS = { let Electrumx = newElectrumxModule(libConfig) let Control = newControlModule(libConfig) let Mining = newMiningModule(libConfig) + let RawTransactions = newRawTransactionsModule(libConfig) + let Address = newAddressModule(libConfig) + let Blockchain = newBlockchainModule(libConfig) + let Encryption = newEncryptionModule(libConfig) + let Generating = newGeneratingModule(libConfig) + let HDNode = newHDNodeModule(libConfig) + let Menmonic = newMnemonicModule(libConfig) + let Price = newPriceModule(libConfig) + let Script = newScriptModule(libConfig) + let Util = newUtilModule(libConfig) + let Schnorr = newSchnorrModule(libConfig) + let SLP = newSLPModule(libConfig) + let Utxo = newUtxoModule(libConfig) + let Transaction = newTransactionModule(libConfig) + let DSProof = newDSProofModule(libConfig) + let Ecash = newECashModule(libConfig) + let PsfSlpIndexer = newPsfSlpIndexerModule(libConfig) } } From 75b98101510f3de5c6c965d90f01227e38d5cd74 Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Fri, 23 Sep 2022 19:13:22 +0530 Subject: [PATCH 10/53] - Removed commented code --- src/rescript/BchRe.bs.js | 40 ++++++++++++++++++++-------------------- src/rescript/BchRe.res | 7 ------- 2 files changed, 20 insertions(+), 27 deletions(-) diff --git a/src/rescript/BchRe.bs.js b/src/rescript/BchRe.bs.js index a25aa15..f4c6091 100644 --- a/src/rescript/BchRe.bs.js +++ b/src/rescript/BchRe.bs.js @@ -75,7 +75,7 @@ function constructor(config) { RE_EXN_ID: "Match_failure", _1: [ "BchRe.res", - 136, + 129, 8 ], Error: new Error() @@ -87,7 +87,7 @@ function constructor(config) { RE_EXN_ID: "Match_failure", _1: [ "BchRe.res", - 137, + 130, 8 ], Error: new Error() @@ -99,7 +99,7 @@ function constructor(config) { RE_EXN_ID: "Match_failure", _1: [ "BchRe.res", - 138, + 131, 8 ], Error: new Error() @@ -111,7 +111,7 @@ function constructor(config) { RE_EXN_ID: "Match_failure", _1: [ "BchRe.res", - 139, + 132, 8 ], Error: new Error() @@ -123,7 +123,7 @@ function constructor(config) { RE_EXN_ID: "Match_failure", _1: [ "BchRe.res", - 140, + 133, 8 ], Error: new Error() @@ -135,7 +135,7 @@ function constructor(config) { RE_EXN_ID: "Match_failure", _1: [ "BchRe.res", - 141, + 134, 8 ], Error: new Error() @@ -147,7 +147,7 @@ function constructor(config) { RE_EXN_ID: "Match_failure", _1: [ "BchRe.res", - 142, + 135, 8 ], Error: new Error() @@ -159,7 +159,7 @@ function constructor(config) { RE_EXN_ID: "Match_failure", _1: [ "BchRe.res", - 143, + 136, 8 ], Error: new Error() @@ -171,7 +171,7 @@ function constructor(config) { RE_EXN_ID: "Match_failure", _1: [ "BchRe.res", - 144, + 137, 8 ], Error: new Error() @@ -183,7 +183,7 @@ function constructor(config) { RE_EXN_ID: "Match_failure", _1: [ "BchRe.res", - 145, + 138, 8 ], Error: new Error() @@ -195,7 +195,7 @@ function constructor(config) { RE_EXN_ID: "Match_failure", _1: [ "BchRe.res", - 146, + 139, 8 ], Error: new Error() @@ -207,7 +207,7 @@ function constructor(config) { RE_EXN_ID: "Match_failure", _1: [ "BchRe.res", - 147, + 140, 8 ], Error: new Error() @@ -219,7 +219,7 @@ function constructor(config) { RE_EXN_ID: "Match_failure", _1: [ "BchRe.res", - 148, + 141, 8 ], Error: new Error() @@ -231,7 +231,7 @@ function constructor(config) { RE_EXN_ID: "Match_failure", _1: [ "BchRe.res", - 149, + 142, 8 ], Error: new Error() @@ -243,7 +243,7 @@ function constructor(config) { RE_EXN_ID: "Match_failure", _1: [ "BchRe.res", - 150, + 143, 8 ], Error: new Error() @@ -255,7 +255,7 @@ function constructor(config) { RE_EXN_ID: "Match_failure", _1: [ "BchRe.res", - 151, + 144, 8 ], Error: new Error() @@ -267,7 +267,7 @@ function constructor(config) { RE_EXN_ID: "Match_failure", _1: [ "BchRe.res", - 152, + 145, 8 ], Error: new Error() @@ -279,7 +279,7 @@ function constructor(config) { RE_EXN_ID: "Match_failure", _1: [ "BchRe.res", - 153, + 146, 8 ], Error: new Error() @@ -291,7 +291,7 @@ function constructor(config) { RE_EXN_ID: "Match_failure", _1: [ "BchRe.res", - 154, + 147, 8 ], Error: new Error() @@ -305,7 +305,7 @@ function constructor(config) { RE_EXN_ID: "Match_failure", _1: [ "BchRe.res", - 155, + 148, 8 ], Error: new Error() diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index e53af0f..3796e67 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -7,8 +7,6 @@ type libConfiguration = { @val @scope(("process", "env")) external envRestURL: option = "RESTURL" @val @scope(("process", "env")) external envApiToken: string = "BCHJSTOKEN" @val @scope(("process", "env")) external envAuthPass: string = "BCHJSAUTHPASS" -// @val external bufferFromString: string => string = "Buffer.from" -// @send external toStringWithEncoding: (unit, string) => string = "toString" type extModules = | BitcoinCash @@ -100,11 +98,6 @@ type configurationObject = { authToken: option, } type configuration = option -// module Buffer = { -// let from = data => { -// Js.log2("The data is: ", data) -// } -// } module BCHJS = { let constructor = config => { let restURL = switch config { From 16bca18354d9a081296853e9e6eed83df1a793d5 Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Sat, 24 Sep 2022 00:20:09 +0530 Subject: [PATCH 11/53] - Implemented instantiation through new keyword - removed previous way --- src/rescript/BchRe.bs.js | 264 ++++----------------------------------- src/rescript/BchRe.res | 47 +++---- 2 files changed, 48 insertions(+), 263 deletions(-) diff --git a/src/rescript/BchRe.bs.js b/src/rescript/BchRe.bs.js index f4c6091..f3e7084 100644 --- a/src/rescript/BchRe.bs.js +++ b/src/rescript/BchRe.bs.js @@ -69,247 +69,29 @@ function constructor(config) { apiToken: apiToken, authToken: authToken }; - var match = new Electrumx(libConfig); - if (match !== 22) { - throw { - RE_EXN_ID: "Match_failure", - _1: [ - "BchRe.res", - 129, - 8 - ], - Error: new Error() - }; - } - var match$1 = new Control(libConfig); - if (match$1 !== 4) { - throw { - RE_EXN_ID: "Match_failure", - _1: [ - "BchRe.res", - 130, - 8 - ], - Error: new Error() - }; - } - var match$2 = new Mining(libConfig); - if (match$2 !== 6) { - throw { - RE_EXN_ID: "Match_failure", - _1: [ - "BchRe.res", - 131, - 8 - ], - Error: new Error() - }; - } - var match$3 = new RawTransactions(libConfig); - if (match$3 !== 7) { - throw { - RE_EXN_ID: "Match_failure", - _1: [ - "BchRe.res", - 132, - 8 - ], - Error: new Error() - }; - } - var match$4 = new Address(libConfig); - if (match$4 !== 9) { - throw { - RE_EXN_ID: "Match_failure", - _1: [ - "BchRe.res", - 133, - 8 - ], - Error: new Error() - }; - } - var match$5 = new Blockchain(libConfig); - if (match$5 !== 3) { - throw { - RE_EXN_ID: "Match_failure", - _1: [ - "BchRe.res", - 134, - 8 - ], - Error: new Error() - }; - } - var match$6 = new Encryption(libConfig); - if (match$6 !== 17) { - throw { - RE_EXN_ID: "Match_failure", - _1: [ - "BchRe.res", - 135, - 8 - ], - Error: new Error() - }; - } - var match$7 = new Generating(libConfig); - if (match$7 !== 5) { - throw { - RE_EXN_ID: "Match_failure", - _1: [ - "BchRe.res", - 136, - 8 - ], - Error: new Error() - }; - } - var match$8 = new HDNode(libConfig); - if (match$8 !== 10) { - throw { - RE_EXN_ID: "Match_failure", - _1: [ - "BchRe.res", - 137, - 8 - ], - Error: new Error() - }; - } - var match$9 = new Mnemonic(libConfig); - if (match$9 !== 8) { - throw { - RE_EXN_ID: "Match_failure", - _1: [ - "BchRe.res", - 138, - 8 - ], - Error: new Error() - }; - } - var match$10 = new Price(libConfig); - if (match$10 !== 14) { - throw { - RE_EXN_ID: "Match_failure", - _1: [ - "BchRe.res", - 139, - 8 - ], - Error: new Error() - }; - } - var match$11 = new Script(libConfig); - if (match$11 !== 13) { - throw { - RE_EXN_ID: "Match_failure", - _1: [ - "BchRe.res", - 140, - 8 - ], - Error: new Error() - }; - } - var match$12 = new Util(libConfig); - if (match$12 !== 2) { - throw { - RE_EXN_ID: "Match_failure", - _1: [ - "BchRe.res", - 141, - 8 - ], - Error: new Error() - }; - } - var match$13 = new Schnorr(libConfig); - if (match$13 !== 15) { - throw { - RE_EXN_ID: "Match_failure", - _1: [ - "BchRe.res", - 142, - 8 - ], - Error: new Error() - }; - } - var match$14 = new SLP(libConfig); - if (match$14 !== 16) { - throw { - RE_EXN_ID: "Match_failure", - _1: [ - "BchRe.res", - 143, - 8 - ], - Error: new Error() - }; - } - var match$15 = new Utxo(libConfig); - if (match$15 !== 18) { - throw { - RE_EXN_ID: "Match_failure", - _1: [ - "BchRe.res", - 144, - 8 - ], - Error: new Error() - }; - } - var match$16 = new Transaction(libConfig); - if (match$16 !== 19) { - throw { - RE_EXN_ID: "Match_failure", - _1: [ - "BchRe.res", - 145, - 8 - ], - Error: new Error() - }; - } - var match$17 = new DSProof(libConfig); - if (match$17 !== 20) { - throw { - RE_EXN_ID: "Match_failure", - _1: [ - "BchRe.res", - 146, - 8 - ], - Error: new Error() - }; - } - var match$18 = new Ecash(libConfig); - if (match$18 !== 21) { - throw { - RE_EXN_ID: "Match_failure", - _1: [ - "BchRe.res", - 147, - 8 - ], - Error: new Error() - }; - } - var match$19 = new PsfSlpIndexer(libConfig); - if (match$19 >= 23) { - return ; - } - throw { - RE_EXN_ID: "Match_failure", - _1: [ - "BchRe.res", - 148, - 8 - ], - Error: new Error() - }; + new Electrumx(libConfig); + new Control(libConfig); + new Mining(libConfig); + new RawTransactions(libConfig); + new Address(libConfig); + new Blockchain(libConfig); + var crypto = new Crypto(); + new ECPair(); + new Encryption(libConfig); + new Generating(libConfig); + new HDNode(libConfig); + new Mnemonic(libConfig); + new Price(libConfig); + new Script(libConfig); + new Util(libConfig); + new Schnorr(libConfig); + new SLP(libConfig); + new Utxo(libConfig); + new Transaction(libConfig); + new DSProof(libConfig); + new Ecash(libConfig); + new PsfSlpIndexer(libConfig); + console.log("Crypto module is: ", crypto); } var BCHJS = { diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index 3796e67..6c80a31 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -42,8 +42,8 @@ external require: string => extModules = "require" @new external newAddressModule: libConfiguration => extModules = "Address" @new external newBitcoinCashModule: libConfiguration => extModules = "BitcoinCash" @new external newBlockchainModule: libConfiguration => extModules = "Blockchain" -@new external newCryptoModule: libConfiguration => extModules = "Crypto" -@new external newECPairModule: libConfiguration => extModules = "ECPair" +@new external newCryptoModule: unit => extModules = "Crypto" +@new external newECPairModule: unit => extModules = "ECPair" @new external newEncryptionModule: libConfiguration => extModules = "Encryption" @new external newGeneratingModule: libConfiguration => extModules = "Generating" @new external newHDNodeModule: libConfiguration => extModules = "HDNode" @@ -126,25 +126,28 @@ module BCHJS = { apiToken, authToken, } - let Electrumx = newElectrumxModule(libConfig) - let Control = newControlModule(libConfig) - let Mining = newMiningModule(libConfig) - let RawTransactions = newRawTransactionsModule(libConfig) - let Address = newAddressModule(libConfig) - let Blockchain = newBlockchainModule(libConfig) - let Encryption = newEncryptionModule(libConfig) - let Generating = newGeneratingModule(libConfig) - let HDNode = newHDNodeModule(libConfig) - let Menmonic = newMnemonicModule(libConfig) - let Price = newPriceModule(libConfig) - let Script = newScriptModule(libConfig) - let Util = newUtilModule(libConfig) - let Schnorr = newSchnorrModule(libConfig) - let SLP = newSLPModule(libConfig) - let Utxo = newUtxoModule(libConfig) - let Transaction = newTransactionModule(libConfig) - let DSProof = newDSProofModule(libConfig) - let Ecash = newECashModule(libConfig) - let PsfSlpIndexer = newPsfSlpIndexerModule(libConfig) + let electrumx = newElectrumxModule(libConfig) + let control = newControlModule(libConfig) + let mining = newMiningModule(libConfig) + let rawTransactions = newRawTransactionsModule(libConfig) + let address = newAddressModule(libConfig) + let blockchain = newBlockchainModule(libConfig) + let crypto = newCryptoModule() + let ecPair = newECPairModule() + let encryption = newEncryptionModule(libConfig) + let generating = newGeneratingModule(libConfig) + let hdNode = newHDNodeModule(libConfig) + let mnemonic = newMnemonicModule(libConfig) + let price = newPriceModule(libConfig) + let script = newScriptModule(libConfig) + let util = newUtilModule(libConfig) + let schnorr = newSchnorrModule(libConfig) + let slp = newSLPModule(libConfig) + let utxo = newUtxoModule(libConfig) + let transaction = newTransactionModule(libConfig) + let dsProof = newDSProofModule(libConfig) + let ecash = newECashModule(libConfig) + let psfSlpIndexer = newPsfSlpIndexerModule(libConfig) + Js.log2("Crypto module is: ", crypto) } } From 6741ea9de9691d786fbe0290a07873dcc34170fb Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Mon, 26 Sep 2022 22:47:17 +0530 Subject: [PATCH 12/53] - Implemented two different modules for `ECPair` and `Address` --- src/rescript/BchRe.bs.js | 6 ------ src/rescript/BchRe.res | 28 ++++++++++++++++++++++------ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/rescript/BchRe.bs.js b/src/rescript/BchRe.bs.js index f3e7084..7b9990a 100644 --- a/src/rescript/BchRe.bs.js +++ b/src/rescript/BchRe.bs.js @@ -21,14 +21,10 @@ var rawTransactions = require("./raw-transactions"); var mnemonic = require("./mnemonic"); -var address = require("./address"); - var hdNode = require("./hdnode"); var transactionBuilder = require("./transaction-builder"); -var ecPair = require("./ecpair"); - var script = require("./script"); var price = require("./price"); @@ -109,10 +105,8 @@ export { mining , rawTransactions , mnemonic , - address , hdNode , transactionBuilder , - ecPair , script , price , schnorr , diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index 6c80a31..3642ead 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -8,6 +8,8 @@ type libConfiguration = { @val @scope(("process", "env")) external envApiToken: string = "BCHJSTOKEN" @val @scope(("process", "env")) external envAuthPass: string = "BCHJSAUTHPASS" +type ecPairModule +type addressModule type extModules = | BitcoinCash | Crypto @@ -39,11 +41,11 @@ external require: string => extModules = "require" @new external newControlModule: libConfiguration => extModules = "Control" @new external newMiningModule: libConfiguration => extModules = "Mining" @new external newRawTransactionsModule: libConfiguration => extModules = "RawTransactions" -@new external newAddressModule: libConfiguration => extModules = "Address" +// @new external newAddressModule: libConfiguration => extModules = "Address" @new external newBitcoinCashModule: libConfiguration => extModules = "BitcoinCash" @new external newBlockchainModule: libConfiguration => extModules = "Blockchain" @new external newCryptoModule: unit => extModules = "Crypto" -@new external newECPairModule: unit => extModules = "ECPair" +// @new external newECPairModule: unit => extModules = "ECPair" @new external newEncryptionModule: libConfiguration => extModules = "Encryption" @new external newGeneratingModule: libConfiguration => extModules = "Generating" @new external newHDNodeModule: libConfiguration => extModules = "HDNode" @@ -69,10 +71,10 @@ let generating = require("./generating") let mining = require("./mining") let rawTransactions = require("./raw-transactions") let mnemonic = require("./mnemonic") -let address = require("./address") +// let address = require("./address") let hdNode = require("./hdnode") let transactionBuilder = require("./transaction-builder") -let ecPair = require("./ecpair") +// let ecPair = require("./ecpair") let script = require("./script") let price = require("./price") let schnorr = require("./schnorr") @@ -126,14 +128,26 @@ module BCHJS = { apiToken, authToken, } + + module Address = { + type addressModule + @new external newAddressModule: libConfiguration => addressModule = "Address" + } + module ECPair = { + type ecPairModule + @send + external setAddress: (ecPairModule, Address.addressModule) => ecPairModule = "setAddress" + @new external newECPairModule: unit => ecPairModule = "ECPair" + } + let electrumx = newElectrumxModule(libConfig) let control = newControlModule(libConfig) let mining = newMiningModule(libConfig) let rawTransactions = newRawTransactionsModule(libConfig) - let address = newAddressModule(libConfig) + let address = Address.newAddressModule(libConfig) let blockchain = newBlockchainModule(libConfig) let crypto = newCryptoModule() - let ecPair = newECPairModule() + let ecPair = ECPair.newECPairModule() let encryption = newEncryptionModule(libConfig) let generating = newGeneratingModule(libConfig) let hdNode = newHDNodeModule(libConfig) @@ -149,5 +163,7 @@ module BCHJS = { let ecash = newECashModule(libConfig) let psfSlpIndexer = newPsfSlpIndexerModule(libConfig) Js.log2("Crypto module is: ", crypto) + // ECPair.setAddress(address) + // ecPair->ECPair.setAddress(address) } } From 3d224347f96268ac45dbb888ba130a89021772ef Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Tue, 27 Sep 2022 00:17:46 +0530 Subject: [PATCH 13/53] - Implemented module bodies for some modules --- src/rescript/BchRe.bs.js | 16 ++++++++++++---- src/rescript/BchRe.res | 34 +++++++++++++++++++++++----------- 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/src/rescript/BchRe.bs.js b/src/rescript/BchRe.bs.js index 7b9990a..c95b06f 100644 --- a/src/rescript/BchRe.bs.js +++ b/src/rescript/BchRe.bs.js @@ -21,10 +21,14 @@ var rawTransactions = require("./raw-transactions"); var mnemonic = require("./mnemonic"); +var address = require("./address"); + var hdNode = require("./hdnode"); var transactionBuilder = require("./transaction-builder"); +var ecPair = require("./ecpair"); + var script = require("./script"); var price = require("./price"); @@ -69,14 +73,12 @@ function constructor(config) { new Control(libConfig); new Mining(libConfig); new RawTransactions(libConfig); - new Address(libConfig); + var address = new Address(libConfig); new Blockchain(libConfig); var crypto = new Crypto(); - new ECPair(); + var ecPair = new ECPair(); new Encryption(libConfig); new Generating(libConfig); - new HDNode(libConfig); - new Mnemonic(libConfig); new Price(libConfig); new Script(libConfig); new Util(libConfig); @@ -88,6 +90,10 @@ function constructor(config) { new Ecash(libConfig); new PsfSlpIndexer(libConfig); console.log("Crypto module is: ", crypto); + ecPair.setAddress(address); + new HDNode(address); + new Mnemonic(address); + new TransactionBuilder(address); } var BCHJS = { @@ -105,8 +111,10 @@ export { mining , rawTransactions , mnemonic , + address , hdNode , transactionBuilder , + ecPair , script , price , schnorr , diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index 3642ead..cb3189a 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -8,8 +8,6 @@ type libConfiguration = { @val @scope(("process", "env")) external envApiToken: string = "BCHJSTOKEN" @val @scope(("process", "env")) external envAuthPass: string = "BCHJSAUTHPASS" -type ecPairModule -type addressModule type extModules = | BitcoinCash | Crypto @@ -48,11 +46,11 @@ external require: string => extModules = "require" // @new external newECPairModule: unit => extModules = "ECPair" @new external newEncryptionModule: libConfiguration => extModules = "Encryption" @new external newGeneratingModule: libConfiguration => extModules = "Generating" -@new external newHDNodeModule: libConfiguration => extModules = "HDNode" -@new external newMnemonicModule: libConfiguration => extModules = "Mnemonic" +// @new external newHDNodeModule: extModules => extModules = "HDNode" +// @new external newMnemonicModule: libConfiguration => extModules = "Mnemonic" @new external newPriceModule: libConfiguration => extModules = "Price" @new external newScriptModule: libConfiguration => extModules = "Script" -@new external newTransactionBuilderModule: libConfiguration => extModules = "TransactionBuilder" +// @new external newTransactionBuilderModule: libConfiguration => extModules = "TransactionBuilder" @new external newUtilModule: libConfiguration => extModules = "Util" @new external newSchnorrModule: libConfiguration => extModules = "Schnorr" @new external newSLPModule: libConfiguration => extModules = "SLP" @@ -71,10 +69,10 @@ let generating = require("./generating") let mining = require("./mining") let rawTransactions = require("./raw-transactions") let mnemonic = require("./mnemonic") -// let address = require("./address") +let address = require("./address") let hdNode = require("./hdnode") let transactionBuilder = require("./transaction-builder") -// let ecPair = require("./ecpair") +let ecPair = require("./ecpair") let script = require("./script") let price = require("./price") let schnorr = require("./schnorr") @@ -139,6 +137,18 @@ module BCHJS = { external setAddress: (ecPairModule, Address.addressModule) => ecPairModule = "setAddress" @new external newECPairModule: unit => ecPairModule = "ECPair" } + module HDNode = { + type hdNode + @new external newHDNodeModule: Address.addressModule => hdNode = "HDNode" + } + module Mnemonic = { + type mnemonic + @new external newMnemonicModule: Address.addressModule => mnemonic = "Mnemonic" + } + module TransactionBuilder = { + type transactionBuilder + @new external setAddress: Address.addressModule => transactionBuilder = "TransactionBuilder" + } let electrumx = newElectrumxModule(libConfig) let control = newControlModule(libConfig) @@ -150,8 +160,8 @@ module BCHJS = { let ecPair = ECPair.newECPairModule() let encryption = newEncryptionModule(libConfig) let generating = newGeneratingModule(libConfig) - let hdNode = newHDNodeModule(libConfig) - let mnemonic = newMnemonicModule(libConfig) + //let hdNode = newHDNodeModule(address) + // let mnemonic = newMnemonicModule(libConfig) let price = newPriceModule(libConfig) let script = newScriptModule(libConfig) let util = newUtilModule(libConfig) @@ -163,7 +173,9 @@ module BCHJS = { let ecash = newECashModule(libConfig) let psfSlpIndexer = newPsfSlpIndexerModule(libConfig) Js.log2("Crypto module is: ", crypto) - // ECPair.setAddress(address) - // ecPair->ECPair.setAddress(address) + let ecPair = ecPair->ECPair.setAddress(address) + let hdNode = HDNode.newHDNodeModule(address) + let mnemonic = Mnemonic.newMnemonicModule(address) + let transactionBuilder = TransactionBuilder.setAddress(address) } } From a0c5c0c12b590193842d87ce12660991cfb378e3 Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Fri, 30 Sep 2022 19:21:54 +0530 Subject: [PATCH 14/53] - Created an `es6` class based api to expose BchRe --- src/rescript/index.js | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/rescript/index.js diff --git a/src/rescript/index.js b/src/rescript/index.js new file mode 100644 index 0000000..c5190a3 --- /dev/null +++ b/src/rescript/index.js @@ -0,0 +1,9 @@ +const BchRe = require("./BchRe.bs") + +class BCHJS { + constructor(config){ + return BchRe.BCHJS.constructor(config) + } +} + +module.exports = BCHJS \ No newline at end of file From 0821ad0492d2a1dbb4df053d7a80cbe8bcbb2ca8 Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Wed, 5 Oct 2022 18:31:29 +0530 Subject: [PATCH 15/53] - Added `Script` module in the returned object --- src/rescript/BchRe.bs.js | 181 ++++++++++++++++++++++----------------- src/rescript/BchRe.res | 158 +++++++++++++++++++--------------- src/rescript/index.js | 4 +- 3 files changed, 192 insertions(+), 151 deletions(-) diff --git a/src/rescript/BchRe.bs.js b/src/rescript/BchRe.bs.js index c95b06f..17adac2 100644 --- a/src/rescript/BchRe.bs.js +++ b/src/rescript/BchRe.bs.js @@ -1,57 +1,70 @@ // Generated by ReScript, PLEASE EDIT WITH CARE +'use strict'; var defaultRestApi = "https://api.fullstack.cash/v5/"; -var bitcoincash = require("./bitcoincash"); +var bitcoinCash = require("../bitcoincash"); -var crypto = require("./crypto"); +var crypto = require("../crypto"); -var until = require("./util"); +var util = require("../util"); -var blockchain = require("./blockchain"); +var blockchain = require("../blockchain"); -var control = require("./control"); +var control = require("../control"); -var generating = require("./generating"); +var generating = require("../generating"); -var mining = require("./mining"); +var mining = require("../mining"); -var rawTransactions = require("./raw-transactions"); +var rawTransactions = require("../raw-transactions"); -var mnemonic = require("./mnemonic"); +var mnemonic = require("../mnemonic"); -var address = require("./address"); +var address = require("../address"); -var hdNode = require("./hdnode"); +var hdNode = require("../hdnode"); -var transactionBuilder = require("./transaction-builder"); +var transactionBuilder = require("../transaction-builder"); -var ecPair = require("./ecpair"); +var ecPair = require("../ecpair"); -var script = require("./script"); +var script = require("../script"); -var price = require("./price"); +var price = require("../price"); -var schnorr = require("./schnorr"); +var schnorr = require("../schnorr"); -var slp = require("./slp/slp"); +var slp = require("../slp/slp"); -var encryption = require("./encryption"); +var encryption = require("../encryption"); -var utxo = require("./utxo"); +var utxo = require("../utxo"); -var transaction = require("./transaction"); +var transaction = require("../transaction"); -var dsProof = require("./dsproof"); +var dsProof = require("../dsproof"); -var eCash = require("./ecash"); +var eCash = require("../ecash"); -var electrumx = require("./electrumx"); +var electrumx = require("../electrumx"); -var psfSlpIndexer = require("./psf-slp-indexer"); +var psfSlpIndexer = require("../psf-slp-indexer"); -function constructor(config) { +var Address = {}; + +var ECPair = {}; + +var HDNode = {}; + +var Mnemonic = {}; + +var TransactionBuilder = {}; + +var BitcoinCash = {}; + +function make(config) { var restURL; if (config !== undefined) { restURL = config; @@ -69,63 +82,71 @@ function constructor(config) { apiToken: apiToken, authToken: authToken }; - new Electrumx(libConfig); - new Control(libConfig); - new Mining(libConfig); - new RawTransactions(libConfig); - var address = new Address(libConfig); - new Blockchain(libConfig); - var crypto = new Crypto(); - var ecPair = new ECPair(); - new Encryption(libConfig); - new Generating(libConfig); - new Price(libConfig); - new Script(libConfig); - new Util(libConfig); - new Schnorr(libConfig); - new SLP(libConfig); - new Utxo(libConfig); - new Transaction(libConfig); - new DSProof(libConfig); - new Ecash(libConfig); - new PsfSlpIndexer(libConfig); - console.log("Crypto module is: ", crypto); - ecPair.setAddress(address); - new HDNode(address); - new Mnemonic(address); - new TransactionBuilder(address); + new electrumx(libConfig); + new control(libConfig); + new mining(libConfig); + new rawTransactions(libConfig); + var address$2 = new address(libConfig); + new blockchain(libConfig); + new crypto(); + new encryption(libConfig); + new generating(libConfig); + new price(libConfig); + var script$2 = new script(libConfig); + new util(libConfig); + new schnorr(libConfig); + new slp(libConfig); + new utxo(libConfig); + new transaction(libConfig); + new dsProof(libConfig); + new eCash(libConfig); + new psfSlpIndexer(libConfig); + ecPair.setAddress(address$2); + new hdNode(address$2); + new mnemonic(address$2); + new transactionBuilder(address$2); + var bitcoinCash$2 = new bitcoinCash(address$2); + return { + Address: address$2, + BitcoinCash: bitcoinCash$2, + Script: script$2 + }; } var BCHJS = { - constructor: constructor + make: make }; -export { - defaultRestApi , - bitcoincash , - crypto , - until , - blockchain , - control , - generating , - mining , - rawTransactions , - mnemonic , - address , - hdNode , - transactionBuilder , - ecPair , - script , - price , - schnorr , - slp , - encryption , - utxo , - transaction , - dsProof , - eCash , - electrumx , - psfSlpIndexer , - BCHJS , -} -/* bitcoincash Not a pure module */ +exports.defaultRestApi = defaultRestApi; +exports.bitcoinCash = bitcoinCash; +exports.crypto = crypto; +exports.util = util; +exports.blockchain = blockchain; +exports.control = control; +exports.generating = generating; +exports.mining = mining; +exports.rawTransactions = rawTransactions; +exports.mnemonic = mnemonic; +exports.address = address; +exports.hdNode = hdNode; +exports.transactionBuilder = transactionBuilder; +exports.ecPair = ecPair; +exports.script = script; +exports.price = price; +exports.schnorr = schnorr; +exports.slp = slp; +exports.encryption = encryption; +exports.utxo = utxo; +exports.transaction = transaction; +exports.dsProof = dsProof; +exports.eCash = eCash; +exports.electrumx = electrumx; +exports.psfSlpIndexer = psfSlpIndexer; +exports.Address = Address; +exports.ECPair = ECPair; +exports.HDNode = HDNode; +exports.Mnemonic = Mnemonic; +exports.TransactionBuilder = TransactionBuilder; +exports.BitcoinCash = BitcoinCash; +exports.BCHJS = BCHJS; +/* bitcoinCash Not a pure module */ diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index cb3189a..b98f743 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -35,55 +35,55 @@ type extModules = | PsfSlpIndexer external require: string => extModules = "require" -@new external newElectrumxModule: libConfiguration => extModules = "Electrumx" -@new external newControlModule: libConfiguration => extModules = "Control" -@new external newMiningModule: libConfiguration => extModules = "Mining" -@new external newRawTransactionsModule: libConfiguration => extModules = "RawTransactions" -// @new external newAddressModule: libConfiguration => extModules = "Address" -@new external newBitcoinCashModule: libConfiguration => extModules = "BitcoinCash" -@new external newBlockchainModule: libConfiguration => extModules = "Blockchain" -@new external newCryptoModule: unit => extModules = "Crypto" +@new external newElectrumxModule: libConfiguration => extModules = "electrumx" +@new external newControlModule: libConfiguration => extModules = "control" +@new external newMiningModule: libConfiguration => extModules = "mining" +@new external newRawTransactionsModule: libConfiguration => extModules = "rawTransactions" +// @new external newAddressModule: libConfiguration => extModules = "address" +// @new external newBitcoinCashModule: libConfiguration => extModules = "bitcoinCash" +@new external newBlockchainModule: libConfiguration => extModules = "blockchain" +@new external newCryptoModule: unit => extModules = "crypto" // @new external newECPairModule: unit => extModules = "ECPair" -@new external newEncryptionModule: libConfiguration => extModules = "Encryption" -@new external newGeneratingModule: libConfiguration => extModules = "Generating" +@new external newEncryptionModule: libConfiguration => extModules = "encryption" +@new external newGeneratingModule: libConfiguration => extModules = "generating" // @new external newHDNodeModule: extModules => extModules = "HDNode" // @new external newMnemonicModule: libConfiguration => extModules = "Mnemonic" -@new external newPriceModule: libConfiguration => extModules = "Price" -@new external newScriptModule: libConfiguration => extModules = "Script" +@new external newPriceModule: libConfiguration => extModules = "price" +@new external newScriptModule: libConfiguration => extModules = "script" // @new external newTransactionBuilderModule: libConfiguration => extModules = "TransactionBuilder" -@new external newUtilModule: libConfiguration => extModules = "Util" -@new external newSchnorrModule: libConfiguration => extModules = "Schnorr" -@new external newSLPModule: libConfiguration => extModules = "SLP" -@new external newUtxoModule: libConfiguration => extModules = "Utxo" -@new external newTransactionModule: libConfiguration => extModules = "Transaction" -@new external newDSProofModule: libConfiguration => extModules = "DSProof" -@new external newECashModule: libConfiguration => extModules = "Ecash" -@new external newPsfSlpIndexerModule: libConfiguration => extModules = "PsfSlpIndexer" +@new external newUtilModule: libConfiguration => extModules = "util" +@new external newSchnorrModule: libConfiguration => extModules = "schnorr" +@new external newSLPModule: libConfiguration => extModules = "slp" +@new external newUtxoModule: libConfiguration => extModules = "utxo" +@new external newTransactionModule: libConfiguration => extModules = "transaction" +@new external newDSProofModule: libConfiguration => extModules = "dsProof" +@new external newECashModule: libConfiguration => extModules = "eCash" +@new external newPsfSlpIndexerModule: libConfiguration => extModules = "psfSlpIndexer" -let bitcoincash = require("./bitcoincash") -let crypto = require("./crypto") -let until = require("./util") -let blockchain = require("./blockchain") -let control = require("./control") -let generating = require("./generating") -let mining = require("./mining") -let rawTransactions = require("./raw-transactions") -let mnemonic = require("./mnemonic") -let address = require("./address") -let hdNode = require("./hdnode") -let transactionBuilder = require("./transaction-builder") -let ecPair = require("./ecpair") -let script = require("./script") -let price = require("./price") -let schnorr = require("./schnorr") -let slp = require("./slp/slp") -let encryption = require("./encryption") -let utxo = require("./utxo") -let transaction = require("./transaction") -let dsProof = require("./dsproof") -let eCash = require("./ecash") -let electrumx = require("./electrumx") -let psfSlpIndexer = require("./psf-slp-indexer") +let bitcoinCash = require("../bitcoincash") +let crypto = require("../crypto") +let util = require("../util") +let blockchain = require("../blockchain") +let control = require("../control") +let generating = require("../generating") +let mining = require("../mining") +let rawTransactions = require("../raw-transactions") +let mnemonic = require("../mnemonic") +let address = require("../address") +let hdNode = require("../hdnode") +let transactionBuilder = require("../transaction-builder") +let ecPair = require("../ecpair") +let script = require("../script") +let price = require("../price") +let schnorr = require("../schnorr") +let slp = require("../slp/slp") +let encryption = require("../encryption") +let utxo = require("../utxo") +let transaction = require("../transaction") +let dsProof = require("../dsproof") +let eCash = require("../ecash") +let electrumx = require("../electrumx") +let psfSlpIndexer = require("../psf-slp-indexer") type restURL = string type apiToken @@ -98,8 +98,40 @@ type configurationObject = { authToken: option, } type configuration = option + +module Address = { + type addressModule + @new external newAddressModule: libConfiguration => addressModule = "address" +} +module ECPair = { + type ecPairModule + @send + external setAddress: (extModules, Address.addressModule) => ecPairModule = "setAddress" + @new external newECPairModule: unit => ecPairModule = "ecPair" +} +module HDNode = { + type hdNode + @new external newHDNodeModule: Address.addressModule => hdNode = "hdNode" +} +module Mnemonic = { + type mnemonic + @new external newMnemonicModule: Address.addressModule => mnemonic = "mnemonic" +} +module TransactionBuilder = { + type transactionBuilder + @new external setAddress: Address.addressModule => transactionBuilder = "transactionBuilder" +} +module BitcoinCash = { + type bitcoinCash +@new external newBitcoinCashModule: Address.addressModule => bitcoinCash = "bitcoinCash" +} + module BCHJS = { - let constructor = config => { + type t = {@as("Address") address: Address.addressModule, + @as("BitcoinCash") bitcoinCash :BitcoinCash.bitcoinCash, + @as("Script") script: extModules} + + let make = config => { let restURL = switch config { | Some(url) => url | None => @@ -127,43 +159,23 @@ module BCHJS = { authToken, } - module Address = { - type addressModule - @new external newAddressModule: libConfiguration => addressModule = "Address" - } - module ECPair = { - type ecPairModule - @send - external setAddress: (ecPairModule, Address.addressModule) => ecPairModule = "setAddress" - @new external newECPairModule: unit => ecPairModule = "ECPair" - } - module HDNode = { - type hdNode - @new external newHDNodeModule: Address.addressModule => hdNode = "HDNode" - } - module Mnemonic = { - type mnemonic - @new external newMnemonicModule: Address.addressModule => mnemonic = "Mnemonic" - } - module TransactionBuilder = { - type transactionBuilder - @new external setAddress: Address.addressModule => transactionBuilder = "TransactionBuilder" - } - let electrumx = newElectrumxModule(libConfig) + // Js.log(electrumx) let control = newControlModule(libConfig) let mining = newMiningModule(libConfig) let rawTransactions = newRawTransactionsModule(libConfig) let address = Address.newAddressModule(libConfig) + // Js.log2("Address module is: ", address) let blockchain = newBlockchainModule(libConfig) let crypto = newCryptoModule() - let ecPair = ECPair.newECPairModule() + // let ecPair = ECPair.newECPairModule() let encryption = newEncryptionModule(libConfig) let generating = newGeneratingModule(libConfig) //let hdNode = newHDNodeModule(address) // let mnemonic = newMnemonicModule(libConfig) let price = newPriceModule(libConfig) let script = newScriptModule(libConfig) + // Js.log2("Script module is: ", script) let util = newUtilModule(libConfig) let schnorr = newSchnorrModule(libConfig) let slp = newSLPModule(libConfig) @@ -172,10 +184,16 @@ module BCHJS = { let dsProof = newDSProofModule(libConfig) let ecash = newECashModule(libConfig) let psfSlpIndexer = newPsfSlpIndexerModule(libConfig) - Js.log2("Crypto module is: ", crypto) + // Js.log2("Crypto module is: ", crypto) let ecPair = ecPair->ECPair.setAddress(address) let hdNode = HDNode.newHDNodeModule(address) let mnemonic = Mnemonic.newMnemonicModule(address) let transactionBuilder = TransactionBuilder.setAddress(address) + let bitcoinCash = BitcoinCash.newBitcoinCashModule(address) + { + address: address, + bitcoinCash: bitcoinCash, + script: script + } } } diff --git a/src/rescript/index.js b/src/rescript/index.js index c5190a3..3a0c5a4 100644 --- a/src/rescript/index.js +++ b/src/rescript/index.js @@ -2,7 +2,9 @@ const BchRe = require("./BchRe.bs") class BCHJS { constructor(config){ - return BchRe.BCHJS.constructor(config) + let bchjs = BchRe.BCHJS.make(config) + // console.log("bchjs object:", bchjs) + return bchjs } } From 1e9a9cefda9e77c63edc7024270d4c744865c657 Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Wed, 5 Oct 2022 18:58:39 +0530 Subject: [PATCH 16/53] - Implemented `Crypto` module --- src/rescript/BchRe.bs.js | 5 +++-- src/rescript/BchRe.res | 9 ++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/rescript/BchRe.bs.js b/src/rescript/BchRe.bs.js index 17adac2..9eaec6f 100644 --- a/src/rescript/BchRe.bs.js +++ b/src/rescript/BchRe.bs.js @@ -88,7 +88,7 @@ function make(config) { new rawTransactions(libConfig); var address$2 = new address(libConfig); new blockchain(libConfig); - new crypto(); + console.log("Crypto module is: ", crypto); new encryption(libConfig); new generating(libConfig); new price(libConfig); @@ -109,7 +109,8 @@ function make(config) { return { Address: address$2, BitcoinCash: bitcoinCash$2, - Script: script$2 + Script: script$2, + Crypto: crypto }; } diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index b98f743..084cc3d 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -129,7 +129,8 @@ module BitcoinCash = { module BCHJS = { type t = {@as("Address") address: Address.addressModule, @as("BitcoinCash") bitcoinCash :BitcoinCash.bitcoinCash, - @as("Script") script: extModules} + @as("Script") script: extModules, + @as("Crypto") crypto: extModules} let make = config => { let restURL = switch config { @@ -167,7 +168,8 @@ module BCHJS = { let address = Address.newAddressModule(libConfig) // Js.log2("Address module is: ", address) let blockchain = newBlockchainModule(libConfig) - let crypto = newCryptoModule() + // let crypto = newCryptoModule() + Js.log2("Crypto module is: ", crypto) // let ecPair = ECPair.newECPairModule() let encryption = newEncryptionModule(libConfig) let generating = newGeneratingModule(libConfig) @@ -193,7 +195,8 @@ module BCHJS = { { address: address, bitcoinCash: bitcoinCash, - script: script + script: script, + crypto: crypto } } } From eb79e7a36d8c7000e8ed39a1093725795c4b0b74 Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Wed, 5 Oct 2022 19:01:11 +0530 Subject: [PATCH 17/53] - Commiting all pending files --- bsconfig.json | 2 +- package.json | 2 +- test/unit/address.js | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/bsconfig.json b/bsconfig.json index 9ec636a..5fc013b 100644 --- a/bsconfig.json +++ b/bsconfig.json @@ -8,7 +8,7 @@ ], "package-specs": [ { - "module": "es6", + "module": "commonjs", "in-source": true } ], diff --git a/package.json b/package.json index 0c9cb91..46fe502 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ ], "main": "src/bch-js", "scripts": { - "test": "nyc mocha --trace-warnings --unhandled-rejections=strict --timeout 30000 test/unit/", + "test": "nyc --reporter=text-summary mocha --trace-warnings --unhandled-rejections=strict --timeout 30000 test/unit/", "test:integration": "npm run test:integration:bchn", "test:integration:nft": "export RESTURL=https://bchn.fullstack.cash/v5/ && export IS_USING_FREE_TIER=true && mocha --timeout 30000 -g '#nft1' test/integration/chains/bchn/slp.js", "test:integration:abc": "export RESTURL=https://abc.fullstack.cash/v5/ && mocha --timeout 30000 test/integration/ && mocha --timeout 30000 test/integration/chains/abc/", diff --git a/test/unit/address.js b/test/unit/address.js index 198d45c..a3dfe2b 100644 --- a/test/unit/address.js +++ b/test/unit/address.js @@ -6,7 +6,7 @@ const Bitcoin = require('@psf/bitcoincashjs-lib') const fixtures = require('./fixtures/address.json') // Unit under test (uut) -const BCHJS = require('../../src/bch-js') +const BCHJS = require('../../src/rescript/index') let bchjs function flatten (arrays) { @@ -79,7 +79,7 @@ const P2SH_ADDRESSES = flatten([ fixtures.cashaddrMainnetP2SH ]) -describe('#address.js', () => { +describe.only('#address.js', () => { beforeEach(() => { bchjs = new BCHJS() }) @@ -915,7 +915,7 @@ describe('#address.js', () => { }) describe('#fromOutputScript', () => { - it('generate address from output script', () => { + it.only('generate address from output script', () => { const script = bchjs.Script.encode([ Buffer.from('BOX', 'ascii'), bchjs.Script.opcodes.OP_CAT, @@ -924,6 +924,7 @@ describe('#address.js', () => { ]) // hash160 script buffer + console.log("From address.js, Crypto module is: ", bchjs.Crypto) const p2shHash160 = bchjs.Crypto.hash160(script) // encode hash160 as P2SH output From d21cf60a19c65e92cddef391c5d10853fa526971 Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Thu, 6 Oct 2022 01:40:53 +0530 Subject: [PATCH 18/53] - Implemented all the modules - All the tests are running good --- package.json | 2 +- src/rescript/BchRe.bs.js | 60 ++++++++++++++++++++++++++-------------- src/rescript/BchRe.res | 44 +++++++++++++++++++++++++++-- test/unit/address.js | 5 ++-- 4 files changed, 86 insertions(+), 25 deletions(-) diff --git a/package.json b/package.json index 46fe502..0c9cb91 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ ], "main": "src/bch-js", "scripts": { - "test": "nyc --reporter=text-summary mocha --trace-warnings --unhandled-rejections=strict --timeout 30000 test/unit/", + "test": "nyc mocha --trace-warnings --unhandled-rejections=strict --timeout 30000 test/unit/", "test:integration": "npm run test:integration:bchn", "test:integration:nft": "export RESTURL=https://bchn.fullstack.cash/v5/ && export IS_USING_FREE_TIER=true && mocha --timeout 30000 -g '#nft1' test/integration/chains/bchn/slp.js", "test:integration:abc": "export RESTURL=https://abc.fullstack.cash/v5/ && mocha --timeout 30000 test/integration/ && mocha --timeout 30000 test/integration/chains/abc/", diff --git a/src/rescript/BchRe.bs.js b/src/rescript/BchRe.bs.js index 9eaec6f..cbfcd8c 100644 --- a/src/rescript/BchRe.bs.js +++ b/src/rescript/BchRe.bs.js @@ -82,35 +82,55 @@ function make(config) { apiToken: apiToken, authToken: authToken }; - new electrumx(libConfig); - new control(libConfig); - new mining(libConfig); - new rawTransactions(libConfig); + var electrumx$2 = new electrumx(libConfig); + var control$2 = new control(libConfig); + var mining$2 = new mining(libConfig); + var rawTransactions$2 = new rawTransactions(libConfig); var address$2 = new address(libConfig); - new blockchain(libConfig); + var blockchain$2 = new blockchain(libConfig); console.log("Crypto module is: ", crypto); - new encryption(libConfig); - new generating(libConfig); - new price(libConfig); + var encryption$2 = new encryption(libConfig); + var generating$2 = new generating(libConfig); + var price$2 = new price(libConfig); var script$2 = new script(libConfig); - new util(libConfig); - new schnorr(libConfig); - new slp(libConfig); - new utxo(libConfig); - new transaction(libConfig); - new dsProof(libConfig); + var util$2 = new util(libConfig); + var schnorr$2 = new schnorr(libConfig); + var slp$2 = new slp(libConfig); + var utxo$2 = new utxo(libConfig); + var transaction$2 = new transaction(libConfig); + var dsProof$2 = new dsProof(libConfig); new eCash(libConfig); - new psfSlpIndexer(libConfig); - ecPair.setAddress(address$2); - new hdNode(address$2); - new mnemonic(address$2); - new transactionBuilder(address$2); + var psfSlpIndexer$2 = new psfSlpIndexer(libConfig); + var ecPair$1 = ecPair.setAddress(address$2); + var hdNode$2 = new hdNode(address$2); + var mnemonic$2 = new mnemonic(address$2); + var transactionBuilder$2 = new transactionBuilder(address$2); var bitcoinCash$2 = new bitcoinCash(address$2); return { Address: address$2, BitcoinCash: bitcoinCash$2, Script: script$2, - Crypto: crypto + Crypto: crypto, + Util: util$2, + Blockchain: blockchain$2, + Control: control$2, + Generating: generating$2, + Mining: mining$2, + RawTransacations: rawTransactions$2, + Mnemonic: mnemonic$2, + HDNode: hdNode$2, + TransactionBuilder: transactionBuilder$2, + ECPair: ecPair$1, + Price: price$2, + Schnorr: schnorr$2, + SLP: slp$2, + Encryption: encryption$2, + Utxo: utxo$2, + Transaction: transaction$2, + DSProof: dsProof$2, + Ecash: eCash, + Electrumx: electrumx$2, + PsfSlpIndexer: psfSlpIndexer$2 }; } diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index 084cc3d..593f9b8 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -130,7 +130,27 @@ module BCHJS = { type t = {@as("Address") address: Address.addressModule, @as("BitcoinCash") bitcoinCash :BitcoinCash.bitcoinCash, @as("Script") script: extModules, - @as("Crypto") crypto: extModules} + @as("Crypto") crypto: extModules, + @as("Util") util: extModules, + @as("Blockchain") blockchain: extModules, + @as("Control") control: extModules, + @as("Generating") generating: extModules, + @as("Mining") mining: extModules, + @as("RawTransacations") rawTransactions: extModules, + @as("Mnemonic") mnemonic: Mnemonic.mnemonic, + @as("HDNode") hdNode: HDNode.hdNode, + @as("TransactionBuilder") transactionBuilder: TransactionBuilder.transactionBuilder, + @as("ECPair") ecPair: ECPair.ecPairModule, + @as("Price") price: extModules, + @as("Schnorr") schnorr: extModules, + @as("SLP") slp:extModules, + @as("Encryption") encryption: extModules, + @as("Utxo") utxo: extModules, + @as("Transaction") transaction: extModules, + @as("DSProof") dsProof: extModules, + @as("Ecash") eCash: extModules, + @as("Electrumx") electrumx: extModules, + @as("PsfSlpIndexer") psfSlpIndexer: extModules} let make = config => { let restURL = switch config { @@ -196,7 +216,27 @@ module BCHJS = { address: address, bitcoinCash: bitcoinCash, script: script, - crypto: crypto + crypto: crypto, + util: util, + blockchain: blockchain, + control: control, + generating: generating, + mining: mining, + rawTransactions: rawTransactions, + mnemonic: mnemonic, + hdNode: hdNode, + transactionBuilder: transactionBuilder, + ecPair: ecPair, + price: price, + schnorr: schnorr, + slp: slp, + encryption: encryption, + utxo: utxo, + transaction: transaction, + dsProof: dsProof, + eCash: eCash, + electrumx: electrumx, + psfSlpIndexer: psfSlpIndexer } } } diff --git a/test/unit/address.js b/test/unit/address.js index a3dfe2b..85fc42a 100644 --- a/test/unit/address.js +++ b/test/unit/address.js @@ -6,6 +6,7 @@ const Bitcoin = require('@psf/bitcoincashjs-lib') const fixtures = require('./fixtures/address.json') // Unit under test (uut) +// const BCHJS = require('../../src/bch-js') const BCHJS = require('../../src/rescript/index') let bchjs @@ -79,7 +80,7 @@ const P2SH_ADDRESSES = flatten([ fixtures.cashaddrMainnetP2SH ]) -describe.only('#address.js', () => { +describe('#address.js', () => { beforeEach(() => { bchjs = new BCHJS() }) @@ -915,7 +916,7 @@ describe.only('#address.js', () => { }) describe('#fromOutputScript', () => { - it.only('generate address from output script', () => { + it('generate address from output script', () => { const script = bchjs.Script.encode([ Buffer.from('BOX', 'ascii'), bchjs.Script.opcodes.OP_CAT, From f8ad95257419604f2ab85a2c1c8c12095e05fa24 Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Thu, 6 Oct 2022 18:33:10 +0530 Subject: [PATCH 19/53] - Changed the address type to `t` in Address mod --- src/rescript/BchRe.res | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index 593f9b8..67e94bc 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -100,34 +100,34 @@ type configurationObject = { type configuration = option module Address = { - type addressModule - @new external newAddressModule: libConfiguration => addressModule = "address" + type t + @new external newAddressModule: libConfiguration => t = "address" } module ECPair = { type ecPairModule @send - external setAddress: (extModules, Address.addressModule) => ecPairModule = "setAddress" + external setAddress: (extModules, Address.t) => ecPairModule = "setAddress" @new external newECPairModule: unit => ecPairModule = "ecPair" } module HDNode = { type hdNode - @new external newHDNodeModule: Address.addressModule => hdNode = "hdNode" + @new external newHDNodeModule: Address.t => hdNode = "hdNode" } module Mnemonic = { type mnemonic - @new external newMnemonicModule: Address.addressModule => mnemonic = "mnemonic" + @new external newMnemonicModule: Address.t => mnemonic = "mnemonic" } module TransactionBuilder = { type transactionBuilder - @new external setAddress: Address.addressModule => transactionBuilder = "transactionBuilder" + @new external setAddress: Address.t => transactionBuilder = "transactionBuilder" } module BitcoinCash = { type bitcoinCash -@new external newBitcoinCashModule: Address.addressModule => bitcoinCash = "bitcoinCash" +@new external newBitcoinCashModule: Address.t => bitcoinCash = "bitcoinCash" } module BCHJS = { - type t = {@as("Address") address: Address.addressModule, + type t = {@as("Address") address: Address.t, @as("BitcoinCash") bitcoinCash :BitcoinCash.bitcoinCash, @as("Script") script: extModules, @as("Crypto") crypto: extModules, From 2037aba4643a952e4d3722f7e7aac5492bb0e7da Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Thu, 6 Oct 2022 18:37:40 +0530 Subject: [PATCH 20/53] - Changed the ECPair type to t --- src/rescript/BchRe.res | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index 67e94bc..e9cec4d 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -104,10 +104,10 @@ module Address = { @new external newAddressModule: libConfiguration => t = "address" } module ECPair = { - type ecPairModule + type t @send - external setAddress: (extModules, Address.t) => ecPairModule = "setAddress" - @new external newECPairModule: unit => ecPairModule = "ecPair" + external setAddress: (extModules, Address.t) => t = "setAddress" + @new external newECPairModule: unit => t = "ecPair" } module HDNode = { type hdNode @@ -140,7 +140,7 @@ module BCHJS = { @as("Mnemonic") mnemonic: Mnemonic.mnemonic, @as("HDNode") hdNode: HDNode.hdNode, @as("TransactionBuilder") transactionBuilder: TransactionBuilder.transactionBuilder, - @as("ECPair") ecPair: ECPair.ecPairModule, + @as("ECPair") ecPair: ECPair.t, @as("Price") price: extModules, @as("Schnorr") schnorr: extModules, @as("SLP") slp:extModules, From 9c822d76eb848d6a599e1ca695b118d3d7ebf5ff Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Thu, 6 Oct 2022 18:38:57 +0530 Subject: [PATCH 21/53] - Changed the HDNode type to t --- src/rescript/BchRe.res | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index e9cec4d..1e60cf5 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -110,8 +110,8 @@ module ECPair = { @new external newECPairModule: unit => t = "ecPair" } module HDNode = { - type hdNode - @new external newHDNodeModule: Address.t => hdNode = "hdNode" + type t + @new external newHDNodeModule: Address.t => t = "hdNode" } module Mnemonic = { type mnemonic @@ -138,7 +138,7 @@ module BCHJS = { @as("Mining") mining: extModules, @as("RawTransacations") rawTransactions: extModules, @as("Mnemonic") mnemonic: Mnemonic.mnemonic, - @as("HDNode") hdNode: HDNode.hdNode, + @as("HDNode") hdNode: HDNode.t, @as("TransactionBuilder") transactionBuilder: TransactionBuilder.transactionBuilder, @as("ECPair") ecPair: ECPair.t, @as("Price") price: extModules, From 6a6331d12ddfe1fdb0404e856ec8b7f4e76e5237 Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Thu, 6 Oct 2022 18:49:38 +0530 Subject: [PATCH 22/53] - Changed `Mnemonic` type to `t` --- src/rescript/BchRe.res | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index 1e60cf5..30de081 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -114,8 +114,8 @@ module HDNode = { @new external newHDNodeModule: Address.t => t = "hdNode" } module Mnemonic = { - type mnemonic - @new external newMnemonicModule: Address.t => mnemonic = "mnemonic" + type t + @new external newMnemonicModule: Address.t => t = "mnemonic" } module TransactionBuilder = { type transactionBuilder @@ -137,7 +137,7 @@ module BCHJS = { @as("Generating") generating: extModules, @as("Mining") mining: extModules, @as("RawTransacations") rawTransactions: extModules, - @as("Mnemonic") mnemonic: Mnemonic.mnemonic, + @as("Mnemonic") mnemonic: Mnemonic.t, @as("HDNode") hdNode: HDNode.t, @as("TransactionBuilder") transactionBuilder: TransactionBuilder.transactionBuilder, @as("ECPair") ecPair: ECPair.t, From 9d14e176345a3779f25d3b571175bf8f152e966f Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Thu, 6 Oct 2022 18:51:25 +0530 Subject: [PATCH 23/53] - Changed the `TransactionBuilder` type to `t` --- src/rescript/BchRe.res | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index 30de081..d5f2914 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -118,8 +118,8 @@ module Mnemonic = { @new external newMnemonicModule: Address.t => t = "mnemonic" } module TransactionBuilder = { - type transactionBuilder - @new external setAddress: Address.t => transactionBuilder = "transactionBuilder" + type t + @new external setAddress: Address.t => t = "transactionBuilder" } module BitcoinCash = { type bitcoinCash @@ -139,7 +139,7 @@ module BCHJS = { @as("RawTransacations") rawTransactions: extModules, @as("Mnemonic") mnemonic: Mnemonic.t, @as("HDNode") hdNode: HDNode.t, - @as("TransactionBuilder") transactionBuilder: TransactionBuilder.transactionBuilder, + @as("TransactionBuilder") transactionBuilder: TransactionBuilder.t, @as("ECPair") ecPair: ECPair.t, @as("Price") price: extModules, @as("Schnorr") schnorr: extModules, From eb7604afe803c47f4f7ee98e60d861a5c31d6dda Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Thu, 6 Oct 2022 18:54:24 +0530 Subject: [PATCH 24/53] - Changed `BitcoinCash` type to `t` --- src/rescript/BchRe.res | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index d5f2914..c40c0a4 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -122,13 +122,13 @@ module TransactionBuilder = { @new external setAddress: Address.t => t = "transactionBuilder" } module BitcoinCash = { - type bitcoinCash -@new external newBitcoinCashModule: Address.t => bitcoinCash = "bitcoinCash" + type t +@new external newBitcoinCashModule: Address.t => t = "bitcoinCash" } module BCHJS = { type t = {@as("Address") address: Address.t, - @as("BitcoinCash") bitcoinCash :BitcoinCash.bitcoinCash, + @as("BitcoinCash") bitcoinCash :BitcoinCash.t, @as("Script") script: extModules, @as("Crypto") crypto: extModules, @as("Util") util: extModules, From 84c98a9d3642e884faae8060b56a7d4d7d705774 Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Thu, 6 Oct 2022 19:41:14 +0530 Subject: [PATCH 25/53] - Implemented `ECPair` and `Encryption` module --- src/rescript/BchRe.bs.js | 42 +++++++++------- src/rescript/BchRe.res | 102 +++++++++++++++++++++++++++------------ 2 files changed, 95 insertions(+), 49 deletions(-) diff --git a/src/rescript/BchRe.bs.js b/src/rescript/BchRe.bs.js index cbfcd8c..0fe75d9 100644 --- a/src/rescript/BchRe.bs.js +++ b/src/rescript/BchRe.bs.js @@ -4,6 +4,22 @@ var defaultRestApi = "https://api.fullstack.cash/v5/"; +var Address = {}; + +var ECPair = {}; + +var HDNode = {}; + +var Mnemonic = {}; + +var TransactionBuilder = {}; + +var BitcoinCash = {}; + +var $$Crypto = {}; + +var Encryption = {}; + var bitcoinCash = require("../bitcoincash"); var crypto = require("../crypto"); @@ -52,18 +68,6 @@ var electrumx = require("../electrumx"); var psfSlpIndexer = require("../psf-slp-indexer"); -var Address = {}; - -var ECPair = {}; - -var HDNode = {}; - -var Mnemonic = {}; - -var TransactionBuilder = {}; - -var BitcoinCash = {}; - function make(config) { var restURL; if (config !== undefined) { @@ -139,6 +143,14 @@ var BCHJS = { }; exports.defaultRestApi = defaultRestApi; +exports.Address = Address; +exports.ECPair = ECPair; +exports.HDNode = HDNode; +exports.Mnemonic = Mnemonic; +exports.TransactionBuilder = TransactionBuilder; +exports.BitcoinCash = BitcoinCash; +exports.$$Crypto = $$Crypto; +exports.Encryption = Encryption; exports.bitcoinCash = bitcoinCash; exports.crypto = crypto; exports.util = util; @@ -163,11 +175,5 @@ exports.dsProof = dsProof; exports.eCash = eCash; exports.electrumx = electrumx; exports.psfSlpIndexer = psfSlpIndexer; -exports.Address = Address; -exports.ECPair = ECPair; -exports.HDNode = HDNode; -exports.Mnemonic = Mnemonic; -exports.TransactionBuilder = TransactionBuilder; -exports.BitcoinCash = BitcoinCash; exports.BCHJS = BCHJS; /* bitcoinCash Not a pure module */ diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index c40c0a4..8084e0d 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -42,9 +42,9 @@ external require: string => extModules = "require" // @new external newAddressModule: libConfiguration => extModules = "address" // @new external newBitcoinCashModule: libConfiguration => extModules = "bitcoinCash" @new external newBlockchainModule: libConfiguration => extModules = "blockchain" -@new external newCryptoModule: unit => extModules = "crypto" +// @new external newCryptoModule: unit => extModules = "crypto" // @new external newECPairModule: unit => extModules = "ECPair" -@new external newEncryptionModule: libConfiguration => extModules = "encryption" +// @new external newEncryptionModule: libConfiguration => extModules = "encryption" @new external newGeneratingModule: libConfiguration => extModules = "generating" // @new external newHDNodeModule: extModules => extModules = "HDNode" // @new external newMnemonicModule: libConfiguration => extModules = "Mnemonic" @@ -60,6 +60,41 @@ external require: string => extModules = "require" @new external newECashModule: libConfiguration => extModules = "eCash" @new external newPsfSlpIndexerModule: libConfiguration => extModules = "psfSlpIndexer" +module Address = { + type t + @new external newAddressModule: libConfiguration => t = "address" +} +module ECPair = { + type t +external require: string => t = "require" + @send + external setAddress: (t, Address.t) => t = "setAddress" + @new external newECPairModule: unit => t = "ecPair" +} +module HDNode = { + type t + @new external newHDNodeModule: Address.t => t = "hdNode" +} +module Mnemonic = { + type t + @new external newMnemonicModule: Address.t => t = "mnemonic" +} +module TransactionBuilder = { + type t + @new external setAddress: Address.t => t = "transactionBuilder" +} +module BitcoinCash = { + type t +@new external newBitcoinCashModule: Address.t => t = "bitcoinCash" +} +module Crypto = { + type t +@new external newCryptoModule: unit => t = "crypto" +} +module Encryption = { + type t +@new external newEncryptionModule: libConfiguration => t = "encryption" +} let bitcoinCash = require("../bitcoincash") let crypto = require("../crypto") let util = require("../util") @@ -72,7 +107,7 @@ let mnemonic = require("../mnemonic") let address = require("../address") let hdNode = require("../hdnode") let transactionBuilder = require("../transaction-builder") -let ecPair = require("../ecpair") +let ecPair = ECPair.require("../ecpair") let script = require("../script") let price = require("../price") let schnorr = require("../schnorr") @@ -99,32 +134,37 @@ type configurationObject = { } type configuration = option -module Address = { - type t - @new external newAddressModule: libConfiguration => t = "address" -} -module ECPair = { - type t - @send - external setAddress: (extModules, Address.t) => t = "setAddress" - @new external newECPairModule: unit => t = "ecPair" -} -module HDNode = { - type t - @new external newHDNodeModule: Address.t => t = "hdNode" -} -module Mnemonic = { - type t - @new external newMnemonicModule: Address.t => t = "mnemonic" -} -module TransactionBuilder = { - type t - @new external setAddress: Address.t => t = "transactionBuilder" -} -module BitcoinCash = { - type t -@new external newBitcoinCashModule: Address.t => t = "bitcoinCash" -} +// module Address = { +// type t +// @new external newAddressModule: libConfiguration => t = "address" +// } +// module ECPair = { +// type t +// @send +// external setAddress: (t, Address.t) => t = "setAddress" +// @new external newECPairModule: unit => t = "ecPair" +// } +// module HDNode = { +// type t +// @new external newHDNodeModule: Address.t => t = "hdNode" +// } +// module Mnemonic = { +// type t +// @new external newMnemonicModule: Address.t => t = "mnemonic" +// } +// module TransactionBuilder = { +// type t +// @new external setAddress: Address.t => t = "transactionBuilder" +// } +// module BitcoinCash = { +// type t +// @new external newBitcoinCashModule: Address.t => t = "bitcoinCash" +// } +// module Crypto = { +// type t +// external require: string => t = "require" +// @new external newCryptoModule: unit => t = "crypto" +// } module BCHJS = { type t = {@as("Address") address: Address.t, @@ -144,7 +184,7 @@ module BCHJS = { @as("Price") price: extModules, @as("Schnorr") schnorr: extModules, @as("SLP") slp:extModules, - @as("Encryption") encryption: extModules, + @as("Encryption") encryption: Encryption.t, @as("Utxo") utxo: extModules, @as("Transaction") transaction: extModules, @as("DSProof") dsProof: extModules, @@ -191,7 +231,7 @@ module BCHJS = { // let crypto = newCryptoModule() Js.log2("Crypto module is: ", crypto) // let ecPair = ECPair.newECPairModule() - let encryption = newEncryptionModule(libConfig) + let encryption = Encryption.newEncryptionModule(libConfig) let generating = newGeneratingModule(libConfig) //let hdNode = newHDNodeModule(address) // let mnemonic = newMnemonicModule(libConfig) From a2c82f872ab9ad3d6e65a21238692a5edcd9014b Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Thu, 6 Oct 2022 20:19:43 +0530 Subject: [PATCH 26/53] - Implemented `Generating` module --- src/rescript/BchRe.bs.js | 3 +++ src/rescript/BchRe.res | 11 ++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/rescript/BchRe.bs.js b/src/rescript/BchRe.bs.js index 0fe75d9..8ae5c26 100644 --- a/src/rescript/BchRe.bs.js +++ b/src/rescript/BchRe.bs.js @@ -20,6 +20,8 @@ var $$Crypto = {}; var Encryption = {}; +var Generating = {}; + var bitcoinCash = require("../bitcoincash"); var crypto = require("../crypto"); @@ -151,6 +153,7 @@ exports.TransactionBuilder = TransactionBuilder; exports.BitcoinCash = BitcoinCash; exports.$$Crypto = $$Crypto; exports.Encryption = Encryption; +exports.Generating = Generating; exports.bitcoinCash = bitcoinCash; exports.crypto = crypto; exports.util = util; diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index 8084e0d..046c9c5 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -45,7 +45,7 @@ external require: string => extModules = "require" // @new external newCryptoModule: unit => extModules = "crypto" // @new external newECPairModule: unit => extModules = "ECPair" // @new external newEncryptionModule: libConfiguration => extModules = "encryption" -@new external newGeneratingModule: libConfiguration => extModules = "generating" +// @new external newGeneratingModule: libConfiguration => extModules = "generating" // @new external newHDNodeModule: extModules => extModules = "HDNode" // @new external newMnemonicModule: libConfiguration => extModules = "Mnemonic" @new external newPriceModule: libConfiguration => extModules = "price" @@ -95,6 +95,11 @@ module Encryption = { type t @new external newEncryptionModule: libConfiguration => t = "encryption" } +module Generating = { + type t +external require: string => t = "require" +@new external newGeneratingModule: libConfiguration => extModules = "generating" +} let bitcoinCash = require("../bitcoincash") let crypto = require("../crypto") let util = require("../util") @@ -112,7 +117,7 @@ let script = require("../script") let price = require("../price") let schnorr = require("../schnorr") let slp = require("../slp/slp") -let encryption = require("../encryption") +let encryption = Generating.require("../encryption") let utxo = require("../utxo") let transaction = require("../transaction") let dsProof = require("../dsproof") @@ -232,7 +237,7 @@ module BCHJS = { Js.log2("Crypto module is: ", crypto) // let ecPair = ECPair.newECPairModule() let encryption = Encryption.newEncryptionModule(libConfig) - let generating = newGeneratingModule(libConfig) + let generating = Generating.newGeneratingModule(libConfig) //let hdNode = newHDNodeModule(address) // let mnemonic = newMnemonicModule(libConfig) let price = newPriceModule(libConfig) From 23d418810bdb8bc86767fa98ba2d98096a21281d Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Thu, 6 Oct 2022 20:31:06 +0530 Subject: [PATCH 27/53] - Implemented `Price` module --- src/rescript/BchRe.bs.js | 3 +++ src/rescript/BchRe.res | 14 ++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/rescript/BchRe.bs.js b/src/rescript/BchRe.bs.js index 8ae5c26..23b55dc 100644 --- a/src/rescript/BchRe.bs.js +++ b/src/rescript/BchRe.bs.js @@ -22,6 +22,8 @@ var Encryption = {}; var Generating = {}; +var Price = {}; + var bitcoinCash = require("../bitcoincash"); var crypto = require("../crypto"); @@ -154,6 +156,7 @@ exports.BitcoinCash = BitcoinCash; exports.$$Crypto = $$Crypto; exports.Encryption = Encryption; exports.Generating = Generating; +exports.Price = Price; exports.bitcoinCash = bitcoinCash; exports.crypto = crypto; exports.util = util; diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index 046c9c5..821baf4 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -48,7 +48,7 @@ external require: string => extModules = "require" // @new external newGeneratingModule: libConfiguration => extModules = "generating" // @new external newHDNodeModule: extModules => extModules = "HDNode" // @new external newMnemonicModule: libConfiguration => extModules = "Mnemonic" -@new external newPriceModule: libConfiguration => extModules = "price" +// @new external newPriceModule: libConfiguration => extModules = "price" @new external newScriptModule: libConfiguration => extModules = "script" // @new external newTransactionBuilderModule: libConfiguration => extModules = "TransactionBuilder" @new external newUtilModule: libConfiguration => extModules = "util" @@ -73,6 +73,7 @@ external require: string => t = "require" } module HDNode = { type t +external require: string => t = "require" @new external newHDNodeModule: Address.t => t = "hdNode" } module Mnemonic = { @@ -100,6 +101,11 @@ module Generating = { external require: string => t = "require" @new external newGeneratingModule: libConfiguration => extModules = "generating" } +module Price = { + type t +@new external newPriceModule: libConfiguration => t = "price" +external require: string => t = "require" +} let bitcoinCash = require("../bitcoincash") let crypto = require("../crypto") let util = require("../util") @@ -114,7 +120,7 @@ let hdNode = require("../hdnode") let transactionBuilder = require("../transaction-builder") let ecPair = ECPair.require("../ecpair") let script = require("../script") -let price = require("../price") +let price = Price.require("../price") let schnorr = require("../schnorr") let slp = require("../slp/slp") let encryption = Generating.require("../encryption") @@ -186,7 +192,7 @@ module BCHJS = { @as("HDNode") hdNode: HDNode.t, @as("TransactionBuilder") transactionBuilder: TransactionBuilder.t, @as("ECPair") ecPair: ECPair.t, - @as("Price") price: extModules, + @as("Price") price: Price.t, @as("Schnorr") schnorr: extModules, @as("SLP") slp:extModules, @as("Encryption") encryption: Encryption.t, @@ -240,7 +246,7 @@ module BCHJS = { let generating = Generating.newGeneratingModule(libConfig) //let hdNode = newHDNodeModule(address) // let mnemonic = newMnemonicModule(libConfig) - let price = newPriceModule(libConfig) + let price = Price.newPriceModule(libConfig) let script = newScriptModule(libConfig) // Js.log2("Script module is: ", script) let util = newUtilModule(libConfig) From 5564fdd95e4b820c3e944832beb48991cabd0d7d Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Thu, 6 Oct 2022 23:10:06 +0530 Subject: [PATCH 28/53] - Implemented `Script` module --- src/rescript/BchRe.bs.js | 3 +++ src/rescript/BchRe.res | 11 ++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/rescript/BchRe.bs.js b/src/rescript/BchRe.bs.js index 23b55dc..ae9c3b7 100644 --- a/src/rescript/BchRe.bs.js +++ b/src/rescript/BchRe.bs.js @@ -24,6 +24,8 @@ var Generating = {}; var Price = {}; +var Script = {}; + var bitcoinCash = require("../bitcoincash"); var crypto = require("../crypto"); @@ -157,6 +159,7 @@ exports.$$Crypto = $$Crypto; exports.Encryption = Encryption; exports.Generating = Generating; exports.Price = Price; +exports.Script = Script; exports.bitcoinCash = bitcoinCash; exports.crypto = crypto; exports.util = util; diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index 821baf4..c3a2307 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -49,7 +49,7 @@ external require: string => extModules = "require" // @new external newHDNodeModule: extModules => extModules = "HDNode" // @new external newMnemonicModule: libConfiguration => extModules = "Mnemonic" // @new external newPriceModule: libConfiguration => extModules = "price" -@new external newScriptModule: libConfiguration => extModules = "script" +// @new external newScriptModule: libConfiguration => extModules = "script" // @new external newTransactionBuilderModule: libConfiguration => extModules = "TransactionBuilder" @new external newUtilModule: libConfiguration => extModules = "util" @new external newSchnorrModule: libConfiguration => extModules = "schnorr" @@ -106,6 +106,11 @@ module Price = { @new external newPriceModule: libConfiguration => t = "price" external require: string => t = "require" } +module Script = { + type t +external require: string => t = "require" +@new external newScriptModule: libConfiguration => t = "script" +} let bitcoinCash = require("../bitcoincash") let crypto = require("../crypto") let util = require("../util") @@ -180,7 +185,7 @@ type configuration = option module BCHJS = { type t = {@as("Address") address: Address.t, @as("BitcoinCash") bitcoinCash :BitcoinCash.t, - @as("Script") script: extModules, + @as("Script") script: Script.t, @as("Crypto") crypto: extModules, @as("Util") util: extModules, @as("Blockchain") blockchain: extModules, @@ -247,7 +252,7 @@ module BCHJS = { //let hdNode = newHDNodeModule(address) // let mnemonic = newMnemonicModule(libConfig) let price = Price.newPriceModule(libConfig) - let script = newScriptModule(libConfig) + let script = Script.newScriptModule(libConfig) // Js.log2("Script module is: ", script) let util = newUtilModule(libConfig) let schnorr = newSchnorrModule(libConfig) From 287bc5a7e1f1a590db85280dbe6c4e0b878074e3 Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Thu, 6 Oct 2022 23:36:28 +0530 Subject: [PATCH 29/53] - Implemented `Util`,`Schnorr` & `SLP` modules --- src/rescript/BchRe.bs.js | 9 +++++++++ src/rescript/BchRe.res | 43 +++++++++++++++++++++++++++------------- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/src/rescript/BchRe.bs.js b/src/rescript/BchRe.bs.js index ae9c3b7..e545fb6 100644 --- a/src/rescript/BchRe.bs.js +++ b/src/rescript/BchRe.bs.js @@ -26,6 +26,12 @@ var Price = {}; var Script = {}; +var Util = {}; + +var Schnorr = {}; + +var SLP = {}; + var bitcoinCash = require("../bitcoincash"); var crypto = require("../crypto"); @@ -160,6 +166,9 @@ exports.Encryption = Encryption; exports.Generating = Generating; exports.Price = Price; exports.Script = Script; +exports.Util = Util; +exports.Schnorr = Schnorr; +exports.SLP = SLP; exports.bitcoinCash = bitcoinCash; exports.crypto = crypto; exports.util = util; diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index c3a2307..1c5a87a 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -51,9 +51,9 @@ external require: string => extModules = "require" // @new external newPriceModule: libConfiguration => extModules = "price" // @new external newScriptModule: libConfiguration => extModules = "script" // @new external newTransactionBuilderModule: libConfiguration => extModules = "TransactionBuilder" -@new external newUtilModule: libConfiguration => extModules = "util" -@new external newSchnorrModule: libConfiguration => extModules = "schnorr" -@new external newSLPModule: libConfiguration => extModules = "slp" +// @new external newUtilModule: libConfiguration => extModules = "util" +// @new external newSchnorrModule: libConfiguration => extModules = "schnorr" +// @new external newSLPModule: libConfiguration => extModules = "slp" @new external newUtxoModule: libConfiguration => extModules = "utxo" @new external newTransactionModule: libConfiguration => extModules = "transaction" @new external newDSProofModule: libConfiguration => extModules = "dsProof" @@ -111,9 +111,24 @@ module Script = { external require: string => t = "require" @new external newScriptModule: libConfiguration => t = "script" } +module Util = { + type t +external require: string => t = "require" +@new external newUtilModule: libConfiguration => t = "util" +} +module Schnorr = { + type t +external require: string => t = "require" +@new external newSchnorrModule: libConfiguration => t = "schnorr" +} +module SLP = { + type t +external require: string => t = "require" +@new external newSLPModule: libConfiguration => t = "slp" +} let bitcoinCash = require("../bitcoincash") let crypto = require("../crypto") -let util = require("../util") +let util = Util.require("../util") let blockchain = require("../blockchain") let control = require("../control") let generating = require("../generating") @@ -126,8 +141,8 @@ let transactionBuilder = require("../transaction-builder") let ecPair = ECPair.require("../ecpair") let script = require("../script") let price = Price.require("../price") -let schnorr = require("../schnorr") -let slp = require("../slp/slp") +let schnorr = Schnorr.require("../schnorr") +let slp = SLP.require("../slp/slp") let encryption = Generating.require("../encryption") let utxo = require("../utxo") let transaction = require("../transaction") @@ -187,7 +202,7 @@ module BCHJS = { @as("BitcoinCash") bitcoinCash :BitcoinCash.t, @as("Script") script: Script.t, @as("Crypto") crypto: extModules, - @as("Util") util: extModules, + @as("Util") util: Util.t, @as("Blockchain") blockchain: extModules, @as("Control") control: extModules, @as("Generating") generating: extModules, @@ -198,8 +213,8 @@ module BCHJS = { @as("TransactionBuilder") transactionBuilder: TransactionBuilder.t, @as("ECPair") ecPair: ECPair.t, @as("Price") price: Price.t, - @as("Schnorr") schnorr: extModules, - @as("SLP") slp:extModules, + @as("Schnorr") schnorr: Schnorr.t, + @as("SLP") slp:SLP.t, @as("Encryption") encryption: Encryption.t, @as("Utxo") utxo: extModules, @as("Transaction") transaction: extModules, @@ -226,9 +241,9 @@ module BCHJS = { | None => envAuthPass } let combined = `fullstackcash:${authPass}` - open NodeJs + let base64Credential = - Buffer.fromString(combined)->Buffer.toStringWithEncoding(StringEncoding.base64) + NodeJs.Buffer.fromString(combined)->NodeJs.Buffer.toStringWithEncoding(NodeJs.StringEncoding.base64) let authToken = `Basic ${base64Credential}` let libConfig = { restURL, @@ -254,9 +269,9 @@ module BCHJS = { let price = Price.newPriceModule(libConfig) let script = Script.newScriptModule(libConfig) // Js.log2("Script module is: ", script) - let util = newUtilModule(libConfig) - let schnorr = newSchnorrModule(libConfig) - let slp = newSLPModule(libConfig) + let util = Util.newUtilModule(libConfig) + let schnorr = Schnorr.newSchnorrModule(libConfig) + let slp = SLP.newSLPModule(libConfig) let utxo = newUtxoModule(libConfig) let transaction = newTransactionModule(libConfig) let dsProof = newDSProofModule(libConfig) From 9cde1b6b41443f75c5da3eec849be8f324408220 Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Thu, 6 Oct 2022 23:45:42 +0530 Subject: [PATCH 30/53] - Implemented `Utxo` & `Transaction` modules --- src/rescript/BchRe.bs.js | 6 ++++++ src/rescript/BchRe.res | 26 ++++++++++++++++++-------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/rescript/BchRe.bs.js b/src/rescript/BchRe.bs.js index e545fb6..992be9f 100644 --- a/src/rescript/BchRe.bs.js +++ b/src/rescript/BchRe.bs.js @@ -32,6 +32,10 @@ var Schnorr = {}; var SLP = {}; +var Utxo = {}; + +var Transaction = {}; + var bitcoinCash = require("../bitcoincash"); var crypto = require("../crypto"); @@ -169,6 +173,8 @@ exports.Script = Script; exports.Util = Util; exports.Schnorr = Schnorr; exports.SLP = SLP; +exports.Utxo = Utxo; +exports.Transaction = Transaction; exports.bitcoinCash = bitcoinCash; exports.crypto = crypto; exports.util = util; diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index 1c5a87a..52608d9 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -54,8 +54,8 @@ external require: string => extModules = "require" // @new external newUtilModule: libConfiguration => extModules = "util" // @new external newSchnorrModule: libConfiguration => extModules = "schnorr" // @new external newSLPModule: libConfiguration => extModules = "slp" -@new external newUtxoModule: libConfiguration => extModules = "utxo" -@new external newTransactionModule: libConfiguration => extModules = "transaction" +// @new external newUtxoModule: libConfiguration => extModules = "utxo" +// @new external newTransactionModule: libConfiguration => extModules = "transaction" @new external newDSProofModule: libConfiguration => extModules = "dsProof" @new external newECashModule: libConfiguration => extModules = "eCash" @new external newPsfSlpIndexerModule: libConfiguration => extModules = "psfSlpIndexer" @@ -126,6 +126,16 @@ module SLP = { external require: string => t = "require" @new external newSLPModule: libConfiguration => t = "slp" } +module Utxo = { + type t +external require: string => t = "require" +@new external newUtxoModule: libConfiguration => t = "utxo" +} +module Transaction = { + type t +external require: string => t = "require" +@new external newTransactionModule: libConfiguration => t = "transaction" +} let bitcoinCash = require("../bitcoincash") let crypto = require("../crypto") let util = Util.require("../util") @@ -144,8 +154,8 @@ let price = Price.require("../price") let schnorr = Schnorr.require("../schnorr") let slp = SLP.require("../slp/slp") let encryption = Generating.require("../encryption") -let utxo = require("../utxo") -let transaction = require("../transaction") +let utxo = Utxo.require("../utxo") +let transaction = Transaction.require("../transaction") let dsProof = require("../dsproof") let eCash = require("../ecash") let electrumx = require("../electrumx") @@ -216,8 +226,8 @@ module BCHJS = { @as("Schnorr") schnorr: Schnorr.t, @as("SLP") slp:SLP.t, @as("Encryption") encryption: Encryption.t, - @as("Utxo") utxo: extModules, - @as("Transaction") transaction: extModules, + @as("Utxo") utxo: Utxo.t, + @as("Transaction") transaction:Transaction.t, @as("DSProof") dsProof: extModules, @as("Ecash") eCash: extModules, @as("Electrumx") electrumx: extModules, @@ -272,8 +282,8 @@ module BCHJS = { let util = Util.newUtilModule(libConfig) let schnorr = Schnorr.newSchnorrModule(libConfig) let slp = SLP.newSLPModule(libConfig) - let utxo = newUtxoModule(libConfig) - let transaction = newTransactionModule(libConfig) + let utxo = Utxo.newUtxoModule(libConfig) + let transaction = Transaction.newTransactionModule(libConfig) let dsProof = newDSProofModule(libConfig) let ecash = newECashModule(libConfig) let psfSlpIndexer = newPsfSlpIndexerModule(libConfig) From 8b64eed6ef6a36cdfe3ccb45529209df0cbbaea2 Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Thu, 6 Oct 2022 23:52:44 +0530 Subject: [PATCH 31/53] - Implemented `DSProof` & `Ecash` module --- src/rescript/BchRe.bs.js | 6 ++++++ src/rescript/BchRe.res | 26 ++++++++++++++++++-------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/rescript/BchRe.bs.js b/src/rescript/BchRe.bs.js index 992be9f..7174feb 100644 --- a/src/rescript/BchRe.bs.js +++ b/src/rescript/BchRe.bs.js @@ -36,6 +36,10 @@ var Utxo = {}; var Transaction = {}; +var DSProof = {}; + +var Ecash = {}; + var bitcoinCash = require("../bitcoincash"); var crypto = require("../crypto"); @@ -175,6 +179,8 @@ exports.Schnorr = Schnorr; exports.SLP = SLP; exports.Utxo = Utxo; exports.Transaction = Transaction; +exports.DSProof = DSProof; +exports.Ecash = Ecash; exports.bitcoinCash = bitcoinCash; exports.crypto = crypto; exports.util = util; diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index 52608d9..355f640 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -56,8 +56,8 @@ external require: string => extModules = "require" // @new external newSLPModule: libConfiguration => extModules = "slp" // @new external newUtxoModule: libConfiguration => extModules = "utxo" // @new external newTransactionModule: libConfiguration => extModules = "transaction" -@new external newDSProofModule: libConfiguration => extModules = "dsProof" -@new external newECashModule: libConfiguration => extModules = "eCash" +// @new external newDSProofModule: libConfiguration => extModules = "dsProof" +// @new external newECashModule: libConfiguration => extModules = "eCash" @new external newPsfSlpIndexerModule: libConfiguration => extModules = "psfSlpIndexer" module Address = { @@ -136,6 +136,16 @@ module Transaction = { external require: string => t = "require" @new external newTransactionModule: libConfiguration => t = "transaction" } +module DSProof = { + type t +external require: string => t = "require" +@new external newDSProofModule: libConfiguration => t = "dsProof" +} +module Ecash = { + type t +external require: string => t = "require" +@new external newECashModule: libConfiguration => t = "eCash" +} let bitcoinCash = require("../bitcoincash") let crypto = require("../crypto") let util = Util.require("../util") @@ -156,8 +166,8 @@ let slp = SLP.require("../slp/slp") let encryption = Generating.require("../encryption") let utxo = Utxo.require("../utxo") let transaction = Transaction.require("../transaction") -let dsProof = require("../dsproof") -let eCash = require("../ecash") +let dsProof = DSProof.require("../dsproof") +let eCash = Ecash.require("../ecash") let electrumx = require("../electrumx") let psfSlpIndexer = require("../psf-slp-indexer") @@ -228,8 +238,8 @@ module BCHJS = { @as("Encryption") encryption: Encryption.t, @as("Utxo") utxo: Utxo.t, @as("Transaction") transaction:Transaction.t, - @as("DSProof") dsProof: extModules, - @as("Ecash") eCash: extModules, + @as("DSProof") dsProof: DSProof.t, + @as("Ecash") eCash: Ecash.t, @as("Electrumx") electrumx: extModules, @as("PsfSlpIndexer") psfSlpIndexer: extModules} @@ -284,8 +294,8 @@ module BCHJS = { let slp = SLP.newSLPModule(libConfig) let utxo = Utxo.newUtxoModule(libConfig) let transaction = Transaction.newTransactionModule(libConfig) - let dsProof = newDSProofModule(libConfig) - let ecash = newECashModule(libConfig) + let dsProof = DSProof.newDSProofModule(libConfig) + let ecash = Ecash.newECashModule(libConfig) let psfSlpIndexer = newPsfSlpIndexerModule(libConfig) // Js.log2("Crypto module is: ", crypto) let ecPair = ecPair->ECPair.setAddress(address) From 634ac0af743dbbad8e44d790938f1564b0049d6d Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Thu, 6 Oct 2022 23:56:29 +0530 Subject: [PATCH 32/53] - Implemented `PsfSlpIndexer` module --- src/rescript/BchRe.bs.js | 3 +++ src/rescript/BchRe.res | 13 +++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/rescript/BchRe.bs.js b/src/rescript/BchRe.bs.js index 7174feb..1bd6216 100644 --- a/src/rescript/BchRe.bs.js +++ b/src/rescript/BchRe.bs.js @@ -40,6 +40,8 @@ var DSProof = {}; var Ecash = {}; +var PsfSlpIndexer = {}; + var bitcoinCash = require("../bitcoincash"); var crypto = require("../crypto"); @@ -181,6 +183,7 @@ exports.Utxo = Utxo; exports.Transaction = Transaction; exports.DSProof = DSProof; exports.Ecash = Ecash; +exports.PsfSlpIndexer = PsfSlpIndexer; exports.bitcoinCash = bitcoinCash; exports.crypto = crypto; exports.util = util; diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index 355f640..b980464 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -58,7 +58,7 @@ external require: string => extModules = "require" // @new external newTransactionModule: libConfiguration => extModules = "transaction" // @new external newDSProofModule: libConfiguration => extModules = "dsProof" // @new external newECashModule: libConfiguration => extModules = "eCash" -@new external newPsfSlpIndexerModule: libConfiguration => extModules = "psfSlpIndexer" +// @new external newPsfSlpIndexerModule: libConfiguration => extModules = "psfSlpIndexer" module Address = { type t @@ -146,6 +146,11 @@ module Ecash = { external require: string => t = "require" @new external newECashModule: libConfiguration => t = "eCash" } +module PsfSlpIndexer = { + type t +external require: string => t = "require" +@new external newPsfSlpIndexerModule: libConfiguration => t = "psfSlpIndexer" +} let bitcoinCash = require("../bitcoincash") let crypto = require("../crypto") let util = Util.require("../util") @@ -169,7 +174,7 @@ let transaction = Transaction.require("../transaction") let dsProof = DSProof.require("../dsproof") let eCash = Ecash.require("../ecash") let electrumx = require("../electrumx") -let psfSlpIndexer = require("../psf-slp-indexer") +let psfSlpIndexer = PsfSlpIndexer.require("../psf-slp-indexer") type restURL = string type apiToken @@ -241,7 +246,7 @@ module BCHJS = { @as("DSProof") dsProof: DSProof.t, @as("Ecash") eCash: Ecash.t, @as("Electrumx") electrumx: extModules, - @as("PsfSlpIndexer") psfSlpIndexer: extModules} + @as("PsfSlpIndexer") psfSlpIndexer: PsfSlpIndexer.t} let make = config => { let restURL = switch config { @@ -296,7 +301,7 @@ module BCHJS = { let transaction = Transaction.newTransactionModule(libConfig) let dsProof = DSProof.newDSProofModule(libConfig) let ecash = Ecash.newECashModule(libConfig) - let psfSlpIndexer = newPsfSlpIndexerModule(libConfig) + let psfSlpIndexer = PsfSlpIndexer.newPsfSlpIndexerModule(libConfig) // Js.log2("Crypto module is: ", crypto) let ecPair = ecPair->ECPair.setAddress(address) let hdNode = HDNode.newHDNodeModule(address) From 30ad3089bca101adb2023662781ce167c0662368 Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Thu, 6 Oct 2022 23:59:55 +0530 Subject: [PATCH 33/53] - Implemented `Electrumx` module --- src/rescript/BchRe.bs.js | 3 +++ src/rescript/BchRe.res | 11 ++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/rescript/BchRe.bs.js b/src/rescript/BchRe.bs.js index 1bd6216..058405e 100644 --- a/src/rescript/BchRe.bs.js +++ b/src/rescript/BchRe.bs.js @@ -4,6 +4,8 @@ var defaultRestApi = "https://api.fullstack.cash/v5/"; +var Electrumx = {}; + var Address = {}; var ECPair = {}; @@ -165,6 +167,7 @@ var BCHJS = { }; exports.defaultRestApi = defaultRestApi; +exports.Electrumx = Electrumx; exports.Address = Address; exports.ECPair = ECPair; exports.HDNode = HDNode; diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index b980464..bc2c0a5 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -35,7 +35,7 @@ type extModules = | PsfSlpIndexer external require: string => extModules = "require" -@new external newElectrumxModule: libConfiguration => extModules = "electrumx" +// @new external newElectrumxModule: libConfiguration => extModules = "electrumx" @new external newControlModule: libConfiguration => extModules = "control" @new external newMiningModule: libConfiguration => extModules = "mining" @new external newRawTransactionsModule: libConfiguration => extModules = "rawTransactions" @@ -59,6 +59,11 @@ external require: string => extModules = "require" // @new external newDSProofModule: libConfiguration => extModules = "dsProof" // @new external newECashModule: libConfiguration => extModules = "eCash" // @new external newPsfSlpIndexerModule: libConfiguration => extModules = "psfSlpIndexer" +module Electrumx = { + type t +external require: string => t = "require" +@new external newElectrumxModule: libConfiguration => t = "electrumx" +} module Address = { type t @@ -245,7 +250,7 @@ module BCHJS = { @as("Transaction") transaction:Transaction.t, @as("DSProof") dsProof: DSProof.t, @as("Ecash") eCash: Ecash.t, - @as("Electrumx") electrumx: extModules, + @as("Electrumx") electrumx: Electrumx.t, @as("PsfSlpIndexer") psfSlpIndexer: PsfSlpIndexer.t} let make = config => { @@ -276,7 +281,7 @@ module BCHJS = { authToken, } - let electrumx = newElectrumxModule(libConfig) + let electrumx = Electrumx.newElectrumxModule(libConfig) // Js.log(electrumx) let control = newControlModule(libConfig) let mining = newMiningModule(libConfig) From 0e80ebb7725a5a5e4753b76751b110d9eaa9772f Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Fri, 7 Oct 2022 00:02:50 +0530 Subject: [PATCH 34/53] - Implemented `Control` module --- src/rescript/BchRe.bs.js | 3 +++ src/rescript/BchRe.res | 13 +++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/rescript/BchRe.bs.js b/src/rescript/BchRe.bs.js index 058405e..1331f98 100644 --- a/src/rescript/BchRe.bs.js +++ b/src/rescript/BchRe.bs.js @@ -6,6 +6,8 @@ var defaultRestApi = "https://api.fullstack.cash/v5/"; var Electrumx = {}; +var Control = {}; + var Address = {}; var ECPair = {}; @@ -168,6 +170,7 @@ var BCHJS = { exports.defaultRestApi = defaultRestApi; exports.Electrumx = Electrumx; +exports.Control = Control; exports.Address = Address; exports.ECPair = ECPair; exports.HDNode = HDNode; diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index bc2c0a5..53cafad 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -36,7 +36,7 @@ type extModules = external require: string => extModules = "require" // @new external newElectrumxModule: libConfiguration => extModules = "electrumx" -@new external newControlModule: libConfiguration => extModules = "control" +// @new external newControlModule: libConfiguration => extModules = "control" @new external newMiningModule: libConfiguration => extModules = "mining" @new external newRawTransactionsModule: libConfiguration => extModules = "rawTransactions" // @new external newAddressModule: libConfiguration => extModules = "address" @@ -65,6 +65,11 @@ external require: string => t = "require" @new external newElectrumxModule: libConfiguration => t = "electrumx" } +module Control = { + type t +external require: string => t = "require" +@new external newControlModule: libConfiguration => t = "control" +} module Address = { type t @new external newAddressModule: libConfiguration => t = "address" @@ -160,7 +165,7 @@ let bitcoinCash = require("../bitcoincash") let crypto = require("../crypto") let util = Util.require("../util") let blockchain = require("../blockchain") -let control = require("../control") +let control = Control.require("../control") let generating = require("../generating") let mining = require("../mining") let rawTransactions = require("../raw-transactions") @@ -234,7 +239,7 @@ module BCHJS = { @as("Crypto") crypto: extModules, @as("Util") util: Util.t, @as("Blockchain") blockchain: extModules, - @as("Control") control: extModules, + @as("Control") control: Control.t, @as("Generating") generating: extModules, @as("Mining") mining: extModules, @as("RawTransacations") rawTransactions: extModules, @@ -283,7 +288,7 @@ module BCHJS = { let electrumx = Electrumx.newElectrumxModule(libConfig) // Js.log(electrumx) - let control = newControlModule(libConfig) + let control = Control.newControlModule(libConfig) let mining = newMiningModule(libConfig) let rawTransactions = newRawTransactionsModule(libConfig) let address = Address.newAddressModule(libConfig) From eb1b20476fec19ebf280fa7df48a40969177651a Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Fri, 7 Oct 2022 00:06:10 +0530 Subject: [PATCH 35/53] - Implemented `Mining` module --- src/rescript/BchRe.bs.js | 3 +++ src/rescript/BchRe.res | 13 +++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/rescript/BchRe.bs.js b/src/rescript/BchRe.bs.js index 1331f98..64a3c5c 100644 --- a/src/rescript/BchRe.bs.js +++ b/src/rescript/BchRe.bs.js @@ -8,6 +8,8 @@ var Electrumx = {}; var Control = {}; +var Mining = {}; + var Address = {}; var ECPair = {}; @@ -171,6 +173,7 @@ var BCHJS = { exports.defaultRestApi = defaultRestApi; exports.Electrumx = Electrumx; exports.Control = Control; +exports.Mining = Mining; exports.Address = Address; exports.ECPair = ECPair; exports.HDNode = HDNode; diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index 53cafad..241fa1d 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -37,7 +37,7 @@ type extModules = external require: string => extModules = "require" // @new external newElectrumxModule: libConfiguration => extModules = "electrumx" // @new external newControlModule: libConfiguration => extModules = "control" -@new external newMiningModule: libConfiguration => extModules = "mining" +// @new external newMiningModule: libConfiguration => extModules = "mining" @new external newRawTransactionsModule: libConfiguration => extModules = "rawTransactions" // @new external newAddressModule: libConfiguration => extModules = "address" // @new external newBitcoinCashModule: libConfiguration => extModules = "bitcoinCash" @@ -70,6 +70,11 @@ module Control = { external require: string => t = "require" @new external newControlModule: libConfiguration => t = "control" } +module Mining = { + type t +external require: string => t = "require" +@new external newMiningModule: libConfiguration => t = "mining" +} module Address = { type t @new external newAddressModule: libConfiguration => t = "address" @@ -167,7 +172,7 @@ let util = Util.require("../util") let blockchain = require("../blockchain") let control = Control.require("../control") let generating = require("../generating") -let mining = require("../mining") +let mining = Mining.require("../mining") let rawTransactions = require("../raw-transactions") let mnemonic = require("../mnemonic") let address = require("../address") @@ -241,7 +246,7 @@ module BCHJS = { @as("Blockchain") blockchain: extModules, @as("Control") control: Control.t, @as("Generating") generating: extModules, - @as("Mining") mining: extModules, + @as("Mining") mining: Mining.t, @as("RawTransacations") rawTransactions: extModules, @as("Mnemonic") mnemonic: Mnemonic.t, @as("HDNode") hdNode: HDNode.t, @@ -289,7 +294,7 @@ module BCHJS = { let electrumx = Electrumx.newElectrumxModule(libConfig) // Js.log(electrumx) let control = Control.newControlModule(libConfig) - let mining = newMiningModule(libConfig) + let mining = Mining.newMiningModule(libConfig) let rawTransactions = newRawTransactionsModule(libConfig) let address = Address.newAddressModule(libConfig) // Js.log2("Address module is: ", address) From 6f54cf75cb3c74a404dafeec6828b8ef1929acb3 Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Fri, 7 Oct 2022 00:17:23 +0530 Subject: [PATCH 36/53] - Implemented `RawTransactions` module --- src/rescript/BchRe.bs.js | 3 +++ src/rescript/BchRe.res | 13 +++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/rescript/BchRe.bs.js b/src/rescript/BchRe.bs.js index 64a3c5c..22e4584 100644 --- a/src/rescript/BchRe.bs.js +++ b/src/rescript/BchRe.bs.js @@ -6,6 +6,8 @@ var defaultRestApi = "https://api.fullstack.cash/v5/"; var Electrumx = {}; +var RawTransactions = {}; + var Control = {}; var Mining = {}; @@ -172,6 +174,7 @@ var BCHJS = { exports.defaultRestApi = defaultRestApi; exports.Electrumx = Electrumx; +exports.RawTransactions = RawTransactions; exports.Control = Control; exports.Mining = Mining; exports.Address = Address; diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index 241fa1d..d170d75 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -38,7 +38,7 @@ external require: string => extModules = "require" // @new external newElectrumxModule: libConfiguration => extModules = "electrumx" // @new external newControlModule: libConfiguration => extModules = "control" // @new external newMiningModule: libConfiguration => extModules = "mining" -@new external newRawTransactionsModule: libConfiguration => extModules = "rawTransactions" +// @new external newRawTransactionsModule: libConfiguration => extModules = "rawTransactions" // @new external newAddressModule: libConfiguration => extModules = "address" // @new external newBitcoinCashModule: libConfiguration => extModules = "bitcoinCash" @new external newBlockchainModule: libConfiguration => extModules = "blockchain" @@ -65,6 +65,11 @@ external require: string => t = "require" @new external newElectrumxModule: libConfiguration => t = "electrumx" } +module RawTransactions = { + type t +external require: string => t = "require" +@new external newRawTransactionsModule: libConfiguration => t = "rawTransactions" +} module Control = { type t external require: string => t = "require" @@ -173,7 +178,7 @@ let blockchain = require("../blockchain") let control = Control.require("../control") let generating = require("../generating") let mining = Mining.require("../mining") -let rawTransactions = require("../raw-transactions") +let rawTransactions = RawTransactions.require("../raw-transactions") let mnemonic = require("../mnemonic") let address = require("../address") let hdNode = require("../hdnode") @@ -247,7 +252,7 @@ module BCHJS = { @as("Control") control: Control.t, @as("Generating") generating: extModules, @as("Mining") mining: Mining.t, - @as("RawTransacations") rawTransactions: extModules, + @as("RawTransacations") rawTransactions:RawTransactions.t, @as("Mnemonic") mnemonic: Mnemonic.t, @as("HDNode") hdNode: HDNode.t, @as("TransactionBuilder") transactionBuilder: TransactionBuilder.t, @@ -295,7 +300,7 @@ module BCHJS = { // Js.log(electrumx) let control = Control.newControlModule(libConfig) let mining = Mining.newMiningModule(libConfig) - let rawTransactions = newRawTransactionsModule(libConfig) + let rawTransactions = RawTransactions.newRawTransactionsModule(libConfig) let address = Address.newAddressModule(libConfig) // Js.log2("Address module is: ", address) let blockchain = newBlockchainModule(libConfig) From 1e9d80071a7d3aaadd7e385018b83d9fbb3a2dd0 Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Fri, 7 Oct 2022 00:21:35 +0530 Subject: [PATCH 37/53] - Implemented `Blockchain` module --- src/rescript/BchRe.bs.js | 3 +++ src/rescript/BchRe.res | 13 +++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/rescript/BchRe.bs.js b/src/rescript/BchRe.bs.js index 22e4584..3d7ac70 100644 --- a/src/rescript/BchRe.bs.js +++ b/src/rescript/BchRe.bs.js @@ -24,6 +24,8 @@ var TransactionBuilder = {}; var BitcoinCash = {}; +var Blockchain = {}; + var $$Crypto = {}; var Encryption = {}; @@ -183,6 +185,7 @@ exports.HDNode = HDNode; exports.Mnemonic = Mnemonic; exports.TransactionBuilder = TransactionBuilder; exports.BitcoinCash = BitcoinCash; +exports.Blockchain = Blockchain; exports.$$Crypto = $$Crypto; exports.Encryption = Encryption; exports.Generating = Generating; diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index d170d75..6dfc7a9 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -41,7 +41,7 @@ external require: string => extModules = "require" // @new external newRawTransactionsModule: libConfiguration => extModules = "rawTransactions" // @new external newAddressModule: libConfiguration => extModules = "address" // @new external newBitcoinCashModule: libConfiguration => extModules = "bitcoinCash" -@new external newBlockchainModule: libConfiguration => extModules = "blockchain" +// @new external newBlockchainModule: libConfiguration => extModules = "blockchain" // @new external newCryptoModule: unit => extModules = "crypto" // @new external newECPairModule: unit => extModules = "ECPair" // @new external newEncryptionModule: libConfiguration => extModules = "encryption" @@ -108,6 +108,11 @@ module BitcoinCash = { type t @new external newBitcoinCashModule: Address.t => t = "bitcoinCash" } +module Blockchain = { + type t +external require: string => t = "require" +@new external newBlockchainModule: libConfiguration => t = "blockchain" +} module Crypto = { type t @new external newCryptoModule: unit => t = "crypto" @@ -174,7 +179,7 @@ external require: string => t = "require" let bitcoinCash = require("../bitcoincash") let crypto = require("../crypto") let util = Util.require("../util") -let blockchain = require("../blockchain") +let blockchain = Blockchain.require("../blockchain") let control = Control.require("../control") let generating = require("../generating") let mining = Mining.require("../mining") @@ -248,7 +253,7 @@ module BCHJS = { @as("Script") script: Script.t, @as("Crypto") crypto: extModules, @as("Util") util: Util.t, - @as("Blockchain") blockchain: extModules, + @as("Blockchain") blockchain: Blockchain.t, @as("Control") control: Control.t, @as("Generating") generating: extModules, @as("Mining") mining: Mining.t, @@ -303,7 +308,7 @@ module BCHJS = { let rawTransactions = RawTransactions.newRawTransactionsModule(libConfig) let address = Address.newAddressModule(libConfig) // Js.log2("Address module is: ", address) - let blockchain = newBlockchainModule(libConfig) + let blockchain = Blockchain.newBlockchainModule(libConfig) // let crypto = newCryptoModule() Js.log2("Crypto module is: ", crypto) // let ecPair = ECPair.newECPairModule() From d1fb56d400433112aa80842784ddc5581b1aa038 Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Fri, 7 Oct 2022 17:16:17 +0530 Subject: [PATCH 38/53] - Moved require method into `BitcoinCash` module --- src/rescript/BchRe.res | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index 6dfc7a9..1e0b7c8 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -106,6 +106,7 @@ module TransactionBuilder = { } module BitcoinCash = { type t +external require: string => t = "require" @new external newBitcoinCashModule: Address.t => t = "bitcoinCash" } module Blockchain = { @@ -176,7 +177,7 @@ module PsfSlpIndexer = { external require: string => t = "require" @new external newPsfSlpIndexerModule: libConfiguration => t = "psfSlpIndexer" } -let bitcoinCash = require("../bitcoincash") +let bitcoinCash = BitcoinCash.require("../bitcoincash") let crypto = require("../crypto") let util = Util.require("../util") let blockchain = Blockchain.require("../blockchain") From 21a8bc92091d10f5f5d73fa8923bf43384ad0bda Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Fri, 7 Oct 2022 18:19:31 +0530 Subject: [PATCH 39/53] - Created `require` method in `Crypto` module --- src/rescript/BchRe.res | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index 1e0b7c8..8749ff7 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -116,6 +116,7 @@ external require: string => t = "require" } module Crypto = { type t +external require: string => t = "require" @new external newCryptoModule: unit => t = "crypto" } module Encryption = { @@ -178,7 +179,7 @@ external require: string => t = "require" @new external newPsfSlpIndexerModule: libConfiguration => t = "psfSlpIndexer" } let bitcoinCash = BitcoinCash.require("../bitcoincash") -let crypto = require("../crypto") +let crypto = Crypto.require("../crypto") let util = Util.require("../util") let blockchain = Blockchain.require("../blockchain") let control = Control.require("../control") @@ -252,7 +253,7 @@ module BCHJS = { type t = {@as("Address") address: Address.t, @as("BitcoinCash") bitcoinCash :BitcoinCash.t, @as("Script") script: Script.t, - @as("Crypto") crypto: extModules, + @as("Crypto") crypto: Crypto.t, @as("Util") util: Util.t, @as("Blockchain") blockchain: Blockchain.t, @as("Control") control: Control.t, From 8ea6276952d1dfa550976edf11b67cabaf08cbfe Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Fri, 7 Oct 2022 18:28:27 +0530 Subject: [PATCH 40/53] - Implemented `require` method in `Generating` mod --- src/rescript/BchRe.res | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index 8749ff7..bb6ad81 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -126,7 +126,7 @@ module Encryption = { module Generating = { type t external require: string => t = "require" -@new external newGeneratingModule: libConfiguration => extModules = "generating" +@new external newGeneratingModule: libConfiguration => t = "generating" } module Price = { type t @@ -257,7 +257,7 @@ module BCHJS = { @as("Util") util: Util.t, @as("Blockchain") blockchain: Blockchain.t, @as("Control") control: Control.t, - @as("Generating") generating: extModules, + @as("Generating") generating: Generating.t, @as("Mining") mining: Mining.t, @as("RawTransacations") rawTransactions:RawTransactions.t, @as("Mnemonic") mnemonic: Mnemonic.t, From 0e8b9d0fcf30970dd7312ffa93b28e3533bac0cb Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Fri, 7 Oct 2022 18:54:29 +0530 Subject: [PATCH 41/53] - Implemented `require` method inside modules --- src/rescript/BchRe.res | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index bb6ad81..b9afaf9 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -82,6 +82,7 @@ external require: string => t = "require" } module Address = { type t +external require: string => t = "require" @new external newAddressModule: libConfiguration => t = "address" } module ECPair = { @@ -98,10 +99,12 @@ external require: string => t = "require" } module Mnemonic = { type t +external require: string => t = "require" @new external newMnemonicModule: Address.t => t = "mnemonic" } module TransactionBuilder = { type t +external require: string => t = "require" @new external setAddress: Address.t => t = "transactionBuilder" } module BitcoinCash = { @@ -121,6 +124,7 @@ external require: string => t = "require" } module Encryption = { type t +external require: string => t = "require" @new external newEncryptionModule: libConfiguration => t = "encryption" } module Generating = { @@ -183,15 +187,15 @@ let crypto = Crypto.require("../crypto") let util = Util.require("../util") let blockchain = Blockchain.require("../blockchain") let control = Control.require("../control") -let generating = require("../generating") +let generating = Generating.require("../generating") let mining = Mining.require("../mining") let rawTransactions = RawTransactions.require("../raw-transactions") -let mnemonic = require("../mnemonic") -let address = require("../address") -let hdNode = require("../hdnode") -let transactionBuilder = require("../transaction-builder") +let mnemonic = Mnemonic.require("../mnemonic") +let address = Address.require("../address") +let hdNode = HDNode.require("../hdnode") +let transactionBuilder = TransactionBuilder.require("../transaction-builder") let ecPair = ECPair.require("../ecpair") -let script = require("../script") +let script = Script.require("../script") let price = Price.require("../price") let schnorr = Schnorr.require("../schnorr") let slp = SLP.require("../slp/slp") @@ -200,7 +204,7 @@ let utxo = Utxo.require("../utxo") let transaction = Transaction.require("../transaction") let dsProof = DSProof.require("../dsproof") let eCash = Ecash.require("../ecash") -let electrumx = require("../electrumx") +let electrumx = Electrumx.require("../electrumx") let psfSlpIndexer = PsfSlpIndexer.require("../psf-slp-indexer") type restURL = string From bc7f4bf4883bf588c9bb75e3757d3e1504bbe2f7 Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Fri, 7 Oct 2022 19:01:32 +0530 Subject: [PATCH 42/53] - Removed the earlier used common`require` method --- src/rescript/BchRe.res | 1 - 1 file changed, 1 deletion(-) diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index b9afaf9..63d5624 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -34,7 +34,6 @@ type extModules = | Electrumx | PsfSlpIndexer -external require: string => extModules = "require" // @new external newElectrumxModule: libConfiguration => extModules = "electrumx" // @new external newControlModule: libConfiguration => extModules = "control" // @new external newMiningModule: libConfiguration => extModules = "mining" From 222deb1202086765b5979509d1f15c4d3606f4a5 Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Fri, 7 Oct 2022 19:05:22 +0530 Subject: [PATCH 43/53] - Removed commented code, was for new modules --- src/rescript/BchRe.res | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index 63d5624..d7bc9e8 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -34,30 +34,6 @@ type extModules = | Electrumx | PsfSlpIndexer -// @new external newElectrumxModule: libConfiguration => extModules = "electrumx" -// @new external newControlModule: libConfiguration => extModules = "control" -// @new external newMiningModule: libConfiguration => extModules = "mining" -// @new external newRawTransactionsModule: libConfiguration => extModules = "rawTransactions" -// @new external newAddressModule: libConfiguration => extModules = "address" -// @new external newBitcoinCashModule: libConfiguration => extModules = "bitcoinCash" -// @new external newBlockchainModule: libConfiguration => extModules = "blockchain" -// @new external newCryptoModule: unit => extModules = "crypto" -// @new external newECPairModule: unit => extModules = "ECPair" -// @new external newEncryptionModule: libConfiguration => extModules = "encryption" -// @new external newGeneratingModule: libConfiguration => extModules = "generating" -// @new external newHDNodeModule: extModules => extModules = "HDNode" -// @new external newMnemonicModule: libConfiguration => extModules = "Mnemonic" -// @new external newPriceModule: libConfiguration => extModules = "price" -// @new external newScriptModule: libConfiguration => extModules = "script" -// @new external newTransactionBuilderModule: libConfiguration => extModules = "TransactionBuilder" -// @new external newUtilModule: libConfiguration => extModules = "util" -// @new external newSchnorrModule: libConfiguration => extModules = "schnorr" -// @new external newSLPModule: libConfiguration => extModules = "slp" -// @new external newUtxoModule: libConfiguration => extModules = "utxo" -// @new external newTransactionModule: libConfiguration => extModules = "transaction" -// @new external newDSProofModule: libConfiguration => extModules = "dsProof" -// @new external newECashModule: libConfiguration => extModules = "eCash" -// @new external newPsfSlpIndexerModule: libConfiguration => extModules = "psfSlpIndexer" module Electrumx = { type t external require: string => t = "require" From c792c3e7ea315146daf12c8f177175c6316fe3f5 Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Fri, 7 Oct 2022 19:21:19 +0530 Subject: [PATCH 44/53] - Removed redundant commented code --- src/rescript/BchRe.res | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index d7bc9e8..7fe2c6d 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -196,38 +196,6 @@ type configurationObject = { } type configuration = option -// module Address = { -// type t -// @new external newAddressModule: libConfiguration => t = "address" -// } -// module ECPair = { -// type t -// @send -// external setAddress: (t, Address.t) => t = "setAddress" -// @new external newECPairModule: unit => t = "ecPair" -// } -// module HDNode = { -// type t -// @new external newHDNodeModule: Address.t => t = "hdNode" -// } -// module Mnemonic = { -// type t -// @new external newMnemonicModule: Address.t => t = "mnemonic" -// } -// module TransactionBuilder = { -// type t -// @new external setAddress: Address.t => t = "transactionBuilder" -// } -// module BitcoinCash = { -// type t -// @new external newBitcoinCashModule: Address.t => t = "bitcoinCash" -// } -// module Crypto = { -// type t -// external require: string => t = "require" -// @new external newCryptoModule: unit => t = "crypto" -// } - module BCHJS = { type t = {@as("Address") address: Address.t, @as("BitcoinCash") bitcoinCash :BitcoinCash.t, From 4cca0335bfbd59365d519ebf669ec31c2eceabd7 Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Fri, 7 Oct 2022 19:22:39 +0530 Subject: [PATCH 45/53] - Corrected the `ecash` --- src/rescript/BchRe.bs.js | 4 ++-- src/rescript/BchRe.res | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rescript/BchRe.bs.js b/src/rescript/BchRe.bs.js index 3d7ac70..addb9e3 100644 --- a/src/rescript/BchRe.bs.js +++ b/src/rescript/BchRe.bs.js @@ -135,7 +135,7 @@ function make(config) { var utxo$2 = new utxo(libConfig); var transaction$2 = new transaction(libConfig); var dsProof$2 = new dsProof(libConfig); - new eCash(libConfig); + var ecash = new eCash(libConfig); var psfSlpIndexer$2 = new psfSlpIndexer(libConfig); var ecPair$1 = ecPair.setAddress(address$2); var hdNode$2 = new hdNode(address$2); @@ -164,7 +164,7 @@ function make(config) { Utxo: utxo$2, Transaction: transaction$2, DSProof: dsProof$2, - Ecash: eCash, + Ecash: ecash, Electrumx: electrumx$2, PsfSlpIndexer: psfSlpIndexer$2 }; diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index 7fe2c6d..ee02d0c 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -304,7 +304,7 @@ module BCHJS = { utxo: utxo, transaction: transaction, dsProof: dsProof, - eCash: eCash, + eCash: ecash, electrumx: electrumx, psfSlpIndexer: psfSlpIndexer } From f209ad6eb04b529b4b920f2373e6d16e49aade7f Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Fri, 7 Oct 2022 19:56:38 +0530 Subject: [PATCH 46/53] - Renamed all newModule methods to `new` --- src/rescript/BchRe.res | 88 +++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index ee02d0c..ae0844c 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -37,45 +37,45 @@ type extModules = module Electrumx = { type t external require: string => t = "require" -@new external newElectrumxModule: libConfiguration => t = "electrumx" +@new external new: libConfiguration => t = "electrumx" } module RawTransactions = { type t external require: string => t = "require" -@new external newRawTransactionsModule: libConfiguration => t = "rawTransactions" +@new external new: libConfiguration => t = "rawTransactions" } module Control = { type t external require: string => t = "require" -@new external newControlModule: libConfiguration => t = "control" +@new external new: libConfiguration => t = "control" } module Mining = { type t external require: string => t = "require" -@new external newMiningModule: libConfiguration => t = "mining" +@new external new: libConfiguration => t = "mining" } module Address = { type t external require: string => t = "require" - @new external newAddressModule: libConfiguration => t = "address" + @new external new: libConfiguration => t = "address" } module ECPair = { type t external require: string => t = "require" @send external setAddress: (t, Address.t) => t = "setAddress" - @new external newECPairModule: unit => t = "ecPair" + @new external new: unit => t = "ecPair" } module HDNode = { type t external require: string => t = "require" - @new external newHDNodeModule: Address.t => t = "hdNode" + @new external new: Address.t => t = "hdNode" } module Mnemonic = { type t external require: string => t = "require" - @new external newMnemonicModule: Address.t => t = "mnemonic" + @new external new: Address.t => t = "mnemonic" } module TransactionBuilder = { type t @@ -85,77 +85,77 @@ external require: string => t = "require" module BitcoinCash = { type t external require: string => t = "require" -@new external newBitcoinCashModule: Address.t => t = "bitcoinCash" +@new external new: Address.t => t = "bitcoinCash" } module Blockchain = { type t external require: string => t = "require" -@new external newBlockchainModule: libConfiguration => t = "blockchain" +@new external new: libConfiguration => t = "blockchain" } module Crypto = { type t external require: string => t = "require" -@new external newCryptoModule: unit => t = "crypto" +@new external new: unit => t = "crypto" } module Encryption = { type t external require: string => t = "require" -@new external newEncryptionModule: libConfiguration => t = "encryption" +@new external new: libConfiguration => t = "encryption" } module Generating = { type t external require: string => t = "require" -@new external newGeneratingModule: libConfiguration => t = "generating" +@new external new: libConfiguration => t = "generating" } module Price = { type t -@new external newPriceModule: libConfiguration => t = "price" +@new external new: libConfiguration => t = "price" external require: string => t = "require" } module Script = { type t external require: string => t = "require" -@new external newScriptModule: libConfiguration => t = "script" +@new external new: libConfiguration => t = "script" } module Util = { type t external require: string => t = "require" -@new external newUtilModule: libConfiguration => t = "util" +@new external new: libConfiguration => t = "util" } module Schnorr = { type t external require: string => t = "require" -@new external newSchnorrModule: libConfiguration => t = "schnorr" +@new external new: libConfiguration => t = "schnorr" } module SLP = { type t external require: string => t = "require" -@new external newSLPModule: libConfiguration => t = "slp" +@new external new: libConfiguration => t = "slp" } module Utxo = { type t external require: string => t = "require" -@new external newUtxoModule: libConfiguration => t = "utxo" +@new external new: libConfiguration => t = "utxo" } module Transaction = { type t external require: string => t = "require" -@new external newTransactionModule: libConfiguration => t = "transaction" +@new external new: libConfiguration => t = "transaction" } module DSProof = { type t external require: string => t = "require" -@new external newDSProofModule: libConfiguration => t = "dsProof" +@new external new: libConfiguration => t = "dsProof" } module Ecash = { type t external require: string => t = "require" -@new external newECashModule: libConfiguration => t = "eCash" +@new external new: libConfiguration => t = "eCash" } module PsfSlpIndexer = { type t external require: string => t = "require" -@new external newPsfSlpIndexerModule: libConfiguration => t = "psfSlpIndexer" +@new external new: libConfiguration => t = "psfSlpIndexer" } let bitcoinCash = BitcoinCash.require("../bitcoincash") let crypto = Crypto.require("../crypto") @@ -250,38 +250,38 @@ module BCHJS = { authToken, } - let electrumx = Electrumx.newElectrumxModule(libConfig) + let electrumx = Electrumx.new(libConfig) // Js.log(electrumx) - let control = Control.newControlModule(libConfig) - let mining = Mining.newMiningModule(libConfig) - let rawTransactions = RawTransactions.newRawTransactionsModule(libConfig) - let address = Address.newAddressModule(libConfig) + let control = Control.new(libConfig) + let mining = Mining.new(libConfig) + let rawTransactions = RawTransactions.new(libConfig) + let address = Address.new(libConfig) // Js.log2("Address module is: ", address) - let blockchain = Blockchain.newBlockchainModule(libConfig) + let blockchain = Blockchain.new(libConfig) // let crypto = newCryptoModule() Js.log2("Crypto module is: ", crypto) // let ecPair = ECPair.newECPairModule() - let encryption = Encryption.newEncryptionModule(libConfig) - let generating = Generating.newGeneratingModule(libConfig) + let encryption = Encryption.new(libConfig) + let generating = Generating.new(libConfig) //let hdNode = newHDNodeModule(address) // let mnemonic = newMnemonicModule(libConfig) - let price = Price.newPriceModule(libConfig) - let script = Script.newScriptModule(libConfig) + let price = Price.new(libConfig) + let script = Script.new(libConfig) // Js.log2("Script module is: ", script) - let util = Util.newUtilModule(libConfig) - let schnorr = Schnorr.newSchnorrModule(libConfig) - let slp = SLP.newSLPModule(libConfig) - let utxo = Utxo.newUtxoModule(libConfig) - let transaction = Transaction.newTransactionModule(libConfig) - let dsProof = DSProof.newDSProofModule(libConfig) - let ecash = Ecash.newECashModule(libConfig) - let psfSlpIndexer = PsfSlpIndexer.newPsfSlpIndexerModule(libConfig) + let util = Util.new(libConfig) + let schnorr = Schnorr.new(libConfig) + let slp = SLP.new(libConfig) + let utxo = Utxo.new(libConfig) + let transaction = Transaction.new(libConfig) + let dsProof = DSProof.new(libConfig) + let ecash = Ecash.new(libConfig) + let psfSlpIndexer = PsfSlpIndexer.new(libConfig) // Js.log2("Crypto module is: ", crypto) let ecPair = ecPair->ECPair.setAddress(address) - let hdNode = HDNode.newHDNodeModule(address) - let mnemonic = Mnemonic.newMnemonicModule(address) + let hdNode = HDNode.new(address) + let mnemonic = Mnemonic.new(address) let transactionBuilder = TransactionBuilder.setAddress(address) - let bitcoinCash = BitcoinCash.newBitcoinCashModule(address) + let bitcoinCash = BitcoinCash.new(address) { address: address, bitcoinCash: bitcoinCash, From 85490c70d9fbbe17ace835f12574c5fcedfb5996 Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Mon, 10 Oct 2022 20:16:43 +0530 Subject: [PATCH 47/53] - Attempt to create a wrapped method for `require` method for Electrumx module --- src/rescript/BchRe.bs.js | 65 ++++++++++++++++++++++++++++++++++++++-- src/rescript/BchRe.res | 41 +++++++++++++++++++++++-- 2 files changed, 101 insertions(+), 5 deletions(-) diff --git a/src/rescript/BchRe.bs.js b/src/rescript/BchRe.bs.js index addb9e3..25b4a5e 100644 --- a/src/rescript/BchRe.bs.js +++ b/src/rescript/BchRe.bs.js @@ -4,7 +4,67 @@ var defaultRestApi = "https://api.fullstack.cash/v5/"; -var Electrumx = {}; +function requireInternal(modules, moduleType) { + switch (modules) { + case /* BitcoinCash */0 : + return require("../bitcoincash", moduleType); + case /* Crypto */1 : + return require("../crypto", moduleType); + case /* Util */2 : + return require("../util", moduleType); + case /* Blockchain */3 : + return require("../blockchain", moduleType); + case /* Control */4 : + return require("../control", moduleType); + case /* Generating */5 : + return require("../generating", moduleType); + case /* Mining */6 : + return require("../mining", moduleType); + case /* RawTransactions */7 : + return require("../raw-transaction", moduleType); + case /* Menmonic */8 : + return require("../mnemonic", moduleType); + case /* Address */9 : + return require("../address", moduleType); + case /* HDNode */10 : + return require("../hdnode", moduleType); + case /* TransactionBuilder */11 : + return require("../transaction-builder", moduleType); + case /* ECPair */12 : + return require("../ecpair", moduleType); + case /* Script */13 : + return require("../script", moduleType); + case /* Price */14 : + return require("../price", moduleType); + case /* Schnorr */15 : + return require("../schnorr", moduleType); + case /* SLP */16 : + return require("../slp/slp", moduleType); + case /* Encryption */17 : + return require("../ecryption", moduleType); + case /* Utxo */18 : + return require("../utxo", moduleType); + case /* Transaction */19 : + return require("../transaction", moduleType); + case /* DSProof */20 : + return require("../dsproof", moduleType); + case /* Ecash */21 : + return require("../ecash", moduleType); + case /* Electrumx */22 : + return require("../electrumx", moduleType); + case /* PsfSlpIndexer */23 : + return require("../psf-slp-indexer", moduleType); + + } +} + +function $$require$1(t) { + return require("../electrumx", t); +} + +var Electrumx = { + $$require: $$require$1 +}; var RawTransactions = {}; @@ -96,7 +156,7 @@ var dsProof = require("../dsproof"); var eCash = require("../ecash"); -var electrumx = require("../electrumx"); +var electrumx = require("../electrumx", undefined); var psfSlpIndexer = require("../psf-slp-indexer"); @@ -175,6 +235,7 @@ var BCHJS = { }; exports.defaultRestApi = defaultRestApi; +exports.requireInternal = requireInternal; exports.Electrumx = Electrumx; exports.RawTransactions = RawTransactions; exports.Control = Control; diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index ae0844c..be02dfc 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -8,7 +8,7 @@ type libConfiguration = { @val @scope(("process", "env")) external envApiToken: string = "BCHJSTOKEN" @val @scope(("process", "env")) external envAuthPass: string = "BCHJSAUTHPASS" -type extModules = +type modules = | BitcoinCash | Crypto | Util @@ -34,9 +34,42 @@ type extModules = | Electrumx | PsfSlpIndexer +external requireModule: (string, 'a) => 'a = "require" + +let requireInternal = (modules, moduleType) => { + switch modules { + | BitcoinCash => requireModule("../bitcoincash", moduleType) + | Crypto => requireModule("../crypto", moduleType) + | Util => requireModule("../util", moduleType) + | Blockchain => requireModule("../blockchain", moduleType) + | Control => requireModule("../control", moduleType) + | Generating => requireModule("../generating", moduleType) + | Mining => requireModule("../mining", moduleType) + | RawTransactions => requireModule("../raw-transaction", moduleType) + | Menmonic => requireModule("../mnemonic", moduleType) + | Address => requireModule("../address", moduleType) + | HDNode => requireModule("../hdnode", moduleType) + | TransactionBuilder => requireModule("../transaction-builder", moduleType) + | ECPair => requireModule("../ecpair", moduleType) + | Script => requireModule("../script", moduleType) + | Price => requireModule("../price", moduleType) + | Schnorr => requireModule("../schnorr", moduleType) + | SLP => requireModule("../slp/slp", moduleType) + | Encryption => requireModule("../ecryption", moduleType) + | Utxo => requireModule("../utxo", moduleType) + | Transaction => requireModule("../transaction", moduleType) + | DSProof => requireModule("../dsproof", moduleType) + | Ecash => requireModule("../ecash", moduleType) + | Electrumx => requireModule("../electrumx", moduleType) + | PsfSlpIndexer => requireModule("../psf-slp-indexer", moduleType) + } +} + module Electrumx = { type t -external require: string => t = "require" + let require = (t) => { + requireInternal(Electrumx, t) + } @new external new: libConfiguration => t = "electrumx" } @@ -157,6 +190,8 @@ module PsfSlpIndexer = { external require: string => t = "require" @new external new: libConfiguration => t = "psfSlpIndexer" } + + let bitcoinCash = BitcoinCash.require("../bitcoincash") let crypto = Crypto.require("../crypto") let util = Util.require("../util") @@ -179,7 +214,7 @@ let utxo = Utxo.require("../utxo") let transaction = Transaction.require("../transaction") let dsProof = DSProof.require("../dsproof") let eCash = Ecash.require("../ecash") -let electrumx = Electrumx.require("../electrumx") +let electrumx = Electrumx.require() let psfSlpIndexer = PsfSlpIndexer.require("../psf-slp-indexer") type restURL = string From d5b7e4ab1d949ada3d32348673ff3e6261fcc214 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Thu, 13 Oct 2022 10:31:22 -0700 Subject: [PATCH 48/53] fix(tests): Removing integration tests that trips rate limit --- .../bchn/psf-slp-indexer.integration.js | 42 ++++++++++--------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/test/integration/chains/bchn/psf-slp-indexer.integration.js b/test/integration/chains/bchn/psf-slp-indexer.integration.js index 6880450..893c6b7 100644 --- a/test/integration/chains/bchn/psf-slp-indexer.integration.js +++ b/test/integration/chains/bchn/psf-slp-indexer.integration.js @@ -156,26 +156,28 @@ describe('#psf-slp-indexer', () => { }) }) - describe('#getTokenData2', () => { - it('should get token data', async () => { - const tokenId = - 'd9aafa7acb514c597caf440ae268b5e4e955f2687e05f044cdf8fd9550d9a27b' - - // bchjs.PsfSlpIndexer.restURL = 'http://localhost:3000/v5/' - const result = await bchjs.PsfSlpIndexer.getTokenData2(tokenId) - // console.log('result: ', result) - - assert.property(result, 'tokenStats') - assert.property(result, 'mutableData') - assert.property(result, 'immutableData') - assert.property(result, 'tokenIcon') - assert.property(result, 'fullSizedUrl') - assert.property(result, 'optimizedTokenIcon') - assert.property(result, 'optimizedFullSizedUrl') - assert.property(result, 'iconRepoCompatible') - assert.property(result, 'ps002Compatible') - }) - }) + // This test is commented out because it can not succeed in the BVT without + // tripping rate limits. + // describe('#getTokenData2', () => { + // it('should get token data', async () => { + // const tokenId = + // 'd9aafa7acb514c597caf440ae268b5e4e955f2687e05f044cdf8fd9550d9a27b' + // + // // bchjs.PsfSlpIndexer.restURL = 'http://localhost:3000/v5/' + // const result = await bchjs.PsfSlpIndexer.getTokenData2(tokenId) + // // console.log('result: ', result) + // + // assert.property(result, 'tokenStats') + // assert.property(result, 'mutableData') + // assert.property(result, 'immutableData') + // assert.property(result, 'tokenIcon') + // assert.property(result, 'fullSizedUrl') + // assert.property(result, 'optimizedTokenIcon') + // assert.property(result, 'optimizedFullSizedUrl') + // assert.property(result, 'iconRepoCompatible') + // assert.property(result, 'ps002Compatible') + // }) + // }) }) // Promise-based sleep function From 70b47c9c31fb8bcb224a44fd37aab14d26a8794a Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Fri, 14 Oct 2022 00:18:10 +0530 Subject: [PATCH 49/53] - Implemented @module and @new - All tests are passing. --- src/rescript/BchRe.bs.js | 413 ++++++++++++++++++++------------------- src/rescript/BchRe.res | 291 +++++++++------------------ 2 files changed, 309 insertions(+), 395 deletions(-) diff --git a/src/rescript/BchRe.bs.js b/src/rescript/BchRe.bs.js index 25b4a5e..120f0f5 100644 --- a/src/rescript/BchRe.bs.js +++ b/src/rescript/BchRe.bs.js @@ -1,164 +1,206 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Util = require("../util"); +var Utxo = require("../utxo"); +var Ecash = require("../ecash"); +var Price = require("../price"); +var Hdnode = require("../hdnode"); +var Mining = require("../mining"); +var Script = require("../script"); +var Address = require("../address"); +var Control = require("../control"); +var Dsproof = require("../dsproof"); +var Schnorr = require("../schnorr"); +var Slp = require("../slp/slp"); +var Mnemonic = require("../mnemonic"); +var Electrumx = require("../electrumx"); +var Blockchain = require("../blockchain"); +var Encryption = require("../encryption"); +var Generating = require("../generating"); +var Bitcoincash = require("../bitcoincash"); +var Transaction = require("../transaction"); +var PsfSlpIndexer = require("../psf-slp-indexer"); +var RawTransactions = require("../raw-transactions"); var defaultRestApi = "https://api.fullstack.cash/v5/"; -function requireInternal(modules, moduleType) { - switch (modules) { - case /* BitcoinCash */0 : - return require("../bitcoincash", moduleType); - case /* Crypto */1 : - return require("../crypto", moduleType); - case /* Util */2 : - return require("../util", moduleType); - case /* Blockchain */3 : - return require("../blockchain", moduleType); - case /* Control */4 : - return require("../control", moduleType); - case /* Generating */5 : - return require("../generating", moduleType); - case /* Mining */6 : - return require("../mining", moduleType); - case /* RawTransactions */7 : - return require("../raw-transaction", moduleType); - case /* Menmonic */8 : - return require("../mnemonic", moduleType); - case /* Address */9 : - return require("../address", moduleType); - case /* HDNode */10 : - return require("../hdnode", moduleType); - case /* TransactionBuilder */11 : - return require("../transaction-builder", moduleType); - case /* ECPair */12 : - return require("../ecpair", moduleType); - case /* Script */13 : - return require("../script", moduleType); - case /* Price */14 : - return require("../price", moduleType); - case /* Schnorr */15 : - return require("../schnorr", moduleType); - case /* SLP */16 : - return require("../slp/slp", moduleType); - case /* Encryption */17 : - return require("../ecryption", moduleType); - case /* Utxo */18 : - return require("../utxo", moduleType); - case /* Transaction */19 : - return require("../transaction", moduleType); - case /* DSProof */20 : - return require("../dsproof", moduleType); - case /* Ecash */21 : - return require("../ecash", moduleType); - case /* Electrumx */22 : - return require("../electrumx", moduleType); - case /* PsfSlpIndexer */23 : - return require("../psf-slp-indexer", moduleType); - - } -} - -function $$require$1(t) { - return require("../electrumx", t); +function $$new(prim) { + return new Electrumx(prim); } -var Electrumx = { - $$require: $$require$1 +var Electrumx$1 = { + $$new: $$new }; -var RawTransactions = {}; - -var Control = {}; - -var Mining = {}; - -var Address = {}; +function $$new$1(prim) { + return new RawTransactions(prim); +} -var ECPair = {}; +var RawTransactions$1 = { + $$new: $$new$1 +}; -var HDNode = {}; +function $$new$2(prim) { + return new Control(prim); +} -var Mnemonic = {}; +var Control$1 = { + $$new: $$new$2 +}; -var TransactionBuilder = {}; +function $$new$3(prim) { + return new Mining(prim); +} -var BitcoinCash = {}; +var Mining$1 = { + $$new: $$new$3 +}; -var Blockchain = {}; +function $$new$4(prim) { + return new Address(prim); +} -var $$Crypto = {}; +var Address$1 = { + $$new: $$new$4 +}; -var Encryption = {}; +var ECPair = {}; -var Generating = {}; +function $$new$5(prim) { + return new Hdnode(prim); +} -var Price = {}; +var HDNode = { + $$new: $$new$5 +}; -var Script = {}; +function $$new$6(prim) { + return new Mnemonic(prim); +} -var Util = {}; +var Mnemonic$1 = { + $$new: $$new$6 +}; -var Schnorr = {}; +var TransactionBuilder = {}; -var SLP = {}; +function $$new$7(prim) { + return new Bitcoincash(prim); +} -var Utxo = {}; +var BitcoinCash = { + $$new: $$new$7 +}; -var Transaction = {}; +function $$new$8(prim) { + return new Blockchain(prim); +} -var DSProof = {}; +var Blockchain$1 = { + $$new: $$new$8 +}; -var Ecash = {}; +var $$Crypto = {}; -var PsfSlpIndexer = {}; +function $$new$9(prim) { + return new Encryption(prim); +} -var bitcoinCash = require("../bitcoincash"); +var Encryption$1 = { + $$new: $$new$9 +}; -var crypto = require("../crypto"); +function $$new$10(prim) { + return new Generating(prim); +} -var util = require("../util"); +var Generating$1 = { + $$new: $$new$10 +}; -var blockchain = require("../blockchain"); +function $$new$11(prim) { + return new Price(prim); +} -var control = require("../control"); +var Price$1 = { + $$new: $$new$11 +}; -var generating = require("../generating"); +function $$new$12(prim) { + return new Script(); +} -var mining = require("../mining"); +var Script$1 = { + $$new: $$new$12 +}; -var rawTransactions = require("../raw-transactions"); +function $$new$13(prim) { + return new Util(prim); +} -var mnemonic = require("../mnemonic"); +var Util$1 = { + $$new: $$new$13 +}; -var address = require("../address"); +function $$new$14(prim) { + return new Schnorr(prim); +} -var hdNode = require("../hdnode"); +var Schnorr$1 = { + $$new: $$new$14 +}; -var transactionBuilder = require("../transaction-builder"); +function $$new$15(prim) { + return new Slp(prim); +} -var ecPair = require("../ecpair"); +var HDNode$1 = {}; -var script = require("../script"); +var SLP = { + $$new: $$new$15, + HDNode: HDNode$1 +}; -var price = require("../price"); +function $$new$16(prim) { + return new Utxo(prim); +} -var schnorr = require("../schnorr"); +var Utxo$1 = { + $$new: $$new$16 +}; -var slp = require("../slp/slp"); +function $$new$17(prim) { + return new Transaction(prim); +} -var encryption = require("../encryption"); +var Transaction$1 = { + $$new: $$new$17 +}; -var utxo = require("../utxo"); +function $$new$18(prim) { + return new Dsproof(prim); +} -var transaction = require("../transaction"); +var DSProof = { + $$new: $$new$18 +}; -var dsProof = require("../dsproof"); +function $$new$19(prim) { + return new Ecash(); +} -var eCash = require("../ecash"); +var Ecash$1 = { + $$new: $$new$19 +}; -var electrumx = require("../electrumx", undefined); +function $$new$20(prim) { + return new PsfSlpIndexer(prim); +} -var psfSlpIndexer = require("../psf-slp-indexer"); +var PsfSlpIndexer$1 = { + $$new: $$new$20 +}; function make(config) { var restURL; @@ -178,55 +220,57 @@ function make(config) { apiToken: apiToken, authToken: authToken }; - var electrumx$2 = new electrumx(libConfig); - var control$2 = new control(libConfig); - var mining$2 = new mining(libConfig); - var rawTransactions$2 = new rawTransactions(libConfig); - var address$2 = new address(libConfig); - var blockchain$2 = new blockchain(libConfig); - console.log("Crypto module is: ", crypto); - var encryption$2 = new encryption(libConfig); - var generating$2 = new generating(libConfig); - var price$2 = new price(libConfig); - var script$2 = new script(libConfig); - var util$2 = new util(libConfig); - var schnorr$2 = new schnorr(libConfig); - var slp$2 = new slp(libConfig); - var utxo$2 = new utxo(libConfig); - var transaction$2 = new transaction(libConfig); - var dsProof$2 = new dsProof(libConfig); - var ecash = new eCash(libConfig); - var psfSlpIndexer$2 = new psfSlpIndexer(libConfig); - var ecPair$1 = ecPair.setAddress(address$2); - var hdNode$2 = new hdNode(address$2); - var mnemonic$2 = new mnemonic(address$2); - var transactionBuilder$2 = new transactionBuilder(address$2); - var bitcoinCash$2 = new bitcoinCash(address$2); + var electrumx = new Electrumx(libConfig); + var control = new Control(libConfig); + var mining = new Mining(libConfig); + var rawTransactions = new RawTransactions(libConfig); + var address = new Address(libConfig); + var bitcoinCash = new Bitcoincash(address); + var blockchain = new Blockchain(libConfig); + var crypto = require("../crypto"); + var ecPair = require("../ecpair"); + ecPair.setAddress(address); + var encryption = new Encryption(libConfig); + var generating = new Generating(libConfig); + var hdNode = new Hdnode(address); + var mnemonic = new Mnemonic(address); + var price = new Price(libConfig); + var script = new Script(); + var transactionBuilder = require("../transaction-builder"); + transactionBuilder.setAddress(address); + var util = new Util(libConfig); + var schnorr = new Schnorr(libConfig); + var slp = new Slp(libConfig); + var utxo = new Utxo(libConfig); + var transaction = new Transaction(libConfig); + var dsProof = new Dsproof(libConfig); + var ecash = new Ecash(); + var psfSlpIndexer = new PsfSlpIndexer(libConfig); return { - Address: address$2, - BitcoinCash: bitcoinCash$2, - Script: script$2, + Address: address, + BitcoinCash: bitcoinCash, + Script: script, Crypto: crypto, - Util: util$2, - Blockchain: blockchain$2, - Control: control$2, - Generating: generating$2, - Mining: mining$2, - RawTransacations: rawTransactions$2, - Mnemonic: mnemonic$2, - HDNode: hdNode$2, - TransactionBuilder: transactionBuilder$2, - ECPair: ecPair$1, - Price: price$2, - Schnorr: schnorr$2, - SLP: slp$2, - Encryption: encryption$2, - Utxo: utxo$2, - Transaction: transaction$2, - DSProof: dsProof$2, + Util: util, + Blockchain: blockchain, + Control: control, + Generating: generating, + Mining: mining, + RawTransacations: rawTransactions, + Mnemonic: mnemonic, + HDNode: hdNode, + TransactionBuilder: transactionBuilder, + ECPair: ecPair, + Price: price, + Schnorr: schnorr, + SLP: slp, + Encryption: encryption, + Utxo: utxo, + Transaction: transaction, + DSProof: dsProof, Ecash: ecash, - Electrumx: electrumx$2, - PsfSlpIndexer: psfSlpIndexer$2 + Electrumx: electrumx, + PsfSlpIndexer: psfSlpIndexer }; } @@ -235,54 +279,29 @@ var BCHJS = { }; exports.defaultRestApi = defaultRestApi; -exports.requireInternal = requireInternal; -exports.Electrumx = Electrumx; -exports.RawTransactions = RawTransactions; -exports.Control = Control; -exports.Mining = Mining; -exports.Address = Address; +exports.Electrumx = Electrumx$1; +exports.RawTransactions = RawTransactions$1; +exports.Control = Control$1; +exports.Mining = Mining$1; +exports.Address = Address$1; exports.ECPair = ECPair; exports.HDNode = HDNode; -exports.Mnemonic = Mnemonic; +exports.Mnemonic = Mnemonic$1; exports.TransactionBuilder = TransactionBuilder; exports.BitcoinCash = BitcoinCash; -exports.Blockchain = Blockchain; +exports.Blockchain = Blockchain$1; exports.$$Crypto = $$Crypto; -exports.Encryption = Encryption; -exports.Generating = Generating; -exports.Price = Price; -exports.Script = Script; -exports.Util = Util; -exports.Schnorr = Schnorr; +exports.Encryption = Encryption$1; +exports.Generating = Generating$1; +exports.Price = Price$1; +exports.Script = Script$1; +exports.Util = Util$1; +exports.Schnorr = Schnorr$1; exports.SLP = SLP; -exports.Utxo = Utxo; -exports.Transaction = Transaction; +exports.Utxo = Utxo$1; +exports.Transaction = Transaction$1; exports.DSProof = DSProof; -exports.Ecash = Ecash; -exports.PsfSlpIndexer = PsfSlpIndexer; -exports.bitcoinCash = bitcoinCash; -exports.crypto = crypto; -exports.util = util; -exports.blockchain = blockchain; -exports.control = control; -exports.generating = generating; -exports.mining = mining; -exports.rawTransactions = rawTransactions; -exports.mnemonic = mnemonic; -exports.address = address; -exports.hdNode = hdNode; -exports.transactionBuilder = transactionBuilder; -exports.ecPair = ecPair; -exports.script = script; -exports.price = price; -exports.schnorr = schnorr; -exports.slp = slp; -exports.encryption = encryption; -exports.utxo = utxo; -exports.transaction = transaction; -exports.dsProof = dsProof; -exports.eCash = eCash; -exports.electrumx = electrumx; -exports.psfSlpIndexer = psfSlpIndexer; +exports.Ecash = Ecash$1; +exports.PsfSlpIndexer = PsfSlpIndexer$1; exports.BCHJS = BCHJS; -/* bitcoinCash Not a pure module */ +/* ../util Not a pure module */ diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index be02dfc..9ef4d56 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -8,215 +8,112 @@ type libConfiguration = { @val @scope(("process", "env")) external envApiToken: string = "BCHJSTOKEN" @val @scope(("process", "env")) external envAuthPass: string = "BCHJSAUTHPASS" -type modules = - | BitcoinCash - | Crypto - | Util - | Blockchain - | Control - | Generating - | Mining - | RawTransactions - | Menmonic - | Address - | HDNode - | TransactionBuilder - | ECPair - | Script - | Price - | Schnorr - | SLP - | Encryption - | Utxo - | Transaction - | DSProof - | Ecash - | Electrumx - | PsfSlpIndexer - -external requireModule: (string, 'a) => 'a = "require" - -let requireInternal = (modules, moduleType) => { - switch modules { - | BitcoinCash => requireModule("../bitcoincash", moduleType) - | Crypto => requireModule("../crypto", moduleType) - | Util => requireModule("../util", moduleType) - | Blockchain => requireModule("../blockchain", moduleType) - | Control => requireModule("../control", moduleType) - | Generating => requireModule("../generating", moduleType) - | Mining => requireModule("../mining", moduleType) - | RawTransactions => requireModule("../raw-transaction", moduleType) - | Menmonic => requireModule("../mnemonic", moduleType) - | Address => requireModule("../address", moduleType) - | HDNode => requireModule("../hdnode", moduleType) - | TransactionBuilder => requireModule("../transaction-builder", moduleType) - | ECPair => requireModule("../ecpair", moduleType) - | Script => requireModule("../script", moduleType) - | Price => requireModule("../price", moduleType) - | Schnorr => requireModule("../schnorr", moduleType) - | SLP => requireModule("../slp/slp", moduleType) - | Encryption => requireModule("../ecryption", moduleType) - | Utxo => requireModule("../utxo", moduleType) - | Transaction => requireModule("../transaction", moduleType) - | DSProof => requireModule("../dsproof", moduleType) - | Ecash => requireModule("../ecash", moduleType) - | Electrumx => requireModule("../electrumx", moduleType) - | PsfSlpIndexer => requireModule("../psf-slp-indexer", moduleType) - } -} module Electrumx = { type t - let require = (t) => { - requireInternal(Electrumx, t) - } -@new external new: libConfiguration => t = "electrumx" + + @module @new external new: libConfiguration => t = "../electrumx" } module RawTransactions = { type t -external require: string => t = "require" -@new external new: libConfiguration => t = "rawTransactions" + @module @new external new: libConfiguration => t = "../raw-transactions" } module Control = { type t -external require: string => t = "require" -@new external new: libConfiguration => t = "control" + @module @new external new: libConfiguration => t = "../control" } module Mining = { type t -external require: string => t = "require" -@new external new: libConfiguration => t = "mining" + @module @new external new: libConfiguration => t = "../mining" } module Address = { type t -external require: string => t = "require" - @new external new: libConfiguration => t = "address" + @module @new external new: libConfiguration => t = "../address" } module ECPair = { type t -external require: string => t = "require" + external require: string => t = "require" @send - external setAddress: (t, Address.t) => t = "setAddress" - @new external new: unit => t = "ecPair" + external setAddress: (t, Address.t) => () = "setAddress" } module HDNode = { type t -external require: string => t = "require" - @new external new: Address.t => t = "hdNode" + @module @new external new: Address.t => t = "../hdnode" } module Mnemonic = { type t -external require: string => t = "require" - @new external new: Address.t => t = "mnemonic" + @module @new external new: Address.t => t = "../mnemonic" } module TransactionBuilder = { type t -external require: string => t = "require" - @new external setAddress: Address.t => t = "transactionBuilder" + external require: string => t = "require" + @send external setAddress:(t,Address.t) => () = "setAddress" } module BitcoinCash = { type t -external require: string => t = "require" -@new external new: Address.t => t = "bitcoinCash" + @module @new external new: Address.t => t = "../bitcoincash" } module Blockchain = { type t -external require: string => t = "require" -@new external new: libConfiguration => t = "blockchain" + @module @new external new: libConfiguration => t = "../blockchain" } module Crypto = { type t -external require: string => t = "require" -@new external new: unit => t = "crypto" + external require: string => t = "require" } module Encryption = { type t -external require: string => t = "require" -@new external new: libConfiguration => t = "encryption" + @module @new external new: libConfiguration => t = "../encryption" } module Generating = { type t -external require: string => t = "require" -@new external new: libConfiguration => t = "generating" + @module @new external new: libConfiguration => t = "../generating" } module Price = { type t -@new external new: libConfiguration => t = "price" -external require: string => t = "require" + @module @new external new: libConfiguration => t = "../price" } module Script = { type t -external require: string => t = "require" -@new external new: libConfiguration => t = "script" + @module @new external new: () => t = "../script" } module Util = { type t -external require: string => t = "require" -@new external new: libConfiguration => t = "util" + @module @new external new: libConfiguration => t = "../util" } module Schnorr = { type t -external require: string => t = "require" -@new external new: libConfiguration => t = "schnorr" + @module @new external new: libConfiguration => t = "../schnorr" } module SLP = { type t -external require: string => t = "require" -@new external new: libConfiguration => t = "slp" + @module @new external new: libConfiguration => t = "../slp/slp" + module HDNode = { + type t + } } module Utxo = { type t -external require: string => t = "require" -@new external new: libConfiguration => t = "utxo" + @module @new external new: libConfiguration => t = "../utxo" } module Transaction = { type t -external require: string => t = "require" -@new external new: libConfiguration => t = "transaction" + @module @new external new: libConfiguration => t = "../transaction" } module DSProof = { type t -external require: string => t = "require" -@new external new: libConfiguration => t = "dsProof" + @module @new external new: libConfiguration => t = "../dsproof" } module Ecash = { type t -external require: string => t = "require" -@new external new: libConfiguration => t = "eCash" + @module @new external new: () => t = "../ecash" } module PsfSlpIndexer = { type t -external require: string => t = "require" -@new external new: libConfiguration => t = "psfSlpIndexer" + @module @new external new: libConfiguration => t = "../psf-slp-indexer" } - -let bitcoinCash = BitcoinCash.require("../bitcoincash") -let crypto = Crypto.require("../crypto") -let util = Util.require("../util") -let blockchain = Blockchain.require("../blockchain") -let control = Control.require("../control") -let generating = Generating.require("../generating") -let mining = Mining.require("../mining") -let rawTransactions = RawTransactions.require("../raw-transactions") -let mnemonic = Mnemonic.require("../mnemonic") -let address = Address.require("../address") -let hdNode = HDNode.require("../hdnode") -let transactionBuilder = TransactionBuilder.require("../transaction-builder") -let ecPair = ECPair.require("../ecpair") -let script = Script.require("../script") -let price = Price.require("../price") -let schnorr = Schnorr.require("../schnorr") -let slp = SLP.require("../slp/slp") -let encryption = Generating.require("../encryption") -let utxo = Utxo.require("../utxo") -let transaction = Transaction.require("../transaction") -let dsProof = DSProof.require("../dsproof") -let eCash = Ecash.require("../ecash") -let electrumx = Electrumx.require() -let psfSlpIndexer = PsfSlpIndexer.require("../psf-slp-indexer") - type restURL = string type apiToken type authPass @@ -232,30 +129,32 @@ type configurationObject = { type configuration = option module BCHJS = { - type t = {@as("Address") address: Address.t, - @as("BitcoinCash") bitcoinCash :BitcoinCash.t, - @as("Script") script: Script.t, - @as("Crypto") crypto: Crypto.t, - @as("Util") util: Util.t, - @as("Blockchain") blockchain: Blockchain.t, - @as("Control") control: Control.t, - @as("Generating") generating: Generating.t, - @as("Mining") mining: Mining.t, - @as("RawTransacations") rawTransactions:RawTransactions.t, - @as("Mnemonic") mnemonic: Mnemonic.t, - @as("HDNode") hdNode: HDNode.t, - @as("TransactionBuilder") transactionBuilder: TransactionBuilder.t, - @as("ECPair") ecPair: ECPair.t, - @as("Price") price: Price.t, - @as("Schnorr") schnorr: Schnorr.t, - @as("SLP") slp:SLP.t, - @as("Encryption") encryption: Encryption.t, - @as("Utxo") utxo: Utxo.t, - @as("Transaction") transaction:Transaction.t, - @as("DSProof") dsProof: DSProof.t, - @as("Ecash") eCash: Ecash.t, - @as("Electrumx") electrumx: Electrumx.t, - @as("PsfSlpIndexer") psfSlpIndexer: PsfSlpIndexer.t} + type t = { + @as("Address") address: Address.t, + @as("BitcoinCash") bitcoinCash: BitcoinCash.t, + @as("Script") script: Script.t, + @as("Crypto") crypto: Crypto.t, + @as("Util") util: Util.t, + @as("Blockchain") blockchain: Blockchain.t, + @as("Control") control: Control.t, + @as("Generating") generating: Generating.t, + @as("Mining") mining: Mining.t, + @as("RawTransacations") rawTransactions: RawTransactions.t, + @as("Mnemonic") mnemonic: Mnemonic.t, + @as("HDNode") hdNode: HDNode.t, + @as("TransactionBuilder") transactionBuilder: TransactionBuilder.t, + @as("ECPair") ecPair: ECPair.t, + @as("Price") price: Price.t, + @as("Schnorr") schnorr: Schnorr.t, + @as("SLP") slp: SLP.t, + @as("Encryption") encryption: Encryption.t, + @as("Utxo") utxo: Utxo.t, + @as("Transaction") transaction: Transaction.t, + @as("DSProof") dsProof: DSProof.t, + @as("Ecash") eCash: Ecash.t, + @as("Electrumx") electrumx: Electrumx.t, + @as("PsfSlpIndexer") psfSlpIndexer: PsfSlpIndexer.t, + } let make = config => { let restURL = switch config { @@ -275,9 +174,11 @@ module BCHJS = { | None => envAuthPass } let combined = `fullstackcash:${authPass}` - + let base64Credential = - NodeJs.Buffer.fromString(combined)->NodeJs.Buffer.toStringWithEncoding(NodeJs.StringEncoding.base64) + NodeJs.Buffer.fromString(combined)->NodeJs.Buffer.toStringWithEncoding( + NodeJs.StringEncoding.base64, + ) let authToken = `Basic ${base64Credential}` let libConfig = { restURL, @@ -286,62 +187,56 @@ module BCHJS = { } let electrumx = Electrumx.new(libConfig) - // Js.log(electrumx) let control = Control.new(libConfig) let mining = Mining.new(libConfig) let rawTransactions = RawTransactions.new(libConfig) let address = Address.new(libConfig) - // Js.log2("Address module is: ", address) + let bitcoinCash = BitcoinCash.new(address) let blockchain = Blockchain.new(libConfig) - // let crypto = newCryptoModule() - Js.log2("Crypto module is: ", crypto) - // let ecPair = ECPair.newECPairModule() + let crypto = Crypto.require("../crypto") + let ecPair = ECPair.require("../ecpair") + ecPair->ECPair.setAddress(address) let encryption = Encryption.new(libConfig) let generating = Generating.new(libConfig) - //let hdNode = newHDNodeModule(address) - // let mnemonic = newMnemonicModule(libConfig) + let hdNode = HDNode.new(address) + let mnemonic = Mnemonic.new(address) let price = Price.new(libConfig) - let script = Script.new(libConfig) - // Js.log2("Script module is: ", script) + let script = Script.new() + let transactionBuilder = TransactionBuilder.require("../transaction-builder") + transactionBuilder->TransactionBuilder.setAddress(address) let util = Util.new(libConfig) let schnorr = Schnorr.new(libConfig) let slp = SLP.new(libConfig) let utxo = Utxo.new(libConfig) let transaction = Transaction.new(libConfig) let dsProof = DSProof.new(libConfig) - let ecash = Ecash.new(libConfig) + let ecash = Ecash.new() let psfSlpIndexer = PsfSlpIndexer.new(libConfig) - // Js.log2("Crypto module is: ", crypto) - let ecPair = ecPair->ECPair.setAddress(address) - let hdNode = HDNode.new(address) - let mnemonic = Mnemonic.new(address) - let transactionBuilder = TransactionBuilder.setAddress(address) - let bitcoinCash = BitcoinCash.new(address) { - address: address, - bitcoinCash: bitcoinCash, - script: script, - crypto: crypto, - util: util, - blockchain: blockchain, - control: control, - generating: generating, - mining: mining, - rawTransactions: rawTransactions, - mnemonic: mnemonic, - hdNode: hdNode, - transactionBuilder: transactionBuilder, - ecPair: ecPair, - price: price, - schnorr: schnorr, - slp: slp, - encryption: encryption, - utxo: utxo, - transaction: transaction, - dsProof: dsProof, + address, + bitcoinCash, + script, + crypto, + util, + blockchain, + control, + generating, + mining, + rawTransactions, + mnemonic, + hdNode, + transactionBuilder, + ecPair, + price, + schnorr, + slp, + encryption, + utxo, + transaction, + dsProof, eCash: ecash, - electrumx: electrumx, - psfSlpIndexer: psfSlpIndexer + electrumx, + psfSlpIndexer, } } } From e5ef85c7f84e8d23f8470e3d5f33a358139a4628 Mon Sep 17 00:00:00 2001 From: amit-singhs Date: Fri, 14 Oct 2022 00:22:02 +0530 Subject: [PATCH 50/53] - Formatted the code. --- src/rescript/BchRe.res | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/rescript/BchRe.res b/src/rescript/BchRe.res index 9ef4d56..c3caaf6 100644 --- a/src/rescript/BchRe.res +++ b/src/rescript/BchRe.res @@ -8,7 +8,6 @@ type libConfiguration = { @val @scope(("process", "env")) external envApiToken: string = "BCHJSTOKEN" @val @scope(("process", "env")) external envAuthPass: string = "BCHJSAUTHPASS" - module Electrumx = { type t @@ -35,7 +34,7 @@ module ECPair = { type t external require: string => t = "require" @send - external setAddress: (t, Address.t) => () = "setAddress" + external setAddress: (t, Address.t) => unit = "setAddress" } module HDNode = { type t @@ -48,7 +47,7 @@ module Mnemonic = { module TransactionBuilder = { type t external require: string => t = "require" - @send external setAddress:(t,Address.t) => () = "setAddress" + @send external setAddress: (t, Address.t) => unit = "setAddress" } module BitcoinCash = { type t @@ -76,7 +75,7 @@ module Price = { } module Script = { type t - @module @new external new: () => t = "../script" + @module @new external new: unit => t = "../script" } module Util = { type t @@ -107,7 +106,7 @@ module DSProof = { } module Ecash = { type t - @module @new external new: () => t = "../ecash" + @module @new external new: unit => t = "../ecash" } module PsfSlpIndexer = { type t From 1d91eed5dfd8137edc6119f663431d037c7ef005 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Sun, 16 Oct 2022 13:23:16 -0700 Subject: [PATCH 51/53] Fixing script in package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 24a7101..7c063e5 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "test:integration:local:bchn": "export RESTURL=http://localhost:3000/v5/ && mocha --timeout 30000 test/integration/ && mocha --timeout 30000 test/integration/chains/bchn/", "test:integration:local:testnet": "RESTURL=http://localhost:4000/v5/ mocha --timeout 30000 test/integration/chains/testnet", "test:integration:decatur:bchn": "export RESTURL=http://192.168.2.129:3000/v5/ && mocha --timeout 30000 test/integration/ && mocha --timeout 30000 test/integration/chains/bchn/", - "test:integration:decatur:abc": "export RESTURL=http://192.168.2.141:3000/v5/ && mocha --timeout 30000 test/integration && mocha --timeout 30000 test/integration/chains/abc/", + "test:integration:decatur:abc": "export RESTURL=http://192.168.2.142:3000/v5/ && mocha --timeout 30000 test/integration && mocha --timeout 30000 test/integration/chains/abc/", "test:integration:temp:bchn": "export RESTURL=http://157.90.174.219:3000/v5/ && mocha --timeout 30000 test/integration/", "test:temp": "export RESTURL=http://localhost:3000/v5/ && mocha --timeout 30000 -g '#Encryption' test/integration/", "test:temp2": "mocha --timeout=30000 -g '#TransactionLib' test/unit/", From 9326fd6e594917f9980fea5a67cd0096ac58fc69 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Tue, 1 Nov 2022 14:58:28 -0700 Subject: [PATCH 52/53] fix(utxo.get()): Detecting out-of-sync SLP indexer, protecting tokens --- src/utxo.js | 14 ++++++++++++++ test/e2e/utxo/unsynced-indexer.js | 27 +++++++++++++++++++++++++++ test/unit/utxo-unit.js | 4 ++++ 3 files changed, 45 insertions(+) create mode 100644 test/e2e/utxo/unsynced-indexer.js diff --git a/src/utxo.js b/src/utxo.js index 0a0ec59..9845f05 100644 --- a/src/utxo.js +++ b/src/utxo.js @@ -109,6 +109,11 @@ class UTXO { } } + // Get the sync status of the SLP indexer + const syncStatus = await this.psfSlpIndexer.status() + const slpIndexerHeight = syncStatus.status.syncedBlockHeight + const chainBlockHeight = syncStatus.status.chainBlockHeight + // Loop through the Fulcrum UTXOs. for (let i = 0; i < utxos.length; i++) { const thisUtxo = utxos[i] @@ -152,6 +157,15 @@ class UTXO { thisUtxo.isSlp = false } // console.log(`thisUtxo.isSlp: ${thisUtxo.isSlp}`) + + // If the SLP indexer more than 1 block behind the full node, then + // move any BCH UTXOs of 600 sats or less into the null array. This + // protects token UTXOs from being burned accidentally. + if (slpIndexerHeight < chainBlockHeight - 1) { + if (thisUtxo.value < 601) { + thisUtxo.isSlp = null + } + } } } diff --git a/test/e2e/utxo/unsynced-indexer.js b/test/e2e/utxo/unsynced-indexer.js new file mode 100644 index 0000000..bf3128f --- /dev/null +++ b/test/e2e/utxo/unsynced-indexer.js @@ -0,0 +1,27 @@ +/* + This test is used to interrogate the behavior of bch-js when a psf-slp-indexer + panicks and starts indexing from SLP genesis. In this corner-case, bch-js + should detect the indexer is out of sync, and protect any token UTXOs by + moving any UTXO under 600 sats into the null array. + + TO RUN THIS TEST: + - Reset a local instance of psf-slp-indexer to sync from genesis. + - Start a local copy of bch-api +*/ + +const BCHJS = require('../../../src/bch-js.js') +const bchjs = new BCHJS({ + restURL: 'http://localhost:3000/v5/' +}) + +async function startTest () { + try { + const addr = 'bitcoincash:qzkvas58zag9tjry693mflkjze2m20ps7vx7uw7z9d' + + const result = await bchjs.Utxo.get(addr) + console.log(`result: ${JSON.stringify(result, null, 2)}`) + } catch (err) { + console.error('Error in startTest(): ', err) + } +} +startTest() diff --git a/test/unit/utxo-unit.js b/test/unit/utxo-unit.js index aab01ef..7490f6c 100644 --- a/test/unit/utxo-unit.js +++ b/test/unit/utxo-unit.js @@ -121,6 +121,8 @@ describe('#utxo', () => { sandbox .stub(bchjs.Utxo.psfSlpIndexer, 'tx') .resolves({ txData: { isValidSlp: false } }) + sandbox.stub(bchjs.Utxo.psfSlpIndexer, 'status') + .resolves({ status: { syncedBlockHeight: 600000, chainBlockHeight: 600000 } }) // Mock function to return the same input. Good enough for this test. sandbox.stub(bchjs.Utxo, 'hydrateTokenData').resolves(x => x) @@ -154,6 +156,8 @@ describe('#utxo', () => { sandbox .stub(bchjs.Utxo.psfSlpIndexer, 'tx') .resolves({ txData: { isValidSlp: false } }) + sandbox.stub(bchjs.Utxo.psfSlpIndexer, 'status') + .resolves({ status: { syncedBlockHeight: 600000, chainBlockHeight: 600000 } }) // Force psf-slp-indexer to return no UTXOs sandbox From 055cd7fecaec01b030f5db115287d1bfaad437b6 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Wed, 14 Dec 2022 10:05:41 -0800 Subject: [PATCH 53/53] fix(encryption): Adding documentation for the encryption library --- src/encryption.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/encryption.js b/src/encryption.js index d80e026..2b1c88a 100644 --- a/src/encryption.js +++ b/src/encryption.js @@ -32,6 +32,28 @@ class Encryption { _this = this } + /** + * @api encryption.getPubKey() getPubKey() + * @apiName Encryption getPubKey() + * @apiGroup Encryption + * @apiDescription Get the public key for an address + * Given an address, the command will search the blockchain for a public + * key associated with that address. The address needs to have made at least + * one spend transaction, in order for its public key to be retrievable. + * + * @apiExample Example usage: + *(async () => { + * try { + * const addr = 'bitcoincash:qqlrzp23w08434twmvr4fxw672whkjy0py26r63g3d' + * const pubkey = await bchjs.encryption.getPubKey(addr); + * console.log(pubkey); + * } catch(err) { + * console.error(err) + * } + *})() + * + */ + // Search the blockchain for a public key associated with a BCH address. async getPubKey (addr) { try {