use of org.aion.util.types.ByteArrayWrapper in project aion by aionnetwork.
the class TransactionStore method putAliasesToBatch.
public void putAliasesToBatch(AionTxInfo txInfo) {
byte[] txHash = txInfo.getReceipt().getTransaction().getTransactionHash();
lock.writeLock().lock();
try {
for (InternalTransaction itx : txInfo.getInternalTransactions()) {
byte[] invokableHash = itx.copyOfInvokableHash();
if (invokableHash != null) {
Set<ByteArrayWrapper> existingAliases = aliasSource.get(invokableHash);
if (existingAliases == null) {
existingAliases = new HashSet<>();
}
existingAliases.add(ByteArrayWrapper.wrap(txHash));
aliasSource.put(invokableHash, existingAliases);
}
}
} finally {
lock.writeLock().unlock();
}
}
use of org.aion.util.types.ByteArrayWrapper in project aion by aionnetwork.
the class Keystore method backupAccount.
public static Map<AionAddress, ByteArrayWrapper> backupAccount(Map<AionAddress, String> account) {
if (account == null) {
throw new NullPointerException();
}
List<File> files = org.aion.util.file.File.getFiles(PATH);
if (files == null) {
if (LOG.isWarnEnabled()) {
LOG.warn("No key file been stored in the kernel.");
}
return new java.util.HashMap<>();
}
List<File> matchedFile = files.parallelStream().filter(file -> account.entrySet().parallelStream().anyMatch(ac -> file.getName().contains(ac.getKey().toString()))).collect(Collectors.toList());
Map<AionAddress, ByteArrayWrapper> res = new HashMap<>();
for (File file : matchedFile) {
try {
String[] frags = file.getName().split("--");
if (frags.length == 3) {
if (frags[2].startsWith(AION_PREFIX)) {
AionAddress addr = AddressUtils.wrapAddress(frags[2]);
byte[] content = Files.readAllBytes(file.toPath());
String pw = account.get(addr);
if (pw != null) {
ECKey key = KeystoreFormat.fromKeystore(content, pw);
if (key != null) {
res.put(addr, ByteArrayWrapper.wrap(content));
}
}
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Wrong address format: {}", frags[2]);
}
}
}
} catch (IOException e) {
LOG.error("backupAccount exception {}", e.toString());
}
}
return res;
}
use of org.aion.util.types.ByteArrayWrapper in project aion by aionnetwork.
the class AionPendingStateImpl method getStorageValue.
@Override
public Optional<ByteArrayWrapper> getStorageValue(AionAddress address, ByteArrayWrapper key) {
Objects.requireNonNull(address);
Objects.requireNonNull(key);
ByteArrayWrapper values = pendingState.getStorageValue(address, key);
return values == null ? Optional.empty() : Optional.of(values);
}
use of org.aion.util.types.ByteArrayWrapper in project aion by aionnetwork.
the class AvmContractDetails method getEncoded.
/**
* Returns an rlp encoding of this AvmContractDetails object.
*
* <p>The encoding is a list of 3 elements:<br>
* { 0:address, 1:storageRoot, 2:code }
*
* @return an rlp encoding of this.
*/
@Override
public byte[] getEncoded() {
byte[] rlpAddress = RLP.encodeElement(address.toByteArray());
byte[] rlpStorageRoot = RLP.encodeElement(computeAvmStorageHash());
byte[][] codesArray = new byte[codes.size()][];
int i = 0;
for (ByteArrayWrapper bytes : codes.values()) {
codesArray[i++] = RLP.encodeElement(bytes.toBytes());
}
byte[] rlpCode = RLP.encodeList(codesArray);
return RLP.encodeList(rlpAddress, rlpStorageRoot, rlpCode);
}
use of org.aion.util.types.ByteArrayWrapper in project aion by aionnetwork.
the class AvmContractDetails method getStorage.
/**
* @throws NullPointerException when any of the given keys are null.
*/
@Override
public Map<ByteArrayWrapper, ByteArrayWrapper> getStorage(Collection<ByteArrayWrapper> keys) {
Objects.requireNonNull(keys, "The keys cannot be null.");
if (keys.contains(null)) {
throw new NullPointerException("The keys cannot be null.");
}
Map<ByteArrayWrapper, ByteArrayWrapper> storage = new HashMap<>();
for (ByteArrayWrapper key : keys) {
ByteArrayWrapper value = get(key);
// cause we keep all historical keys
if (value != null) {
storage.put(key, value);
}
}
return storage;
}
Aggregations