New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

smart-exchange

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

smart-exchange - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

kraken.json

19

config.json
{
"contract": "lib/contract/SmartExchange.sol",
"contract_name": "SmartExchange",
"jsonrpc_host": "localhost",
"jsonrpc_port": "8101",
"exchange_interface": "http",
"exchange_port": 8545,
"owner": "0x195940f806d8afad1f7e6d2d68c936aa69e26e18",
"namereg": "0x9314b8851c15c564c15942cb7d64ce2c190fd33b"
}
"contract": "lib/contract/SmartExchange.sol",
"contract_name": "SmartExchange",
"jsonrpc_host": "localhost",
"jsonrpc_port": "8101",
"exchange_interface": "http",
"exchange_port": 8545,
"owner": "0x29f1467c4f755e074fccfb5e9cd8bf2c02eaaf95",
"namereg": "0x9499660747fcfc52e0b218fcd83fa5f7de869a8a"
}

@@ -10,7 +10,12 @@ /**

/**
* If any synchronous JSON-RPC request fails, UNKNOWN_ERROR should be thrown
*/
var balance = function (config, identifier, callback) {
try {
// setup configurable properties
var namereg = config.namereg === 'default' ? web3.eth.namereg : globalRegistrar.at(config.namereg);
// start web3.js
web3.setProvider(new web3.providers.HttpProvider('http://' + config.jsonrpc_host + ':' + config.jsonrpc_port));

@@ -21,2 +26,3 @@ if (!utils.validateIdentifier(identifier)) {

// validate exchange identifier
var address = namereg.addr(identifier);

@@ -27,2 +33,3 @@ if (utils.isEmptyAddress(address)) {

// get balance
var balance = web3.eth.getBalance(address);

@@ -29,0 +36,0 @@ callback(null, balance);

@@ -12,8 +12,16 @@ /**

/**
* If any synchronous JSON-RPC request fails, UNKNOWN_ERROR should be thrown
*/
var create = function (config, identifier, overwrite, callback) {
try {
// setup configurable properties
var owner = config.owner;
var namereg = config.namereg === 'default' ? web3.eth.namereg : globalRegistrar.at(config.namereg);
// start web3.js
web3.setProvider(new web3.providers.HttpProvider('http://' + config.jsonrpc_host + ':' + config.jsonrpc_port));
// validate new exchange identifier
if (!utils.validateIdentifier(identifier)) {

@@ -23,2 +31,3 @@ return callback(errors.IDENTIFIER_IS_INCORRECT);

// check if exchange with given identifier can be created
var idOwner = namereg.owner(identifier);

@@ -35,15 +44,19 @@ if (!utils.isEmptyAddress(idOwner)) {

// compile contract, TODO: it should use config contract location instead
var file = fs.readFileSync(__dirname + '/contracts/SmartExchange.sol');
var compiled = web3.eth.compile.solidity(file.toString());
// TODO: config add contract class name to config
var code = compiled.SmartExchange.code;
var abi = compiled.SmartExchange.info.abiDefinition;
// create new contract and get it's transaction hash
var transactionHash = web3.eth.contract(abi).new({data: code, from: owner, gas: 2500000}).transactionHash;
// wait for contract to be mined for 120 seconds
// TODO: validate receipt code
var receipt = null;
var counter = 0;
while ((receipt = web3.eth.getTransactionReceipt(transactionHash)) === null) {
if (counter++ > 60) {
callback(errors.CONTRACT_DEPLOYMENT_ERROR);
if (counter++ > 120) {
break;

@@ -55,5 +68,9 @@ }

if (receipt) {
// after receiving transaction receipt we can assume, that contract is properly created
// let's reserve identifier in namereg && save pair (identifier, address)
namereg.reserve(identifier, {from: owner});
namereg.setAddress(identifier, receipt.contractAddress, true, {from: owner});
callback(null, receipt.contractAddress);
} else {
callback(errors.CONTRACT_DEPLOYMENT_ERROR);
}

@@ -60,0 +77,0 @@

@@ -49,7 +49,12 @@ /**

/**
* 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 : globalRegistrar.at(config.namereg);
// start web3.js
web3.setProvider(new web3.providers.HttpProvider('http://' + config.jsonrpc_host + ':' + config.jsonrpc_port));

@@ -60,2 +65,3 @@ if (!utils.validateIdentifier(identifier)) {

// validate exchange identifier
var address = namereg.addr(identifier);

@@ -66,11 +72,5 @@ if (utils.isEmptyAddress(address)) {

// this may take a while if we search from block 0
// TODO: merge everything together ?
var SmartExchange = web3.eth.contract(abi).at(address);
var deposits = SmartExchange.Deposit({}, options).get();
var anonymousDeposits = SmartExchange.AnonymousDeposit({}, options).get();
var txs = SmartExchange.Transfer({}, options).get();
var icapTxs = SmartExchange.IcapTransfer({}, options).get();
callback(null, deposits.concat(anonymousDeposits).concat(txs).concat(icapTxs));
var transactions = SmartExchange.allEvents(options).get();
callback(null, transactions);
} catch(err) {

@@ -77,0 +77,0 @@ callback(errors.UNKNOWN_ERROR(err));

@@ -41,6 +41,10 @@ /**

// setup configurable properties
var owner = config.owner;
var namereg = config.namereg === 'default' ? web3.eth.namereg : globalRegistrar.at(config.namereg);
// start web3.js
web3.setProvider(new web3.providers.HttpProvider('http://' + config.jsonrpc_host + ':' + config.jsonrpc_port));
var owner = config.owner;
// validate new exchange identifier
if (!utils.validateIdentifier(identifier)) {

@@ -50,2 +54,4 @@ return callback(errors.IDENTIFIER_IS_INCORRECT);

// check if identifier is owned by us
// TODO: This is not required
if (namereg.owner(identifier) !== owner) {

@@ -55,2 +61,3 @@ return callback(errors.IDENTIFIER_NOT_OWNED);

// check if identifier is empty
var contractAddress = namereg.addr(identifier);

@@ -61,2 +68,3 @@ if (utils.isEmptyAddress(contractAddress)) {

// validate from
if (!utils.validateUserid(from)) {

@@ -66,2 +74,3 @@ return callback(errors.FROM_IS_INCORRECT);

// validate to
var toAddress = utils.validateAddress(to);

@@ -77,3 +86,3 @@ var toDirectIBAN = utils.validateDirectIBAN(to);

} else if (toDirectIBAN || toUserid) {
} else if (toIndirectIBAN || toUserid) {
var toIdentifier = toUserid ? identifier : utils.indirectIBANToIdentifier(to);

@@ -80,0 +89,0 @@

@@ -6,3 +6,5 @@ var workerFarm = require('worker-farm');

var extTransfer = require.resolve('./exchange_transfer');
var extTransaction = require.resolve('./exchange_transaction');
var extTransactions = require.resolve('./exchange_transactions');
var extAddress = require.resolve('./exchange_address');

@@ -56,2 +58,3 @@ /**

* @method create
* @param {Object} config
* @param {String} identifier @see IDENTIFIER

@@ -74,2 +77,3 @@ * @param {Function} callback triggered on result

* @method transfer
* @param {Object} config
* @param {String} identifier @see IDENTIFIER

@@ -100,2 +104,3 @@ * @param {String} from @see USERID

* @method transactions
* @param {Object} config
* @param {String} identifier @see IDENTIFIER

@@ -132,11 +137,29 @@ * @param {Object} options (optional) may contain additional

* @method transaction
* @param {Object} config
* @param {String} identifier @see IDENTIFIER
* @param {String} hash, transactionHash - TODO
* @param {Function} callback triggered on result
* @TODO
* @throws UNKNOWN_ERROR
* @throws IDENTIFIER_IS_INCORRECT
* @throws IDENTIFIER_NO_ADDRESS
*/
var transaction = function (config, identifier, hash, callback) {
runInProcess(extTransaction, [config, identifier, hash], callback);
};
/**
* Should be used to get address of the exchnage
*
* @method address
* @param {Object} config
* @param {String} identifier @see IDENTIFIER
* @param {Function} callback triggered on result
* @throws UNKNOWN_ERROR
* @throws IDENTIFIER_IS_INCORRECT
*/
var address = function (config, identifier, callback) {
runInProcess(extAddress, [config, identifier], callback);
};
module.exports = {

@@ -147,4 +170,5 @@ create: create,

transaction: transaction,
balance: balance
balance: balance,
address: address
};

@@ -85,2 +85,10 @@ var jayson = require('jayson');

exchange_transaction: requireParams(2, function (identifier, hash, callback) {
logRequest('exchange_transaction');
inter.transaction(config, identifier, hash, function (err, result) {
logResponse('exchange_transaction', err, result);
callback(err, result);
});
}),
exchange_transactions: requireParams(2, function (identifier, options, callback) {

@@ -100,2 +108,10 @@ logRequest('exchange_transactions');

});
}),
exchange_address: requireParams(1, function (identifier, callback) {
logRequest('exchange_address');
inter.address(config, identifier, function (err, result) {
logResponse('exchange_address', err, result);
callback(err, result);
});
})

@@ -102,0 +118,0 @@ }));

{
"name": "smart-exchange",
"version": "0.1.0",
"version": "0.2.0",
"description": "",

@@ -5,0 +5,0 @@ "main": "./lib/interface.js",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc