core/types: reuse signtx #29152, close XFN-63 (#1631)

This commit is contained in:
Daniel Liu 2025-11-03 17:24:31 +08:00 committed by benjamin202410
parent 30a5b17152
commit b902fe4b07

View file

@ -98,13 +98,7 @@ func SignTx(tx *Transaction, s Signer, prv *ecdsa.PrivateKey) (*Transaction, err
// SignNewTx creates a transaction and signs it. // SignNewTx creates a transaction and signs it.
func SignNewTx(prv *ecdsa.PrivateKey, s Signer, txdata TxData) (*Transaction, error) { func SignNewTx(prv *ecdsa.PrivateKey, s Signer, txdata TxData) (*Transaction, error) {
tx := NewTx(txdata) return SignTx(NewTx(txdata), s, prv)
h := s.Hash(tx)
sig, err := crypto.Sign(h[:], prv)
if err != nil {
return nil, err
}
return tx.WithSignature(s, sig)
} }
// MustSignNewTx creates a transaction and signs it. // MustSignNewTx creates a transaction and signs it.