Fix PublicKey generation from Tx

The original tx struct was being overwritten by the append action, copy the data first to prevent this