Search in sources :

Example 6 with UInt16

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

use of neo.model.bytes.UInt16 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)

Aggregations

UInt16 (neo.model.bytes.UInt16)7 CoinReference (neo.model.core.CoinReference)6 UInt256 (neo.model.bytes.UInt256)5 Transaction (neo.model.core.Transaction)4 TransactionOutput (neo.model.core.TransactionOutput)4 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 JSONArray (org.json.JSONArray)2 JSONObject (org.json.JSONObject)2 Fixed8 (neo.model.bytes.Fixed8)1 UInt160 (neo.model.bytes.UInt160)1 Block (neo.model.core.Block)1 Test (org.junit.Test)1 BTreeMap (org.mapdb.BTreeMap)1