Search in sources :

Example 1 with TransactionType

use of neo.model.core.TransactionType in project neo-java by coranos.

the class TestBlockSerialization method test00ZAllBlocks.

/**
 * pulls all the blocks (slow) to check for full coverage.
 *
 * @throws ClientProtocolException
 *             if an error occurs.
 * @throws IOException
 *             if an error occurs.
 * @throws DecoderException
 *             if an error occurs.
 * @throws InterruptedException
 *             if an error occurs.
 */
@Test
@Ignore
public void test00ZAllBlocks() throws ClientProtocolException, IOException, DecoderException, InterruptedException {
    final BlockDb blockDb = new AbstractJsonMockBlockDb() {

        @Override
        public JSONArray getMockBlockDb() {
            return new JSONArray();
        }
    };
    final long maxBlockIx = blockDb.getHeaderOfBlockWithMaxIndex().getIndexAsLong();
    final Set<TransactionType> knownTypeSet = new TreeSet<>();
    for (long blockIx = 0; blockIx <= maxBlockIx; blockIx++) {
        final Block block = blockDb.getFullBlockFromHeight(blockIx);
        for (int txIx = 0; txIx < block.getTransactionList().size(); txIx++) {
            final Transaction tx = block.getTransactionList().get(txIx);
            if (!knownTypeSet.contains(tx.type)) {
                LOG.error("getBlock {} {} tx {} {}", block.getIndexAsLong(), block.prevHash, txIx, tx.type);
                knownTypeSet.add(tx.type);
            }
        }
    }
    blockDb.close();
}
Also used : TransactionType(neo.model.core.TransactionType) Transaction(neo.model.core.Transaction) TreeSet(java.util.TreeSet) AbstractJsonMockBlockDb(neo.rpc.client.test.util.AbstractJsonMockBlockDb) JSONArray(org.json.JSONArray) Block(neo.model.core.Block) BlockDb(neo.model.db.BlockDb) AbstractJsonMockBlockDb(neo.rpc.client.test.util.AbstractJsonMockBlockDb) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with TransactionType

use of neo.model.core.TransactionType in project neo-java by coranos.

the class LocalControllerNode method getTransactionSystemFeeMap.

/**
 * return the map of system fees to transaction types.
 *
 * @param localJson
 *            the local json to use.
 * @return the map of system fees to transaction types.
 */
private Map<TransactionType, Fixed8> getTransactionSystemFeeMap(final JSONObject localJson) {
    final Map<TransactionType, Fixed8> transactionSystemFeeMap = new EnumMap<>(TransactionType.class);
    final JSONObject transactionSystemFeeJson = localJson.getJSONObject(ConfigurationUtil.SYSTEM_FEE);
    for (final String key : transactionSystemFeeJson.keySet()) {
        final long value = transactionSystemFeeJson.getLong(key);
        final TransactionType txType = TransactionType.valueOf(key);
        transactionSystemFeeMap.put(txType, ModelUtil.getFixed8(BigInteger.valueOf(value)));
    }
    for (final TransactionType txType : TransactionType.values()) {
        if (!transactionSystemFeeMap.containsKey(txType)) {
            LOG.error("TransactionType {} has no SystemFee in the configuration, setting SystemFee to zero", txType);
            transactionSystemFeeMap.put(txType, ModelUtil.FIXED8_ZERO);
        }
    }
    return transactionSystemFeeMap;
}
Also used : TransactionType(neo.model.core.TransactionType) JSONObject(org.json.JSONObject) Fixed8(neo.model.bytes.Fixed8) EnumMap(java.util.EnumMap)

Example 3 with TransactionType

use of neo.model.core.TransactionType in project neo-java by coranos.

the class BlockImportExportUtil method getStats.

/**
 * gets stats.
 *
 * @param blockDb
 *            the block db to use.
 * @param interimBlocks
 *            the interim block count to use.
 * @param interimBytes
 *            the interim byte count to use.
 * @param interimTx
 *            the interim transaction count to use.
 * @param activeAccountSet
 *            the active account set to use.
 * @param procStartMs
 *            start milliseconds.
 * @param blockTs
 *            block timestamp.
 * @param interimTxNetworkFees
 *            the interim transaction network fees to use.
 * @param numBlocksByTxCountMap
 *            the bins of how many transactions were in each block.
 * @return the stats JSON.
 */
