aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorreinerRubin <tolstov.georgij@gmail.com>2018-09-30 04:47:59 +0800
committerFelix Lange <fjl@users.noreply.github.com>2018-09-30 04:47:59 +0800
commit86ec213076ac52a7b427a0fb25994bfb4e78720b (patch)
treef5486420f7a1f39c7d47c727310451f52aa9c667
parent3d782bc727fb58630b1d811b9ab95d626c68e40f (diff)
downloaddexon-86ec213076ac52a7b427a0fb25994bfb4e78720b.tar
dexon-86ec213076ac52a7b427a0fb25994bfb4e78720b.tar.gz
dexon-86ec213076ac52a7b427a0fb25994bfb4e78720b.tar.bz2
dexon-86ec213076ac52a7b427a0fb25994bfb4e78720b.tar.lz
dexon-86ec213076ac52a7b427a0fb25994bfb4e78720b.tar.xz
dexon-86ec213076ac52a7b427a0fb25994bfb4e78720b.tar.zst
dexon-86ec213076ac52a7b427a0fb25994bfb4e78720b.zip
core/types: make tx signature values optional in JSON (#17742)
-rw-r--r--core/types/transaction.go23
-rw-r--r--core/types/transaction_test.go12
2 files changed, 23 insertions, 12 deletions
diff --git a/core/types/transaction.go b/core/types/transaction.go
index 9c6e77be9..7b53cac2c 100644
--- a/core/types/transaction.go
+++ b/core/types/transaction.go
@@ -153,16 +153,21 @@ func (tx *Transaction) UnmarshalJSON(input []byte) error {
if err := dec.UnmarshalJSON(input); err != nil {
return err
}
- var V byte
- if isProtectedV(dec.V) {
- chainID := deriveChainId(dec.V).Uint64()
- V = byte(dec.V.Uint64() - 35 - 2*chainID)
- } else {
- V = byte(dec.V.Uint64() - 27)
- }
- if !crypto.ValidateSignatureValues(V, dec.R, dec.S, false) {
- return ErrInvalidSig
+
+ 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()
+ V = byte(dec.V.Uint64() - 35 - 2*chainID)
+ } else {
+ V = byte(dec.V.Uint64() - 27)
+ }
+ if !crypto.ValidateSignatureValues(V, dec.R, dec.S, false) {
+ return ErrInvalidSig
+ }
}
+
*tx = Transaction{data: dec}
return nil
}
diff --git a/core/types/transaction_test.go b/core/types/transaction_test.go
index b390f45c6..f38d8e717 100644
--- a/core/types/transaction_test.go
+++ b/core/types/transaction_test.go
@@ -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