use of neo.model.bytes.UInt256 in project neo-java by coranos.
the class BlockDbMapDbImpl method getAccountAssetValueMap.
@Override
public Map<UInt160, Map<UInt256, Fixed8>> getAccountAssetValueMap() {
LOG.info("getAccountAssetValueMap STARTED");
final Map<UInt160, Map<UInt256, Fixed8>> accountAssetValueMap = new TreeMap<>();
final BTreeMap<byte[], byte[]> assetAndValueByAccountMap = getAssetAndValueByAccountMap();
LOG.info("getAccountAssetValueMap INTERIM assetAndValueByAccountMap.size:{};", assetAndValueByAccountMap.size());
for (final byte[] key : assetAndValueByAccountMap.getKeys()) {
final byte[] value = assetAndValueByAccountMap.get(key);
final UInt160 account = new UInt160(key);
final Map<UInt256, Fixed8> map = getAssetValueMapFromByteArray(value);
accountAssetValueMap.put(account, map);
}
LOG.info("getAccountAssetValueMap SUCCESS, count:{}", accountAssetValueMap.size());
return accountAssetValueMap;
}
use of neo.model.bytes.UInt256 in project neo-java by coranos.
the class BlockDbMapDbImpl method getByteArrayFromAssetValueMap.
/**
* converts a map of assets and values into a byte array.
*
* @param friendAssetValueMap
* the map to use.
* @return the byte array.
*/
private byte[] getByteArrayFromAssetValueMap(final Map<UInt256, Fixed8> friendAssetValueMap) {
final byte[] mapBa;
final ByteArrayOutputStream bout;
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
NetworkUtil.writeVarInt(out, friendAssetValueMap.size());
for (final UInt256 key : friendAssetValueMap.keySet()) {
final Fixed8 value = friendAssetValueMap.get(key);
NetworkUtil.writeByteArray(out, key.toByteArray());
final byte[] valueBa = value.toByteArray();
ArrayUtils.reverse(valueBa);
NetworkUtil.writeByteArray(out, valueBa);
}
bout = out;
} catch (final IOException e) {
throw new RuntimeException(e);
}
mapBa = bout.toByteArray();
return mapBa;
}
use of neo.model.bytes.UInt256 in project neo-java by coranos.
the class BlockDbMapDbImpl method getUnspentTransactionOutputListMap.
@Override
public Map<UInt256, Map<TransactionOutput, CoinReference>> getUnspentTransactionOutputListMap(final UInt160 account) {
final List<Transaction> transactionList = getTransactionWithAccountList(account);
final BTreeMap<byte[], Boolean> transactionOutputSpentStateMap = getTransactionOutputSpentStateMap();
final Map<UInt256, Map<TransactionOutput, CoinReference>> assetIdTxoMap = new TreeMap<>();
final BTreeMap<byte[], byte[]> txKeyByHashMap = getTransactionKeyByTransactionHashMap();
for (final Transaction transaction : transactionList) {
final byte[] hashBa = transaction.getHash().toByteArray();
final byte[] txKeyBa = txKeyByHashMap.get(hashBa);
for (final TransactionOutput to : transaction.outputs) {
if (to.scriptHash.equals(account)) {
final byte[] toBa = to.toByteArray();
if (transactionOutputSpentStateMap.containsKey(toBa)) {
if (transactionOutputSpentStateMap.get(toBa) == true) {
if (!assetIdTxoMap.containsKey(to.assetId)) {
assetIdTxoMap.put(to.assetId, new TreeMap<>());
}
final int txIx = getTransactionIndexInBlockFromTransactionKey(txKeyBa);
final CoinReference cr = new CoinReference(transaction.getHash(), new UInt16(txIx));
assetIdTxoMap.get(to.assetId).put(to, cr);
}
}
}
}
}
return assetIdTxoMap;
}
use of neo.model.bytes.UInt256 in project neo-java by coranos.
the class CoinReferenceFactory method toObject.
@Override
public CoinReference toObject(final ByteBuffer bb) {
bb.getLong();
final byte[] prevHashBa = ModelUtil.getVariableLengthByteArray(bb);
final byte[] prevIndexBa = ModelUtil.getVariableLengthByteArray(bb);
final UInt256 prevHash = new UInt256(ByteBuffer.wrap(prevHashBa));
final UInt16 prevIndex = new UInt16(prevIndexBa);
final CoinReference coinReference = new CoinReference(prevHash, prevIndex);
return coinReference;
}
use of neo.model.bytes.UInt256 in project neo-java by coranos.
the class GetBlocksPayload method toJSONObject.
@Override
public JSONObject toJSONObject() {
final JSONObject json = new JSONObject();
final JSONArray hashStartListJson = new JSONArray();
json.put("hashStartList", hashStartListJson);
for (final UInt256 hashStart : hashStartList) {
hashStartListJson.put(hashStart.toHexString());
}
json.put("hashStop", hashStop.toHexString());
return json;
}
Aggregations