From 80103454c0afe8ebb1d0572dfc54ee90ab001382 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Mon, 15 Aug 2016 11:21:26 -0700 Subject: [PATCH] walletdb: refactor. --- lib/bcoin/txdb.js | 27 +++++++++++++-------------- lib/bcoin/walletdb.js | 32 +++++++++++++++----------------- 2 files changed, 28 insertions(+), 31 deletions(-) diff --git a/lib/bcoin/txdb.js b/lib/bcoin/txdb.js index c3f86eb8..15b836fd 100644 --- a/lib/bcoin/txdb.js +++ b/lib/bcoin/txdb.js @@ -12,25 +12,24 @@ var utils = require('./utils'); var assert = bcoin.utils.assert; var constants = bcoin.protocol.constants; var DUMMY = new Buffer([0]); -var pad32 = utils.pad32; var BufferReader = require('./reader'); var BufferWriter = require('./writer'); /* * Database Layout: - * t/[hash] -> extended tx - * c/[hash]/[index] -> coin - * d/[hash]/[index] -> undo coin - * s/[hash]/[index] -> spent by hash - * o/[hash]/[index] -> orphan inputs - * p/[hash] -> dummy (pending flag) - * m/[time]/[hash] -> dummy (tx by time) - * h/[height]/[hash] -> dummy (tx by height) - * T/[account]/[hash] -> dummy (tx by account) - * P/[account]/[hash] -> dummy (pending tx by account) - * M/[account]/[time]/[hash] -> dummy (tx by time + account) - * H/[account]/[height]/[hash] -> dummy (tx by height + account) - * C/[account]/[hash]/[index] -> dummy (coin by account) + * t[hash] -> extended tx + * c[hash][index] -> coin + * d[hash][index] -> undo coin + * s[hash][index] -> spent by hash + * o[hash][index] -> orphan inputs + * p[hash] -> dummy (pending flag) + * m[time][hash] -> dummy (tx by time) + * h[height][hash] -> dummy (tx by height) + * T[account][hash] -> dummy (tx by account) + * P[account][hash] -> dummy (pending tx by account) + * M[account][time][hash] -> dummy (tx by time + account) + * H[account][height][hash] -> dummy (tx by height + account) + * C[account][hash][index] -> dummy (coin by account) */ function Layout(wallet) { diff --git a/lib/bcoin/walletdb.js b/lib/bcoin/walletdb.js index 387ebe5a..968f5daa 100644 --- a/lib/bcoin/walletdb.js +++ b/lib/bcoin/walletdb.js @@ -7,23 +7,9 @@ 'use strict'; -/* - * Database Layout: - * p/[address] -> path data - * w/[wid] -> wallet - * l/[id] -> wid - * a/[wid]/[index] -> account - * i/[wid]/[name] -> account index - * t/[wid]/* -> txdb - * R -> tip - * b/[hash] -> wallet block - * e/[hash] -> tx->wid map - */ - var bcoin = require('./env'); var AsyncObject = require('./async'); var utils = require('./utils'); -var pad32 = utils.pad32; var assert = utils.assert; var constants = bcoin.protocol.constants; var BufferReader = require('./reader'); @@ -31,6 +17,19 @@ var BufferWriter = require('./writer'); var TXDB = require('./txdb'); var keyTypes = bcoin.keyring.types; +/* + * Database Layout: + * p[addr-hash] -> path data + * w[wid] -> wallet + * l[id] -> wid + * a[wid][index] -> account + * i[wid][name] -> account index + * t[wid]* -> txdb + * R -> tip + * b[hash] -> wallet block + * e[hash] -> tx->wid map + */ + /* String Keys var layout = { p: function(hash) { @@ -113,9 +112,9 @@ var layout = { return key; }, ii: function ii(key) { - return [+key.readUInt32BE(1, true), key.toString('ascii', 5)]; + return [key.readUInt32BE(1, true), key.toString('ascii', 5)]; }, - R: 'R', + R: new Buffer([0x52]), b: function b(hash) { var key = new Buffer(33); key[0] = 0x62; @@ -130,7 +129,6 @@ var layout = { } }; - /** * WalletDB * @exports WalletDB