Guest User

byteball vs travelflex

a guest
Jul 23rd, 2018
658
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 49.16 KB | None | 0 0
  1. diff --git a/LICENSE b/LICENSE
  2. index f236bf6..0c7c545 100644
  3. --- a/LICENSE
  4. +++ b/LICENSE
  5. @@ -1,6 +1,6 @@
  6. -The MIT License (MIT)
  7. +MIT License
  8.  
  9. -Copyright (c) 2016 Byteball developers
  10. +Copyright (c) 2018 TravelFlex
  11.  
  12.  Permission is hereby granted, free of charge, to any person obtaining a copy
  13.  of this software and associated documentation files (the "Software"), to deal
  14. @@ -9,14 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  15.  copies of the Software, and to permit persons to whom the Software is
  16.  furnished to do so, subject to the following conditions:
  17.  
  18. -The above copyright notice and this permission notice shall be included in
  19. -all copies or substantial portions of the Software.
  20. +The above copyright notice and this permission notice shall be included in all
  21. +copies or substantial portions of the Software.
  22.  
  23.  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  24.  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  25.  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  26.  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  27.  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  28. -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  29. -THE SOFTWARE.
  30. -
  31. +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. +SOFTWARE.
  33. diff --git a/README.md b/README.md
  34. index a91191e..5961930 100644
  35. --- a/README.md
  36. +++ b/README.md
  37. @@ -1,109 +1 @@
  38. -# Byteball core
  39. -
  40. -This is a library used in [Byteball](https://byteball.org) clients.  Never used directly.  Some of the clients that require the library:
  41. -
  42. -* [Byteball](../../../byteball) - GUI wallet for Mac, Windows, Linux, iOS, and Android.
  43. -* [Headless Byteball](../../../headless-byteball) - headless wallet, primarily for server side use.
  44. -* [Byteball Relay](../../../byteball-relay) - relay node for Byteball network.  It doesn't hold any private keys.
  45. -* [Byteball Hub](../../../byteball-hub) - hub for Byteball network.  Includes the relay, plus can store and forward end-to-end encrypted messages among devices on the Byteball network.
  46. -
  47. -## Developer guides
  48. -
  49. -See the [wiki](https://github.com/byteball/byteballcore/wiki/Byteball-Developer-Guides).  Many of the features are not documented yet, see other [byteball repositories](https://github.com/byteball) as samples, for APIs see the `exports` of node.js modules.
  50. -
  51. -## Configuring
  52. -
  53. -The default settings are in the library's [conf.js](conf.js), they can be overridden in your project root's conf.js (see the clients above as examples), then in conf.json in the app data folder.  The app data folder is:
  54. -
  55. -* macOS: `~/Library/Application Support/<appname>`
  56. -* Linux: `~/.config/<appname>`
  57. -* Windows: `%LOCALAPPDATA%\<appname>`
  58. -
  59. -`<appname>` is `name` in your `package.json`.
  60. -
  61. -### Settings
  62. -
  63. -This is the list of some of the settings that the library understands (your app can add more settings that only your app understands):
  64. -
  65. -#### conf.port
  66. -
  67. -The port to listen on.  If you don't want to accept incoming connections at all, set port to `null`, which is the default.  If you do want to listen, you will usually have a proxy, such as nginx, accept websocket connections on standard port 443 and forward them to your byteball daemon that listens on port 6611 on the local interface.
  68. -
  69. -#### conf.storage
  70. -
  71. -Storage backend -- mysql or sqlite, the default is sqlite.  If sqlite, the database files are stored in the app data folder.  If mysql, you need to also initialize the database with [byteball.sql](byteball.sql) and set connection params, e.g. in conf.json in the app data folder:
  72. -
  73. -```json
  74. -{
  75. -   "port": 6611,
  76. -   "storage": "mysql",
  77. -   "database": {
  78. -       "max_connections": 30,
  79. -       "host"     : "localhost",
  80. -       "user"     : "byteball",
  81. -       "password" : "yourmysqlpassword",
  82. -       "name"     : "byteball"
  83. -   }
  84. -}
  85. -```
  86. -#### conf.bLight
  87. -
  88. -Work as light client (`true`) or full node (`false`).  The default is full client.
  89. -
  90. -#### conf.bServeAsHub
  91. -
  92. -Whether to serve as hub on the Byteball network (store and forward e2e-encrypted messages for devices that connect to your hub).  The default is `false`.
  93. -
  94. -#### conf.myUrl
  95. -
  96. -If your node accepts incoming connections, this is its URL.  The node will share this URL with all its outgoing peers so that they can reconnect in any direction in the future.  By default the node doesn't share its URL even if it accepts connections.
  97. -
  98. -#### conf.bWantNewPeers
  99. -
  100. -Whether your node wants to learn about new peers from its current peers (`true`, the default) or not (`false`).  Set it to `false` to run your node in stealth mode so that only trusted peers can see its IP address (e.g. if you have online wallets on your server and don't want potential attackers to learn its IP).
  101. -
  102. -#### conf.socksHost, conf.socksPort, and conf.socksLocalDNS
  103. -
  104. -Settings for connecting through optional SOCKS5 proxy.  Use them to connect through TOR and hide your IP address from peers even when making outgoing connections.  This is useful and highly recommended when you are running an online wallet on your server and want to make it harder for potential attackers to learn the IP address of the target to attack.  Set `socksLocalDNS` to `false` to route DNS queries through TOR as well.
  105. -
  106. -#### MySQL conf for faster syncing
  107. -
  108. -To lower disk load and increase sync speed, you can optionally disable flushing to disk every transaction, instead doing it once a second. This can be done by setting `innodb_flush_log_at_trx_commit=0` in your MySQL server config file (my.ini)
  109. -
  110. -## Accepting incoming connections
  111. -
  112. -Byteball network works over secure WebSocket protocol wss://.  To accept incoming connections, you'll need a valid TLS certificate (you can get a free one from [letsencrypt.org](https://letsencrypt.org)) and a domain name (you can get a free domain from [Freenom](http://www.freenom.com/)).  Then you accept connections on standard port 443 and proxy them to your locally running byteball daemon.
  113. -
  114. -This is an example configuration for nginx to accept websocket connections at wss://byteball.one/bb and forward them to locally running daemon that listens on port 6611:
  115. -
  116. -```nginx
  117. -server {
  118. -   listen 80 default_server;
  119. -   listen [::]:80 default_server;
  120. -   listen 443 ssl;
  121. -   listen [::]:443 ssl;
  122. -   ssl_certificate "/etc/letsencrypt/live/byteball.one/fullchain.pem";
  123. -   ssl_certificate_key "/etc/letsencrypt/live/byteball.one/privkey.pem";
  124. -
  125. -   if ($host != "byteball.one") {
  126. -       rewrite ^(.*)$ https://byteball.one$1 permanent;
  127. -   }
  128. -   if ($https != "on") {
  129. -       rewrite ^(.*)$ https://byteball.one$1 permanent;
  130. -   }
  131. -
  132. -   location = /bb {
  133. -       proxy_pass http://localhost:6611;
  134. -       proxy_http_version 1.1;
  135. -       proxy_set_header X-Real-IP $remote_addr;
  136. -       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  137. -       proxy_set_header Upgrade $http_upgrade;
  138. -       proxy_set_header Connection "upgrade";
  139. -   }
  140. -
  141. -   root /var/www/html;
  142. -   server_name _;
  143. -}
  144. -```
  145. -
  146. -
  147. +TravelFlex
  148. diff --git a/byteball-sqlite-light.sql b/byteball-sqlite-light.sql
  149. index f1c3726..f70daba 100644
  150. --- a/byteball-sqlite-light.sql
  151. +++ b/byteball-sqlite-light.sql
  152. @@ -310,7 +310,6 @@ CREATE INDEX dobyAddressSpent ON outputs(address, is_spent);
  153.  CREATE INDEX outputsIndexByAsset ON outputs(asset);
  154.  CREATE INDEX outputsIsSerial ON outputs(is_serial);
  155.  
  156. -
  157.  -- ------------
  158.  -- Commissions
  159.  
  160. @@ -723,7 +722,6 @@ CREATE TABLE private_profile_fields (
  161.  );
  162.  CREATE INDEX ppfByField ON private_profile_fields(`field`);
  163.  
  164. -
  165.  CREATE TABLE attested_fields (
  166.     unit CHAR(44) NOT NULL,
  167.     message_index TINYINT NOT NULL,
  168. diff --git a/byteball-sqlite.sql b/byteball-sqlite.sql
  169. index 64faa58..e832750 100644
  170. --- a/byteball-sqlite.sql
  171. +++ b/byteball-sqlite.sql
  172. @@ -750,7 +750,6 @@ CREATE TABLE attested_fields (
  173.     `field` VARCHAR(50) NOT NULL,
  174.     `value` VARCHAR(100) NOT NULL,
  175.     PRIMARY KEY (unit, message_index, `field`),
  176. -   CONSTRAINT attestationsByAttestorAddress FOREIGN KEY (attestor_address) REFERENCES addresses(address),
  177.     FOREIGN KEY (unit) REFERENCES units(unit)
  178.  );
  179.  CREATE INDEX attestedFieldsByAttestorFieldValue ON attested_fields(attestor_address, `field`, `value`);
  180. diff --git a/composer.js b/composer.js
  181. index 298753a..f57a0a9 100644
  182. --- a/composer.js
  183. +++ b/composer.js
  184. @@ -357,10 +357,6 @@ function composeAttestationJoint(from_address, attested_address, profile_data, s
  185.     composeContentJoint(from_address, "attestation", {address: attested_address, profile: profile_data}, signer, callbacks);
  186.  }
  187.  
  188. -function composeAssetDefinitionJoint(from_address, asset_definition, signer, callbacks){
  189. -   composeContentJoint(from_address, "asset", asset_definition, signer, callbacks);
  190. -}
  191. -
  192.  function composeAssetAttestorsJoint(from_address, asset, arrNewAttestors, signer, callbacks){
  193.     composeContentJoint(from_address, "asset_attestors", {asset: asset, attestors: arrNewAttestors}, signer, callbacks);
  194.  }
  195. @@ -380,7 +376,7 @@ function composeJoint(params){
  196.         return;
  197.     }
  198.    
  199. -   if (conf.bLight && !params.lightProps){
  200. +   /*if (conf.bLight && !params.lightProps){
  201.         var network = require('./network.js');
  202.         network.requestFromLightVendor(
  203.             'light/get_parents_and_last_ball_and_witness_list_unit',
  204. @@ -395,7 +391,7 @@ function composeJoint(params){
  205.             }
  206.         );
  207.         return;
  208. -   }
  209. +   }*/
  210.    
  211.     // try to use as few paying_addresses as possible. Assuming paying_addresses are sorted such that the most well-funded addresses come first
  212.     if (params.minimal && !params.send_all){
  213. @@ -429,12 +425,12 @@ function composeJoint(params){
  214.     var arrMessages = _.clone(params.messages || []);
  215.     var assocPrivatePayloads = params.private_payloads || {}; // those that correspond to a subset of params.messages
  216.     var fnRetrieveMessages = params.retrieveMessages;
  217. -   var lightProps = params.lightProps;
  218. +   //var lightProps = params.lightProps;
  219.     var signer = params.signer;
  220.     var callbacks = params.callbacks;
  221.    
  222. -   if (conf.bLight && !lightProps)
  223. -       throw Error("no parent props for light");
  224. +   //if (conf.bLight && !lightProps)
  225. +   //  throw Error("no parent props for light");
  226.    
  227.    
  228.     //profiler.start();
  229. @@ -488,6 +484,7 @@ function composeJoint(params){
  230.     var assocSigningPaths = {};
  231.     var unlock_callback;
  232.     var conn;
  233. +    var lightProps;
  234.    
  235.     var handleError = function(err){
  236.         //profiler.stop('compose');
  237. @@ -507,6 +504,23 @@ function composeJoint(params){
  238.                 cb();
  239.             });
  240.         },
  241. +        function(cb){ // lightProps
  242. +            if (!conf.bLight)
  243. +                return cb();
  244. +            var network = require('./network.js');
  245. +            network.requestFromLightVendor(
  246. +                'light/get_parents_and_last_ball_and_witness_list_unit',
  247. +                {witnesses: arrWitnesses},
  248. +                function(ws, request, response){
  249. +                    if (response.error)
  250. +                        return handleError(response.error); // cb is not called
  251. +                    if (!response.parent_units || !response.last_stable_mc_ball || !response.last_stable_mc_ball_unit || typeof response.last_stable_mc_ball_mci !== 'number')
  252. +                        return handleError("invalid parents from light vendor"); // cb is not called
  253. +                    lightProps = response;
  254. +                    cb();
  255. +                }
  256. +            );
  257. +        },
  258.         function(cb){ // start transaction
  259.             db.takeConnectionFromPool(function(new_conn){
  260.                 conn = new_conn;
  261. @@ -947,7 +961,6 @@ exports.composePollJoint = composePollJoint;
  262.  exports.composeVoteJoint = composeVoteJoint;
  263.  exports.composeProfileJoint = composeProfileJoint;
  264.  exports.composeAttestationJoint = composeAttestationJoint;
  265. -exports.composeAssetDefinitionJoint = composeAssetDefinitionJoint;
  266.  exports.composeAssetAttestorsJoint = composeAssetAttestorsJoint;
  267.  
  268.  exports.composeJoint = composeJoint;
  269. diff --git a/constants.js b/constants.js
  270. index 878dfb8..225af59 100644
  271. --- a/constants.js
  272. +++ b/constants.js
  273. @@ -1,17 +1,16 @@
  274.  /*jslint node: true */
  275.  "use strict";
  276.  
  277. -exports.COUNT_WITNESSES = 12;
  278. +exports.COUNT_WITNESSES = 7;
  279.  exports.MAX_WITNESS_LIST_MUTATIONS = 1;
  280. -exports.TOTAL_WHITEBYTES = 1e15;
  281. +exports.TOTAL_WHITEBYTES = 1315e11;
  282.  exports.MAJORITY_OF_WITNESSES = (exports.COUNT_WITNESSES%2===0) ? (exports.COUNT_WITNESSES/2+1) : Math.ceil(exports.COUNT_WITNESSES/2);
  283.  exports.COUNT_MC_BALLS_FOR_PAID_WITNESSING = 100;
  284.  
  285.  exports.version = '1.0';
  286.  exports.alt = '1';
  287.  
  288. -exports.GENESIS_UNIT = (exports.alt === '2' && exports.version === '1.0t') ? 'TvqutGPz3T4Cs6oiChxFlclY92M2MvCvfXR5/FETato=' : 'oj8yEksX9Ubq7lLc+p6F2uyHUuynugeVq4+ikT67X6E=';
  289. -exports.BLACKBYTES_ASSET = (exports.alt === '2' && exports.version === '1.0t') ? 'LUQu5ik4WLfCrr8OwXezqBa+i3IlZLqxj2itQZQm8WY=' : 'qO2JsiuDMh/j+pqJYZw3u82O71WjCDf0vTNvsnntr8o=';
  290. +exports.GENESIS_UNIT = 'q0vnHPuI3Sd3lkTyX8Jv7qOARayGN9weHW0uj5mlSBA=';
  291.  
  292.  exports.HASH_LENGTH = 44;
  293.  exports.PUBKEY_LENGTH = 44;
  294. @@ -30,14 +29,8 @@ exports.MAX_ATTESTORS_PER_ASSET = 64;
  295.  exports.MAX_DATA_FEED_NAME_LENGTH = 64;
  296.  exports.MAX_DATA_FEED_VALUE_LENGTH = 64;
  297.  exports.MAX_AUTHENTIFIER_LENGTH = 4096;
  298. -exports.MAX_CAP = 9e15;
  299. +exports.MAX_CAP = 1315e11;
  300.  exports.MAX_COMPLEXITY = 100;
  301.  
  302.  exports.MAX_PROFILE_FIELD_LENGTH = 50;
  303.  exports.MAX_PROFILE_VALUE_LENGTH = 100;
  304. -
  305. -exports.TEXTCOIN_CLAIM_FEE = 548;
  306. -exports.TEXTCOIN_ASSET_CLAIM_FEE = 750;
  307. -exports.TEXTCOIN_ASSET_CLAIM_HEADER_FEE = 391;
  308. -exports.TEXTCOIN_ASSET_CLAIM_MESSAGE_FEE = 209;
  309. -exports.TEXTCOIN_ASSET_CLAIM_BASE_MSG_FEE = 158;
  310. \ No newline at end of file
  311. diff --git a/device.js b/device.js
  312. index 44487ee..89e0030 100644
  313. --- a/device.js
  314. +++ b/device.js
  315. @@ -159,10 +159,14 @@ function loginToHub(){
  316.  setInterval(loginToHub, RECONNECT_TO_HUB_PERIOD);
  317.  eventBus.on('connected', loginToHub);
  318.  
  319. +function loginMessage(challenge, priv, pubkey) {
  320. +    var objLogin = {challenge: challenge, pubkey: pubkey};
  321. +    objLogin.signature = ecdsaSig.sign(objectHash.getDeviceMessageHashToSign(objLogin), priv);
  322. +    return objLogin;
  323. +}
  324. +
  325.  function sendLoginCommand(ws, challenge){
  326. -   var objLogin = {challenge: challenge, pubkey: objMyPermanentDeviceKey.pub_b64};
  327. -   objLogin.signature = ecdsaSig.sign(objectHash.getDeviceMessageHashToSign(objLogin), objMyPermanentDeviceKey.priv);
  328. -   network.sendJustsaying(ws, 'hub/login', objLogin);
  329. +    network.sendJustsaying(ws, 'hub/login', loginMessage(challenge, objMyPermanentDeviceKey.priv, objMyPermanentDeviceKey.pub_b64));
  330.     ws.bLoggedIn = true;
  331.     sendTempPubkey(ws, objMyTempDeviceKey.pub_b64);
  332.     network.initWitnessesIfNecessary(ws);
  333. @@ -734,6 +738,7 @@ function requestFromHub(command, params, responseHandler){
  334.  exports.getMyDevicePubKey = getMyDevicePubKey;
  335.  exports.getMyDeviceAddress = getMyDeviceAddress;
  336.  exports.isValidPubKey = isValidPubKey;
  337. +exports.loginMessage = loginMessage;
  338.  
  339.  exports.genPrivKey = genPrivKey;
  340.  
  341. diff --git a/initial.byteball-light.sqlite b/initial.byteball-light.sqlite
  342. index 1ace473..9a953db 100644
  343. Binary files a/initial.byteball-light.sqlite and b/initial.byteball-light.sqlite differ
  344. diff --git a/light.js b/light.js
  345. index 2e730cd..672f1b6 100644
  346. --- a/light.js
  347. +++ b/light.js
  348. @@ -302,9 +302,11 @@ function processHistory(objResponse, callbacks){
  349.                     return callbacks.ifError("wrong ball hash: unit "+objBall.unit+", ball "+objBall.ball);
  350.                 if (!assocKnownBalls[objBall.ball])
  351.                     return callbacks.ifError("ball not known: "+objBall.ball);
  352. +               if (objBall.parent_balls != null) {
  353.                      objBall.parent_balls.forEach(function (parent_ball) {
  354.                          assocKnownBalls[parent_ball] = true;
  355.                      });
  356. +                }
  357.                 if (objBall.skiplist_balls)
  358.                     objBall.skiplist_balls.forEach(function(skiplist_ball){
  359.                         assocKnownBalls[skiplist_ball] = true;
  360. diff --git a/mysql_pool.js b/mysql_pool.js
  361. index 276f9f5..ce545c9 100644
  362. --- a/mysql_pool.js
  363. +++ b/mysql_pool.js
  364. @@ -8,7 +8,6 @@ module.exports = function(connection_or_pool){
  365.     var safe_connection = connection_or_pool;
  366.     safe_connection.original_query = safe_connection.query;
  367.     safe_connection.original_release = safe_connection.release;
  368. -   safe_connection.original_escape = safe_connection.escape;
  369.    
  370.     // this is a hack to make all errors throw exception that would kill the program
  371.     safe_connection.query = function () {
  372. @@ -49,9 +48,7 @@ module.exports = function(connection_or_pool){
  373.         return q;
  374.     };
  375.  
  376. -   safe_connection.escape = function(str){
  377. -       return connection_or_pool.original_escape(str);
  378. -   };
  379. +   //safe_connection.escape = connection_or_pool.escape;
  380.    
  381.     safe_connection.release = function(){
  382.         //console.log("releasing connection");
  383. diff --git a/network.js b/network.js
  384. index 627752d..5d61654 100644
  385. --- a/network.js
  386. +++ b/network.js
  387. @@ -1356,6 +1356,8 @@ function flushEvents(forceFlushing) {
  388.  }
  389.  
  390.  function writeEvent(event, host){
  391. +    if (conf.bLight)
  392. +        return;
  393.     if (event === 'invalid' || event === 'nonserial'){
  394.         var column = "count_"+event+"_joints";
  395.         db.query("UPDATE peer_hosts SET "+column+"="+column+"+1 WHERE peer_host=?", [host]);
  396. @@ -1367,6 +1369,7 @@ function writeEvent(event, host){
  397.     flushEvents();
  398.  }
  399.  
  400. +if (!conf.bLight)
  401.      setInterval(function(){flushEvents(true)}, 1000 * 60);
  402.  
  403.  
  404. @@ -1937,7 +1940,7 @@ function handleJustsaying(ws, subject, body){
  405.                 return;
  406.             }
  407.             ws.library_version = body.library_version;
  408. -           if (typeof ws.library_version === 'string' && version2int(ws.library_version) < version2int('0.2.70') && constants.version === '1.0')
  409. +           if (typeof ws.library_version === 'string' && version2int(ws.library_version) < version2int('0.1.0') && constants.version === '1.0')
  410.                 ws.old_core = true;
  411.             eventBus.emit('peer_version', ws, body); // handled elsewhere
  412.             break;
  413. diff --git a/package.json b/package.json
  414. index f1b0c14..1a59fe5 100644
  415. --- a/package.json
  416. +++ b/package.json
  417. @@ -1,20 +1,20 @@
  418.  {
  419. -  "name": "byteballcore",
  420. -  "description": "Byteball Core",
  421. -  "author": "Byteball",
  422. -  "version": "0.2.88",
  423. +  "name": "core",
  424. +  "description": "TravelFlexCore Core",
  425. +  "author": "TravelFlexCore",
  426. +  "version": "0.1.0",
  427.    "keywords": [
  428. -    "byteball",
  429. +    "TravelFlex",
  430.      "multisignature"
  431.    ],
  432. -  "homepage": "https://github.com/byteball/byteballcore",
  433. +  "homepage": "https://github.com/TravelFlex/TravelFlexCore",
  434.    "license": "MIT",
  435.    "repository": {
  436. -    "url": "git://github.com/byteball/byteballcore.git",
  437. +    "url": "git://github.com/TravelFlex/TravelFlexCore.git",
  438.      "type": "git"
  439.    },
  440.    "bugs": {
  441. -    "url": "https://github.com/byteball/byteballcore/issues"
  442. +    "url": "https://github.com/TravelFlex/TravelFlexCore/issues"
  443.    },
  444.    "browser": {
  445.      "request": "browser-request",
  446. @@ -34,10 +34,11 @@
  447.      "ws": "^1.0.1"
  448.    },
  449.    "scripts": {
  450. -    "test": "yarn ava"
  451. +    "test": "ava"
  452.    },
  453.    "devDependencies": {
  454. -    "ava": "^0.22.0",
  455. +    "ava": "^1.0.0-beta.1",
  456. +    "ava-config": "^1.1.0",
  457.      "testcheck": "^1.0.0-rc.2"
  458.    }
  459.  }
  460. diff --git a/storage.js b/storage.js
  461. index e88762e..b265bb6 100644
  462. --- a/storage.js
  463. +++ b/storage.js
  464. @@ -71,7 +71,7 @@ function readJointDirectly(conn, unit, callbacks, bRetrying) {
  465.        var bVoided = (objUnit.content_hash && main_chain_index < min_retrievable_mci);
  466.        var bRetrievable = (main_chain_index >= min_retrievable_mci || main_chain_index === null);
  467.  
  468. -           if (!conf.bLight && !objUnit.last_ball)
  469. +      if (!conf.bLight && !objUnit.last_ball && !isGenesisUnit(unit))
  470.          throw Error("no last ball in unit "+JSON.stringify(objUnit));
  471.  
  472.        // unit hash verification below will fail if:
  473. diff --git a/test/string_utils.test.js b/test/string_utils.test.js
  474. index bba9001..ca47e87 100644
  475. --- a/test/string_utils.test.js
  476. +++ b/test/string_utils.test.js
  477. @@ -13,24 +13,35 @@ const simpleString = 'simple test string';
  478.  const simpleStringResult = ['s', simpleString].join(STRING_JOIN_CHAR);
  479.  test('Test a simple string', t => {
  480.      t.true(getSourceString(simpleString) === simpleStringResult);
  481. +    t.true(20 === getSourceString(simpleString).length);
  482.  });
  483.  
  484.  const integer = 27090;
  485.  const simpleIntResult = ['n', integer].join(STRING_JOIN_CHAR);
  486.  test('Test an integer', t => {
  487.      t.true(getSourceString(integer) === simpleIntResult);
  488. +    t.true(7 === getSourceString(integer).length);
  489.  });
  490.  
  491.  const float = 8.103;
  492.  const simpleFloatResult = ['n', float].join(STRING_JOIN_CHAR);
  493.  test('Test a float', t => {
  494.      t.true(getSourceString(float) === simpleFloatResult);
  495. +    t.true(7 === getSourceString(float).length);
  496. +});
  497. +
  498. +const floatInt = 1.0;
  499. +const simpleFloatIntResult = ['n', floatInt].join(STRING_JOIN_CHAR);
  500. +test('Test a float int, 1.0 => n1', t => {
  501. +    t.true(getSourceString(floatInt) === simpleFloatIntResult);
  502. +    t.true(3 === getSourceString(floatInt).length);
  503.  });
  504.  
  505.  const boolean = false;
  506.  const simpleBooleanResult = ['b', boolean].join(STRING_JOIN_CHAR);
  507.  test('Test a boolean', t => {
  508.      t.true(getSourceString(boolean) === simpleBooleanResult);
  509. +    t.true(7 === getSourceString(boolean).length);
  510.  });
  511.  
  512.  const arrayInput = ['a', 81, 'b', 'c', 3.6903690369, true];
  513. @@ -40,6 +51,7 @@ const arrayInputResultPairs = ['s', 'n', 's', 's', 'n', 'b'].map(function(typ, i
  514.  const arrayInputResult = ['[', arrayInputResultPairs, ']'].join(STRING_JOIN_CHAR);
  515.  test('Test an array', t => {
  516.      t.true(getSourceString(arrayInput) === arrayInputResult);
  517. +    t.true(42 === getSourceString(arrayInput).length);
  518.  });
  519.  
  520.  // Just hard-coding this...
  521. @@ -48,6 +60,5 @@ const objectPairs = ['bunch', getSourceString(9), 'unit', getSourceString('clust
  522.  const objectResult = objectPairs.join(STRING_JOIN_CHAR);
  523.  test('Test an object', t => {
  524.      t.true(getSourceString(object) === objectResult);
  525. +    t.true(54 === getSourceString(object).length);
  526.  });
  527. \ No newline at end of file
  528. -
  529. -
  530. diff --git a/wallet.js b/wallet.js
  531. index d99040d..c508399 100644
  532. --- a/wallet.js
  533. +++ b/wallet.js
  534. @@ -122,12 +122,14 @@ eventBus.on("message_from_hub", handleJustsaying);
  535.  eventBus.on("message_for_light", handleJustsaying);
  536.  
  537.  
  538. -
  539. -
  540. -
  541.  // called from UI after user confirms signing request initiated from another device, initiator device being the recipient of this message
  542.  function sendSignature(device_address, signed_text, signature, signing_path, address) {
  543. -   device.sendMessageToDevice(device_address, "signature", {signed_text: signed_text, signature: signature, signing_path: signing_path, address: address});
  544. +  device.sendMessageToDevice(device_address, "signature", {
  545. +    signed_text: signed_text,
  546. +    signature: signature,
  547. +    signing_path: signing_path,
  548. +    address: address
  549. +  });
  550.  }
  551.  
  552.  // one of callbacks MUST be called, otherwise the mutex will stay locked
  553. @@ -310,7 +312,9 @@ function handleMessageFromHub(ws, json, device_pubkey, bIndirectCorrespondent, c
  554.              return callbacks.ifError("private payload hash does not match");
  555.            if (!ValidationUtils.isNonemptyArray(objUnit.messages))
  556.              return callbacks.ifError("no messages in unsigned unit");
  557. -                   if (objUnit.messages.filter(function(objMessage){ return (objMessage.payload_hash === payload_hash); }).length !== 1)
  558. +          if (objUnit.messages.filter(function (objMessage) {
  559. +              return (objMessage.payload_hash === payload_hash);
  560. +            }).length !== 1)
  561.              return callbacks.ifError("no such payload hash in the messages");
  562.          }
  563.        }
  564. @@ -362,7 +366,11 @@ function handleMessageFromHub(ws, json, device_pubkey, bIndirectCorrespondent, c
  565.            callbacks.ifError("not aware of address " + body.address + " but will see if I learn about it later");
  566.            eventBus.once("new_address-" + body.address, function () {
  567.              // rewrite callbacks to avoid duplicate unlocking of mutex
  568. -                       handleMessageFromHub(ws, json, device_pubkey, bIndirectCorrespondent, { ifOk: function(){}, ifError: function(){} });
  569. +            handleMessageFromHub(ws, json, device_pubkey, bIndirectCorrespondent, {
  570. +              ifOk: function () {
  571. +              }, ifError: function () {
  572. +              }
  573. +            });
  574.            });
  575.          }
  576.        });
  577. @@ -410,9 +418,13 @@ function handleMessageFromHub(ws, json, device_pubkey, bIndirectCorrespondent, c
  578.          if (!body.forwarded) {
  579.            emitNewPrivatePaymentReceived(from_address, arrChains, current_message_counter);
  580.            // note, this forwarding won't work if the user closes the wallet before validation of the private chains
  581. -                   var arrUnits = arrChains.map(function(arrPrivateElements){ return arrPrivateElements[0].unit; });
  582. +          var arrUnits = arrChains.map(function (arrPrivateElements) {
  583. +            return arrPrivateElements[0].unit;
  584. +          });
  585.            db.query("SELECT address FROM unit_authors WHERE unit IN(?)", [arrUnits], function (rows) {
  586. -                       var arrAuthorAddresses = rows.map(function(row){ return row.address; });
  587. +            var arrAuthorAddresses = rows.map(function (row) {
  588. +              return row.address;
  589. +            });
  590.              // if the addresses are not shared, it doesn't forward anything
  591.              forwardPrivateChainsToOtherMembersOfSharedAddresses(arrChains, arrAuthorAddresses, from_address, true);
  592.            });
  593. @@ -527,7 +539,8 @@ function forwardPrivateChainsToOtherMembersOfOutputAddresses(arrChains, conn, on
  594.    console.log("output addresses", arrOutputAddresses);
  595.    conn = conn || db;
  596.    if (!onSaved)
  597. -       onSaved = function(){};
  598. +    onSaved = function () {
  599. +    };
  600.    readWalletsByAddresses(conn, arrOutputAddresses, function (arrWallets) {
  601.      if (arrWallets.length === 0) {
  602.        //   breadcrumbs.add("forwardPrivateChainsToOtherMembersOfOutputAddresses: " + JSON.stringify(arrChains)); // remove in livenet
  603. @@ -548,11 +561,15 @@ function forwardPrivateChainsToOtherMembersOfOutputAddresses(arrChains, conn, on
  604.  
  605.  function readWalletsByAddresses(conn, arrAddresses, handleWallets) {
  606.    conn.query("SELECT DISTINCT wallet FROM my_addresses WHERE address IN(?)", [arrAddresses], function (rows) {
  607. -       var arrWallets = rows.map(function(row){ return row.wallet; });
  608. +    var arrWallets = rows.map(function (row) {
  609. +      return row.wallet;
  610. +    });
  611.      conn.query("SELECT DISTINCT address FROM shared_address_signing_paths WHERE shared_address IN(?)", [arrAddresses], function (rows) {
  612.        if (rows.length === 0)
  613.          return handleWallets(arrWallets);
  614. -           var arrNewAddresses = rows.map(function(row){ return row.address; });
  615. +      var arrNewAddresses = rows.map(function (row) {
  616. +        return row.address;
  617. +      });
  618.        readWalletsByAddresses(conn, arrNewAddresses, function (arrNewWallets) {
  619.          handleWallets(_.union(arrWallets, arrNewWallets));
  620.        });
  621. @@ -688,10 +705,14 @@ function findAddress(address, signing_path, callbacks, fallback_remote_device_ad
  622.  function readSharedBalance(wallet, handleBalance) {
  623.    balances.readSharedBalance(wallet, function (assocBalances) {
  624.      if (conf.bLight) { // make sure we have all asset definitions available
  625. -           var arrAssets = Object.keys(assocBalances).filter(function(asset){ return (asset !== 'base'); });
  626. +      var arrAssets = Object.keys(assocBalances).filter(function (asset) {
  627. +        return (asset !== 'base');
  628. +      });
  629.        if (arrAssets.length === 0)
  630.          return handleBalance(assocBalances);
  631. -           network.requestProofsOfJointsIfNewOrUnstable(arrAssets, function(){handleBalance(assocBalances)});
  632. +      network.requestProofsOfJointsIfNewOrUnstable(arrAssets, function () {
  633. +        handleBalance(assocBalances)
  634. +      });
  635.      } else {
  636.        handleBalance(assocBalances);
  637.      }
  638. @@ -701,10 +722,14 @@ function readSharedBalance(wallet, handleBalance){
  639.  function readBalance(wallet, handleBalance) {
  640.    balances.readBalance(wallet, function (assocBalances) {
  641.      if (conf.bLight) { // make sure we have all asset definitions available
  642. -           var arrAssets = Object.keys(assocBalances).filter(function(asset){ return (asset !== 'base'); });
  643. +      var arrAssets = Object.keys(assocBalances).filter(function (asset) {
  644. +        return (asset !== 'base');
  645. +      });
  646.        if (arrAssets.length === 0)
  647.          return handleBalance(assocBalances);
  648. -           network.requestProofsOfJointsIfNewOrUnstable(arrAssets, function(){handleBalance(assocBalances)});
  649. +      network.requestProofsOfJointsIfNewOrUnstable(arrAssets, function () {
  650. +        handleBalance(assocBalances)
  651. +      });
  652.      } else {
  653.        handleBalance(assocBalances);
  654.      }
  655. @@ -740,7 +765,8 @@ function readAssetMetadata(arrAssets, handleMetadata){
  656.      // after calling the callback, try to fetch missing data about assets
  657.      if (!arrAssets)
  658.        return;
  659. -       network.requestProofsOfJointsIfNewOrUnstable(arrAssets, function(){ // make sure we have assets itself
  660. +    var updateAssets = conf.bLight ? network.requestProofsOfJointsIfNewOrUnstable : function(arrAssets, onDone){ onDone(); };
  661. +    updateAssets(arrAssets, function(){ // make sure we have assets itself
  662.        arrAssets.forEach(function (asset) {
  663.          if (assocAssetMetadata[asset] || asset === 'base' && asset === constants.BLACKBYTES_ASSET)
  664.            return;
  665. @@ -861,7 +887,14 @@ function readTransactionHistory(opts, handleHistory){
  666.          //    row.fee = null;
  667.          if (!assocMovements[row.unit])
  668.            assocMovements[row.unit] = {
  669. -                       plus:0, has_minus:false, ts: row.ts, level: row.level, is_stable: row.is_stable, sequence: row.sequence, fee: row.fee, mci: row.mci
  670. +            plus: 0,
  671. +            has_minus: false,
  672. +            ts: row.ts,
  673. +            level: row.level,
  674. +            is_stable: row.is_stable,
  675. +            sequence: row.sequence,
  676. +            fee: row.fee,
  677. +            mci: row.mci
  678.            };
  679.          if (row.to_address) {
  680.            assocMovements[row.unit].plus += row.amount;
  681. @@ -897,7 +930,9 @@ function readTransactionHistory(opts, handleHistory){
  682.                "SELECT DISTINCT address FROM inputs WHERE unit=? AND " + asset_condition + " ORDER BY address",
  683.                [unit],
  684.                function (address_rows) {
  685. -                               var arrPayerAddresses = address_rows.map(function(address_row){ return address_row.address; });
  686. +                var arrPayerAddresses = address_rows.map(function (address_row) {
  687. +                  return address_row.address;
  688. +                });
  689.                  movement.arrMyRecipients.forEach(function (objRecipient) {
  690.                    var transaction = {
  691.                      action: 'received',
  692. @@ -933,12 +968,16 @@ function readTransactionHistory(opts, handleHistory){
  693.              parameters = [wallet, unit];
  694.              db.query(queryString, parameters,
  695.                function (payee_rows) {
  696. -                               var action = payee_rows.some(function(payee){ return payee.is_external; }) ? 'sent' : 'moved';
  697. +                var action = payee_rows.some(function (payee) {
  698. +                  return payee.is_external;
  699. +                }) ? 'sent' : 'moved';
  700.                  if (payee_rows.length == 0) {
  701.                    cb();
  702.                    return;
  703.                  }
  704. -                               var has_asset = payee_rows.some(function(payee){ return payee.asset; });
  705. +                var has_asset = payee_rows.some(function (payee) {
  706. +                  return payee.asset;
  707. +                });
  708.                  if (has_asset && !asset) { // filter out "fees" txs from history
  709.                    cb();
  710.                    return;
  711. @@ -1009,7 +1048,9 @@ function readTransactionHistory(opts, handleHistory){
  712.                return -1;
  713.              return 0;
  714.            });
  715. -                   arrTransactions.forEach(function(transaction){ transaction.asset = opts.asset; });
  716. +          arrTransactions.forEach(function (transaction) {
  717. +            transaction.asset = opts.asset;
  718. +          });
  719.            handleHistory(arrTransactions);
  720.          }
  721.        );
  722. @@ -1097,7 +1138,7 @@ function readFundedAddresses(asset, wallet, estimated_amount, handleFundedAddres
  723.                 SELECT * FROM unit_authors JOIN units USING(unit) \n\
  724.                 WHERE is_stable=0 AND unit_authors.address=outputs.address AND definition_chash IS NOT NULL \n\
  725.             ) \n\
  726. -       GROUP BY address ORDER BY "+order_by,
  727. +       GROUP BY address ORDER BY " + order_by + " LIMIT "+constants.MAX_AUTHORS_PER_UNIT,
  728.      asset ? [wallet, asset] : [wallet],
  729.      function (rows) {
  730.        determineIfFixedDenominations(asset, function (bFixedDenominations) {
  731. @@ -1147,7 +1188,9 @@ function readAdditionalSigningAddresses(arrPayingAddresses, arrSigningAddresses,
  732.      sql,
  733.      arrParams,
  734.      function (rows) {
  735. -           var arrAdditionalAddresses = rows.map(function(row){ return row.address; });
  736. +      var arrAdditionalAddresses = rows.map(function (row) {
  737. +        return row.address;
  738. +      });
  739.        if (arrAdditionalAddresses.length === 0)
  740.          return handleAdditionalSigningAddresses([]);
  741.        readAdditionalSigningAddresses([], arrSigningAddresses.concat(arrAdditionalAddresses), arrSigningDeviceAddresses, function (arrMoreAddresses) {
  742. @@ -1160,9 +1203,7 @@ function readAdditionalSigningAddresses(arrPayingAddresses, arrSigningAddresses,
  743.  var TYPICAL_FEE = 1000;
  744.  
  745.  // fee_paying_wallet is used only if there are no bytes on the asset wallet, it is a sort of fallback wallet for fees
  746. -function readFundedAndSigningAddresses(
  747. -       asset, wallet, estimated_amount, fee_paying_wallet, arrSigningAddresses, arrSigningDeviceAddresses, handleFundedAndSigningAddresses)
  748. -{
  749. +function readFundedAndSigningAddresses(asset, wallet, estimated_amount, fee_paying_wallet, arrSigningAddresses, arrSigningDeviceAddresses, handleFundedAndSigningAddresses) {
  750.    readFundedAddresses(asset, wallet, estimated_amount, function (arrFundedAddresses) {
  751.      if (arrFundedAddresses.length === 0)
  752.        return handleFundedAndSigningAddresses([], [], []);
  753. @@ -1189,9 +1230,7 @@ function readFundedAndSigningAddresses(
  754.    });
  755.  }
  756.  
  757. -function sendPaymentFromWallet(
  758. -       asset, wallet, to_address, amount, change_address, arrSigningDeviceAddresses, recipient_device_address, signWithLocalPrivateKey, handleResult)
  759. -{
  760. +function sendPaymentFromWallet(asset, wallet, to_address, amount, change_address, arrSigningDeviceAddresses, recipient_device_address, signWithLocalPrivateKey, handleResult) {
  761.    sendMultiPayment({
  762.      asset: asset,
  763.      wallet: wallet,
  764. @@ -1204,8 +1243,7 @@ function sendPaymentFromWallet(
  765.    }, handleResult);
  766.  }
  767.  
  768. -function sendMultiPayment(opts, handleResult)
  769. -{
  770. +function sendMultiPayment(opts, handleResult) {
  771.    var asset = opts.asset;
  772.    if (asset === 'base')
  773.      asset = null;
  774. @@ -1246,7 +1284,9 @@ function sendMultiPayment(opts, handleResult)
  775.  
  776.    var estimated_amount = amount;
  777.    if (!estimated_amount && asset_outputs)
  778. -       estimated_amount = asset_outputs.reduce(function(acc, output){ return acc+output.amount; }, 0);
  779. +    estimated_amount = asset_outputs.reduce(function (acc, output) {
  780. +      return acc + output.amount;
  781. +    }, 0);
  782.    if (estimated_amount && !asset)
  783.      estimated_amount += TYPICAL_FEE;
  784.  
  785. @@ -1332,6 +1372,7 @@ function sendMultiPayment(opts, handleResult)
  786.        var assocPaymentsByEmail = {}; // wallet mnemonics to send by emails
  787.        var assocAddresses = {};
  788.        var prefix = "textcoin:";
  789. +
  790.        function generateNewMnemonicIfNoAddress(output_asset, outputs) {
  791.          var generated = 0;
  792.          outputs.forEach(function (output) {
  793. @@ -1357,6 +1398,7 @@ function sendMultiPayment(opts, handleResult)
  794.          });
  795.          return generated;
  796.        }
  797. +
  798.        if (to_address) {
  799.          var to_address_output = {address: to_address, amount: amount};
  800.          var cnt = generateNewMnemonicIfNoAddress(asset, [to_address_output]);
  801. @@ -1422,7 +1464,9 @@ function sendMultiPayment(opts, handleResult)
  802.            var _addAssetFees = function () {
  803.              var asset_fees = objAsset && objAsset.fixed_denominations ? indivisibleAssetFeesByAddress[new_address] : constants.TEXTCOIN_ASSET_CLAIM_FEE;
  804.              if (!params.base_outputs) params.base_outputs = [];
  805. -                       var base_output = _.find(params.base_outputs, function(output) {return output.address == new_address});
  806. +            var base_output = _.find(params.base_outputs, function (output) {
  807. +              return output.address == new_address
  808. +            });
  809.              if (base_output)
  810.                base_output.amount += asset_fees;
  811.              else
  812. @@ -1430,19 +1474,25 @@ function sendMultiPayment(opts, handleResult)
  813.            }
  814.  
  815.            // first calculate fees for textcoins in (bytes) outputs
  816. -                   var output = _.find(params.outputs, function(output) {return output.address == new_address});
  817. +          var output = _.find(params.outputs, function (output) {
  818. +            return output.address == new_address
  819. +          });
  820.            if (output) {
  821.              output.amount += constants.TEXTCOIN_CLAIM_FEE;
  822.            }
  823.  
  824.            // second calculate fees for textcoins in base_outputs
  825. -                   output = _.find(params.base_outputs, function(output) {return output.address == new_address});
  826. +          output = _.find(params.base_outputs, function (output) {
  827. +            return output.address == new_address
  828. +          });
  829.            if (output) {
  830.              output.amount += constants.TEXTCOIN_CLAIM_FEE;
  831.            }
  832.  
  833.            // then check for textcoins in asset_outputs
  834. -                   output = _.find(params.asset_outputs, function(output) {return output.address == new_address});
  835. +          output = _.find(params.asset_outputs, function (output) {
  836. +            return output.address == new_address
  837. +          });
  838.            if (output) {
  839.              _addAssetFees();
  840.            }
  841. @@ -1594,7 +1644,12 @@ function sendTextcoinEmail(email, subject, amount, asset, mnemonic){
  842.      amount = (amount / 1e9).toLocaleString([], {maximumFractionDigits: 9});
  843.      asset = 'GB';
  844.    }
  845. -   replaceInTextcoinTemplate({amount: amount, asset: asset, mnemonic: mnemonic, usd_amount_str: usd_amount_str}, function(html, text){
  846. +  replaceInTextcoinTemplate({
  847. +    amount: amount,
  848. +    asset: asset,
  849. +    mnemonic: mnemonic,
  850. +    usd_amount_str: usd_amount_str
  851. +  }, function (html, text) {
  852.      mail.sendmail({
  853.        to: email,
  854.        from: conf.from_email || "noreply@byteball.org",
  855. @@ -1759,7 +1814,8 @@ function eraseTextcoin(unit, address) {
  856.      "UPDATE sent_mnemonics \n\
  857.      SET mnemonic='' WHERE unit=? AND address=?",
  858.      [unit, address],
  859. -       function(){}
  860. +    function () {
  861. +    }
  862.    );
  863.  }
  864.  
  865. @@ -1773,7 +1829,9 @@ function readDeviceAddressesUsedInSigningPaths(onDone){
  866.      sql,
  867.      function (rows) {
  868.  
  869. -           var arrDeviceAddress = rows.map(function(r) { return r.device_address; });
  870. +      var arrDeviceAddress = rows.map(function (r) {
  871. +        return r.device_address;
  872. +      });
  873.  
  874.        onDone(arrDeviceAddress);
  875.      }
  876. @@ -1804,7 +1862,6 @@ walletGeneral.readMyAddresses(function(arrAddresses){
  877.   */
  878.  
  879.  
  880. -
  881.  exports.sendSignature = sendSignature;
  882.  exports.readSharedBalance = readSharedBalance;
  883.  exports.readBalance = readBalance;
  884. diff --git a/wallet_defined_by_keys.js b/wallet_defined_by_keys.js
  885. index c522427..370d288 100644
  886. --- a/wallet_defined_by_keys.js
  887. +++ b/wallet_defined_by_keys.js
  888. @@ -40,7 +40,13 @@ function loadBitcoreFromNearestParent(mod){
  889.  }
  890.  
  891.  function sendOfferToCreateNewWallet(device_address, wallet, arrWalletDefinitionTemplate, walletName, arrOtherCosigners, isSingleAddress, callbacks) {
  892. -   var body = {wallet: wallet, wallet_definition_template: arrWalletDefinitionTemplate, wallet_name: walletName, other_cosigners: arrOtherCosigners, is_single_address: isSingleAddress};
  893. +  var body = {
  894. +    wallet: wallet,
  895. +    wallet_definition_template: arrWalletDefinitionTemplate,
  896. +    wallet_name: walletName,
  897. +    other_cosigners: arrOtherCosigners,
  898. +    is_single_address: isSingleAddress
  899. +  };
  900.    device.sendMessageToDevice(device_address, "create_new_wallet", body, callbacks);
  901.  }
  902.  
  903. @@ -63,7 +69,6 @@ function sendNewWalletAddress(device_address, wallet, is_change, address_index,
  904.  }
  905.  
  906.  
  907. -
  908.  // {wallet: "base64", wallet_definition_template: [...]}
  909.  function handleOfferToCreateNewWallet(body, from_address, callbacks) {
  910.    if (!ValidationUtils.isNonemptyString(body.wallet))
  911. @@ -85,7 +90,9 @@ function handleOfferToCreateNewWallet(body, from_address, callbacks){
  912.        return callbacks.ifError(err);
  913.      if (body.other_cosigners.length !== arrDeviceAddresses.length - 1)
  914.        return callbacks.ifError("wrong length of other_cosigners");
  915. -       var arrOtherDeviceAddresses = _.uniq(body.other_cosigners.map(function(cosigner){ return cosigner.device_address; }));
  916. +    var arrOtherDeviceAddresses = _.uniq(body.other_cosigners.map(function (cosigner) {
  917. +      return cosigner.device_address;
  918. +    }));
  919.      arrOtherDeviceAddresses.push(from_address);
  920.      if (!_.isEqual(arrDeviceAddresses.sort(), arrOtherDeviceAddresses.sort()))
  921.        return callbacks.ifError("wrong other_cosigners");
  922. @@ -110,7 +117,6 @@ function handleOfferToCreateNewWallet(body, from_address, callbacks){
  923.  }
  924.  
  925.  
  926. -
  927.  function readNextAccount(handleAccount) {
  928.    db.query("SELECT MAX(account) AS max_account FROM wallets", function (rows) {
  929.      var account = (rows.length === 0) ? 0 : (rows[0].max_account + 1);
  930. @@ -126,7 +132,9 @@ function checkAndFinalizeWallet(wallet, onDone){
  931.        console.log("no wallet in checkAndFinalizeWallet");
  932.        return onDone ? onDone() : null;
  933.      }
  934. -       if (rows.some(function(row){ return !row.member_ready_date; }))
  935. +    if (rows.some(function (row) {
  936. +        return !row.member_ready_date;
  937. +      }))
  938.        return onDone ? onDone() : null;
  939.      db.query("UPDATE wallets SET ready_date=" + db.getNow() + " WHERE wallet=? AND ready_date IS NULL", [wallet], function () {
  940.        if (onDone)
  941. @@ -140,7 +148,9 @@ function checkAndFullyApproveWallet(wallet, onDone){
  942.    db.query("SELECT approval_date FROM wallets LEFT JOIN extended_pubkeys USING(wallet) WHERE wallets.wallet=?", [wallet], function (rows) {
  943.      if (rows.length === 0) // wallet not created yet
  944.        return onDone ? onDone() : null;
  945. -       if (rows.some(function(row){ return !row.approval_date; }))
  946. +    if (rows.some(function (row) {
  947. +        return !row.approval_date;
  948. +      }))
  949.        return onDone ? onDone() : null;
  950.      db.query("UPDATE wallets SET full_approval_date=" + db.getNow() + " WHERE wallet=? AND full_approval_date IS NULL", [wallet], function () {
  951.        db.query(
  952. @@ -259,7 +269,9 @@ function createWallet(xPubKey, account, arrWalletDefinitionTemplate, walletName,
  953.  function createMultisigWallet(xPubKey, account, count_required_signatures, arrDeviceAddresses, walletName, isSingleAddress, handleWallet) {
  954.    if (count_required_signatures > arrDeviceAddresses.length)
  955.      throw Error("required > length");
  956. -   var set = arrDeviceAddresses.map(function(device_address){ return ["sig", {pubkey: '$pubkey@'+device_address}]; });
  957. +  var set = arrDeviceAddresses.map(function (device_address) {
  958. +    return ["sig", {pubkey: '$pubkey@' + device_address}];
  959. +  });
  960.    var arrDefinitionTemplate = ["r of set", {required: count_required_signatures, set: set}];
  961.    createWallet(xPubKey, account, arrDefinitionTemplate, walletName, isSingleAddress, handleWallet);
  962.  }
  963. @@ -309,7 +321,9 @@ function cancelWallet(wallet, arrDeviceAddresses, arrOtherCosigners){
  964.     if (device_address !== device.getMyDeviceAddress())
  965.     sendCommandToCancelNewWallet(device_address, wallet);
  966.     });*/
  967. -   var arrOtherDeviceAddresses = _.uniq(arrOtherCosigners.map(function(cosigner){ return cosigner.device_address; }));
  968. +  var arrOtherDeviceAddresses = _.uniq(arrOtherCosigners.map(function (cosigner) {
  969. +    return cosigner.device_address;
  970. +  }));
  971.    var arrInitiatorDeviceAddresses = _.difference(arrDeviceAddresses, arrOtherDeviceAddresses);
  972.    if (arrInitiatorDeviceAddresses.length !== 1)
  973.      throw Error("not one initiator?");
  974. @@ -322,7 +336,8 @@ function cancelWallet(wallet, arrDeviceAddresses, arrOtherCosigners){
  975.      device.sendMessageToHub(cosigner.hub, cosigner.pubkey, "cancel_new_wallet", {wallet: wallet});
  976.    });
  977.    db.query("DELETE FROM extended_pubkeys WHERE wallet=?", [wallet], function () {
  978. -       db.query("DELETE FROM wallet_signing_paths WHERE wallet=?", [wallet], function(){});
  979. +    db.query("DELETE FROM wallet_signing_paths WHERE wallet=?", [wallet], function () {
  980. +    });
  981.    });
  982.  }
  983.  
  984. @@ -335,7 +350,9 @@ function deleteWallet(wallet, rejector_device_address, onDone){
  985.      if (rows[0].approval_date) // you've already approved this wallet, you can't change your mind
  986.        return onDone();
  987.      db.query("SELECT device_address FROM extended_pubkeys WHERE wallet=?", [wallet], function (rows) {
  988. -           var arrMemberAddresses = rows.map(function(row){ return row.device_address; });
  989. +      var arrMemberAddresses = rows.map(function (row) {
  990. +        return row.device_address;
  991. +      });
  992.        var arrQueries = [];
  993.        db.addQuery(arrQueries, "DELETE FROM extended_pubkeys WHERE wallet=?", [wallet]);
  994.        db.addQuery(arrQueries, "DELETE FROM wallet_signing_paths WHERE wallet=?", [wallet]);
  995. @@ -475,6 +492,7 @@ function getDeviceAddressesBySigningPaths(arrWalletDefinitionTemplate){
  996.        // all other ops cannot reference device address
  997.      }
  998.    }
  999. +
  1000.    var assocDeviceAddressesBySigningPaths = {};
  1001.    evaluate(arrWalletDefinitionTemplate, 'r');
  1002.    return assocDeviceAddressesBySigningPaths;
  1003. @@ -508,8 +526,6 @@ function validateWalletDefinitionTemplate(arrWalletDefinitionTemplate, from_addr
  1004.  }
  1005.  
  1006.  
  1007. -
  1008. -
  1009.  function readNextAddressIndex(wallet, is_change, handleNextAddressIndex) {
  1010.    db.query("SELECT MAX(address_index) AS last_used_index FROM my_addresses WHERE wallet=? AND is_change=?", [wallet, is_change], function (rows) {
  1011.      var last_used_index = rows[0].last_used_index;
  1012. @@ -597,7 +613,12 @@ function issueAddress(wallet, is_change, address_index, handleNewAddress){
  1013.          if (row.device_address !== device.getMyDeviceAddress())
  1014.            sendNewWalletAddress(row.device_address, wallet, is_change, address_index, address);
  1015.        });
  1016. -           handleNewAddress({address: address, is_change: is_change, address_index: address_index, creation_ts: parseInt(Date.now()/1000)});
  1017. +      handleNewAddress({
  1018. +        address: address,
  1019. +        is_change: is_change,
  1020. +        address_index: address_index,
  1021. +        creation_ts: parseInt(Date.now() / 1000)
  1022. +      });
  1023.      });
  1024.    });
  1025.    setTimeout(function () {
  1026. @@ -750,17 +771,14 @@ function readAllAddresses(wallet, handleAddresses){
  1027.      "SELECT address FROM my_addresses WHERE wallet=?",
  1028.      [wallet],
  1029.      function (rows) {
  1030. -           handleAddresses(rows.map(function(row){ return row.address; }));
  1031. +      handleAddresses(rows.map(function (row) {
  1032. +        return row.address;
  1033. +      }));
  1034.      }
  1035.    );
  1036.  }
  1037.  
  1038.  
  1039. -
  1040. -
  1041. -
  1042. -
  1043. -
  1044.  function forwardPrivateChainsToOtherMembersOfWallets(arrChains, arrWallets, conn, onSaved) {
  1045.    console.log("forwardPrivateChainsToOtherMembersOfWallets", arrWallets);
  1046.    conn = conn || db;
  1047. @@ -768,7 +786,9 @@ function forwardPrivateChainsToOtherMembersOfWallets(arrChains, arrWallets, conn
  1048.      "SELECT device_address FROM extended_pubkeys WHERE wallet IN(?) AND device_address!=?",
  1049.      [arrWallets, device.getMyDeviceAddress()],
  1050.      function (rows) {
  1051. -           var arrDeviceAddresses = rows.map(function(row){ return row.device_address; });
  1052. +      var arrDeviceAddresses = rows.map(function (row) {
  1053. +        return row.device_address;
  1054. +      });
  1055.        walletGeneral.forwardPrivateChainsToDevices(arrDeviceAddresses, arrChains, true, conn, onSaved);
  1056.      }
  1057.    );
  1058. @@ -782,7 +802,9 @@ function readDeviceAddressesControllingPaymentAddresses(conn, arrAddresses, hand
  1059.      "SELECT DISTINCT device_address FROM my_addresses JOIN extended_pubkeys USING(wallet) WHERE address IN(?) AND device_address!=?",
  1060.      [arrAddresses, device.getMyDeviceAddress()],
  1061.      function (rows) {
  1062. -           var arrDeviceAddresses = rows.map(function(row){ return row.device_address; });
  1063. +      var arrDeviceAddresses = rows.map(function (row) {
  1064. +        return row.device_address;
  1065. +      });
  1066.        handleDeviceAddresses(arrDeviceAddresses);
  1067.      }
  1068.    );
  1069. @@ -797,7 +819,6 @@ function forwardPrivateChainsToOtherMembersOfAddresses(arrChains, arrAddresses,
  1070.  }
  1071.  
  1072.  
  1073. -
  1074.  exports.readNextAccount = readNextAccount;
  1075.  exports.createWalletByDevices = createWalletByDevices;
  1076.  exports.createSinglesigWalletWithExternalPrivateKey = createSinglesigWalletWithExternalPrivateKey;
  1077. diff --git a/writer.js b/writer.js
  1078. index bed1415..3605144 100644
  1079. --- a/writer.js
  1080. +++ b/writer.js
  1081. @@ -292,7 +292,9 @@ function saveJoint(objJoint, objValidationState, preCommitCallback, onDone) {
  1082.  
  1083.                determineInputAddress(function (address) {
  1084.                  var is_unique =
  1085. -                                   objValidationState.arrDoubleSpendInputs.some(function(ds){ return (ds.message_index === i && ds.input_index === j); })
  1086. +                  objValidationState.arrDoubleSpendInputs.some(function (ds) {
  1087. +                    return (ds.message_index === i && ds.input_index === j);
  1088. +                  })
  1089.                      ? null : 1;
  1090.                  conn.addQuery(arrQueries, "INSERT INTO inputs \n\
  1091.                                         (unit, message_index, input_index, type, \n\
  1092. @@ -366,7 +368,9 @@ function saveJoint(objJoint, objValidationState, preCommitCallback, onDone) {
  1093.            my_best_parent_unit = rows[0].unit;
  1094.            if (my_best_parent_unit !== objValidationState.best_parent_unit)
  1095.              throwError("different best parents, validation: " + objValidationState.best_parent_unit + ", writer: " + my_best_parent_unit);
  1096. -                   conn.query("UPDATE units SET best_parent_unit=? WHERE unit=?", [my_best_parent_unit, objUnit.unit], function(){ cb(); });
  1097. +          conn.query("UPDATE units SET best_parent_unit=? WHERE unit=?", [my_best_parent_unit, objUnit.unit], function () {
  1098. +            cb();
  1099. +          });
  1100.          }
  1101.        );
  1102.      }
Add Comment
Please, Sign In to add comment