Search in sources :

Example 6 with UInt160

use of neo.model.bytes.UInt160 in project neo-java by coranos.

the class BlockDbH2Impl method getAccountAssetValueMap.

@Override
public Map<UInt160, Map<UInt256, Fixed8>> getAccountAssetValueMap() {
    final JdbcTemplate jdbcOperations = new JdbcTemplate(ds);
    final String sql = getSql("getAccountAssetValueMap");
    final List<Map<String, Object>> mapList = jdbcOperations.queryForList(sql);
    final Map<UInt160, Map<UInt256, Fixed8>> accountAssetValueMap = new TreeMap<>();
    final TransactionOutputMapToObject mapToObject = new TransactionOutputMapToObject();
    for (final Map<String, Object> map : mapList) {
        final TransactionOutput output = mapToObject.toObject(map);
        if (!accountAssetValueMap.containsKey(output.scriptHash)) {
            accountAssetValueMap.put(output.scriptHash, new TreeMap<>());
        }
        final Map<UInt256, Fixed8> assetValueMap = accountAssetValueMap.get(output.scriptHash);
        assetValueMap.put(output.assetId, output.value);
    }
    return accountAssetValueMap;
}
Also used : TransactionOutput(neo.model.core.TransactionOutput) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) TreeMap(java.util.TreeMap) UInt160(neo.model.bytes.UInt160) Fixed8(neo.model.bytes.Fixed8) JSONObject(org.json.JSONObject) Map(java.util.Map) TreeMap(java.util.TreeMap) UInt256(neo.model.bytes.UInt256)

Example 7 with UInt160

use of neo.model.bytes.UInt160 in project neo-java by coranos.

the class TransactionOutputMapToObject method toObject.

@Override
public TransactionOutput toObject(final Map<String, Object> map) {
    final byte[] assetIdBa = getBytes(map, "asset_id");
    final byte[] valueBa = getBytes(map, "value");
    ArrayUtils.reverse(valueBa);
    final byte[] scriptHashBa = getBytes(map, "script_hash");
    final UInt256 assetId = new UInt256(ByteBuffer.wrap(assetIdBa));
    final Fixed8 value = new Fixed8(ByteBuffer.wrap(valueBa));
    final UInt160 scriptHash = new UInt160(scriptHashBa);
    final TransactionOutput transactionOutput = new TransactionOutput(assetId, value, scriptHash);
    return transactionOutput;
}
Also used : TransactionOutput(neo.model.core.TransactionOutput) Fixed8(neo.model.bytes.Fixed8) UInt160(neo.model.bytes.UInt160) UInt256(neo.model.bytes.UInt256)

Example 8 with UInt160

use of neo.model.bytes.UInt160 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 9 with UInt160

use of neo.model.bytes.UInt160 in project neo-java by coranos.

the class Transaction method getScriptHashesForVerifying.

/**
 * return the script hashes used for verification.
 *
 * @param blockDb
 *            the blockdb to use.
 * @return the script hashes used for verification.
 */
public UInt160[] getScriptHashesForVerifying(final BlockDb blockDb) {
    final Set<UInt160> hashes = new LinkedHashSet<>();
    for (final CoinReference cr : inputs) {
        final TransactionOutput to = ModelUtil.getTransactionOutput(blockDb, cr);
        hashes.add(to.scriptHash);
    }
    for (final TransactionAttribute attribute : attributes) {
        if (attribute.usage.equals(TransactionAttributeUsage.SCRIPT)) {
            hashes.add(new UInt160(attribute.getCopyOfData()));
        }
    }
    if (type.equals(TransactionType.ISSUE_TRANSACTION)) {
    // TODO: handle issue transactions.
    }
    return hashes.toArray(new UInt160[0]);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) UInt160(neo.model.bytes.UInt160)

Example 10 with UInt160

use of neo.model.bytes.UInt160 in project neo-java by coranos.

the class AbstractJsonMockBlockDb method getAccountAssetValueMap.

@Override
public final Map<UInt160, Map<UInt256, Fixed8>> getAccountAssetValueMap() {
    final Map<UInt160, Map<UInt256, Fixed8>> accountAssetValueMap = new TreeMap<>();
    final JSONArray mockBlockDb = getMockBlockDb();
    for (int ix = 0; ix < mockBlockDb.length(); ix++) {
        final JSONObject mockBlock = mockBlockDb.getJSONObject(ix);
        final Block block = getBlock(mockBlock, true);
        for (final Transaction transaction : block.getTransactionList()) {
            for (final TransactionOutput output : transaction.outputs) {
                if (!accountAssetValueMap.containsKey(output.scriptHash)) {
                    accountAssetValueMap.put(output.scriptHash, new TreeMap<>());
                }
                final Map<UInt256, Fixed8> assetValueMap = accountAssetValueMap.get(output.scriptHash);
                final Fixed8 value = output.value;
                if (assetValueMap.containsKey(output.assetId)) {
                    final Fixed8 oldValue = assetValueMap.get(output.assetId);
                    final Fixed8 newValue = ModelUtil.add(value, oldValue);
                    assetValueMap.put(output.assetId, newValue);
                } else {
                    assetValueMap.put(output.assetId, value);
                }
            }
        }
    }
    return accountAssetValueMap;
}
Also used : TransactionOutput(neo.model.core.TransactionOutput) JSONArray(org.json.JSONArray) TreeMap(java.util.TreeMap) JSONObject(org.json.JSONObject) Transaction(neo.model.core.Transaction) UInt160(neo.model.bytes.UInt160) Fixed8(neo.model.bytes.Fixed8) Block(neo.model.core.Block) TreeMap(java.util.TreeMap) Map(java.util.Map) UInt256(neo.model.bytes.UInt256)

Aggregations

UInt160 (neo.model.bytes.UInt160)16 UInt256 (neo.model.bytes.UInt256)11 Fixed8 (neo.model.bytes.Fixed8)10 TransactionOutput (neo.model.core.TransactionOutput)9 TreeMap (java.util.TreeMap)8 Transaction (neo.model.core.Transaction)8 Map (java.util.Map)7 JSONObject (org.json.JSONObject)7 BlockDb (neo.model.db.BlockDb)5 CoinReference (neo.model.core.CoinReference)4 JSONArray (org.json.JSONArray)4 Block (neo.model.core.Block)3 Color (java.awt.Color)1 Graphics2D (java.awt.Graphics2D)1 BufferedImage (java.awt.image.BufferedImage)1 File (java.io.File)1 Timestamp (java.sql.Timestamp)1 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1