Exemplo n.º 1
0
    def sign_tx(self, pw):
        if not self.is_wallet_loaded:
            raise Exception('Tried to spend when wallet not loaded.')

        if not self.is_dest_addr_set:
            raise Exception('Tried to spend when destination address not set.')

        if not self.is_send_amount_set:
            raise Exception('Tried to spend when amount not set.')
        
        if self.send_amount + self.txfee > self.balance:
            raise LowBalanceError("Insufficient funds to send {0} + {1} BTC.".format(core.satoshi_to_btc(self.send_amount), core.satoshi_to_btc(self.txfee)))
            
        try:
            prv = wallet.decrypt_privkey(self.encr_privkey, pw)
            addr = bc.privtoaddr(prv, self.magic_byte)
        except:
            raise PasswordError("Wrong password!")
        
        if addr != self.addr:
            raise Exception('Address from wallet does not match address from private key!')

        tx_ins, tx_outs = core.simple_tx_inputs_outputs(self.addr, self.unspent, self.dest_addr, self.send_amount, self.txfee)
        
        # Make transaction
        tx = bc.mktx(tx_ins, tx_outs)
        
        # Sign transaction
        for i in range(len(tx_ins)):
            tx = bc.sign(tx,i,prv)
        
        return tx_ins, tx_outs, tx, bc.deserialize(tx)
Exemplo n.º 2
0
def sign_tx(unsigned_raw_tx, privatekey):
    tx = unsigned_raw_tx
    detx = pybitcointools.deserialize(tx)
    input_length = len(detx['ins'])

    for i in range(0, input_length):
        tx = pybitcointools.sign(tx, i, privatekey)
    return tx
Exemplo n.º 3
0
        print "Enter private key or (double) Electrum seed:"
        priv = raw_input().strip()
        if " " in priv:
            seed = mnemonic.mn_decode(priv.split(" "))
            priv = pbt.electrum_privkey(seed, 0, 0)  # root key
        source = pbt.privkey_to_address(priv)
        if source != data["source"]:
            print "Address from privkey:", source
            raise Exception ("Privkey does not match source address.")
        print


        # sign tx
        for i in range(len(dtx["ins"])):
            rtx = pbt.sign(rtx, i, priv)

        print "signed serialized tx:"
        print
        rtx58 = pbt.changebase(rtx, 16, 58)
        print rtx58
        printqr.print_tx(rtx58)

        print
        print "Restart your computer to clear memory."
        raw_input()
    except:
        import traceback
        traceback.print_exc()
        print
        print "Starting over...."