Skip to content

Commit

Permalink
types: update mempool entries and simple mining.
Browse files Browse the repository at this point in the history
  • Loading branch information
nodech committed Oct 1, 2024
1 parent e13f180 commit 0ce3197
Show file tree
Hide file tree
Showing 11 changed files with 386 additions and 54 deletions.
3 changes: 1 addition & 2 deletions lib/blockstore/abstract.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,9 @@ class AbstractBatch {
}
}

AbstractBlockStore.AbstractBatch = AbstractBatch;

/*
* Expose
*/

AbstractBlockStore.AbstractBatch = AbstractBatch;
module.exports = AbstractBlockStore;
17 changes: 17 additions & 0 deletions lib/covenants/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,20 @@ const {BufferMap} = require('buffer-map');
const NameState = require('./namestate');
const NameUndo = require('./undo');

/** @typedef {import('../types').Hash} Hash */

class View {
constructor() {
/** @type {BufferMap<NameState>} */
this.names = new BufferMap();
}

/**
* @param {Object} db
* @param {Hash} nameHash
* @returns {NameState}
*/

getNameStateSync(db, nameHash) {
assert(db && typeof db.getNameState === 'function');
assert(Buffer.isBuffer(nameHash));
Expand All @@ -19,6 +28,7 @@ class View {
if (cache)
return cache;

/** @type {NameState?} */
const ns = db.getNameState(nameHash);

if (!ns) {
Expand All @@ -33,6 +43,12 @@ class View {
return ns;
}

/**
* @param {Object} db
* @param {Hash} nameHash
* @returns {Promise<NameState>}
*/

async getNameState(db, nameHash) {
assert(db && typeof db.getNameState === 'function');
assert(Buffer.isBuffer(nameHash));
Expand All @@ -42,6 +58,7 @@ class View {
if (cache)
return cache;

/** @type {NameState?} */
const ns = await db.getNameState(nameHash);

if (!ns) {
Expand Down
2 changes: 1 addition & 1 deletion lib/hd/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ common.MAX_ENTROPY = 512;

/**
* LRU cache to avoid deriving keys twice.
* @type {LRU<HDPublicKey|HDPrivateKey>}
* @type {LRU<String, HDPublicKey|HDPrivateKey>}
*/

common.cache = new LRU(500);
Expand Down
17 changes: 10 additions & 7 deletions lib/mempool/airdropentry.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ const policy = require('../protocol/policy');
const util = require('../utils/util');
const Address = require('../primitives/address');

/** @typedef {import('../types').Amount} AmountValue */
/** @typedef {import('../types').Rate} Rate */
/** @typedef {import('../types').BufioWriter} BufioWriter */
/** @typedef {import('../primitives/airdropproof')} AirdropProof */

/*
* Constants
*/
Expand Down Expand Up @@ -73,7 +78,6 @@ class AirdropEntry extends bio.Struct {

/**
* Inject properties from airdrop.
* @private
* @param {AirdropProof} proof
* @param {Number} height
*/
Expand All @@ -99,7 +103,6 @@ class AirdropEntry extends bio.Struct {
/**
* Create a mempool entry from an airdrop proof.
* @param {AirdropProof} proof
* @param {Object} data
* @param {Number} height - Entry height.
* @returns {AirdropEntry}
*/
Expand All @@ -110,7 +113,7 @@ class AirdropEntry extends bio.Struct {

/**
* Get fee.
* @returns {Amount}
* @returns {AmountValue}
*/

getFee() {
Expand Down Expand Up @@ -160,7 +163,8 @@ class AirdropEntry extends bio.Struct {

/**
* Serialize entry to a buffer.
* @returns {Buffer}
* @param {BufioWriter} bw
* @returns {BufioWriter}
*/

write(bw) {
Expand All @@ -180,9 +184,8 @@ class AirdropEntry extends bio.Struct {

/**
* Inject properties from serialized data.
* @private
* @param {Buffer} data
* @returns {AirdropEntry}
* @param {bio.BufferReader} br
* @returns {this}
*/

read(br) {
Expand Down
17 changes: 10 additions & 7 deletions lib/mempool/claimentry.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ const util = require('../utils/util');
const Address = require('../primitives/address');
const rules = require('../covenants/rules');

/** @typedef {import('../primitives/claim')} Claim */
/** @typedef {import('../types').Amount} AmountValue */
/** @typedef {import('../types').Rate} Rate */
/** @typedef {import('../types').BufioWriter} BufioWriter */

/*
* Constants
*/
Expand Down Expand Up @@ -58,7 +63,6 @@ class ClaimEntry extends bio.Struct {

/**
* Inject properties from options object.
* @private
* @param {Object} options
*/

Expand All @@ -84,7 +88,6 @@ class ClaimEntry extends bio.Struct {

/**
* Inject properties from claim.
* @private
* @param {Claim} claim
* @param {Object} data
* @param {Number} height
Expand Down Expand Up @@ -128,7 +131,7 @@ class ClaimEntry extends bio.Struct {

/**
* Get fee.
* @returns {Amount}
* @returns {AmountValue}
*/

getFee() {
Expand Down Expand Up @@ -178,7 +181,8 @@ class ClaimEntry extends bio.Struct {

/**
* Serialize entry to a buffer.
* @returns {Buffer}
* @param {BufioWriter} bw
* @returns {BufioWriter}
*/

write(bw) {
Expand All @@ -204,9 +208,8 @@ class ClaimEntry extends bio.Struct {

/**
* Inject properties from serialized data.
* @private
* @param {Buffer} data
* @returns {ClaimEntry}
* @param {bio.BufferReader} br
* @returns {this}
*/

read(br) {
Expand Down
Loading

0 comments on commit 0ce3197

Please sign in to comment.