expose message construtors by name
This commit is contained in:
parent
6461748cd5
commit
641443f6dd
@ -34,15 +34,32 @@ function builder(options) {
|
|||||||
commands: {}
|
commands: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
var commandsArray = [
|
exported.commandsMap = {
|
||||||
'version', 'verack', 'ping', 'pong', 'block', 'tx', 'getdata', 'headers', 'notfound',
|
version: 'Version',
|
||||||
'inv', 'addr', 'alert', 'reject', 'merkleblock', 'filterload', 'filteradd', 'filterclear',
|
verack: 'VerAck',
|
||||||
'getblocks', 'getheaders', 'mempool', 'getaddr'
|
ping: 'Ping',
|
||||||
];
|
pong: 'Pong',
|
||||||
|
block: 'Block',
|
||||||
|
tx: 'Transaction',
|
||||||
|
getdata: 'GetData',
|
||||||
|
headers: 'Headers',
|
||||||
|
notfound: 'NotFound',
|
||||||
|
inv: 'Inventory',
|
||||||
|
addr: 'Address',
|
||||||
|
alert: 'Alert',
|
||||||
|
reject: 'Reject',
|
||||||
|
merkleblock: 'MerkleBlock',
|
||||||
|
filterload: 'FilterLoad',
|
||||||
|
filteradd: 'FilterAdd',
|
||||||
|
filterclear: 'FilterClear',
|
||||||
|
getblocks: 'GetBlocks',
|
||||||
|
getheaders: 'GetHeaders',
|
||||||
|
mempool: 'MemPool',
|
||||||
|
getaddr: 'GetAddr'
|
||||||
|
};
|
||||||
|
|
||||||
for (var i = 0; i < commandsArray.length; i++) {
|
for (var key in exported.commandsMap) {
|
||||||
var command = commandsArray[i];
|
exported.commands[key] = require('./commands/' + key)(options);
|
||||||
exported.commands[command] = require('./commands/' + command)(options);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return exported;
|
return exported;
|
||||||
|
|||||||
@ -6,6 +6,13 @@ var Hash = bitcore.crypto.Hash;
|
|||||||
|
|
||||||
function Messages(options) {
|
function Messages(options) {
|
||||||
this.builder = Messages.builder(options);
|
this.builder = Messages.builder(options);
|
||||||
|
|
||||||
|
// map message constructors by name
|
||||||
|
for(var key in this.builder.commandsMap) {
|
||||||
|
var name = this.builder.commandsMap[key];
|
||||||
|
this[name] = this.builder.commands[key];
|
||||||
|
}
|
||||||
|
|
||||||
if (!options) {
|
if (!options) {
|
||||||
options = {};
|
options = {};
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user