use of org.aion.crypto.ECKey in project aion by aionnetwork.
the class Keystore method getKey.
public static ECKey getKey(String _address, String _password) {
if (_address.startsWith("0x")) {
_address = _address.substring(2);
}
ECKey key = null;
List<File> files = getFiles();
for (File file : files) {
if (file.getName().contains(_address)) {
try {
byte[] content = Files.readAllBytes(file.toPath());
key = KeystoreFormat.fromKeystore(content, _password);
} catch (IOException e) {
key = null;
}
break;
}
}
return key;
}
use of org.aion.crypto.ECKey in project aion by aionnetwork.
the class ApiWeb3Aion method eth_sign.
public Object eth_sign(String _address, String _message) {
Address address = Address.wrap(_address);
ECKey key = getAccountKey(address.toString());
if (key == null)
return null;
// Message starts with Unicode Character 'END OF MEDIUM' (U+0019)
String message = "\u0019Aion Signed Message:\n" + _message.length() + _message;
byte[] messageHash = HashUtil.keccak256(message.getBytes());
String signature = TypeConverter.toJsonHex(key.sign(messageHash).getSignature());
return signature;
}
use of org.aion.crypto.ECKey in project aion by aionnetwork.
the class ApiWeb3Aion method eth_sendTransaction.
public Object eth_sendTransaction(JSONObject _tx) {
ArgTxCall txParams = ArgTxCall.fromJSON(_tx, getRecommendedNrgPrice(), getDefaultNrgLimit());
// check for unlocked account
Address address = txParams.getFrom();
ECKey key = getAccountKey(address.toString());
// TODO: send json-rpc error code + message
if (key == null)
return null;
if (txParams != null) {
byte[] response = sendTransaction(txParams);
return TypeConverter.toJsonHex(response);
}
return null;
}
use of org.aion.crypto.ECKey in project aion by aionnetwork.
the class TxnPoolTest method benchmarkSnapshot.
@Test
public /* 100K new transactions in pool around 1200ms (cold-call)
*/
void benchmarkSnapshot() {
Properties config = new Properties();
config.put("txn-timeout", "100");
TxPoolA0<ITransaction> tp = new TxPoolA0<>(config);
List<ITransaction> txnl = new ArrayList<>();
int cnt = 10000;
for (ECKey aKey1 : key) {
Address acc = Address.wrap(aKey1.getAddress());
for (int i = 0; i < cnt; i++) {
ITransaction txn = new AionTransaction(BigInteger.valueOf(i).toByteArray(), acc, Address.wrap("0000000000000000000000000000000000000000000000000000000000000001"), ByteUtils.fromHexString("1"), ByteUtils.fromHexString("1"), 10000L, 1L);
((AionTransaction) txn).sign(aKey1);
txn.setNrgConsume(100L);
txnl.add(txn);
}
}
tp.add(txnl);
assertTrue(tp.size() == cnt * key.size());
// sort the inserted txs
long start = System.currentTimeMillis();
tp.snapshot();
System.out.println("time spent: " + (System.currentTimeMillis() - start) + " ms.");
for (ECKey aKey : key) {
List<BigInteger> nl = tp.getNonceList(Address.wrap(aKey.getAddress()));
for (int i = 0; i < cnt; i++) {
assertTrue(nl.get(i).equals(BigInteger.valueOf(i)));
}
}
}
use of org.aion.crypto.ECKey in project aion by aionnetwork.
the class TxnPoolTest method benchmarkSnapshot3.
@Test
public /* 1M new transactions with 10000 accounts (100 txs per account)in pool snapshot around 10s (cold-call)
gen new txns 55s (spent a lot of time to sign tx)
put txns into pool 2.5s
snapshot txn 5s
*/
void benchmarkSnapshot3() {
Properties config = new Properties();
config.put("txn-timeout", "100");
TxPoolA0<ITransaction> tp = new TxPoolA0<>(config);
List<ITransaction> txnl = new ArrayList<>();
int cnt = 100;
System.out.println("Gen new transactions --");
long start = System.currentTimeMillis();
for (ECKey aKey21 : key2) {
Address acc = Address.wrap(aKey21.getAddress());
for (int i = 0; i < cnt; i++) {
ITransaction txn = new AionTransaction(BigInteger.valueOf(i).toByteArray(), acc, Address.wrap("0000000000000000000000000000000000000000000000000000000000000001"), ByteUtils.fromHexString("1"), ByteUtils.fromHexString("1"), 10000L, 1L);
((AionTransaction) txn).sign(aKey21);
txn.setNrgConsume(100L);
txnl.add(txn);
}
}
System.out.println("time spent: " + (System.currentTimeMillis() - start) + " ms.");
System.out.println("Adding transactions into pool--");
start = System.currentTimeMillis();
tp.add(txnl);
System.out.println("time spent: " + (System.currentTimeMillis() - start) + " ms.");
assertTrue(tp.size() == cnt * key2.size());
// sort the inserted txs
System.out.println("Snapshoting --");
start = System.currentTimeMillis();
tp.snapshot();
System.out.println("time spent: " + (System.currentTimeMillis() - start) + " ms.");
for (ECKey aKey2 : key2) {
List<BigInteger> nl = tp.getNonceList(Address.wrap(aKey2.getAddress()));
for (int i = 0; i < cnt; i++) {
assertTrue(nl.get(i).equals(BigInteger.valueOf(i)));
}
}
}
Aggregations