Package org.ethereum.core

Examples of org.ethereum.core.Transaction


    @Test
    public void testVerifySignature3() throws SignatureException {

        byte[] rawtx = Hex.decode("f86e80893635c9adc5dea000008609184e72a00082109f9479b08ad8787060333663d19704909ee7b1903e58801ba0899b92d0c76cbf18df24394996beef19c050baa9823b4a9828cd9b260c97112ea0c9e62eb4cf0a9d95ca35c8830afac567619d6b3ebee841a3c8be61d35acd8049");

        Transaction tx = new Transaction(rawtx);
        ECKey key = ECKey.signatureToKey(HashUtil.sha3(rawtx), tx.getSignature().toBase64());

        System.out.println("Signature public key\t: " + Hex.toHexString(key.getPubKey()));
        System.out.println("Sender is\t\t: " + Hex.toHexString(key.getAddress()));

        //  sender: CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826
View Full Code Here


      assertEquals("14a569d327dcda4b29f74f93c0e9729d2f49ad726e703f9cd90dbb0fbf6649f1", Hex.toHexString(BigIntegers.asUnsignedByteArray(txUnsigned.getSignature().s)));
  }
 
  @Test
  public void testTransactionFromNew1() throws MissingPrivateKeyException {
      Transaction txNew = new Transaction(testNonce, testGasPrice, testGasLimit, testReceiveAddress, testValue, testData);
     
      assertEquals("", Hex.toHexString(txNew.getNonce()));
      assertEquals(new BigInteger(1, testGasPrice), new BigInteger(1, txNew.getGasPrice()));
      assertEquals(new BigInteger(1, testGasLimit), new BigInteger(1, txNew.getGasLimit()));
      assertEquals(Hex.toHexString(testReceiveAddress), Hex.toHexString(txNew.getReceiveAddress()));
      assertEquals(new BigInteger(1, testValue), new BigInteger(1, txNew.getValue()));
      assertEquals("", Hex.toHexString(txNew.getData()));
      assertNull(txNew.getSignature());
     
      assertEquals(RLP_ENCODED_RAW_TX, Hex.toHexString(txNew.getEncodedRaw()));
      assertEquals(HASH_TX, Hex.toHexString(txNew.getHash()));
      assertEquals(RLP_ENCODED_UNSIGNED_TX, Hex.toHexString(txNew.getEncoded()));
      txNew.sign(Hex.decode(KEY));
      assertEquals(RLP_ENCODED_SIGNED_TX, Hex.toHexString(txNew.getEncoded()));    
     
      assertEquals(27, txNew.getSignature().v);
      assertEquals("eab47c1a49bf2fe5d40e01d313900e19ca485867d462fe06e139e3a536c6d4f4", Hex.toHexString(BigIntegers.asUnsignedByteArray(txNew.getSignature().r)));
      assertEquals("14a569d327dcda4b29f74f93c0e9729d2f49ad726e703f9cd90dbb0fbf6649f1", Hex.toHexString(BigIntegers.asUnsignedByteArray(txNew.getSignature().s)));
  }
View Full Code Here

    byte[] gas        = Hex.decode("2710");      // 10000
    byte[] recieveAddress  = Hex.decode("13978aee95f38490e9769c39b2773ed763d9cd5f");
    byte[] value      = Hex.decode("2386f26fc10000"); //10000000000000000"
    byte[] data       = new byte[0];
   
      Transaction tx = new Transaction(nonce, gasPrice, gas, recieveAddress, value, data);
           
      // Testing unsigned
      String encodedUnsigned = Hex.toHexString(tx.getEncoded());
        assertEquals(RLP_TX_UNSIGNED, encodedUnsigned);
        assertEquals(HASH_TX_UNSIGNED, Hex.toHexString(tx.getHash()));

        // Testing signed
        tx.sign(privKeyBytes);
        String encodedSigned = Hex.toHexString(tx.getEncoded());      
        assertEquals(RLP_TX_SIGNED, encodedSigned);
        assertEquals(HASH_TX_UNSIGNED, Hex.toHexString(tx.getHash()));
  }
View Full Code Here

        byte[] recieveAddress  = null;
        byte[] endowment       = Hex.decode("03e8"); //10000000000000000"
        byte[] init       = Hex.decode("4560005444602054600f60056002600a02010b0d630000001d596002602054630000003b5860066000530860056006600202010a0d6300000036596004604054630000003b586005606054");


        Transaction tx1 = new Transaction(nonce, gasPrice, gas,
                recieveAddress, endowment, init);
        tx1.sign(senderPrivKey);

        byte[] payload = tx1.getEncoded();


        System.out.println(Hex.toHexString(payload));
        Transaction tx2 = new Transaction(payload);
//        tx2.getSender();

        String plainTx1 = Hex.toHexString(tx1.getEncodedRaw());
        String plainTx2 = Hex.toHexString(tx2.getEncodedRaw());

//        Transaction tx = new Transaction(Hex.decode(rlp));

        System.out.println("tx1.hash: " + Hex.toHexString(tx1.getHash()));
        System.out.println("tx2.hash: " + Hex.toHexString(tx2.getHash()));
        System.out.println();
        System.out.println("plainTx1: " + plainTx1 );
        System.out.println("plainTx2: " + plainTx2 );

        System.out.println( Hex.toHexString(tx2.getSender()));
    }
