@ -29,7 +29,7 @@ using namespace eth;
# define ETH_ADDRESS_DEBUG 0
Transaction : : Transaction ( bytesConstRef _rlpData )
Transaction : : Transaction ( bytesConstRef _rlpData , bool _checkSender )
{
int field = 0 ;
RLP rlp ( _rlpData ) ;
@ -42,6 +42,8 @@ Transaction::Transaction(bytesConstRef _rlpData)
value = rlp [ field = 4 ] . toInt < u256 > ( ) ;
data = rlp [ field = 5 ] . toBytes ( ) ;
vrs = Signature { rlp [ field = 6 ] . toInt < byte > ( ) , rlp [ field = 7 ] . toInt < u256 > ( ) , rlp [ field = 8 ] . toInt < u256 > ( ) } ;
if ( _checkSender )
m_sender = sender ( ) ;
}
catch ( RLPException const & )
{
@ -63,27 +65,30 @@ Address Transaction::safeSender() const noexcept
Address Transaction : : sender ( ) const
{
secp256k1_start ( ) ;
if ( ! m_sender )
{
secp256k1_start ( ) ;
h256 sig [ 2 ] = { vrs . r , vrs . s } ;
h256 msg = sha3 ( false ) ;
h256 sig [ 2 ] = { vrs . r , vrs . s } ;
h256 msg = sha3 ( false ) ;
byte pubkey [ 65 ] ;
int pubkeylen = 65 ;
if ( ! secp256k1_ecdsa_recover_compact ( msg . data ( ) , 32 , sig [ 0 ] . data ( ) , pubkey , & pubkeylen , 0 , ( int ) vrs . v - 27 ) )
throw InvalidSignature ( ) ;
byte pubkey [ 65 ] ;
int pubkeylen = 65 ;
if ( ! secp256k1_ecdsa_recover_compact ( msg . data ( ) , 32 , sig [ 0 ] . data ( ) , pubkey , & pubkeylen , 0 , ( int ) vrs . v - 27 ) )
throw InvalidSignature ( ) ;
// TODO: check right160 is correct and shouldn't be left160.
auto ret = right160 ( eth : : sha3 ( bytesConstRef ( & ( pubkey [ 1 ] ) , 64 ) ) ) ;
// TODO: check right160 is correct and shouldn't be left160.
m_sender = right160 ( eth : : sha3 ( bytesConstRef ( & ( pubkey [ 1 ] ) , 64 ) ) ) ;
# if ETH_ADDRESS_DEBUG
cout < < " ---- RECOVER ------------------------------- " < < endl ;
cout < < " MSG: " < < msg < < endl ;
cout < < " R S V: " < < sig [ 0 ] < < " " < < sig [ 1 ] < < " " < < ( int ) ( vrs . v - 27 ) < < " +27 " < < endl ;
cout < < " PUB: " < < toHex ( bytesConstRef ( & ( pubkey [ 1 ] ) , 64 ) ) < < endl ;
cout < < " ADR: " < < ret < < endl ;
cout < < " ---- RECOVER ------------------------------- " < < endl ;
cout < < " MSG: " < < msg < < endl ;
cout < < " R S V: " < < sig [ 0 ] < < " " < < sig [ 1 ] < < " " < < ( int ) ( vrs . v - 27 ) < < " +27 " < < endl ;
cout < < " PUB: " < < toHex ( bytesConstRef ( & ( pubkey [ 1 ] ) , 64 ) ) < < endl ;
cout < < " ADR: " < < ret < < endl ;
# endif
return ret ;
}
return m_sender ;
}
void Transaction : : sign ( Secret _priv )