Ejemplo n.º 1
0
    def __init__(self, _conf=None):
        """
        Initialize CtbCoin with given parameters. _conf is a coin config dictionary defined in conf/coins.yml
        """

        # verify _conf is a config dictionary
        if (not _conf or not hasattr(_conf, "name")
                or not hasattr(_conf, "config_file")
                or not hasattr(_conf, "txfee")):
            raise Exception("CtbCoin::__init__(): _conf is empty or invalid")

        self.conf = _conf

        # connect to coin daemon
        try:
            lg.debug("CtbCoin::__init__(): connecting to %s...",
                     self.conf.name)
            self.conn = Bitcoind(self.conf.config_file,
                                 rpcserver=self.conf.config_rpcserver)
        except BitcoindException as e:
            lg.error(
                "CtbCoin::__init__(): error connecting to %s using %s: %s",
                self.conf.name,
                self.conf.config_file,
                e,
            )
            raise

        lg.info("CtbCoin::__init__():: connected to %s", self.conf.name)
        time.sleep(0.5)

        # set transaction fee
        lg.info("Setting tx fee of %f", self.conf.txfee)
        self.conn.settxfee(self.conf.txfee)
Ejemplo n.º 2
0
def tip(ctx, to_user, amount):
    '''Send a tip to another user'''

    # Author is a Member
    from_id = ctx.message.author.id

    if not is_registered(from_id):
        yield from bot.say(
            'You are not registered. Use ?register to create an account.')
        return

    dconn = Bitcoind('~/.dashcore/dash.conf',
                     rpcport=19998)  # testnet, 9998 is realnet
    balance = dconn.getbalance(from_id)
    if float(amount) > balance:
        yield from bot.say('You can only send up to %f.' % balance)
        return

    if to_user.startswith('<@') and to_user.endswith('>'):
        to_id = to_user[2:-1]
    else:
        yield from bot.say(
            'Bad user id "%s", please use @ symbol so Discord sends me a user id.'
            % to_user)
        return

    new_tx(from_id, to_id, float(amount))
    yield from bot.say('A tip of %s dash will be offered to %s.' %
                       (amount, to_user))
Ejemplo n.º 3
0
def register(ctx):
    '''Adds a user to the database, generates a wallet for them, gives them its address to send funds to.'''

    # Author is a Member
    id = ctx.message.author.id
    name = ctx.message.author.name

    if is_registered(id):
        yield from bot.say(
            'You are already registered. Use ?getaddress to get your tip wallet address'
        )
        return

    new_user(id, name)

    # Generate a new address
    dconn = Bitcoind('~/.dashcore/dash.conf',
                     rpcport=19998)  # testnet, 9998 is realnet
    addr = dconn.getnewaddress()
    dconn.setaccount(addr, id)

    # Generate and save a QR code with the address
    im = qrcode.make(addr)
    filename = '/tmp/' + addr + '.png'
    im.save(filename, 'png')

    yield from bot.say(
        'Welcome %s, your tip wallet address is %s.\nPlease send some dash here to be able to tip.'
        % (name, addr))
    yield from bot.send_file(ctx.message.channel, filename)

    # Clean up the image file
    os.remove(filename)
Ejemplo n.º 4
0
def send(ctx, addr, amount):
    '''Send from my account to abitrary dash address'''

    # Author is a Member
    id = ctx.message.author.id

    if not is_registered(id):
        yield from bot.say(
            'You are not registered. Use ?register to create an account.')
        return

    dconn = Bitcoind('~/.dashcore/dash.conf',
                     rpcport=19998)  # testnet, 9998 is realnet
    balance = dconn.getbalance(id)
    if float(amount) > balance:
        yield from bot.say('You can only send up to %f.' % balance)
        return

    txid = dconn.sendfrom(id, addr, amount)

    # Generate and save a QR code with the address
    im = qrcode.make(txid)
    filename = '/tmp/' + txid + '.png'
    im.save(filename, 'png')

    yield from bot.say('Your transaction id is %s.' % (txid))
    yield from bot.send_file(ctx.message.channel, filename)

    # Clean up the image file
    os.remove(filename)
Ejemplo n.º 5
0
def getaddress(ctx):
    '''Resends the user's current account address'''

    # Author is a Member
    id = ctx.message.author.id

    if not is_registered(id):
        yield from bot.say(
            'You are not registered. Use ?register to create an account.')
        return

    dconn = Bitcoind('~/.dashcore/dash.conf',
                     rpcport=19998)  # testnet, 9998 is realnet
    addr = dconn.getaccountaddress(id)
    dconn.setaccount(addr, id)

    # Generate and save a QR code with the address
    im = qrcode.make(addr)
    filename = '/tmp/' + addr + '.png'
    im.save(filename, 'png')

    yield from bot.say('Your tip wallet address is %s.' % (addr))
    yield from bot.send_file(ctx.message.channel, filename)

    # Clean up the image file
    os.remove(filename)