// RpcClient.js // MIT/X11-like license. See LICENSE.txt. // Copyright 2013 BitPay, Inc. // var imports = require('soop').imports(); var http = imports.http || require('http'); var https = imports.https || require('https'); var log = imports.log || require('./util/log'); function RpcClient(opts) { opts = opts || {}; this.host = opts.host || '127.0.0.1'; this.port = opts.port || 8332; this.user = opts.user || 'user'; this.pass = opts.pass || 'pass'; this.protocol = (opts.protocol == 'http') ? http : https; this.batchedCalls = null; this.disableAgent = opts.disableAgent || false; } RpcClient.prototype.batch = function(batchCallback, resultCallback) { this.batchedCalls = []; batchCallback(); rpc.call(this, this.batchedCalls, resultCallback); this.batchedCalls = null; } var callspec = { addMultiSigAddress: '', addNode: '', backupWallet: '', createMultiSig: '', createRawTransaction: '', decodeRawTransaction: '', dumpPrivKey: '', encryptWallet: '', getAccount: '', getAccountAddress: 'str', getAddedNodeInfo: '', getAddressesByAccount: '', getBalance: 'str int', getBestBlockHash: '', getBlock: '', getBlockCount: '', getBlockHash: 'int', getBlockNumber: '', getBlockTemplate: '', getConnectionCount: '', getDifficulty: '', getGenerate: '', getHashesPerSec: '', getInfo: '', getMemoryPool: '', getMiningInfo: '', getNewAddress: '', getPeerInfo: '', getRawMemPool: '', getRawTransaction: 'str int', getReceivedByAccount: 'str int', getReceivedByAddress: 'str int', getTransaction: '', getTxOut: 'str int bool', getTxOutSetInfo: '', getWork: '', help: '', importAddress: 'str str bool', importPrivKey: 'str str bool', keyPoolRefill: '', listAccounts: 'int', listAddressGroupings: '', listReceivedByAccount: 'int bool', listReceivedByAddress: 'int bool', listSinceBlock: 'str int', listTransactions: 'str int int', listUnspent: 'int int', listLockUnspent: 'bool', lockUnspent: '', move: 'str str float int str', sendFrom: 'str str float int str str', sendMany: 'str str int str', //not sure this is will work sendRawTransaction: '', sendToAddress: 'str float str str', setAccount: '', setGenerate: 'bool int', setTxFee: 'float', signMessage: '', signRawTransaction: '', stop: '', submitBlock: '', validateAddress: '', verifyMessage: '', walletLock: '', walletPassPhrase: 'string int', walletPassphraseChange: '', }; var slice = function(arr, start, end) { return Array.prototype.slice.call(arr, start, end); }; function generateRPCMethods(constructor, apiCalls, rpc) { function createRPCMethod(methodName, argMap) { return function() { var limit = arguments.length - 1; if(this.batchedCalls) var limit = arguments.length; for (var i=0; i