diff --git a/pyZcash/rpc/ZDaemon.py b/pyZcash/rpc/ZDaemon.py index 240a691..8b64c9b 100644 --- a/pyZcash/rpc/ZDaemon.py +++ b/pyZcash/rpc/ZDaemon.py @@ -7,9 +7,10 @@ class ZDaemon(object): id_count = 0 - def __init__(self, url=ZURL, user=RPCUSER, password=RPCPASSWORD, timeout=TIMEOUT): + def __init__(self, network=NETWORK, user=RPCUSER, password=RPCPASSWORD, timeout=TIMEOUT): #TODO: check utf safety - self.url = url + self.network = network + print "Network: ", self.network self.user = user.encode('utf8') self.password = password.encode('utf8') self.timeout = timeout @@ -20,11 +21,18 @@ class ZDaemon(object): 'params': args, 'id': self.id_count}) - r = requests.post(self.url, auth=(self.user,self.password), data=jsondata, timeout=self.timeout) + print "JSONDATA: ", jsondata + + r = requests.post(self.network, auth=(self.user,self.password), data=jsondata, timeout=self.timeout) self.id_count += 1 + + # print "Bare text: ", r.text + resp = json.loads(r.text) + # print "Bare response: %s \n\n" % resp + #TODO: deal with errors better. error = resp['error'] if error: @@ -32,6 +40,20 @@ class ZDaemon(object): return resp['result'] + def _get_response(self): + http_response = self.__conn.getresponse() + if http_response is None: + raise JSONRPCException({ + 'code': -342, 'message': 'missing HTTP response from server'}) + + responsedata = http_response.read().decode('utf8') + response = json.loads(responsedata, parse_float=decimal.Decimal) + if "error" in response and response["error"] is None: + log.debug("<-%s- %s"%(response["id"], json.dumps(response["result"], default=EncodeDecimal))) + else: + log.debug("<-- "+responsedata) + return response + #Block Info def getBlockHash(self, blockheight): return self._call('getblockhash', blockheight) @@ -89,5 +111,16 @@ class ZDaemon(object): def z_listaddresses(self): return self._call('z_listaddresses') - def z_listreceivedbyaddress(self, zaddr): - return self._call('z_listreceivedbyaddress', zaddr) + def z_listreceivedbyaddress(self, zaddr, minconf=1): + return self._call('z_listreceivedbyaddress', zaddr, minconf) + + # With addition of encrypted memo field + def z_sendmany(self, sender, receiver, amount=0.0001, memo=''): + amts_array = [] + if memo == '': + amounts = {"address": receiver, "amount": amount} + else: + memo = memo.encode('hex') + amounts = {"address": receiver, "amount": amount, "memo": memo} + amts_array.append(amounts) + return self._call('z_sendmany', sender, amts_array) diff --git a/pyZcash/settings.py b/pyZcash/settings.py index 8807705..1fe4f8c 100644 --- a/pyZcash/settings.py +++ b/pyZcash/settings.py @@ -1,7 +1,12 @@ import os, re -#ZCASH RPC -# Address and port of local zcashd testnet rpc -ZURL = "http://localhost:18232" + +# Address and port of local zcashd testnet RPC ports +testnet = "http://localhost:18232" #testnet +mainnet = "http://localhost:8232" +regtest = "http://localhost:18444" +# Default is testnet +NETWORK = testnet + #Timeout needs to be high for any pour operations TIMEOUT = 600 #Default fee to use on network for txs.