walletdb: refactor.

This commit is contained in:
Christopher Jeffrey 2016-08-15 11:21:26 -07:00
parent fbce69dbad
commit 80103454c0
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 28 additions and 31 deletions

View File

@ -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) {

View File

@ -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