core/types: make tx signature values optional in JSON (#17742)
This commit is contained in:
parent
3d782bc727
commit
86ec213076
@ -153,6 +153,9 @@ func (tx *Transaction) UnmarshalJSON(input []byte) error {
|
||||
if err := dec.UnmarshalJSON(input); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
withSignature := dec.V.Sign() != 0 || dec.R.Sign() != 0 || dec.S.Sign() != 0
|
||||
if withSignature {
|
||||
var V byte
|
||||
if isProtectedV(dec.V) {
|
||||
chainID := deriveChainId(dec.V).Uint64()
|
||||
@ -163,6 +166,8 @@ func (tx *Transaction) UnmarshalJSON(input []byte) error {
|
||||
if !crypto.ValidateSignatureValues(V, dec.R, dec.S, false) {
|
||||
return ErrInvalidSig
|
||||
}
|
||||
}
|
||||
|
||||
*tx = Transaction{data: dec}
|
||||
return nil
|
||||
}
|
||||
|
@ -185,6 +185,7 @@ func TestTransactionJSON(t *testing.T) {
|
||||
}
|
||||
signer := NewEIP155Signer(common.Big1)
|
||||
|
||||
transactions := make([]*Transaction, 0, 50)
|
||||
for i := uint64(0); i < 25; i++ {
|
||||
var tx *Transaction
|
||||
switch i % 2 {
|
||||
@ -193,20 +194,25 @@ func TestTransactionJSON(t *testing.T) {
|
||||
case 1:
|
||||
tx = NewContractCreation(i, common.Big0, 1, common.Big2, []byte("abcdef"))
|
||||
}
|
||||
transactions = append(transactions, tx)
|
||||
|
||||
tx, err := SignTx(tx, signer, key)
|
||||
signedTx, err := SignTx(tx, signer, key)
|
||||
if err != nil {
|
||||
t.Fatalf("could not sign transaction: %v", err)
|
||||
}
|
||||
|
||||
transactions = append(transactions, signedTx)
|
||||
}
|
||||
|
||||
for _, tx := range transactions {
|
||||
data, err := json.Marshal(tx)
|
||||
if err != nil {
|
||||
t.Errorf("json.Marshal failed: %v", err)
|
||||
t.Fatalf("json.Marshal failed: %v", err)
|
||||
}
|
||||
|
||||
var parsedTx *Transaction
|
||||
if err := json.Unmarshal(data, &parsedTx); err != nil {
|
||||
t.Errorf("json.Unmarshal failed: %v", err)
|
||||
t.Fatalf("json.Unmarshal failed: %v", err)
|
||||
}
|
||||
|
||||
// compare nonce, price, gaslimit, recipient, amount, payload, V, R, S
|
||||
|
Loading…
Reference in New Issue
Block a user