Search in sources :

Example 1 with TransactionsMessage

use of org.ethereum.net.eth.message.TransactionsMessage in project rskj by rsksmart.

the class TransactionsMessageTest method test_1.

/* TRANSACTIONS */
@Ignore
@Test
public /* Transactions message 1 */
void test_1() {
    String txsPacketRaw = "f86e12f86b04648609184e72a00094cd2a3d9f938e13cd947ec05abc7fe734df8dd826" + "881bc16d674ec80000801ba05c89ebf2b77eeab88251e553f6f9d53badc1d800" + "bbac02d830801c2aa94a4c9fa00b7907532b1f29c79942b75fff98822293bf5f" + "daa3653a8d9f424c6a3265f06c";
    byte[] payload = Hex.decode(txsPacketRaw);
    TransactionsMessage transactionsMessage = new TransactionsMessage(config, payload);
    System.out.println(transactionsMessage);
    assertEquals(EthMessageCodes.TRANSACTIONS, transactionsMessage.getCommand());
    assertEquals(1, transactionsMessage.getTransactions().size());
    Transaction tx = transactionsMessage.getTransactions().iterator().next();
    assertEquals("5d2aee0490a9228024158433d650335116b4af5a30b8abb10e9b7f9f7e090fd8", tx.getHash().toHexString());
    assertEquals("04", Hex.toHexString(tx.getNonce()));
    assertEquals("1bc16d674ec80000", Hex.toHexString(tx.getValue().getBytes()));
    assertEquals("cd2a3d9f938e13cd947ec05abc7fe734df8dd826", tx.getReceiveAddress().toString());
    assertEquals("64", Hex.toHexString(tx.getGasPrice().getBytes()));
    assertEquals("09184e72a000", Hex.toHexString(tx.getGasLimit()));
    assertEquals("", ByteUtil.toHexString(tx.getData()));
    assertEquals("1b", Hex.toHexString(new byte[] { tx.getSignature().v }));
    assertEquals("5c89ebf2b77eeab88251e553f6f9d53badc1d800bbac02d830801c2aa94a4c9f", Hex.toHexString(tx.getSignature().r.toByteArray()));
    assertEquals("0b7907532b1f29c79942b75fff98822293bf5fdaa3653a8d9f424c6a3265f06c", Hex.toHexString(tx.getSignature().s.toByteArray()));
}
Also used : Transaction(org.ethereum.core.Transaction) TransactionsMessage(org.ethereum.net.eth.message.TransactionsMessage) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with TransactionsMessage

use of org.ethereum.net.eth.message.TransactionsMessage in project rskj by rsksmart.

the class TransactionsMessageTest method test_4.

@Test
public void test_4() {
    String msg = "f872f87083011a6d850ba43b740083015f9094ec210ec3715d5918b37cfa4d344a45d177ed849f881b461c1416b9d000801ba023a3035235ca0a6f80f08a1d4bd760445d5b0f8a25c32678fe18a451a88d6377a0765dde224118bdb40a67f315583d542d93d17d8637302b1da26e1013518d3ae8";
    TransactionsMessage tmsg = new TransactionsMessage(config, Hex.decode(msg));
    assertEquals(1, tmsg.getTransactions().size());
}
Also used : TransactionsMessage(org.ethereum.net.eth.message.TransactionsMessage) Test(org.junit.Test)

Example 3 with TransactionsMessage

use of org.ethereum.net.eth.message.TransactionsMessage in project rskj by rsksmart.

the class TransactionsMessageTest method test_3.

@Test
public /* Transactions msg encode */
void test_3() throws Exception {
    String expected = "f872f870808609184e72a0008242559479b08ad8787060333663d19704909ee7b1903e588b00d3c21bcecceda1000000801ca07c3f47d609d453737ddcf7c403190f67432c41e1f26051296b24e4e10a837083a0375fdb6d3b82dae7e1e78aa7d7413d0bfefeb05341058361d2b5a53d9c8783d6";
    BigInteger value = new BigInteger("1000000000000000000000000");
    byte[] privKey = HashUtil.keccak256("cat".getBytes());
    ECKey ecKey = ECKey.fromPrivate(privKey);
    byte[] gasPrice = Hex.decode("09184e72a000");
    byte[] gasLimit = Hex.decode("4255");
    Transaction tx = new Transaction(null, gasPrice, gasLimit, ecKey.getAddress(), value.toByteArray(), null);
    tx.sign(privKey);
    tx.getEncoded();
    TransactionsMessage transactionsMessage = new TransactionsMessage(config, Collections.singletonList(tx));
    assertEquals(expected, Hex.toHexString(transactionsMessage.getEncoded()));
}
Also used : Transaction(org.ethereum.core.Transaction) TransactionsMessage(org.ethereum.net.eth.message.TransactionsMessage) BigInteger(java.math.BigInteger) ECKey(org.ethereum.crypto.ECKey) Test(org.junit.Test)

Example 4 with TransactionsMessage

use of org.ethereum.net.eth.message.TransactionsMessage in project rskj by rsksmart.

the class RskWireProtocol method sendTransaction.

@Override
public void sendTransaction(List<Transaction> txs) {
    TransactionsMessage msg = new TransactionsMessage(config, txs);
    sendMessage(msg);
}
Also used : TransactionsMessage(org.ethereum.net.eth.message.TransactionsMessage)

Example 5 with TransactionsMessage

use of org.ethereum.net.eth.message.TransactionsMessage in project rskj by rsksmart.

the class P2pHandler method sendTransaction.

/**
 * submit transaction to the network
 *
 * @param tx - fresh transaction object
 */
public void sendTransaction(Transaction tx) {
    TransactionsMessage msg = new TransactionsMessage(config, tx);
    msgQueue.sendMessage(msg);
}
Also used : TransactionsMessage(org.ethereum.net.eth.message.TransactionsMessage)

Aggregations

TransactionsMessage (org.ethereum.net.eth.message.TransactionsMessage)7 Transaction (org.ethereum.core.Transaction)4 Test (org.junit.Test)4 Ignore (org.junit.Ignore)2 AccountBuilder (co.rsk.test.builders.AccountBuilder)1 BigInteger (java.math.BigInteger)1 Account (org.ethereum.core.Account)1 ECKey (org.ethereum.crypto.ECKey)1