UNPKG

webu

Version:

IrChain JavaScript API, middleware to talk to a irchain node over RPC

145 lines (122 loc) 3.37 kB
/* This file is part of webu.js. webu.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. webu.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 webu.js. If not, see <http://www.gnu.org/licenses/>. */ /** * @file bzz.js * @author Alex Beregszaszi <alex@rtfs.hu> * @date 2016 * TODO update reference * Reference: https://github.com/irchain/go-irchain/blob/swarm/internal/webuext/webuext.go#L33 */ 'use strict'; var Method = require('../method'); var Property = require('../property'); function Swarm(webu) { this._requestManager = webu._requestManager; var self = this; methods().forEach(function(method) { method.attachToObject(self); method.setRequestManager(self._requestManager); }); properties().forEach(function(p) { p.attachToObject(self); p.setRequestManager(self._requestManager); }); } var methods = function() { var blockNetworkRead = new Method({ name: 'blockNetworkRead', call: 'bzz_blockNetworkRead', params: 1, inputFormatter: [null], }); var syncEnabled = new Method({ name: 'syncEnabled', call: 'bzz_syncEnabled', params: 1, inputFormatter: [null], }); var swapEnabled = new Method({ name: 'swapEnabled', call: 'bzz_swapEnabled', params: 1, inputFormatter: [null], }); var download = new Method({ name: 'download', call: 'bzz_download', params: 2, inputFormatter: [null, null], }); var upload = new Method({ name: 'upload', call: 'bzz_upload', params: 2, inputFormatter: [null, null], }); var retrieve = new Method({ name: 'retrieve', call: 'bzz_retrieve', params: 1, inputFormatter: [null], }); var store = new Method({ name: 'store', call: 'bzz_store', params: 2, inputFormatter: [null, null], }); var get = new Method({ name: 'get', call: 'bzz_get', params: 1, inputFormatter: [null], }); var put = new Method({ name: 'put', call: 'bzz_put', params: 2, inputFormatter: [null, null], }); var modify = new Method({ name: 'modify', call: 'bzz_modify', params: 4, inputFormatter: [null, null, null, null], }); return [ blockNetworkRead, syncEnabled, swapEnabled, download, upload, retrieve, store, get, put, modify, ]; }; var properties = function() { return [ new Property({ name: 'hive', getter: 'bzz_hive', }), new Property({ name: 'info', getter: 'bzz_info', }), ]; }; module.exports = Swarm;