@Test public void testDecodingSigned() throws Exception { BigInteger nonce = BigInteger.ZERO; BigInteger gasPrice = BigInteger.ONE; BigInteger gasLimit = BigInteger.TEN; String to = "0x0add5355"; BigInteger value = BigInteger.valueOf(Long.MAX_VALUE); RawTransaction rawTransaction = RawTransaction.createEtherTransaction( nonce, gasPrice, gasLimit, to, value); byte[] signedMessage = TransactionEncoder.signMessage( rawTransaction, SampleKeys.CREDENTIALS); String hexMessage = Numeric.toHexString(signedMessage); RawTransaction result = TransactionDecoder.decode(hexMessage); assertNotNull(result); assertEquals(nonce, result.getNonce()); assertEquals(gasPrice, result.getGasPrice()); assertEquals(gasLimit, result.getGasLimit()); assertEquals(to, result.getTo()); assertEquals(value, result.getValue()); assertEquals("", result.getData()); assertTrue(result instanceof SignedRawTransaction); SignedRawTransaction signedResult = (SignedRawTransaction) result; assertNotNull(signedResult.getSignatureData()); Sign.SignatureData signatureData = signedResult.getSignatureData(); byte[] encodedTransaction = TransactionEncoder.encode(rawTransaction); BigInteger key = Sign.signedMessageToKey(encodedTransaction, signatureData); assertEquals(key, SampleKeys.PUBLIC_KEY); assertEquals(SampleKeys.ADDRESS, signedResult.getFrom()); signedResult.verify(SampleKeys.ADDRESS); assertNull(signedResult.getChainId()); }
public static RawTransaction decode(String hexTransaction) { byte[] transaction = Numeric.hexStringToByteArray(hexTransaction); RlpList rlpList = RlpDecoder.decode(transaction); RlpList values = (RlpList) rlpList.getValues().get(0); BigInteger nonce = ((RlpString) values.getValues().get(0)).asBigInteger(); BigInteger gasPrice = ((RlpString) values.getValues().get(1)).asBigInteger(); BigInteger gasLimit = ((RlpString) values.getValues().get(2)).asBigInteger(); String to = ((RlpString) values.getValues().get(3)).asString(); BigInteger value = ((RlpString) values.getValues().get(4)).asBigInteger(); String data = ((RlpString) values.getValues().get(5)).asString(); if (values.getValues().size() > 6) { byte v = ((RlpString) values.getValues().get(6)).getBytes()[0]; byte[] r = zeroPadded(((RlpString) values.getValues().get(7)).getBytes(), 32); byte[] s = zeroPadded(((RlpString) values.getValues().get(8)).getBytes(), 32); Sign.SignatureData signatureData = new Sign.SignatureData(v, r, s); return new SignedRawTransaction(nonce, gasPrice, gasLimit, to, value, data, signatureData); } else { return RawTransaction.createTransaction(nonce, gasPrice, gasLimit, to, value, data); } }
TransactionDecoder { public static RawTransaction decode(String hexTransaction) { byte[] transaction = Numeric.hexStringToByteArray(hexTransaction); RlpList rlpList = RlpDecoder.decode(transaction); RlpList values = (RlpList) rlpList.getValues().get(0); BigInteger nonce = ((RlpString) values.getValues().get(0)).asBigInteger(); BigInteger gasPrice = ((RlpString) values.getValues().get(1)).asBigInteger(); BigInteger gasLimit = ((RlpString) values.getValues().get(2)).asBigInteger(); String to = ((RlpString) values.getValues().get(3)).asString(); BigInteger value = ((RlpString) values.getValues().get(4)).asBigInteger(); String data = ((RlpString) values.getValues().get(5)).asString(); if (values.getValues().size() > 6) { byte v = ((RlpString) values.getValues().get(6)).getBytes()[0]; byte[] r = zeroPadded(((RlpString) values.getValues().get(7)).getBytes(), 32); byte[] s = zeroPadded(((RlpString) values.getValues().get(8)).getBytes(), 32); Sign.SignatureData signatureData = new Sign.SignatureData(v, r, s); return new SignedRawTransaction(nonce, gasPrice, gasLimit, to, value, data, signatureData); } else { return RawTransaction.createTransaction(nonce, gasPrice, gasLimit, to, value, data); } } }
TransactionDecoder { public static RawTransaction decode(String hexTransaction) { byte[] transaction = Numeric.hexStringToByteArray(hexTransaction); RlpList rlpList = RlpDecoder.decode(transaction); RlpList values = (RlpList) rlpList.getValues().get(0); BigInteger nonce = ((RlpString) values.getValues().get(0)).asBigInteger(); BigInteger gasPrice = ((RlpString) values.getValues().get(1)).asBigInteger(); BigInteger gasLimit = ((RlpString) values.getValues().get(2)).asBigInteger(); String to = ((RlpString) values.getValues().get(3)).asString(); BigInteger value = ((RlpString) values.getValues().get(4)).asBigInteger(); String data = ((RlpString) values.getValues().get(5)).asString(); if (values.getValues().size() > 6) { byte v = ((RlpString) values.getValues().get(6)).getBytes()[0]; byte[] r = zeroPadded(((RlpString) values.getValues().get(7)).getBytes(), 32); byte[] s = zeroPadded(((RlpString) values.getValues().get(8)).getBytes(), 32); Sign.SignatureData signatureData = new Sign.SignatureData(v, r, s); return new SignedRawTransaction(nonce, gasPrice, gasLimit, to, value, data, signatureData); } else { return RawTransaction.createTransaction(nonce, gasPrice, gasLimit, to, value, data); } }  }
TransactionDecoder { public static RawTransaction decode(String hexTransaction) { byte[] transaction = Numeric.hexStringToByteArray(hexTransaction); RlpList rlpList = RlpDecoder.decode(transaction); RlpList values = (RlpList) rlpList.getValues().get(0); BigInteger nonce = ((RlpString) values.getValues().get(0)).asBigInteger(); BigInteger gasPrice = ((RlpString) values.getValues().get(1)).asBigInteger(); BigInteger gasLimit = ((RlpString) values.getValues().get(2)).asBigInteger(); String to = ((RlpString) values.getValues().get(3)).asString(); BigInteger value = ((RlpString) values.getValues().get(4)).asBigInteger(); String data = ((RlpString) values.getValues().get(5)).asString(); if (values.getValues().size() > 6) { byte v = ((RlpString) values.getValues().get(6)).getBytes()[0]; byte[] r = zeroPadded(((RlpString) values.getValues().get(7)).getBytes(), 32); byte[] s = zeroPadded(((RlpString) values.getValues().get(8)).getBytes(), 32); Sign.SignatureData signatureData = new Sign.SignatureData(v, r, s); return new SignedRawTransaction(nonce, gasPrice, gasLimit, to, value, data, signatureData); } else { return RawTransaction.createTransaction(nonce, gasPrice, gasLimit, to, value, data); } }  static RawTransaction decode(String hexTransaction); }
TransactionDecoder { public static RawTransaction decode(String hexTransaction) { byte[] transaction = Numeric.hexStringToByteArray(hexTransaction); RlpList rlpList = RlpDecoder.decode(transaction); RlpList values = (RlpList) rlpList.getValues().get(0); BigInteger nonce = ((RlpString) values.getValues().get(0)).asBigInteger(); BigInteger gasPrice = ((RlpString) values.getValues().get(1)).asBigInteger(); BigInteger gasLimit = ((RlpString) values.getValues().get(2)).asBigInteger(); String to = ((RlpString) values.getValues().get(3)).asString(); BigInteger value = ((RlpString) values.getValues().get(4)).asBigInteger(); String data = ((RlpString) values.getValues().get(5)).asString(); if (values.getValues().size() > 6) { byte v = ((RlpString) values.getValues().get(6)).getBytes()[0]; byte[] r = zeroPadded(((RlpString) values.getValues().get(7)).getBytes(), 32); byte[] s = zeroPadded(((RlpString) values.getValues().get(8)).getBytes(), 32); Sign.SignatureData signatureData = new Sign.SignatureData(v, r, s); return new SignedRawTransaction(nonce, gasPrice, gasLimit, to, value, data, signatureData); } else { return RawTransaction.createTransaction(nonce, gasPrice, gasLimit, to, value, data); } }  static RawTransaction decode(String hexTransaction);  }