use of org.aion.util.types.ByteArrayWrapper in project aion by aionnetwork.
the class ExternalStateForFvm method getStorageValue.
/**
* Returns the value in the key-value pairing associated with the given address and key, or
* {@code null} if no such pairing exists.
*
* @param address The account address.
* @param key The key.
* @return the value.
*/
@Override
public FvmDataWord getStorageValue(AionAddress address, FvmDataWord key) {
ByteArrayWrapper storageKey = ByteArrayWrapper.wrap(key.copyOfData());
ByteArrayWrapper value = this.repository.getStorageValue(address, storageKey);
if (value != null && (value.isZero() || value.isEmpty())) {
// used to ensure FVM correctness
throw new IllegalStateException("A zero or empty value was retrieved from storage. Storing zeros is not allowed by the FVM. An incorrect put was previously performed instead of an explicit call to the delete method.");
}
return (value == null) ? FvmDataWord.fromBytes(new byte[FvmDataWord.SIZE]) : FvmDataWord.fromBytes(value.toBytes());
}
use of org.aion.util.types.ByteArrayWrapper in project aion by aionnetwork.
the class ExternalStateForFvm method removeStorage.
/**
* Removes the provided key from the storage associated with the given address, if that key
* exists.
*
* @param address The account address.
* @param key The key.
*/
@Override
public void removeStorage(AionAddress address, FvmDataWord key) {
ByteArrayWrapper storageKey = ByteArrayWrapper.wrap(key.copyOfData());
this.repository.removeStorageRow(address, storageKey);
setVmType(address);
}
use of org.aion.util.types.ByteArrayWrapper in project aion by aionnetwork.
the class ExternalStateForFvm method addStorageValue.
/**
* Adds the provided key-value pairing to the world state, associating it only with the given
* address.
*
* <p>If the given address already has a key-value pairing whose key is the same as the given
* key, then the given value will overwrite whatever value is currently paired with that key.
*
* @param address The account address.
* @param key The key.
* @param value The value.
*/
@Override
public void addStorageValue(AionAddress address, FvmDataWord key, FvmDataWord value) {
byte[] valueBytes = value.copyOfData();
if (valueBytes == null || valueBytes.length == 0) {
// used to ensure FVM correctness
throw new IllegalArgumentException("Put with null, empty or zero byte array values is not allowed for the FVM. For deletions, make explicit calls to the delete method.");
}
ByteArrayWrapper storageKey = ByteArrayWrapper.wrap(key.copyOfData());
ByteArrayWrapper storageValue = alignValueToWordSizeForPut(valueBytes);
if (storageValue.isZero()) {
// used to ensure FVM correctness
throw new IllegalArgumentException("Put with null, empty or zero byte array values is not allowed for the FVM. For deletions, make explicit calls to the delete method.");
}
this.repository.addStorageRow(address, storageKey, storageValue);
setVmType(address);
}
use of org.aion.util.types.ByteArrayWrapper in project aion by aionnetwork.
the class KeystoreTest method testAccountBackup.
@Test
public void testAccountBackup() {
String password = randomPassword();
ECKey key = ECKeyFac.inst().create();
assertNotNull(key);
String addr = Keystore.create(password, key);
assertEquals(addr.substring(2), ByteUtil.toHexString(key.getAddress()));
Map<AionAddress, String> arg = new HashMap<>();
arg.put(AddressUtils.wrapAddress(addr), password);
Map<AionAddress, ByteArrayWrapper> export = Keystore.backupAccount(arg);
assertNotNull(export);
File f = Keystore.getAccountFile(addr.substring(2), password);
assertNotNull(f);
assertTrue(export.containsKey(AddressUtils.wrapAddress(addr)));
try {
assertTrue(export.containsValue(ByteArrayWrapper.wrap(Files.readAllBytes(f.toPath()))));
} catch (IOException e) {
e.printStackTrace();
}
filesToRemove.add(addr);
}
use of org.aion.util.types.ByteArrayWrapper in project aion by aionnetwork.
the class KeystoreTest method testAccountExport.
@Test
public void testAccountExport() {
String password = randomPassword();
ECKey key = ECKeyFac.inst().create();
assertNotNull(key);
String addr = Keystore.create(password, key);
assertEquals(addr.substring(2), ByteUtil.toHexString(key.getAddress()));
Map<AionAddress, String> arg = new HashMap<>();
arg.put(AddressUtils.wrapAddress(addr), password);
Map<AionAddress, ByteArrayWrapper> export = Keystore.exportAccount(arg);
assertTrue(export.containsKey(AddressUtils.wrapAddress(addr)));
assertTrue(export.containsValue(ByteArrayWrapper.wrap(key.getPrivKeyBytes())));
filesToRemove.add(addr);
}
Aggregations