Skip to content

Commit

Permalink
Merge e74ac10 into e07ba54
Browse files Browse the repository at this point in the history
  • Loading branch information
pinheadmz committed Dec 5, 2022
2 parents e07ba54 + e74ac10 commit 5891fd9
Show file tree
Hide file tree
Showing 9 changed files with 2,073 additions and 301 deletions.
3 changes: 2 additions & 1 deletion lib/primitives/covenant.js
Expand Up @@ -618,7 +618,8 @@ class Covenant extends bio.Struct {
*/

format() {
return `<Covenant: ${this.type}:${this.toString()}>`;
const type = typesByVal[this.type] || this.type;
return `<Covenant: ${type}:${this.toString()}>`;
}

/**
Expand Down
34 changes: 18 additions & 16 deletions lib/wallet/account.js
Expand Up @@ -309,26 +309,28 @@ class Account extends bio.Struct {

/**
* Create a new receiving address (increments receiveDepth).
* @returns {WalletKey}
* @param {Batch} b
* @returns {Promise<WalletKey>}
*/

createReceive() {
return this.createKey(0);
createReceive(b) {
return this.createKey(b, 0);
}

/**
* Create a new change address (increments changeDepth).
* @returns {WalletKey}
* @param {Batch} b
* @returns {Promise<WalletKey>}
*/

createChange() {
return this.createKey(1);
createChange(b) {
return this.createKey(b, 1);
}

/**
* Create a new address (increments depth).
* @param {Boolean} change
* @returns {Promise} - Returns {@link WalletKey}.
* @returns {Promise<WalletKey>}
*/

async createKey(b, branch) {
Expand Down Expand Up @@ -516,37 +518,37 @@ class Account extends bio.Struct {
* @returns {Promise} - Returns {@link WalletKey}.
*/

async syncDepth(b, receive, change) {
async syncDepth(b, receiveDepth, changeDepth) {
let derived = false;
let result = null;

if (receive > this.receiveDepth) {
if (receiveDepth > this.receiveDepth) {
const depth = this.receiveDepth + this.lookahead;

assert(receive <= depth + 1);
assert(receiveDepth <= depth + 1);

for (let i = depth; i < receive + this.lookahead; i++) {
for (let i = depth; i < receiveDepth + this.lookahead; i++) {
const key = this.deriveReceive(i);
await this.saveKey(b, key);
result = key;
}

this.receiveDepth = receive;
this.receiveDepth = receiveDepth;

derived = true;
}

if (change > this.changeDepth) {
if (changeDepth > this.changeDepth) {
const depth = this.changeDepth + this.lookahead;

assert(change <= depth + 1);
assert(changeDepth <= depth + 1);

for (let i = depth; i < change + this.lookahead; i++) {
for (let i = depth; i < changeDepth + this.lookahead; i++) {
const key = this.deriveChange(i);
await this.saveKey(b, key);
}

this.changeDepth = change;
this.changeDepth = changeDepth;

derived = true;
}
Expand Down
12 changes: 6 additions & 6 deletions lib/wallet/layout.js
Expand Up @@ -72,6 +72,12 @@ exports.wdb = {
* H[account][height][hash] -> dummy (tx by height + account)
* C[account][hash][index] -> dummy (coin by account)
* b[height] -> block record
* A[nameHash] -> Name State
* U[hash] -> Name Undo
* i[nameHash][hash][index] -> BlindBid record
* B[nameHash][hash][index] -> BidReveal record
* v[blindHash] -> BlindValue record
* o[nameHash] -> TX Hash (Opens)
*/

exports.txdb = {
Expand All @@ -91,16 +97,10 @@ exports.txdb = {
H: bdb.key('H', ['uint32', 'uint32', 'hash256']),
C: bdb.key('C', ['uint32', 'hash256', 'uint32']),
b: bdb.key('b', ['uint32']),
// Name records
A: bdb.key('A', ['hash256']),
// Name undo records
U: bdb.key('U', ['hash256']),
// Bids
i: bdb.key('i', ['hash256', 'hash256', 'uint32']),
// Reveals
B: bdb.key('B', ['hash256', 'hash256', 'uint32']),
// Blinds
v: bdb.key('v', ['hash256']),
// Opens
o: bdb.key('o', ['hash256'])
};

0 comments on commit 5891fd9

Please sign in to comment.