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