def getnewaddr(self, _user = None):
"""
Generate a new address for _user
Returns (string) address
"""
user = self.verify_user(_user=_user)
addr = ""
counter = 0
while True:
try:
# Unlock wallet for keypoolrefill
if hasattr(self.conf, 'walletpassphrase'):
self.conn.walletpassphrase(self.conf.walletpassphrase, 1)
# Generate new address
addr = self.conn.getnewaddress(user)
# Lock wallet
if hasattr(self.conf, 'walletpassphrase'):
self.conn.walletlock()
if not addr:
raise Exception("CtbCoin::getnewaddr(%s): empty addr", user)
time.sleep(0.1)
return str(addr)
except BitcoindException as e:
lg.error("CtbCoin::getnewaddr(%s): BitcoindException: %s", user, e)
raise
except CannotSendRequest as e:
if counter < 3:
lg.warning("CtbCoin::getnewaddr(%s): CannotSendRequest, retrying")
counter += 1
time.sleep(10)
continue
else:
raise
except Exception as e:
if str(e) == "timed out" and counter < 3:
lg.warning("CtbCoin::getnewaddr(%s): timed out, retrying")
counter += 1
time.sleep(10)
continue
else:
lg.error("CtbCoin::getnewaddr(%s): Exception: %s", user, e)
raise
评论列表
文章目录