diff --git a/demo.js b/demo.js index 3a703b0..63ae92f 100644 --- a/demo.js +++ b/demo.js @@ -3,11 +3,6 @@ var CJDemo = ('object' === typeof module && exports) || {}; (function (window, CJDemo) { 'use strict'; - let ENV = window.ENV || require('./node-env.js'); - - //@ts-ignore - ts can't understand JSON, still... - let pkg = ENV.package || require('./package.json'); - //@ts-ignore let Packer = window.CJPacker || require('./packer.js'); //@ts-ignore @@ -36,26 +31,13 @@ var CJDemo = ('object' === typeof module && exports) || {}; // const COINJOIN_ENTRY_MAX_SIZE = 9; // real const COINJOIN_ENTRY_MAX_SIZE = 2; // just for testing right now - let rpcConfig = { - protocol: ENV.DASHD_RPC_PROTOCOL || 'http', // https for remote, http for local / private networking - user: ENV.DASHD_RPC_USER, - pass: ENV.DASHD_RPC_PASS || ENV.DASHD_RPC_PASSWORD, - host: ENV.DASHD_RPC_HOST || '127.0.0.1', - port: ENV.DASHD_RPC_PORT || '19898', // mainnet=9998, testnet=19998, regtest=19898 - timeout: 10 * 1000, // bump default from 5s to 10s for up to 10k addresses - onconnected: async function () { - console.info(`[info] rpc client connected ${rpcConfig.host}`); - }, - }; - if (ENV.DASHD_RPC_TIMEOUT) { - let rpcTimeoutSec = parseFloat(ENV.DASHD_RPC_TIMEOUT); - rpcConfig.timeout = rpcTimeoutSec * 1000; - } - - async function main() { + CJDemo.run = async function (ENV, rpcConfig) { /* jshint maxstatements: 1000 */ /* jshint maxcomplexity: 100 */ + //@ts-ignore - ts can't understand JSON, still... + let pkg = ENV.package || require('./package.json'); + let walletSalt = ENV.DASH_WALLET_SALT || ''; let isHelp = walletSalt === 'help' || walletSalt === '--help'; if (isHelp) { @@ -1367,7 +1349,7 @@ var CJDemo = ('object' === typeof module && exports) || {}; } console.log('Sweet, sweet victory!'); - } + }; /** * @param {Object} a @@ -1433,17 +1415,6 @@ var CJDemo = ('object' === typeof module && exports) || {}; }); } - main() - .then(function () { - console.info('Done'); - process.exit(0); - }) - .catch(function (err) { - console.error('Fail:'); - console.error(err.stack || err); - process.exit(1); - }); - // @ts-ignore window.CJDemo = CJDemo; })(('object' === typeof window && window) || {}, CJDemo); diff --git a/run-demo.js b/run-demo.js new file mode 100644 index 0000000..710ac62 --- /dev/null +++ b/run-demo.js @@ -0,0 +1,36 @@ +'use strict'; + +let CJDemo = require('./demo.js'); + +// TODO move to +let ENV = require('./node-env.js'); +let rpcConfig = { + protocol: ENV.DASHD_RPC_PROTOCOL || 'http', // https for remote, http for local / private networking + user: ENV.DASHD_RPC_USER, + pass: ENV.DASHD_RPC_PASS || ENV.DASHD_RPC_PASSWORD, + host: ENV.DASHD_RPC_HOST || '127.0.0.1', + port: ENV.DASHD_RPC_PORT || '19898', // mainnet=9998, testnet=19998, regtest=19898 + timeout: 10 * 1000, // bump default from 5s to 10s for up to 10k addresses + onconnected: async function () { + console.info(`[info] rpc client connected ${rpcConfig.host}`); + }, +}; +if (ENV.DASHD_RPC_TIMEOUT) { + let rpcTimeoutSec = parseFloat(ENV.DASHD_RPC_TIMEOUT); + rpcConfig.timeout = rpcTimeoutSec * 1000; +} + +CJDemo.run(ENV, rpcConfig) + .then(function () { + console.info('Done'); + if (typeof process !== 'undefined') { + process.exit(0); + } + }) + .catch(function (err) { + console.error('Fail:'); + console.error(err.stack || err); + if (typeof process !== 'undefined') { + process.exit(1); + } + }); diff --git a/test.html b/test.html index 2b15c76..decac38 100644 --- a/test.html +++ b/test.html @@ -1,7 +1,5 @@ - - @@ -12,72 +10,47 @@ + +