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;
}
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));
}
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);
}
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]);
}
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]);
}
Aggregations