View Full Code Here

    RLPList paramsList = (RLPList) RLP.decode2(encoded).get(0);

    transactions = new HashSet<>();
        for (int i = 1; i < paramsList.size(); ++i) {
            RLPList rlpTxData = (RLPList) paramsList.get(i);
            Transaction tx = new Transaction(rlpTxData.getRLPData());
            transactions.add(tx);
        }
        parsed = true;
    }
View Full Code Here

    @Test  // right way to calc tx trie hash
    public void testCalculatePostTxState() {

        /*    txTrieHash */
        String expected = "a77691cf47bec9021d3f027fc8ef2d51b758b600a79967154354b8e37108896f";
        Transaction tx = new Transaction(
                new byte[]{},
                Hex.decode("09184E72A000"),
                Hex.decode("03E8"),
                Hex.decode("0000000000000000000000000000000000000000"),
                Hex.decode("03e8"),
                Hex.decode("60016000546006601160003960066000f261778e600054")
        );
        byte[] cowPrivKey = Hex.decode("c85ef7d79691fe79573b1a7064c19c1a9819ebdbd1faaab1a8ec92344438aaf4");
        tx.sign(cowPrivKey);

        byte[] postTxState = Hex.decode("7fa5bd00f6e03b5a5718560f1e25179b227167585a3c3da06a48f554365fb527");
        byte[] cumGas      = Hex.decode("0272");

        TransactionReceipt tr = new TransactionReceipt(tx, postTxState, cumGas);
View Full Code Here

        Wallet wallet = new Wallet();
        wallet.setWorldManager(worldManager);

        wallet.importKey(cowKey.getPrivKeyBytes());

        Transaction tx = new Transaction(
                new byte[]{},
                Hex.decode("09184E72A000"),
                Hex.decode("03E8"),
                cowKey.getAddress(),
                Hex.decode("0A"),
                new byte[]{}
        );

        ECKey catKey = ECKey.fromPrivate(HashUtil.sha3("cat".getBytes()));
        tx.sign(catKey.getPrivKeyBytes());

        wallet.applyTransaction(tx);

        BigInteger walletBalance = wallet.getBalance(cowKey.getAddress());
        Assert.assertEquals(BigInteger.valueOf(20), walletBalance);
View Full Code Here

        byte[] gasPrice=  Hex.decode("09184e72a000");
        byte[] gas =      Hex.decode("4255");

        // Tn (nonce); Tp(pgas); Tg(gaslimi); Tt(value); Tv(value); Ti(sender);  Tw; Tr; Ts
        Transaction tx = new Transaction(null, gasPrice, gas, ecKey.getAddress(),
                value.toByteArray(),
                   null);

        tx.sign(senderPrivKey);

        System.out.println("v\t\t\t: " + Hex.toHexString(new byte[] { tx.getSignature().v }));
        System.out.println("r\t\t\t: " + Hex.toHexString(BigIntegers.asUnsignedByteArray(tx.getSignature().r)));
        System.out.println("s\t\t\t: " + Hex.toHexString(BigIntegers.asUnsignedByteArray(tx.getSignature().s)));

        System.out.println("RLP encoded tx\t\t: " + Hex.toHexString(tx.getEncoded()));

        // retrieve the signer/sender of the transaction
        ECKey key = ECKey.signatureToKey(tx.getHash(), tx.getSignature().toBase64());

        System.out.println("Tx unsigned RLP\t\t: " + Hex.toHexString(tx.getEncodedRaw()));
        System.out.println("Tx signed   RLP\t\t: " + Hex.toHexString(tx.getEncoded()));

        System.out.println("Signature public key\t: " + Hex.toHexString(key.getPubKey()));
        System.out.println("Sender is\t\t: " + Hex.toHexString(key.getAddress()));

        Assert.assertEquals("cd2a3d9f938e13cd947ec05abc7fe734df8dd826",
                Hex.toHexString(key.getAddress()));

        System.out.println(tx.toString());
    }
View Full Code Here

    byte[] nonce = { 0x01 };
    byte[] gasPrice = Hex.decode("09184e72a000");
    byte[] gasLimit = Hex.decode("4255");
        BigInteger value = new BigInteger("1000000000000000000000000");

    Transaction tx = new Transaction(nonce, gasPrice, gasLimit,
        ecKey.getAddress(), value.toByteArray(), null);

        tx.sign(senderPrivKey);

        System.out.println("v\t\t\t: " + Hex.toHexString(new byte[] { tx.getSignature().v }));
        System.out.println("r\t\t\t: " + Hex.toHexString(BigIntegers.asUnsignedByteArray(tx.getSignature().r)));
        System.out.println("s\t\t\t: " + Hex.toHexString(BigIntegers.asUnsignedByteArray(tx.getSignature().s)));

        System.out.println("RLP encoded tx\t\t: " + Hex.toHexString(tx.getEncoded()));

        // retrieve the signer/sender of the transaction
        ECKey key = ECKey.signatureToKey(tx.getHash(), tx.getSignature().toBase64());

        System.out.println("Tx unsigned RLP\t\t: " + Hex.toHexString(tx.getEncodedRaw()));
        System.out.println("Tx signed   RLP\t\t: " + Hex.toHexString(tx.getEncoded()));

        System.out.println("Signature public key\t: " + Hex.toHexString(key.getPubKey()));
        System.out.println("Sender is\t\t: " + Hex.toHexString(key.getAddress()));

        Assert.assertEquals("cd2a3d9f938e13cd947ec05abc7fe734df8dd826",
View Full Code Here

TOP

Related Classes of org.ethereum.core.Transaction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.