File tree Expand file tree Collapse file tree
crypto/src/main/java/org/web3j/crypto Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,11 +13,11 @@ public static RawTransaction decode(String hexTransaction) {
1313 byte [] transaction = Numeric .hexStringToByteArray (hexTransaction );
1414 RlpList rlpList = RlpDecoder .decode (transaction );
1515 RlpList values = (RlpList ) rlpList .getValues ().get (0 );
16- BigInteger nonce = ((RlpString ) values .getValues ().get (0 )).asBigInteger ();
17- BigInteger gasPrice = ((RlpString ) values .getValues ().get (1 )).asBigInteger ();
18- BigInteger gasLimit = ((RlpString ) values .getValues ().get (2 )).asBigInteger ();
16+ BigInteger nonce = ((RlpString ) values .getValues ().get (0 )).asPositiveBigInteger ();
17+ BigInteger gasPrice = ((RlpString ) values .getValues ().get (1 )).asPositiveBigInteger ();
18+ BigInteger gasLimit = ((RlpString ) values .getValues ().get (2 )).asPositiveBigInteger ();
1919 String to = ((RlpString ) values .getValues ().get (3 )).asString ();
20- BigInteger value = ((RlpString ) values .getValues ().get (4 )).asBigInteger ();
20+ BigInteger value = ((RlpString ) values .getValues ().get (4 )).asPositiveBigInteger ();
2121 String data = ((RlpString ) values .getValues ().get (5 )).asString ();
2222 if (values .getValues ().size () > 6 ) {
2323 byte v = ((RlpString ) values .getValues ().get (6 )).getBytes ()[0 ];
Original file line number Diff line number Diff line change @@ -21,11 +21,11 @@ public byte[] getBytes() {
2121 return value ;
2222 }
2323
24- public BigInteger asBigInteger () {
24+ public BigInteger asPositiveBigInteger () {
2525 if (value .length == 0 ) {
2626 return BigInteger .ZERO ;
2727 }
28- return new BigInteger (value );
28+ return new BigInteger (1 , value );
2929 }
3030
3131 public String asString () {
Original file line number Diff line number Diff line change @@ -21,6 +21,12 @@ public class RlpDecoderTest {
2121 @ Test
2222 public void testRLPDecode () {
2323
24+ // big positive number should stay positive after encoding-decoding
25+ // https://github.com/web3j/web3j/issues/562
26+ long value = 3000000000L ;
27+ assertThat (RlpString .create (BigInteger .valueOf (value )).asPositiveBigInteger ().longValue (),
28+ equalTo (value ));
29+
2430 // empty array of binary
2531 assertTrue (RlpDecoder .decode (new byte []{}).getValues ().isEmpty ());
2632
@@ -187,6 +193,5 @@ public void testRLPDecode() {
187193 assertThat (((RlpList )
188194 ((RlpList ) rlpList .getValues ().get (0 )).getValues ().get (1 )).getValues ().size (),
189195 equalTo (9 ));
190-
191196 }
192197}
You can’t perform that action at this time.
0 commit comments