public static JSONObject getStats(final BlockDb blockDb, final long interimBlocks, final long interimBytes, final long[] interimTx, final Set<UInt160>[] activeAccountSet, final long procStartMs, final Timestamp blockTs, final long[] interimTxNetworkFees, final Map<String, Long> numBlocksByTxCountMap) {
    final String dateStr = DATE_FORMAT.format(blockTs);
    final JSONObject stats = new JSONObject();
    stats.put(DATE, dateStr);
    final long procMs = System.currentTimeMillis() - procStartMs;
    stats.put(PROCESSING_TIME_MS, procMs);
    final JSONObject active = new JSONObject();
    final Set<UInt160> totalActiveAccountSet = new TreeSet<>();
    for (final TransactionType tType : TransactionType.values()) {
        totalActiveAccountSet.addAll(activeAccountSet[tType.ordinal()]);
        active.put(tType.name().toLowerCase(), activeAccountSet[tType.ordinal()].size());
    }
    active.put(TOTAL, totalActiveAccountSet.size());
    final JSONObject accounts = new JSONObject();
    accounts.put(ACTIVE, active);
    accounts.put(TOTAL, blockDb.getAccountCount());
    stats.put(ACCOUNTS, accounts);
    final JSONObject transactions = new JSONObject();
    for (final TransactionType tType : TransactionType.values()) {
        transactions.put(tType.name().toLowerCase(), interimTx[tType.ordinal()]);
    }
    stats.put(TRANSACTIONS, transactions);
    final JSONObject transactionNetworkFees = new JSONObject();
    for (final TransactionType tType : TransactionType.values()) {
        transactionNetworkFees.put(tType.name().toLowerCase(), interimTxNetworkFees[tType.ordinal()]);
    }
    stats.put(TRANSACTION_NETWORK_FEES, transactionNetworkFees);
    final JSONObject blockBins = new JSONObject();
    for (final String binName : numBlocksByTxCountMap.keySet()) {
        final long numBlocks = numBlocksByTxCountMap.get(binName);
        blockBins.put(binName, numBlocks);
    }
    stats.put(BLOCK_BINS, blockBins);
    stats.put(BLOCKS, interimBlocks);
    stats.put(BYTES, interimBytes);
    return stats;
}
Also used : TransactionType(neo.model.core.TransactionType) JSONObject(org.json.JSONObject) UInt160(neo.model.bytes.UInt160) TreeSet(java.util.TreeSet)

Example 4 with TransactionType

use of neo.model.core.TransactionType in project neo-java by coranos.

the class TestBlockSerialization method assertTransactionTypeEquals.

/**
 * reads in the test json for the given test name, gets the tx at the given
 * index, and verifys that it's transaction type is the expected transaction
 * type.
 *
 * @param testFunctionName
 *            the test function name to use.
 * @param txIx
 *            the transaction index to use.
 * @param expectedTransactionType
 *            the expected transaction type to use.
 */
private void assertTransactionTypeEquals(final String testFunctionName, final int txIx, final TransactionType expectedTransactionType) {
    try {
        final String blockJsonStr = TestUtil.getJsonTestResourceAsString("test", getClass().getSimpleName(), testFunctionName);
        final JSONObject blockJson = new JSONObject(blockJsonStr);
        final String blockStr = TestUtil.fromHexJsonObject(blockJson);
        final byte[] blockBa = Hex.decodeHex(blockStr.toCharArray());
        final Block block = new Block(ByteBuffer.wrap(blockBa));
        final Transaction tx = block.getTransactionList().get(txIx);
        final TransactionType actulaTransactionType = tx.type;
        Assert.assertEquals("transaction types must match", expectedTransactionType, actulaTransactionType);
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : TransactionType(neo.model.core.TransactionType) JSONObject(org.json.JSONObject) Transaction(neo.model.core.Transaction) Block(neo.model.core.Block) ClientProtocolException(org.apache.http.client.ClientProtocolException) DecoderException(org.apache.commons.codec.DecoderException) IOException(java.io.IOException)

Aggregations

TransactionType (neo.model.core.TransactionType)4 JSONObject (org.json.JSONObject)3 TreeSet (java.util.TreeSet)2 Block (neo.model.core.Block)2 Transaction (neo.model.core.Transaction)2 IOException (java.io.IOException)1 EnumMap (java.util.EnumMap)1 Fixed8 (neo.model.bytes.Fixed8)1 UInt160 (neo.model.bytes.UInt160)1 BlockDb (neo.model.db.BlockDb)1 AbstractJsonMockBlockDb (neo.rpc.client.test.util.AbstractJsonMockBlockDb)1 DecoderException (org.apache.commons.codec.DecoderException)1 ClientProtocolException (org.apache.http.client.ClientProtocolException)1 JSONArray (org.json.JSONArray)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1