walletdb: acount index->name index.

This commit is contained in:
Christopher Jeffrey 2016-11-02 16:35:56 -07:00
parent f699b4f12f
commit 185586abb0
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 18 additions and 0 deletions

View File

@ -50,6 +50,9 @@ layout.walletdb = {
ii: function ii(key) { ii: function ii(key) {
return [+key.slice(1, 11), key.slice(11)]; return [+key.slice(1, 11), key.slice(11)];
}, },
n: function n(wid, index) {
return 'n' + pad32(wid) + pad32(index);
},
R: 'R', R: 'R',
h: function c(height) { h: function c(height) {
return 'h' + pad32(height); return 'h' + pad32(height);

View File

@ -38,10 +38,12 @@ var DUMMY = new Buffer([0]);
* Database Layout: * Database Layout:
* p[addr-hash] -> wallet ids * p[addr-hash] -> wallet ids
* P[wid][addr-hash] -> path data * P[wid][addr-hash] -> path data
* r[wid][index][hash] -> path account index
* w[wid] -> wallet * w[wid] -> wallet
* l[id] -> wid * l[id] -> wid
* a[wid][index] -> account * a[wid][index] -> account
* i[wid][name] -> account index * i[wid][name] -> account index
* n[wid][index] -> account name
* t[wid]* -> txdb * t[wid]* -> txdb
* R -> chain sync state * R -> chain sync state
* h[height] -> recent block hash * h[height] -> recent block hash
@ -119,6 +121,13 @@ var layout = {
ii: function ii(key) { ii: function ii(key) {
return [key.readUInt32BE(1, true), key.toString('ascii', 5)]; return [key.readUInt32BE(1, true), key.toString('ascii', 5)];
}, },
n: function n(wid, index) {
var key = new Buffer(9);
key[0] = 0x6e;
key.writeUInt32BE(wid, 1, true);
key.writeUInt32BE(index, 5, true);
return key;
},
R: new Buffer([0x52]), R: new Buffer([0x52]),
h: function h(height) { h: function h(height) {
var key = new Buffer(5); var key = new Buffer(5);
@ -1088,9 +1097,15 @@ WalletDB.prototype.saveAccount = function saveAccount(account) {
var name = account.name; var name = account.name;
var batch = this.batch(wallet); var batch = this.batch(wallet);
// Account data
batch.put(layout.a(wid, index), account.toRaw()); batch.put(layout.a(wid, index), account.toRaw());
// Name->Index lookups
batch.put(layout.i(wid, name), U32(index)); batch.put(layout.i(wid, name), U32(index));
// Index->Name lookups
batch.put(layout.n(wid, index), new Buffer(name, 'ascii'));
wallet.accountCache.push(index, account); wallet.accountCache.push(index, account);
}; };