// MutateTransactionEnvelope for TransactionBuilder causes the underylying
// transaction to be set as the provided envelope's Tx field
func (m TransactionBuilder) MutateTransactionEnvelope(txe *xdr.TransactionEnvelope) error {
	if m.Err != nil {
		return m.Err
	}

	txe.Tx = m.TX
	return nil
}
// MutateTransactionEnvelope adds a signature to the provided envelope
func (m Sign) MutateTransactionEnvelope(txe *xdr.TransactionEnvelope) error {
	tb := TransactionBuilder{TX: txe.Tx}
	hash, err := tb.Hash()

	if err != nil {
		return err
	}

	if m.Key == nil {
		return errors.New("Invalid key")
	}

	sig := m.Key.Sign(hash[:])

	ds := xdr.DecoratedSignature{
		Hint:      m.Key.Hint(),
		Signature: xdr.Uint512(sig),
	}

	txe.Signatures = append(txe.Signatures, ds)
	return nil
}