Search in sources :

Example 66 with ByteArrayWrapper

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();
    }
}
Also used : ByteArrayWrapper(org.aion.util.types.ByteArrayWrapper) InternalTransaction(org.aion.types.InternalTransaction)

Example 67 with ByteArrayWrapper

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;
}
Also used : Date(java.util.Date) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ByteArrayWrapper(org.aion.util.types.ByteArrayWrapper) PosixFilePermissions(java.nio.file.attribute.PosixFilePermissions) AddressUtils(org.aion.util.types.AddressUtils) Map(java.util.Map) AionAddress(org.aion.types.AionAddress) Path(java.nio.file.Path) DateFormat(java.text.DateFormat) AionLoggerFactory(org.aion.log.AionLoggerFactory) PosixFilePermission(java.nio.file.attribute.PosixFilePermission) ECKeyFac(org.aion.crypto.ECKeyFac) Hex(org.aion.util.conversions.Hex) Logger(org.slf4j.Logger) Files(java.nio.file.Files) TimeZone(java.util.TimeZone) FileOutputStream(java.io.FileOutputStream) Set(java.util.Set) IOException(java.io.IOException) FileAttribute(java.nio.file.attribute.FileAttribute) ByteUtil(org.aion.util.bytes.ByteUtil) Collectors(java.util.stream.Collectors) File(java.io.File) List(java.util.List) LogEnum(org.aion.log.LogEnum) StringUtils(org.aion.util.string.StringUtils) Paths(java.nio.file.Paths) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) ECKey(org.aion.crypto.ECKey) AionAddress(org.aion.types.AionAddress) HashMap(java.util.HashMap) ECKey(org.aion.crypto.ECKey) IOException(java.io.IOException) ByteArrayWrapper(org.aion.util.types.ByteArrayWrapper) File(java.io.File)

Example 68 with ByteArrayWrapper

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);
}
Also used : ByteArrayWrapper(org.aion.util.types.ByteArrayWrapper)

Example 69 with ByteArrayWrapper

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);
}
Also used : ByteArrayWrapper(org.aion.util.types.ByteArrayWrapper)

Example 70 with ByteArrayWrapper

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;
}
Also used : ByteArrayWrapper(org.aion.util.types.ByteArrayWrapper) HashMap(java.util.HashMap)

Aggregations

ByteArrayWrapper (org.aion.util.types.ByteArrayWrapper)130 Test (org.junit.Test)51 HashMap (java.util.HashMap)39 ArrayList (java.util.ArrayList)33 AionAddress (org.aion.types.AionAddress)26 Block (org.aion.zero.impl.types.Block)24 Map (java.util.Map)20 BigInteger (java.math.BigInteger)14 MiningBlock (org.aion.zero.impl.types.MiningBlock)14 IOException (java.io.IOException)13 MockDB (org.aion.db.impl.mockdb.MockDB)13 DataWord (org.aion.util.types.DataWord)13 PooledTransaction (org.aion.base.PooledTransaction)11 List (java.util.List)10 AionTransaction (org.aion.base.AionTransaction)10 Properties (java.util.Properties)8 HashSet (java.util.HashSet)5 Optional (java.util.Optional)5 ECKey (org.aion.crypto.ECKey)5 RLPElement (org.aion.rlp.RLPElement)5