Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Return from RPC methods original transaction v value #5811

Merged
merged 2 commits into from
Nov 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Changed: [#5806](https://github.com/ethereum/aleth/pull/5806) Optimize selfdestruct opcode in aleth-interpreter by reducing state accesses in certain out-of-gas scenarios.
- Removed: [#5760](https://github.com/ethereum/aleth/pull/5760) Official support for Visual Studio 2015 has been dropped. Compilation with this compiler is expected to stop working after migration to C++14.
- Fixed: [#5792](https://github.com/ethereum/aleth/pull/5792) Faster and cheaper execution of RPC functions which query blockchain state (e.g. getBalance).
- Fixed: [#5811](https://github.com/ethereum/aleth/pull/5811) RPC methods querying transactions (`eth_getTransactionByHash`, `eth_getBlockByNumber`) return correct `v` value.

## [1.7.0] - Unreleased

Expand Down
16 changes: 12 additions & 4 deletions libethcore/TransactionBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ SignatureStruct const& TransactionBase::signature() const
return *m_vrs;
}

u256 TransactionBase::rawV() const
{
if (!m_vrs)
BOOST_THROW_EXCEPTION(TransactionIsUnsigned());

int const vOffset = m_chainId.has_value() ? *m_chainId * 2 + 35 : 27;
return m_vrs->v + vOffset;
}


void TransactionBase::sign(Secret const& _priv)
{
auto sig = dev::sign(_priv, sha3(WithoutSignature));
Expand Down Expand Up @@ -163,10 +173,8 @@ void TransactionBase::streamRLP(RLPStream& _s, IncludeSignature _sig, bool _forE
if (hasZeroSignature())
_s << *m_chainId;
else
{
int const vOffset = m_chainId.has_value() ? *m_chainId * 2 + 35 : 27;
_s << (m_vrs->v + vOffset);
}
_s << rawV();

_s << (u256)m_vrs->r << (u256)m_vrs->s;
}
else if (_forEip155hash)
Expand Down
4 changes: 4 additions & 0 deletions libethcore/TransactionBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ class TransactionBase
/// @throws TransactionIsUnsigned if signature was not initialized
SignatureStruct const& signature() const;

/// @returns v value of the transaction (has chainID and recoveryID encoded in it)
/// @throws TransactionIsUnsigned if signature was not initialized
u256 rawV() const;

void sign(Secret const& _priv); ///< Sign the transaction.

/// @returns amount of gas required for the basic payment.
Expand Down
6 changes: 3 additions & 3 deletions libweb3jsonrpc/JsonHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Json::Value toJson(dev::eth::Transaction const& _t, std::pair<h256, unsigned> _l
res["blockHash"] = toJS(_location.first);
res["transactionIndex"] = toJS(_location.second);
res["blockNumber"] = toJS(_blockNumber);
res["v"] = toJS(_t.signature().v);
res["v"] = toJS(_t.rawV());
res["r"] = toJS(_t.signature().r);
res["s"] = toJS(_t.signature().s);
}
Expand Down Expand Up @@ -213,7 +213,7 @@ Json::Value toJson(dev::eth::Transaction const& _t)
res["sighash"] = toJS(_t.sha3(WithoutSignature));
res["r"] = toJS(_t.signature().r);
res["s"] = toJS(_t.signature().s);
res["v"] = toJS(_t.signature().v);
res["v"] = toJS(_t.rawV());
return res;
}

Expand Down Expand Up @@ -243,7 +243,7 @@ Json::Value toJson(dev::eth::LocalisedTransaction const& _t)
res["blockNumber"] = toJS(_t.blockNumber());
res["r"] = toJS(_t.signature().r);
res["s"] = toJS(_t.signature().s);
res["v"] = toJS(_t.signature().v);
res["v"] = toJS(_t.rawV());
}
return res;
}
Expand Down