Add ports for testnet, mainnet, regtest; add z_sendmany function
This commit is contained in:
parent
d62bc3075f
commit
810d6fb42a
|
@ -7,9 +7,10 @@ class ZDaemon(object):
|
||||||
|
|
||||||
id_count = 0
|
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
|
#TODO: check utf safety
|
||||||
self.url = url
|
self.network = network
|
||||||
|
print "Network: ", self.network
|
||||||
self.user = user.encode('utf8')
|
self.user = user.encode('utf8')
|
||||||
self.password = password.encode('utf8')
|
self.password = password.encode('utf8')
|
||||||
self.timeout = timeout
|
self.timeout = timeout
|
||||||
|
@ -20,11 +21,18 @@ class ZDaemon(object):
|
||||||
'params': args,
|
'params': args,
|
||||||
'id': self.id_count})
|
'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
|
self.id_count += 1
|
||||||
|
|
||||||
|
# print "Bare text: ", r.text
|
||||||
|
|
||||||
resp = json.loads(r.text)
|
resp = json.loads(r.text)
|
||||||
|
|
||||||
|
# print "Bare response: %s \n\n" % resp
|
||||||
|
|
||||||
#TODO: deal with errors better.
|
#TODO: deal with errors better.
|
||||||
error = resp['error']
|
error = resp['error']
|
||||||
if error:
|
if error:
|
||||||
|
@ -32,6 +40,20 @@ class ZDaemon(object):
|
||||||
|
|
||||||
return resp['result']
|
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
|
#Block Info
|
||||||
def getBlockHash(self, blockheight):
|
def getBlockHash(self, blockheight):
|
||||||
return self._call('getblockhash', blockheight)
|
return self._call('getblockhash', blockheight)
|
||||||
|
@ -89,5 +111,16 @@ class ZDaemon(object):
|
||||||
def z_listaddresses(self):
|
def z_listaddresses(self):
|
||||||
return self._call('z_listaddresses')
|
return self._call('z_listaddresses')
|
||||||
|
|
||||||
def z_listreceivedbyaddress(self, zaddr):
|
def z_listreceivedbyaddress(self, zaddr, minconf=1):
|
||||||
return self._call('z_listreceivedbyaddress', zaddr)
|
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)
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
import os, re
|
import os, re
|
||||||
#ZCASH RPC
|
|
||||||
# Address and port of local zcashd testnet rpc
|
# Address and port of local zcashd testnet RPC ports
|
||||||
ZURL = "http://localhost:18232"
|
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 needs to be high for any pour operations
|
||||||
TIMEOUT = 600
|
TIMEOUT = 600
|
||||||
#Default fee to use on network for txs.
|
#Default fee to use on network for txs.
|
||||||
|
|
Loading…
Reference in New Issue