Search in sources :

Example 1 with ScriptVerificationResultEnum

use of neo.model.ScriptVerificationResultEnum in project neo-java by coranos.

the class TestVm method testTransaction.

private void testTransaction(final long blockHeight, final int txIx) {
    final LocalNodeData localNodeData = CONTROLLER.getLocalNodeData();
    final BlockDb blockDb = localNodeData.getBlockDb();
    final Block block = blockDb.getFullBlockFromHeight(blockHeight);
    final int maxTxIx = block.getTransactionList().size();
    final Transaction tx = block.getTransactionList().get(txIx);
    final long maxIndex = blockDb.getHeaderOfBlockWithMaxIndex().getIndexAsLong();
    LOG.info("STARTED block {} of {} tx {} of {} : {} {}", blockHeight, maxIndex, txIx, maxTxIx, tx.type, tx.getHash());
    final ScriptVerificationResultEnum verifyScriptsResult = VerifyScriptUtil.verifyScripts(blockDb, tx);
    if (!verifyScriptsResult.equals(ScriptVerificationResultEnum.PASS)) {
        LOG.error("FAILURE block {} of {} tx {} of {} : {} {} : {}", blockHeight, maxIndex, txIx, maxTxIx, tx.type, tx.getHash(), verifyScriptsResult);
        throw new RuntimeException("script failed : " + verifyScriptsResult);
    } else {
        LOG.info("SUCCESS block {} of {} tx {} of {} : {} {}", blockHeight, maxIndex, txIx, maxTxIx, tx.type, tx.getHash());
    }
}
Also used : LocalNodeData(neo.network.model.LocalNodeData) Transaction(neo.model.core.Transaction) ScriptVerificationResultEnum(neo.model.ScriptVerificationResultEnum) Block(neo.model.core.Block) BlockDb(neo.model.db.BlockDb)

Example 2 with ScriptVerificationResultEnum

use of neo.model.ScriptVerificationResultEnum in project neo-java by coranos.

the class TestVm method test999Vm.

@Test
public void test999Vm() {
    LOG.info("STARTED vm");
    final LocalNodeData localNodeData = CONTROLLER.getLocalNodeData();
    final BlockDb blockDb = localNodeData.getBlockDb();
    final long maxIndex = blockDb.getHeaderOfBlockWithMaxIndex().getIndexAsLong();
    long startMs = -1;
    for (long blockHeight = 0; blockHeight <= maxIndex; blockHeight++) {
        LOG.info("STARTED block {} of {} ", blockHeight, maxIndex);
        final Block block = blockDb.getFullBlockFromHeight(blockHeight);
        final int maxTxIx = block.getTransactionList().size();
        for (int txIx = 0; txIx < maxTxIx; txIx++) {
            final Transaction tx = block.getTransactionList().get(txIx);
            if (tx.type.equals(TransactionType.ISSUE_TRANSACTION)) {
                LOG.info("SKIPPED block {} of {} tx {} of {} : {}", blockHeight, maxIndex, txIx, maxTxIx, tx.getHash());
            } else {
                LOG.info("STARTED block {} of {} tx {} of {} : {} {}", blockHeight, maxIndex, txIx, maxTxIx, tx.type, tx.getHash());
                final ScriptVerificationResultEnum verifyScriptsResult = VerifyScriptUtil.verifyScripts(blockDb, tx);
                if (!verifyScriptsResult.equals(ScriptVerificationResultEnum.PASS)) {
                    LOG.error("FAILURE block {} of {} tx {} of {} : {} {} : {}", blockHeight, maxIndex, txIx, maxTxIx, tx.type, tx.getHash(), verifyScriptsResult);
                    throw new RuntimeException("script failed : " + tx.type + ":" + verifyScriptsResult);
                } else {
                    LOG.info("SUCCESS block {} of {} tx {} of {} : {} {}", blockHeight, maxIndex, txIx, maxTxIx, tx.type, tx.getHash());
                }
            }
        }
        final Timestamp blockTs = block.getTimestamp();
        if (startMs < 0) {
            startMs = blockTs.getTime();
        }
        final long ms = blockTs.getTime() - startMs;
        if (ms > (86400 * 1000)) {
            final String targetDateStr = DATE_FORMAT.format(blockTs);
            LOG.info("INTERIM vm {} of {}, date {}", INTEGER_FORMAT.format(blockHeight), INTEGER_FORMAT.format(maxIndex), targetDateStr);
            startMs = blockTs.getTime();
        }
    }
    LOG.debug("SUCCESS vm");
}
Also used : LocalNodeData(neo.network.model.LocalNodeData) Transaction(neo.model.core.Transaction) ScriptVerificationResultEnum(neo.model.ScriptVerificationResultEnum) Block(neo.model.core.Block) BlockDb(neo.model.db.BlockDb) Timestamp(java.sql.Timestamp) Test(org.junit.Test)

Aggregations

ScriptVerificationResultEnum (neo.model.ScriptVerificationResultEnum)2 Block (neo.model.core.Block)2 Transaction (neo.model.core.Transaction)2 BlockDb (neo.model.db.BlockDb)2 LocalNodeData (neo.network.model.LocalNodeData)2 Timestamp (java.sql.Timestamp)1 Test (org.junit.Test)1