Skip to content

Commit

Permalink
revert v
Browse files Browse the repository at this point in the history
  • Loading branch information
envestcc committed Sep 25, 2023
1 parent 77d4cf5 commit 0361af2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
15 changes: 9 additions & 6 deletions api/web3server_marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package api
import (
"encoding/hex"
"encoding/json"
"math/big"

"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -229,10 +230,12 @@ func (obj *getTransactionResult) MarshalJSON() ([]byte, error) {
value, _ := intStrToHex(obj.ethTx.Value().String())
gasPrice, _ := intStrToHex(obj.ethTx.GasPrice().String())

r, s, v, err := types.HomesteadSigner{}.SignatureValues(obj.ethTx, obj.signature)
if err != nil {
return nil, err
// TODO: if transaction is support EIP-155, we need to add chainID to v
vVal := uint64(obj.signature[64])
if vVal < 27 {
vVal += 27
}

return json.Marshal(&struct {
Hash string `json:"hash"`
Nonce string `json:"nonce"`
Expand Down Expand Up @@ -260,9 +263,9 @@ func (obj *getTransactionResult) MarshalJSON() ([]byte, error) {
GasPrice: gasPrice,
Gas: uint64ToHex(obj.ethTx.Gas()),
Input: byteToHex(obj.ethTx.Data()),
R: hexutil.EncodeBig(r),
S: hexutil.EncodeBig(s),
V: hexutil.EncodeBig(v),
R: hexutil.EncodeBig(new(big.Int).SetBytes(obj.signature[:32])),
S: hexutil.EncodeBig(new(big.Int).SetBytes(obj.signature[32:64])),
V: uint64ToHex(vVal),
})
}

Expand Down
7 changes: 4 additions & 3 deletions api/web3server_marshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ func TestTransactionObjectMarshal(t *testing.T) {
ethTx: types.NewContractCreation(1, big.NewInt(10), 21000, big.NewInt(0), []byte{}),
receipt: receipt,
pubkey: _testPubKey,
signature: []byte("69d89a0af27dcaa67f1b62a383594d97599aadd2b7b164cb4112aa8ddfd42f895"),
// TODO: should decode signature from hex string
signature: []byte("69d89a0af27dcaa67f1b62a383594d97599aadd2b7b164cb4112aa8ddfd42f895649075cae1b7216c43a491c5e9be68d1d9a27b863d71155ecdd7c95dab5394f01"),
})
require.NoError(err)
require.JSONEq(`
Expand All @@ -250,7 +251,7 @@ func TestTransactionObjectMarshal(t *testing.T) {
"input":"0x",
"r":"0x3639643839613061663237646361613637663162363261333833353934643937",
"s":"0x3539396161646432623762313634636234313132616138646466643432663839",
"v":"0x50"
"v":"0x35"
}
`, string(res))
})
Expand Down Expand Up @@ -292,7 +293,7 @@ func TestTransactionObjectMarshal(t *testing.T) {
"input": "0x1fad948c0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000ec4daee51c4bf81bd00af165f8ca66823ee3b12a000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000003e24491a4f2a946e30baf624fda6b4484d106c12000000000000000000000000000000000000000000000000000000000000005b000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000000000000009fd90000000000000000000000000000000000000000000000000000000000011da4000000000000000000000000000000000000000000000000000000000000db26000000000000000000000000000000000000000000000000000000e8d4a51000000000000000000000000000000000000000000000000000000000e8d4a510000000000000000000000000000000000000000000000000000000000000000240000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000084b61d27f6000000000000000000000000065e1164818487818e6ba714e8d80b91718ad75800000000000000000000000000000000000000000000000000038d7ea4c6800000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000095ccc7012efb2e65aa31752f3ac01e23817c08a47500000000000000000000000000000000000000000000000000000000650af9f8000000000000000000000000000000000000000000000000000000006509a878b5acba7277159ae6fa661ed1988cc10ac2c96c58dc332bde2a6dc0d8531ea3924d9d04cda681c271411250ae7d9e9aea47661dba67a66f08d19804a255e45c561b0000000000000000000000000000000000000000000000000000000000000000000000000000000000004160daa88165299ca7e585d5d286cee98b54397b57ac704b74331a48d67651195322ef3884c7d60023333f2542a07936f34edc9efa3cbd19e8cd0f8972c54171a21b00000000000000000000000000000000000000000000000000000000000000",
"r": "0xd50c3169003e7c9c9392069a1c9e5251c8f558120cceb9aa312f0fa4624770",
"s": "0x1f4cad47a5540cdda5459f7a46c62df752ca588e0b73722ec767ff08994134a4",
"v": "0x36"
"v": "0x1b"
}
`, string(res))
})
Expand Down

0 comments on commit 0361af2

Please sign in to comment.