Esempio n. 1
0
 @Override
 public void setSender(ECKey senderPrivateKey) {
   txSender = senderPrivateKey;
   if (!getBlockchain().getRepository().isExist(senderPrivateKey.getAddress())) {
     Repository repository = getBlockchain().getRepository();
     Repository track = repository.startTracking();
     track.createAccount(senderPrivateKey.getAddress());
     track.commit();
   }
 }
Esempio n. 2
0
 public byte[] getSender() {
   try {
     if (sendAddress == null) {
       ECKey key = ECKey.signatureToKey(getRawHash(), getSignature().toBase64());
       sendAddress = key.getAddress();
     }
     return sendAddress;
   } catch (SignatureException e) {
     logger.error(e.getMessage(), e);
   }
   return null;
 }
Esempio n. 3
0
 @Test
 public void test3() {
   BigInteger privKey =
       new BigInteger("cd244b3015703ddf545595da06ada5516628c5feadbf49dc66049c4b370cc5d8", 16);
   byte[] addr = ECKey.fromPrivate(privKey).getAddress();
   assertEquals("89b44e4d3c81ede05d0f5de8d1a68f754d73d997", Hex.toHexString(addr));
 }
Esempio n. 4
0
 @Test
 public void test10() {
   BigInteger privKey =
       new BigInteger("74ef8a796480dda87b4bc550b94c408ad386af0f65926a392136286784d63858", 16);
   byte[] addr = ECKey.fromPrivate(privKey).getAddress();
   assertEquals("ba73facb4f8291f09f27f90fe1213537b910065e", Hex.toHexString(addr));
 }
Esempio n. 5
0
 public StandaloneBlockchain() {
   withGenesis(
       GenesisLoader.loadGenesis(getClass().getResourceAsStream("/genesis/genesis-light.json")));
   withGasPrice(50_000_000_000L);
   withGasLimit(5_000_000L);
   withMinerCoinbase(Hex.decode("ffffffffffffffffffffffffffffffffffffffff"));
   setSender(
       ECKey.fromPrivate(
           Hex.decode("3ec771c31cac8c0dba77a69e503765701d3c2bb62435888d4ffa38fed60c445c")));
   //        withAccountBalance(txSender.getAddress(), new
   // BigInteger("100000000000000000000000000"));
 }
Esempio n. 6
0
  @Test /* performance test */
  public void test6() {

    long firstTime = System.currentTimeMillis();
    System.out.println(firstTime);
    for (int i = 0; i < 1000; ++i) {

      byte[] horseBytes = HashUtil.sha3("horse".getBytes());
      byte[] addr = ECKey.fromPrivate(horseBytes).getAddress();
      assertEquals("13978AEE95F38490E9769C39B2773ED763D9CD5F", Hex.toHexString(addr).toUpperCase());
    }
    long secondTime = System.currentTimeMillis();
    System.out.println(secondTime);
    System.out.println(secondTime - firstTime + " millisec");
    // 1) result: ~52 address calculation every second
  }
Esempio n. 7
0
 public void sign(byte[] privKeyBytes) throws MissingPrivateKeyException {
   byte[] hash = this.getRawHash();
   ECKey key = ECKey.fromPrivate(privKeyBytes).decompress();
   this.signature = key.sign(hash);
   this.rlpEncoded = null;
 }
Esempio n. 8
0
 public ECKey getKey() {
   byte[] hash = getRawHash();
   return ECKey.recoverFromSignature(signature.v, signature, hash, true);
 }
Esempio n. 9
0
 @Test
 public void test5() {
   byte[] horseBytes = HashUtil.sha3("horse".getBytes());
   byte[] addr = ECKey.fromPrivate(horseBytes).getAddress();
   assertEquals("13978AEE95F38490E9769C39B2773ED763D9CD5F", Hex.toHexString(addr).toUpperCase());
 }
Esempio n. 10
0
 @Test
 public void test4() {
   byte[] cowBytes = HashUtil.sha3("cow".getBytes());
   byte[] addr = ECKey.fromPrivate(cowBytes).getAddress();
   assertEquals("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826", Hex.toHexString(addr).toUpperCase());
 }