Search in sources :

Example 66 with DataWord

use of org.ethereum.vm.DataWord in project rskj by rsksmart.

the class RepositoryBlockStore method getChainHead.

@Override
public StoredBlock getChainHead() throws BlockStoreException {
    byte[] ba = repository.getStorageBytes(contractAddress, new DataWord(BLOCK_STORE_CHAIN_HEAD_KEY.getBytes(StandardCharsets.UTF_8)));
    if (ba == null) {
        return null;
    }
    StoredBlock storedBlock = byteArrayToStoredBlock(ba);
    return storedBlock;
}
Also used : DataWord(org.ethereum.vm.DataWord)

Example 67 with DataWord

use of org.ethereum.vm.DataWord in project rskj by rsksmart.

the class RepositoryBlockStore method get.

@Override
public synchronized StoredBlock get(Sha256Hash hash) throws BlockStoreException {
    byte[] ba = repository.getStorageBytes(contractAddress, new DataWord(hash.toString()));
    if (ba == null) {
        return null;
    }
    StoredBlock storedBlock = byteArrayToStoredBlock(ba);
    return storedBlock;
}
Also used : DataWord(org.ethereum.vm.DataWord)

Example 68 with DataWord

use of org.ethereum.vm.DataWord in project rskj by rsksmart.

the class SamplePrecompiledContract method IncrementResult.

public void IncrementResult(Object... args) {
    DataWord keyWord = new DataWord("result".getBytes(StandardCharsets.UTF_8));
    DataWord storedValue = repository.getStorageValue(contractAddress, keyWord);
    int result = (storedValue != null ? storedValue.intValue() : 0) + 1;
    DataWord valWord = new DataWord(result);
    repository.addStorageRow(contractAddress, keyWord, valWord);
}
Also used : DataWord(org.ethereum.vm.DataWord)

Example 69 with DataWord

use of org.ethereum.vm.DataWord in project rskj by rsksmart.

the class SamplePrecompiledContract method Method1.

public int Method1(Object... args) {
    RskAddress addr = new RskAddress("cd2a3d9f938e13cd947ec05abc7fe734df8dd826");
    Coin balance = Coin.valueOf(50000);
    repository.addBalance(addr, balance);
    DataWord keyWord = new DataWord("result".getBytes(StandardCharsets.UTF_8));
    DataWord storedValue = repository.getStorageValue(contractAddress, keyWord);
    int result = (storedValue != null ? storedValue.intValue() : 0) + 1;
    DataWord valWord = new DataWord(result);
    repository.addStorageRow(contractAddress, keyWord, valWord);
    logs.add(new LogInfo(contractAddress.getBytes(), null, null));
    return result;
}
Also used : Coin(co.rsk.core.Coin) LogInfo(org.ethereum.vm.LogInfo) RskAddress(co.rsk.core.RskAddress) DataWord(org.ethereum.vm.DataWord)

Example 70 with DataWord

use of org.ethereum.vm.DataWord in project rskj by rsksmart.

the class BridgeEventLoggerImpl method logCommitFederation.

public void logCommitFederation(Block executionBlock, Federation oldFederation, Federation newFederation) {
    List<DataWord> topics = Collections.singletonList(Bridge.COMMIT_FEDERATION_TOPIC);
    byte[] oldFedFlatPubKeys = flatKeysAsRlpCollection(oldFederation.getPublicKeys());
    byte[] oldFedData = RLP.encodeList(RLP.encodeElement(oldFederation.getAddress().getHash160()), RLP.encodeList(oldFedFlatPubKeys));
    byte[] newFedFlatPubKeys = flatKeysAsRlpCollection(newFederation.getPublicKeys());
    byte[] newFedData = RLP.encodeList(RLP.encodeElement(newFederation.getAddress().getHash160()), RLP.encodeList(newFedFlatPubKeys));
    long newFedActivationBlockNumber = executionBlock.getNumber() + this.bridgeConstants.getFederationActivationAge();
    byte[] data = RLP.encodeList(oldFedData, newFedData, RLP.encodeString(Long.toString(newFedActivationBlockNumber)));
    this.logs.add(new LogInfo(BRIDGE_CONTRACT_ADDRESS, topics, data));
}
Also used : LogInfo(org.ethereum.vm.LogInfo) DataWord(org.ethereum.vm.DataWord)

Aggregations

DataWord (org.ethereum.vm.DataWord)133 Test (org.junit.Test)88 Repository (org.ethereum.core.Repository)41 RskAddress (co.rsk.core.RskAddress)25 TestUtils.randomDataWord (org.ethereum.TestUtils.randomDataWord)22 BigInteger (java.math.BigInteger)19 LogInfo (org.ethereum.vm.LogInfo)17 HashMapDB (org.ethereum.datasource.HashMapDB)14 Program (org.ethereum.vm.program.Program)13 Stack (org.ethereum.vm.program.Stack)12 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)12 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)11 InvocationOnMock (org.mockito.invocation.InvocationOnMock)11 RepositoryImpl (co.rsk.db.RepositoryImpl)9 ContractDetails (org.ethereum.db.ContractDetails)9 Trie (co.rsk.trie.Trie)8 CallTransaction (org.ethereum.core.CallTransaction)8 TrieImpl (co.rsk.trie.TrieImpl)7 TrieStore (co.rsk.trie.TrieStore)7 Coin (co.rsk.core.Coin)5