Awesome IRC bot
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.5 KiB

#!/usr/bin/env python
.. module:: DogeRPC
:synopsis: Provides a service for interacting with dogecoind.
.. moduleauthor:: Dave Pedu <>
from pyircbot.modulebase import ModuleBase
from bitcoinrpc.authproxy import AuthServiceProxy
class DogeRPC(ModuleBase):
def __init__(self, bot, moduleName):
ModuleBase.__init__(self, bot, moduleName) = ["dogerpc"]
self.rpc = DogeController(self)
def getBal(self, acct):
"Get a balance of a local address or an account "
return self.getAcctBal(acct)
def getAcctAddr(self, acct):
"Returns the address for an account. creates if necessary "
addrs = self.rpc.con.getaddressesbyaccount(acct)
if len(addrs) == 0:
return self.rpc.con.getnewaddress(acct)
return addrs[0]
def getAcctBal(self, acct):
"Returns an account's balance"
return float(self.rpc.con.getbalance(acct))
def canMove(self, fromAcct, toAcct, amount):
"True or false if fromAcct can afford to give toAcct an amount of coins "
balfrom = self.getAcctBal(fromAcct)
return balfrom >= amount
def move(self, fromAcct, toAcct, amount):
"Move coins from one account to another "
if self.canMove(fromAcct, toAcct, amount):
return self.rpc.con.move(fromAcct, toAcct, amount)
return False
def send(self, fromAcct, toAddr, amount):
"Send coins to an external addr "
if self.canMove(fromAcct, toAddr, amount):
return self.rpc.con.sendfrom(fromAcct, toAddr, amount)
return False
class DogeController:
"RPC instance control class"
def __init__(self, master):
self.config = master.config
self.log = master.log
self.con = None
def ping(self):
"Test connection and re-establish if necessary"
if not self.con:
def connect(self):
"Connect to RPC endpoint""DogeRPC: Connecting to dogecoind")
self.con = AuthServiceProxy("http://%s:%s@%s:%s" % (self.config["username"], self.config["password"],
self.config["host"], self.config["port"]))
self.con.getinfo()"DogeRPC: Connected to %s:%s" % (self.config["host"], self.config["port"]))