Get rid of Address.java

This commit is contained in:
romanman 2014-05-22 10:28:16 +03:00
parent 09219f4860
commit 0a4272fc49
7 changed files with 12 additions and 79 deletions

View File

@ -1,64 +0,0 @@
package org.ethereum.core;
import org.ethereum.crypto.ECKey;
import org.ethereum.util.Utils;
import org.spongycastle.util.encoders.Hex;
import java.math.BigInteger;
import java.util.Arrays;
/**
* www.ethereumJ.com
* User: Roman Mandeleil
* Created on: 17/05/14 19:10
*/
public class Address {
byte[] privKey;
byte[] address;
public Address(){
privKey = new BigInteger(130, Utils.getRandom()).toString(32).getBytes();
this.address = ECKey.fromPrivate(privKey).getAddress();
}
public Address(byte[] privKey) {
this.privKey = privKey;
this.address = ECKey.fromPrivate(privKey).getAddress();
}
public Address(byte[] privKey, byte[] address) {
this.privKey = privKey;
this.address = address;
}
public byte[] getPrivKey() {
return privKey;
}
public byte[] getAddress() {
return address;
}
@Override
public String toString() {
return Hex.toHexString(address);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Address address = (Address) o;
if (!Arrays.equals(this.address, address.address)) return false;
return true;
}
@Override
public int hashCode() {
return Arrays.hashCode(address);
}
}

View File

@ -69,7 +69,7 @@ public class ConnectionConsoleWindow extends JFrame implements PeerListener{
Thread t = new Thread() {
public void run() {
// new ClientPeer(thisConsole).connect("54.201.28.117", 30303); // peer discovery
new ClientPeer(thisConsole).connect("54.201.28.117", 30303); // peer discovery
// new ClientPeer(thisConsole).connect("82.217.72.169", 30303); // Nick
@ -77,7 +77,7 @@ public class ConnectionConsoleWindow extends JFrame implements PeerListener{
// new ClientPeer(thisConsole).connect("54.211.14.10", 30303);
// new ClientPeer(thisConsole).connect("54.204.10.41", 30303); // CPP: ZeroGox Poc5
new ClientPeer(thisConsole).connect("54.211.14.10", 40404); // CPP: ver16
// new ClientPeer(thisConsole).connect("54.211.14.10", 40404); // CPP: ver16
// new ClientPeer(thisConsole).connect("192.168.1.102", 30303);
}

View File

@ -1,6 +1,5 @@
package org.ethereum.gui;
import org.ethereum.core.Address;
import org.ethereum.core.Transaction;
import org.ethereum.crypto.HashUtil;
import org.ethereum.manager.MainData;

View File

@ -1,6 +1,5 @@
package org.ethereum.gui;
import org.ethereum.core.Address;
import org.ethereum.util.Utils;
import org.ethereum.wallet.AddressState;
import org.spongycastle.util.encoders.Hex;

View File

@ -1,6 +1,5 @@
package org.ethereum.gui;
import org.ethereum.core.Address;
import org.ethereum.core.Wallet;
import org.ethereum.manager.MainData;
import org.ethereum.wallet.AddressState;

View File

@ -51,7 +51,7 @@ public class TransactionTest {
BigInteger value = new BigInteger("1000000000000000000000");
byte[] privKey = HashUtil.sha3("cat".getBytes());
Address receiveAddress = new Address(privKey);
ECKey ecKey = ECKey.fromPrivate(privKey);
byte[] senderPrivKey = HashUtil.sha3("cow".getBytes());
@ -59,7 +59,7 @@ public class TransactionTest {
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, receiveAddress.getAddress(),
Transaction tx = new Transaction(null, gasPrice, gas, ecKey.getAddress(),
value.toByteArray(),
null);
@ -98,7 +98,7 @@ public class TransactionTest {
byte[] nonce = {01};
byte[] privKey = HashUtil.sha3("cat".getBytes());
Address receiveAddress = new Address(privKey);
ECKey ecKey = ECKey.fromPrivate(privKey);
byte[] senderPrivKey = HashUtil.sha3("cow".getBytes());
@ -106,7 +106,7 @@ public class TransactionTest {
byte[] gas = Hex.decode("4255");
Transaction tx = new Transaction(null, gasPrice, gas,
receiveAddress.getAddress(), value.toByteArray(), null);
ecKey.getAddress(), value.toByteArray(), null);
tx.sign(senderPrivKey);

View File

@ -7,9 +7,9 @@ import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import org.ethereum.core.Address;
import org.ethereum.core.Block;
import org.ethereum.core.Transaction;
import org.ethereum.crypto.ECKey;
import org.ethereum.crypto.HashUtil;
import org.ethereum.net.client.PeerData;
import org.ethereum.net.message.BlocksMessage;
@ -520,16 +520,18 @@ public class MessagesTest {
@Test /* Transactions msg encode */
public void test15() throws Exception {
String expected = "f87312f870808b00d3c21bcecceda10000009479b08ad8787060333663d19704909ee7b1903e588609184e72a000824255801ca00f410a70e42b2c9854a8421d32c87c370a2b9fff0a27f9f031bb4443681d73b5a018a7dc4c4f9dee9f3dc35cb96ca15859aa27e219a8e4a8547be6bd3206979858";
BigInteger value = new BigInteger("1000000000000000000000000");
byte[] privKey = HashUtil.sha3("cat".getBytes());
Address receiveAddress = new Address(privKey);
ECKey ecKey = ECKey.fromPrivate(privKey);
byte[] gasPrice= Hex.decode("09184e72a000");
byte[] gas = Hex.decode("4255");
Transaction tx = new Transaction(null, value.toByteArray(),
receiveAddress.getAddress(), gasPrice, gas, null);
ecKey.getAddress(), gasPrice, gas, null);
tx.sign(privKey);
tx.getEncodedSigned();
@ -538,10 +540,8 @@ public class MessagesTest {
txList.add(tx);
TransactionsMessage transactionsMessage = new TransactionsMessage(txList);
//todo: add assertion to the test whenever you know what should be the result
System.out.println(Hex.toHexString( transactionsMessage.getPayload() ));
assertEquals(expected, Hex.toHexString( transactionsMessage.getPayload()) );
// !!! [ 15:51:24 | eth ] Ignoring invalid transaction: Invalid transaction format: Bad field 1 (8b00d3c21bcecceda1000000)
}
}