forked from FabricLabs/fabric
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b584fd2
commit 8278fed
Showing
7 changed files
with
249 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
'use strict'; | ||
|
||
const Entity = require('./entity'); | ||
const Service = require('./service'); | ||
const Collection = require('./collection'); | ||
const Transaction = require('./transaction'); | ||
|
||
/** | ||
* Stores a list of {@link Transaction} elements. | ||
* @emits {Message} confirmed Emitted when the Mempool has dropped a transaction. | ||
*/ | ||
class Mempool extends Service { | ||
/** | ||
* Creates an instance of a {@link Mempool} {@link Service}. | ||
* @param {Object} settings Map of settings to utilize. | ||
*/ | ||
constructor (settings = {}) { | ||
super(settings); | ||
|
||
this.settings = Object.assign({ | ||
name: '@fabric/mempool' | ||
}, settings); | ||
|
||
this.transactions = new Collection({ | ||
type: Transaction | ||
}); | ||
|
||
this._state = { | ||
transactions: [] | ||
} | ||
|
||
return this; | ||
} | ||
|
||
async _remove (txid) { | ||
return false; | ||
} | ||
|
||
async add (transaction) { | ||
const entity = new Entity(transaction); | ||
const target = await this.transactions.create(transaction); | ||
// TODO: compare target.id and entity.id | ||
this._state.transactions.push(entity.id); | ||
} | ||
|
||
async confirm (txid) { | ||
const found = await this._findByTXID(txid); | ||
if (!found) throw new Error(`Could not find transaction: ${txid} in ${JSON.stringify(this.transactions.map())}`); | ||
this.emit('confirmed', txid); | ||
} | ||
|
||
async _findByTXID (txid) { | ||
return this._state.transactions.filter((x) => { | ||
return x.id == query; | ||
}); | ||
} | ||
} | ||
|
||
module.exports = Mempool; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict'; | ||
|
||
const MAX = Math.pow(2, 64); | ||
const BN = require('bn.js'); | ||
|
||
/** | ||
* {@link Number}-like type. | ||
*/ | ||
class Value { | ||
/** | ||
* Use the {@link Value} type to interact with {@link Number}-like objects. | ||
* @param {Mixed} data Input value. | ||
*/ | ||
constructor (data = {}) { | ||
this._state = { | ||
input: data, | ||
output: null | ||
}; | ||
} | ||
|
||
/** | ||
* Compute the numeric representation of this input. | ||
* @param {String} input Input string to seek for value. | ||
*/ | ||
value (input) { | ||
return new BN(input); | ||
} | ||
} | ||
|
||
module.exports = Value; |
Oops, something went wrong.