Search in sources :

Example 26 with UInt256

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;
}
Also used : UInt160(neo.model.bytes.UInt160) Fixed8(neo.model.bytes.Fixed8) TreeMap(java.util.TreeMap) BTreeMap(org.mapdb.BTreeMap) Map(java.util.Map) TreeMap(java.util.TreeMap) BTreeMap(org.mapdb.BTreeMap) UInt256(neo.model.bytes.UInt256)

Example 27 with UInt256

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;
}
Also used : Fixed8(neo.model.bytes.Fixed8) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) UInt256(neo.model.bytes.UInt256)

Example 28 with UInt256

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;
}
Also used : CoinReference(neo.model.core.CoinReference) TransactionOutput(neo.model.core.TransactionOutput) TreeMap(java.util.TreeMap) BTreeMap(org.mapdb.BTreeMap) Transaction(neo.model.core.Transaction) UInt16(neo.model.bytes.UInt16) Map(java.util.Map) TreeMap(java.util.TreeMap) BTreeMap(org.mapdb.BTreeMap) UInt256(neo.model.bytes.UInt256)

Example 29 with UInt256

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;
}
Also used : CoinReference(neo.model.core.CoinReference) UInt16(neo.model.bytes.UInt16) UInt256(neo.model.bytes.UInt256)

Example 30 with UInt256

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;
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) UInt256(neo.model.bytes.UInt256)

Aggregations

UInt256 (neo.model.bytes.UInt256)36 TransactionOutput (neo.model.core.TransactionOutput)15 JSONObject (org.json.JSONObject)14 TreeMap (java.util.TreeMap)13 Fixed8 (neo.model.bytes.Fixed8)13 Transaction (neo.model.core.Transaction)13 Map (java.util.Map)11 UInt160 (neo.model.bytes.UInt160)11 CoinReference (neo.model.core.CoinReference)11 Block (neo.model.core.Block)8 JSONArray (org.json.JSONArray)7 UInt16 (neo.model.bytes.UInt16)5 BlockDb (neo.model.db.BlockDb)5 ArrayList (java.util.ArrayList)3 Header (neo.model.core.Header)3 BTreeMap (org.mapdb.BTreeMap)3 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 InvPayload (neo.model.network.InvPayload)2 Color (java.awt.Color)1