byte[] data = Numeric.hexStringToByteArray(rawTransaction.getData()); result.add(RlpString.create(data));
@Test public void testDecoding() 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[] encodedMessage = TransactionEncoder.encode(rawTransaction); String hexMessage = Numeric.toHexString(encodedMessage); 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()); }
@Test public void testDecodingSignedChainId() throws Exception { BigInteger nonce = BigInteger.ZERO; BigInteger gasPrice = BigInteger.ONE; BigInteger gasLimit = BigInteger.TEN; String to = "0x0add5355"; BigInteger value = BigInteger.valueOf(Long.MAX_VALUE); Integer chainId = 1; RawTransaction rawTransaction = RawTransaction.createEtherTransaction( nonce, gasPrice, gasLimit, to, value); byte[] signedMessage = TransactionEncoder.signMessage( rawTransaction, chainId.byteValue(), 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; assertEquals(SampleKeys.ADDRESS, signedResult.getFrom()); signedResult.verify(SampleKeys.ADDRESS); assertEquals(chainId, signedResult.getChainId()); }
assertEquals(to, result.getTo()); assertEquals(value, result.getValue()); assertEquals("", result.getData()); assertTrue(result instanceof SignedRawTransaction); SignedRawTransaction signedResult = (SignedRawTransaction) result;
byte[] data = Numeric.hexStringToByteArray(rawTransaction.getData()); result.add(RlpString.create(data));