2
2
import rlp
3
3
from bitcoin import encode_pubkey , N , encode_privkey
4
4
from rlp .sedes import big_endian_int , binary
5
- from rlp .utils import encode_hex , str_to_bytes , ascii_chr
5
+ from rlp .utils import encode_hex , str_to_bytes , ascii_chr , int_to_big_endian
6
6
from secp256k1 import PublicKey , ALL_FLAGS , PrivateKey
7
7
8
8
from ethereum .exceptions import InvalidTransaction
@@ -108,15 +108,6 @@ def sender(self):
108
108
self ._sender = 0
109
109
return self ._sender
110
110
111
- @property
112
- def normalized_v (self ):
113
- """EIP155
114
- """
115
- if self .v in (27 , 28 ):
116
- return self .v - 27
117
- else :
118
- return self .v - (self .__class__ ._chain_id * 2 + 1 )
119
-
120
111
@sender .setter
121
112
def sender (self , value ):
122
113
self ._sender = value
@@ -131,7 +122,19 @@ def sign(self, key, backwards_compatible=True):
131
122
"""
132
123
if key in (0 , '' , b'\x00 ' * 32 , '0' * 64 ):
133
124
raise InvalidTransaction ("Zero privkey cannot sign" )
134
- rawhash = utils .sha3 (rlp .encode (self , UnsignedTransaction ))
125
+ if backwards_compatible :
126
+ rawhash = utils .sha3 (rlp .encode (self , UnsignedTransaction ))
127
+ else :
128
+ rawhash = utils .sha3 (rlp .encode (Transaction (
129
+ self .nonce ,
130
+ self .gasprice ,
131
+ self .startgas ,
132
+ self .to ,
133
+ self .value ,
134
+ self .data ,
135
+ 18 ,
136
+ 0 ,
137
+ 0 ), Transaction ))
135
138
136
139
if len (key ) == 64 :
137
140
# we need a binary key
@@ -156,6 +159,15 @@ def sign(self, key, backwards_compatible=True):
156
159
def hash (self ):
157
160
return utils .sha3 (rlp .encode (self ))
158
161
162
+ @property
163
+ def normalized_v (self ):
164
+ """EIP155
165
+ """
166
+ if self .v in (27 , 28 ):
167
+ return self .v - 27
168
+ else :
169
+ return self .v - (self .__class__ ._chain_id * 2 + 1 )
170
+
159
171
def log_bloom (self ):
160
172
"returns int"
161
173
bloomables = [x .bloomables () for x in self .logs ]
@@ -225,7 +237,7 @@ def __init__(self, *args, **kwargs):
225
237
super (EIP155Transaction , self ).__init__ (* args , ** kwargs )
226
238
227
239
def sign (self , key , backwards_compatible = False ):
228
- return super (self ).sign (key , backwards_compatible )
240
+ return super (self . __class__ , self ).sign (key , backwards_compatible )
229
241
230
242
231
243
UnsignedTransaction = Transaction .exclude (['v' , 'r' , 's' ])
0 commit comments