-
Notifications
You must be signed in to change notification settings - Fork 31
/
exchange_transactions.js
43 lines (34 loc) · 1.34 KB
/
exchange_transactions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* This script should be run as child process
*/
var web3 = require('web3');
var registrar = require('./namereg');
var utils = require('./utils');
var errors = require('./errors');
var abi = require('./contracts/SmartExchange.json');
/**
* If any synchronous JSON-RPC request fails, UNKNOWN_ERROR should be thrown
*/
var transactions = function (config, identifier, options, callback) {
try {
// setup configurable properties
var namereg = config.namereg === 'default' ? web3.eth.namereg : registrar.at(config.namereg);
// start web3.js
web3.setProvider(new web3.providers.HttpProvider('http://' + config.jsonrpc_host + ':' + config.jsonrpc_port));
if (!utils.validateIdentifier(identifier)) {
return callback(errors.IDENTIFIER_IS_INCORRECT);
}
var encodedIdentifier = web3.fromAscii(identifier);
// validate exchange identifier
var address = namereg.addr(encodedIdentifier);
if (utils.isEmptyAddress(address)) {
return callback(errors.IDENTIFIER_NO_ADDRESS);
}
var SmartExchange = web3.eth.contract(abi).at(address);
var transactions = SmartExchange.allEvents(options).get();
callback(null, transactions);
} catch(err) {
callback(errors.UNKNOWN_ERROR(err));
}
};
module.exports = transactions;