Search in sources :

Example 66 with LogInfo

use of org.ethereum.vm.LogInfo 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 67 with LogInfo

use of org.ethereum.vm.LogInfo 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)

Example 68 with LogInfo

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

the class SamplePrecompiledContractTest method samplePrecompiledContractMethod1WrongData.

@Test
public void samplePrecompiledContractMethod1WrongData() {
    DataWord addr = new DataWord(PrecompiledContracts.SAMPLE_ADDR.getBytes());
    SamplePrecompiledContract contract = (SamplePrecompiledContract) precompiledContracts.getContractForAddress(addr);
    String funcJson = "{\n" + "   'constant':false, \n" + "   'inputs':[{'name':'param0','type':'int'}, \n" + "               {'name':'param1','type':'bytes'}, \n" + "               {'name':'param2','type':'int'}], \n" + "    'name':'Method1', \n" + "   'outputs':[{'name':'output0','type':'int'}], \n" + "    'type':'function' \n" + "}\n";
    funcJson = funcJson.replaceAll("'", "\"");
    CallTransaction.Function function = CallTransaction.Function.fromJsonInterface(funcJson);
    byte[] data = new byte[] { (byte) 0xab, (byte) 0xcd, (byte) 0xef };
    contract.init(null, null, new RepositoryImpl(config), null, null, new ArrayList<LogInfo>());
    byte[] result = contract.execute(data);
    assertNull(result);
}
Also used : LogInfo(org.ethereum.vm.LogInfo) RepositoryImpl(co.rsk.db.RepositoryImpl) CallTransaction(org.ethereum.core.CallTransaction) DataWord(org.ethereum.vm.DataWord) Test(org.junit.Test)

Example 69 with LogInfo

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

the class SamplePrecompiledContractTest method samplePrecompiledContractMethod1Ok.

@Test
public void samplePrecompiledContractMethod1Ok() {
    DataWord addr = new DataWord(PrecompiledContracts.SAMPLE_ADDR.getBytes());
    SamplePrecompiledContract contract = (SamplePrecompiledContract) precompiledContracts.getContractForAddress(addr);
    String funcJson = "{\n" + "   'constant':false, \n" + "   'inputs':[{'name':'param0','type':'int'}, \n" + "               {'name':'param1','type':'bytes'}, \n" + "               {'name':'param2','type':'int'}], \n" + "    'name':'Method1', \n" + "   'outputs':[{'name':'output0','type':'int'}], \n" + "    'type':'function' \n" + "}\n";
    funcJson = funcJson.replaceAll("'", "\"");
    CallTransaction.Function function = CallTransaction.Function.fromJsonInterface(funcJson);
    byte[] bytes = new byte[] { (byte) 0xab, (byte) 0xcd, (byte) 0xef };
    byte[] data = function.encode(111, bytes, 222);
    contract.init(null, null, new RepositoryImpl(config), null, null, new ArrayList<LogInfo>());
    byte[] result = contract.execute(data);
    Object[] results = function.decodeResult(result);
    assertEquals(new BigInteger("1"), results[0]);
}
Also used : LogInfo(org.ethereum.vm.LogInfo) RepositoryImpl(co.rsk.db.RepositoryImpl) CallTransaction(org.ethereum.core.CallTransaction) BigInteger(java.math.BigInteger) DataWord(org.ethereum.vm.DataWord) Test(org.junit.Test)

Example 70 with LogInfo

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

the class SamplePrecompiledContractTest method samplePrecompiledContractMethod1LargeData.

@Test
public void samplePrecompiledContractMethod1LargeData() {
    DataWord addr = new DataWord(PrecompiledContracts.SAMPLE_ADDR.getBytes());
    SamplePrecompiledContract contract = (SamplePrecompiledContract) precompiledContracts.getContractForAddress(addr);
    String funcJson = "{\n" + "   'constant':false, \n" + "   'inputs':[{'name':'param0','type':'int'}, \n" + "               {'name':'param1','type':'string'}], \n" + "    'name':'Method1', \n" + "   'outputs':[{'name':'output0','type':'int'}], \n" + "    'type':'function' \n" + "}\n";
    funcJson = funcJson.replaceAll("'", "\"");
    CallTransaction.Function function = CallTransaction.Function.fromJsonInterface(funcJson);
    byte[] data = function.encode(111, StringUtils.leftPad("foobar", 1000000, '*'));
    contract.init(null, null, new RepositoryImpl(config), null, null, new ArrayList<LogInfo>());
    byte[] result = contract.execute(data);
    Object[] results = function.decodeResult(result);
    assertEquals(new BigInteger("1"), results[0]);
}
Also used : LogInfo(org.ethereum.vm.LogInfo) RepositoryImpl(co.rsk.db.RepositoryImpl) CallTransaction(org.ethereum.core.CallTransaction) BigInteger(java.math.BigInteger) DataWord(org.ethereum.vm.DataWord) Test(org.junit.Test)

Aggregations

LogInfo (org.ethereum.vm.LogInfo)74 DataWord (org.ethereum.vm.DataWord)36 Test (org.junit.Test)35 ArrayList (java.util.ArrayList)25 CallTransaction (org.ethereum.core.CallTransaction)23 Transaction (org.ethereum.core.Transaction)17 RskAddress (co.rsk.core.RskAddress)13 BridgeEventLoggerImpl (co.rsk.peg.utils.BridgeEventLoggerImpl)12 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)11 InternalTransaction (org.ethereum.vm.program.InternalTransaction)11 Block (org.ethereum.core.Block)9 Repository (org.ethereum.core.Repository)9 RepositoryImpl (co.rsk.db.RepositoryImpl)8 Keccak256 (co.rsk.crypto.Keccak256)7 BigInteger (java.math.BigInteger)7 ActivationConfig (org.ethereum.config.blockchain.upgrades.ActivationConfig)7 RLPList (org.ethereum.util.RLPList)6 LinkedList (java.util.LinkedList)4 RLPElement (org.ethereum.util.RLPElement)4 Coin (co.rsk.core.Coin)3