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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | 1 1 1 1 1 1 1 1 1 1 1 1 1 1 | /* This file is part of web3.js. web3.js is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. web3.js is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with web3.js. If not, see <http://www.gnu.org/licenses/>. */ /** * @file transfer.js * @author Marek Kotewicz <marek@ethdev.com> * @date 2015 */ var Iban = require('./iban'); var exchangeAbi = require('../contracts/SmartExchange.json'); /** * Should be used to make Iban transfer * * @method transfer * @param {String} from * @param {String} to iban * @param {Value} value to be tranfered * @param {Function} callback, callback */ var transfer = function (eth, from, to, value, callback) { var iban = new Iban(to); Iif (!iban.isValid()) { throw new Error('invalid iban address'); } Iif (iban.isDirect()) { return transferToAddress(eth, from, iban.address(), value, callback); } Eif (!callback) { var address = eth.icapNamereg().addr(iban.institution()); return deposit(eth, from, address, value, iban.client()); } eth.icapNamereg().addr(iban.institution(), function (err, address) { return deposit(eth, from, address, value, iban.client(), callback); }); }; /** * Should be used to transfer funds to certain address * * @method transferToAddress * @param {String} from * @param {String} to * @param {Value} value to be tranfered * @param {Function} callback, callback */ var transferToAddress = function (eth, from, to, value, callback) { return eth.sendTransaction({ address: to, from: from, value: value }, callback); }; /** * Should be used to deposit funds to generic Exchange contract (must implement deposit(bytes32) method!) * * @method deposit * @param {String} from * @param {String} to * @param {Value} value to be transfered * @param {String} client unique identifier * @param {Function} callback, callback */ var deposit = function (eth, from, to, value, client, callback) { var abi = exchangeAbi; return eth.contract(abi).at(to).deposit(client, { from: from, value: value }, callback); }; module.exports = transfer; |