Search in sources :

Example 16 with LogInfo

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

the class ReceiptStoreImplFallbackTest method createReceipt.

// from TransactionTest
private static TransactionReceipt createReceipt() {
    byte[] stateRoot = Hex.decode("f5ff3fbd159773816a7c707a9b8cb6bb778b934a8f6466c7830ed970498f4b68");
    byte[] gasUsed = Hex.decode("01E848");
    Bloom bloom = new Bloom(Hex.decode("0000000000000000800000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"));
    LogInfo logInfo1 = new LogInfo(Hex.decode("cd2a3d9f938e13cd947ec05abc7fe734df8dd826"), null, Hex.decode("a1a1a1"));
    List<LogInfo> logs = new ArrayList<>();
    logs.add(logInfo1);
    // TODO calculate cumulative gas
    TransactionReceipt receipt = new TransactionReceipt(stateRoot, gasUsed, gasUsed, bloom, logs, new byte[] { 0x01 });
    receipt.setTransaction(Transaction.builder().build());
    return receipt;
}
Also used : LogInfo(org.ethereum.vm.LogInfo) Bloom(org.ethereum.core.Bloom) ArrayList(java.util.ArrayList) TransactionReceipt(org.ethereum.core.TransactionReceipt)

Example 17 with LogInfo

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

the class ReceiptStoreImplTest method createReceipt.

// from TransactionTest
private static TransactionReceipt createReceipt(int numOfLogs) {
    byte[] stateRoot = Hex.decode("f5ff3fbd159773816a7c707a9b8cb6bb778b934a8f6466c7830ed970498f4b68");
    byte[] gasUsed = Hex.decode("01E848");
    Bloom bloom = new Bloom(Hex.decode("0000000000000000800000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"));
    List<LogInfo> logs = new ArrayList<>();
    for (int i = 0; i < numOfLogs; i++) {
        LogInfo logInfo = new LogInfo(Hex.decode("cd2a3d9f938e13cd947ec05abc7fe734df8dd826"), null, Hex.decode("a1a1a1"));
        logs.add(logInfo);
    }
    // TODO calculate cumulative gas
    TransactionReceipt receipt = new TransactionReceipt(stateRoot, gasUsed, gasUsed, bloom, logs, new byte[] { 0x01 });
    receipt.setTransaction(Transaction.builder().build());
    return receipt;
}
Also used : LogInfo(org.ethereum.vm.LogInfo) Bloom(org.ethereum.core.Bloom) ArrayList(java.util.ArrayList) TransactionReceipt(org.ethereum.core.TransactionReceipt)

Example 18 with LogInfo

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

the class LogsValidator method valid.

public static List<String> valid(List<LogInfo> origLogs, List<LogInfo> postLogs, ValidationStats vStats) {
    List<String> results = new ArrayList<>();
    int i = 0;
    for (LogInfo postLog : postLogs) {
        if (vStats != null)
            vStats.logChecks++;
        if (origLogs == null || origLogs.size() - 1 < i) {
            String formattedString = String.format("Log: %s: was expected but doesn't exist: address: %s", i, ByteUtil.toHexString(postLog.getAddress()));
            results.add(formattedString);
            continue;
        }
        LogInfo realLog = origLogs.get(i);
        String postAddress = ByteUtil.toHexString(postLog.getAddress());
        String realAddress = ByteUtil.toHexString(realLog.getAddress());
        if (vStats != null)
            vStats.logChecks++;
        if (!postAddress.equals(realAddress)) {
            String formattedString = String.format("Log: %s: has unexpected address, expected address: %s found address: %s", i, postAddress, realAddress);
            results.add(formattedString);
        }
        String postData = ByteUtil.toHexString(postLog.getData());
        String realData = ByteUtil.toHexString(realLog.getData());
        if (vStats != null)
            vStats.logChecks++;
        if (!postData.equals(realData)) {
            String formattedString = String.format("Log: %s: has unexpected data, expected data: %s found data: %s", i, postData, realData);
            results.add(formattedString);
        }
        String postBloom = ByteUtil.toHexString(postLog.getBloom().getData());
        String realBloom = ByteUtil.toHexString(realLog.getBloom().getData());
        if (vStats != null)
            vStats.logChecks++;
        if (!postData.equals(realData)) {
            String formattedString = String.format("Log: %s: has unexpected bloom, expected bloom: %s found bloom: %s", i, postBloom, realBloom);
            results.add(formattedString);
        }
        List<DataWord> postTopics = postLog.getTopics();
        List<DataWord> realTopics = realLog.getTopics();
        int j = 0;
        for (DataWord postTopic : postTopics) {
            DataWord realTopic = realTopics.get(j);
            if (vStats != null)
                vStats.logChecks++;
            if (!postTopic.equals(realTopic)) {
                String formattedString = String.format("Log: %s: has unexpected topic: %s, expected topic: %s found topic: %s", i, j, postTopic, realTopic);
                results.add(formattedString);
            }
            ++j;
        }
        ++i;
    }
    return results;
}
Also used : LogInfo(org.ethereum.vm.LogInfo) ArrayList(java.util.ArrayList) DataWord(org.ethereum.vm.DataWord)

Example 19 with LogInfo

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

the class BridgeEventLoggerImpl method logUnrefundablePegin.

public void logUnrefundablePegin(BtcTransaction btcTx, UnrefundablePeginReason reason) {
    CallTransaction.Function event = BridgeEvents.UNREFUNDABLE_PEGIN.getEvent();
    byte[][] encodedTopicsInBytes = event.encodeEventTopics(btcTx.getHash().getBytes());
    List<DataWord> encodedTopics = LogInfo.byteArrayToList(encodedTopicsInBytes);
    byte[] encodedData = event.encodeEventData(reason.getValue());
    this.logs.add(new LogInfo(BRIDGE_CONTRACT_ADDRESS, encodedTopics, encodedData));
}
Also used : LogInfo(org.ethereum.vm.LogInfo) CallTransaction(org.ethereum.core.CallTransaction) DataWord(org.ethereum.vm.DataWord)

Example 20 with LogInfo

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

the class BridgeEventLoggerImpl method logCommitFederationInRLPFormat.

private void logCommitFederationInRLPFormat(Block executionBlock, Federation oldFederation, Federation newFederation) {
    List<DataWord> topics = Collections.singletonList(Bridge.COMMIT_FEDERATION_TOPIC);
    byte[] oldFedFlatPubKeys = flatKeysAsRlpCollection(oldFederation.getBtcPublicKeys());
    byte[] oldFedData = RLP.encodeList(RLP.encodeElement(oldFederation.getAddress().getHash160()), RLP.encodeList(oldFedFlatPubKeys));
    byte[] newFedFlatPubKeys = flatKeysAsRlpCollection(newFederation.getBtcPublicKeys());
    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

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