From 08aaaecbfb86e9db952199949f381a49d75e001c Mon Sep 17 00:00:00 2001 From: debris Date: Wed, 5 Aug 2015 14:18:42 +0200 Subject: [PATCH] separated namereg from ibanNamereg. both are available at web3.eth.namereg && web3.eth.ibanNamereg. fixed "insitution" bug in transfer.js. created contracts directory --- index.js | 4 +- lib/contracts/FixedFeeRegistrar.json | 203 +++++++++++++++++++++ lib/contracts/GlobalRegistrar.json | 254 +++++++++++++++++++++++++++ lib/contracts/SmartExchange.json | 146 +++++++++++++++ lib/web3/namereg.js | 28 +-- lib/web3/transfer.js | 7 +- test/web3.eth.sendIBANTransaction.js | 3 +- 7 files changed, 619 insertions(+), 26 deletions(-) create mode 100644 lib/contracts/FixedFeeRegistrar.json create mode 100644 lib/contracts/GlobalRegistrar.json create mode 100644 lib/contracts/SmartExchange.json diff --git a/index.js b/index.js index e808844..5d476e4 100644 --- a/index.js +++ b/index.js @@ -1,10 +1,12 @@ var web3 = require('./lib/web3'); +var namereg = require('./lib/web3/namereg'); web3.providers.HttpProvider = require('./lib/web3/httpprovider'); web3.providers.IpcProvider = require('./lib/web3/ipcprovider'); web3.eth.contract = require('./lib/web3/contract'); -web3.eth.namereg = require('./lib/web3/namereg'); +web3.eth.namereg = namereg.namereg; +web3.eth.ibanNamereg = namereg.ibanNamereg; web3.eth.sendIBANTransaction = require('./lib/web3/transfer'); // dont override global variable diff --git a/lib/contracts/FixedFeeRegistrar.json b/lib/contracts/FixedFeeRegistrar.json new file mode 100644 index 0000000..b87e3fb --- /dev/null +++ b/lib/contracts/FixedFeeRegistrar.json @@ -0,0 +1,203 @@ +[ + { + "constant": false, + "inputs": [ + { + "name": "_name", + "type": "string" + }, + { + "name": "_a", + "type": "address" + } + ], + "name": "setAddr", + "outputs": [], + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "name": "_name", + "type": "string" + } + ], + "name": "addr", + "outputs": [ + { + "name": "", + "type": "address" + } + ], + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "name": "_name", + "type": "string" + } + ], + "name": "subRegistrar", + "outputs": [ + { + "name": "", + "type": "address" + } + ], + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "_name", + "type": "string" + } + ], + "name": "reserve", + "outputs": [], + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "_name", + "type": "string" + }, + { + "name": "_refund", + "type": "address" + } + ], + "name": "disown", + "outputs": [], + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "_name", + "type": "string" + }, + { + "name": "_registrar", + "type": "address" + } + ], + "name": "setSubRegistrar", + "outputs": [], + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "name": "_name", + "type": "string" + } + ], + "name": "content", + "outputs": [ + { + "name": "", + "type": "bytes32" + } + ], + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "name": "_name", + "type": "string" + } + ], + "name": "owner", + "outputs": [ + { + "name": "", + "type": "address" + } + ], + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "name": "_name", + "type": "string" + } + ], + "name": "record", + "outputs": [ + { + "name": "o_addr", + "type": "address" + }, + { + "name": "o_subRegistrar", + "type": "address" + }, + { + "name": "o_content", + "type": "bytes32" + }, + { + "name": "o_owner", + "type": "address" + } + ], + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "_name", + "type": "string" + }, + { + "name": "_newOwner", + "type": "address" + } + ], + "name": "transfer", + "outputs": [], + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "_name", + "type": "string" + }, + { + "name": "_content", + "type": "bytes32" + } + ], + "name": "setContent", + "outputs": [], + "type": "function" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "name": "name", + "type": "string" + } + ], + "name": "Changed", + "type": "event" + } +] \ No newline at end of file diff --git a/lib/contracts/GlobalRegistrar.json b/lib/contracts/GlobalRegistrar.json new file mode 100644 index 0000000..a27c738 --- /dev/null +++ b/lib/contracts/GlobalRegistrar.json @@ -0,0 +1,254 @@ +[ + { + "constant": true, + "inputs": [ + { + "name": "_owner", + "type": "address" + } + ], + "name": "name", + "outputs": [ + { + "name": "o_name", + "type": "bytes32" + } + ], + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "name": "_name", + "type": "bytes32" + } + ], + "name": "owner", + "outputs": [ + { + "name": "", + "type": "address" + } + ], + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "name": "_name", + "type": "bytes32" + } + ], + "name": "content", + "outputs": [ + { + "name": "", + "type": "bytes32" + } + ], + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "name": "_name", + "type": "bytes32" + } + ], + "name": "addr", + "outputs": [ + { + "name": "", + "type": "address" + } + ], + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "_name", + "type": "bytes32" + } + ], + "name": "reserve", + "outputs": [], + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "name": "_name", + "type": "bytes32" + } + ], + "name": "subRegistrar", + "outputs": [ + { + "name": "", + "type": "address" + } + ], + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "_name", + "type": "bytes32" + }, + { + "name": "_newOwner", + "type": "address" + } + ], + "name": "transfer", + "outputs": [], + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "_name", + "type": "bytes32" + }, + { + "name": "_registrar", + "type": "address" + } + ], + "name": "setSubRegistrar", + "outputs": [], + "type": "function" + }, + { + "constant": false, + "inputs": [], + "name": "Registrar", + "outputs": [], + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "_name", + "type": "bytes32" + }, + { + "name": "_a", + "type": "address" + }, + { + "name": "_primary", + "type": "bool" + } + ], + "name": "setAddress", + "outputs": [], + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "_name", + "type": "bytes32" + }, + { + "name": "_content", + "type": "bytes32" + } + ], + "name": "setContent", + "outputs": [], + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "_name", + "type": "bytes32" + } + ], + "name": "disown", + "outputs": [], + "type": "function" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "name": "_name", + "type": "bytes32" + }, + { + "indexed": false, + "name": "_winner", + "type": "address" + } + ], + "name": "AuctionEnded", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "name": "_name", + "type": "bytes32" + }, + { + "indexed": false, + "name": "_bidder", + "type": "address" + }, + { + "indexed": false, + "name": "_value", + "type": "uint256" + } + ], + "name": "NewBid", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "name": "name", + "type": "bytes32" + } + ], + "name": "Changed", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "name": "name", + "type": "bytes32" + }, + { + "indexed": true, + "name": "addr", + "type": "address" + } + ], + "name": "PrimaryChanged", + "type": "event" + } +] \ No newline at end of file diff --git a/lib/contracts/SmartExchange.json b/lib/contracts/SmartExchange.json new file mode 100644 index 0000000..501a67d --- /dev/null +++ b/lib/contracts/SmartExchange.json @@ -0,0 +1,146 @@ +[ + { + "constant": false, + "inputs": [ + { + "name": "from", + "type": "bytes32" + }, + { + "name": "to", + "type": "address" + }, + { + "name": "value", + "type": "uint256" + } + ], + "name": "transfer", + "outputs": [], + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "from", + "type": "bytes32" + }, + { + "name": "to", + "type": "address" + }, + { + "name": "indirectId", + "type": "bytes32" + }, + { + "name": "value", + "type": "uint256" + } + ], + "name": "icapTransfer", + "outputs": [], + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "to", + "type": "bytes32" + } + ], + "name": "deposit", + "outputs": [], + "type": "function" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "name": "from", + "type": "address" + }, + { + "indexed": false, + "name": "value", + "type": "uint256" + } + ], + "name": "AnonymousDeposit", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "name": "from", + "type": "address" + }, + { + "indexed": true, + "name": "to", + "type": "bytes32" + }, + { + "indexed": false, + "name": "value", + "type": "uint256" + } + ], + "name": "Deposit", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "name": "from", + "type": "bytes32" + }, + { + "indexed": true, + "name": "to", + "type": "address" + }, + { + "indexed": false, + "name": "value", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "name": "from", + "type": "bytes32" + }, + { + "indexed": true, + "name": "to", + "type": "address" + }, + { + "indexed": false, + "name": "indirectId", + "type": "bytes32" + }, + { + "indexed": false, + "name": "value", + "type": "uint256" + } + ], + "name": "IcapTransfer", + "type": "event" + } +] \ No newline at end of file diff --git a/lib/web3/namereg.js b/lib/web3/namereg.js index 46ee0e1..d4cda44 100644 --- a/lib/web3/namereg.js +++ b/lib/web3/namereg.js @@ -21,26 +21,14 @@ */ var contract = require('./contract'); +var globalRegistrarAbi = require('../contracts/GlobalRegistrar.json'); +var fixedFeeRegistrarAbi = require('../contracts/FixedFeeRegistrar.json'); -var address = '0xc6d9d2cd449a754c494264e1809c50e34d64562b'; +var globalNameregAddress = '0xc6d9d2cd449a754c494264e1809c50e34d64562b'; +var ibanNameregAddress = '0xc6d9d2cd449a754c494264e1809c50e34d64562b'; -var abi = [ - {"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"name","outputs":[{"name":"o_name","type":"bytes32"}],"type":"function"}, - {"constant":true,"inputs":[{"name":"_name","type":"bytes32"}],"name":"owner","outputs":[{"name":"","type":"address"}],"type":"function"}, - {"constant":true,"inputs":[{"name":"_name","type":"bytes32"}],"name":"content","outputs":[{"name":"","type":"bytes32"}],"type":"function"}, - {"constant":true,"inputs":[{"name":"_name","type":"bytes32"}],"name":"addr","outputs":[{"name":"","type":"address"}],"type":"function"}, - {"constant":false,"inputs":[{"name":"_name","type":"bytes32"}],"name":"reserve","outputs":[],"type":"function"}, - {"constant":true,"inputs":[{"name":"_name","type":"bytes32"}],"name":"subRegistrar","outputs":[{"name":"o_subRegistrar","type":"address"}],"type":"function"}, - {"constant":false,"inputs":[{"name":"_name","type":"bytes32"},{"name":"_newOwner","type":"address"}],"name":"transfer","outputs":[],"type":"function"}, - {"constant":false,"inputs":[{"name":"_name","type":"bytes32"},{"name":"_registrar","type":"address"}],"name":"setSubRegistrar","outputs":[],"type":"function"}, - {"constant":false,"inputs":[],"name":"Registrar","outputs":[],"type":"function"}, - {"constant":false,"inputs":[{"name":"_name","type":"bytes32"},{"name":"_a","type":"address"},{"name":"_primary","type":"bool"}],"name":"setAddress","outputs":[],"type":"function"}, - {"constant":false,"inputs":[{"name":"_name","type":"bytes32"},{"name":"_content","type":"bytes32"}],"name":"setContent","outputs":[],"type":"function"}, - {"constant":false,"inputs":[{"name":"_name","type":"bytes32"}],"name":"disown","outputs":[],"type":"function"}, - {"constant":true,"inputs":[{"name":"_name","type":"bytes32"}],"name":"register","outputs":[{"name":"","type":"address"}],"type":"function"}, - {"anonymous":false,"inputs":[{"indexed":true,"name":"name","type":"bytes32"}],"name":"Changed","type":"event"}, - {"anonymous":false,"inputs":[{"indexed":true,"name":"name","type":"bytes32"},{"indexed":true,"name":"addr","type":"address"}],"name":"PrimaryChanged","type":"event"} -]; - -module.exports = contract(abi).at(address); +module.exports = { + namereg: contract(globalRegistrarAbi).at(globalNameregAddress), + ibanNamereg: contract(fixedFeeRegistrarAbi).at(ibanNameregAddress) +}; diff --git a/lib/web3/transfer.js b/lib/web3/transfer.js index 6159889..f1ad243 100644 --- a/lib/web3/transfer.js +++ b/lib/web3/transfer.js @@ -22,8 +22,9 @@ var web3 = require('../web3'); var ICAP = require('./icap'); -var namereg = require('./namereg'); +var namereg = require('./namereg').ibanNamereg; var contract = require('./contract'); +var exchangeAbi = require('../contracts/SmartExchange.json'); /** * Should be used to make ICAP transfer @@ -49,7 +50,7 @@ var transfer = function (from, iban, value, callback) { return deposit(from, address, value, icap.client()); } - namereg.addr(icap.insitution(), function (err, address) { + namereg.addr(icap.institution(), function (err, address) { return deposit(from, address, value, icap.client(), callback); }); @@ -83,7 +84,7 @@ var transferToAddress = function (from, address, value, callback) { * @param {Function} callback, callback */ var deposit = function (from, address, value, client, callback) { - var abi = [{"constant":false,"inputs":[{"name":"name","type":"bytes32"}],"name":"deposit","outputs":[],"type":"function"}]; + var abi = exchangeAbi; return contract(abi).at(address).deposit(client, { from: from, value: value diff --git a/test/web3.eth.sendIBANTransaction.js b/test/web3.eth.sendIBANTransaction.js index 9d478e1..702b5c7 100644 --- a/test/web3.eth.sendIBANTransaction.js +++ b/test/web3.eth.sendIBANTransaction.js @@ -1,7 +1,6 @@ var chai = require('chai'); var assert = chai.assert; var web3 = require('../index'); -var FakeHttpProvider = require('./helpers/FakeHttpProvider'); var FakeHttpProvider2 = require('./helpers/FakeHttpProvider2'); describe('web3.eth.sendIBANTransaction', function () { @@ -27,7 +26,7 @@ describe('web3.eth.sendIBANTransaction', function () { step++; assert.equal(payload.method, 'eth_call'); assert.deepEqual(payload.params, [{ - data: '0x3b3b57de5852454700000000000000000000000000000000000000000000000000000000', + data: "0x511b1df9000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000045852454700000000000000000000000000000000000000000000000000000000", to: web3.eth.namereg.address }, "latest"]);