'Sign a transaction. The wallet keys will be used unless a private key is provided.'

@command('wp')
def signtransaction(self, tx, privkey=None, password=None):

    tx = Transaction(tx)
    if privkey:
        pubkey = bitcoin.public_key_from_private_key(privkey)
        h160 = bitcoin.hash_160(pubkey.decode('hex'))
        x_pubkey = ('fd' + (chr(0) + h160).encode('hex'))
        tx.sign({x_pubkey: privkey})
    else:
        self.wallet.sign_transaction(tx, password)
    return tx.as_dict()
