Ejemplo n.º 1
0
    def recv_tx(self, nick, txhex):
        try:
            self.tx = btc.deserialize(txhex)
        except IndexError as e:
            self.maker.msgchan.send_error(nick, 'malformed txhex. ' + repr(e))
        log.debug('obtained tx\n' + pprint.pformat(self.tx))
        goodtx, errmsg = self.verify_unsigned_tx(self.tx)
        if not goodtx:
            log.debug('not a good tx, reason=' + errmsg)
            self.maker.msgchan.send_error(nick, errmsg)
        # TODO: the above 3 errors should be encrypted, but it's a bit messy.
        log.debug('goodtx')
        sigs = []
        for index, ins in enumerate(self.tx['ins']):
            utxo = ins['outpoint']['hash'] + ':' + str(ins['outpoint']['index'])
            if utxo not in self.utxos:
                continue
            addr = self.utxos[utxo]['address']
            txs = btc.sign(txhex, index,
                           self.maker.wallet.get_key_from_addr(addr))
            sigs.append(base64.b64encode(btc.deserialize(txs)['ins'][index][
                                             'script'].decode('hex')))
        # len(sigs) > 0 guarenteed since i did verify_unsigned_tx()

        jm_single().bc_interface.add_tx_notify(
                self.tx, self.unconfirm_callback,
                self.confirm_callback, self.cj_addr)
        log.debug('sending sigs ' + str(sigs))
        self.maker.msgchan.send_sigs(nick, sigs)
        self.maker.active_orders[nick] = None
Ejemplo n.º 2
0
    def recv_tx(self, nick, txhex):
        try:
            self.tx = btc.deserialize(txhex)
        except IndexError as e:
            self.maker.msgchan.send_error(nick, 'malformed txhex. ' + repr(e))
        log.debug('obtained tx\n' + pprint.pformat(self.tx))
        goodtx, errmsg = self.verify_unsigned_tx(self.tx)
        if not goodtx:
            log.debug('not a good tx, reason=' + errmsg)
            self.maker.msgchan.send_error(nick, errmsg)
        # TODO: the above 3 errors should be encrypted, but it's a bit messy.
        log.debug('goodtx')
        sigs = []
        for index, ins in enumerate(self.tx['ins']):
            utxo = ins['outpoint']['hash'] + ':' + str(
                ins['outpoint']['index'])
            if utxo not in self.utxos:
                continue
            addr = self.utxos[utxo]['address']
            txs = btc.sign(txhex, index,
                           self.maker.wallet.get_key_from_addr(addr))
            sigs.append(
                base64.b64encode(
                    btc.deserialize(txs)['ins'][index]['script'].decode(
                        'hex')))
        # len(sigs) > 0 guarenteed since i did verify_unsigned_tx()

        jm_single().bc_interface.add_tx_notify(self.tx,
                                               self.unconfirm_callback,
                                               self.confirm_callback,
                                               self.cj_addr)
        log.debug('sending sigs ' + str(sigs))
        self.maker.msgchan.send_sigs(nick, sigs)
        self.maker.active_orders[nick] = None
Ejemplo n.º 3
0
 def sign_tx(self, tx, i, priv):
     if self.my_cj_addr:
         return btc.sign(tx, i, priv)
     else:
         #Note: donation code removed (possibly temporarily)
         raise NotImplementedError
Ejemplo n.º 4
0
 def sign(self, tx, i, priv, amount):
     """Sign a transaction; the amount field
     triggers the segwit style signing.
     """
     log.debug("About to sign for this amount: " + str(amount))
     return btc.sign(tx, i, priv, amount=amount)
Ejemplo n.º 5
0
 def sign(self, tx, i, priv, amount):
     """Sign a transaction for pushing
     onto the network. The amount field
     is not used in this case (p2pkh)
     """
     return btc.sign(tx, i, priv)
Ejemplo n.º 6
0
 def sign_tx(self, tx, i, priv):
     if self.my_cj_addr:
         return btc.sign(tx, i, priv)
     else:
         return sign_donation_tx(tx, i, priv)
Ejemplo n.º 7
0
 def sign_tx(self, tx, i, priv):
     if self.my_cj_addr:
         return btc.sign(tx, i, priv)
     else:
         return sign_donation_tx(tx, i, priv)