Skip to content

Commit

Permalink
Merge PR #657 from 'nodech/wallet-record-blockmeta'
Browse files Browse the repository at this point in the history
  • Loading branch information
nodech committed Nov 30, 2021
2 parents c62293f + 5f11532 commit eea15c2
Show file tree
Hide file tree
Showing 3 changed files with 440 additions and 20 deletions.
29 changes: 14 additions & 15 deletions lib/wallet/records.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,6 @@ class BlockMeta extends bio.Struct {
return this;
}

/**
* Instantiate block meta from json object.
* @private
* @param {Object} json
*/

fromJSON(json) {
this.hash = json.hash;
this.height = json.height;
this.time = json.time;
return this;
}

/**
* Instantiate block meta from serialized tip data.
* @private
Expand Down Expand Up @@ -181,7 +168,7 @@ class BlockMeta extends bio.Struct {
*/

getSize() {
return 42;
return 40;
}

/**
Expand All @@ -196,14 +183,26 @@ class BlockMeta extends bio.Struct {
return bw;
}

/**
* Instantiate block meta from json object.
* @param {Object} json
*/

fromJSON(json) {
this.hash = util.parseHex(json.hash, 32);
this.height = json.height;
this.time = json.time;
return this;
}

/**
* Convert the block meta to a more json-friendly object.
* @returns {Object}
*/

getJSON() {
return {
hash: this.hash,
hash: this.hash.toString('hex'),
height: this.height,
time: this.time
};
Expand Down
6 changes: 1 addition & 5 deletions lib/wallet/walletdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -2115,11 +2115,7 @@ class WalletDB extends EventEmitter {
if (!hash)
return null;

const block = new BlockMeta();
block.hash = hash;
block.height = height;

return block;
return new BlockMeta(hash, height);
}

/**
Expand Down
Loading

0 comments on commit eea15c2

Please sign in to comment.