Search in sources :

Example 6 with TransactionOutput

use of neo.model.core.TransactionOutput in project neo-java by coranos.

the class BlockDbH2Impl method getUnspentTransactionOutputListMap.

@Override
public Map<UInt256, Map<TransactionOutput, CoinReference>> getUnspentTransactionOutputListMap(final UInt160 account) {
    synchronized (this) {
        if (closed) {
            return null;
        }
    }
    final JdbcTemplate t = new JdbcTemplate(ds);
    final String sql = getSql("getUnspentTransactionOutputListMap");
    final List<Map<String, Object>> mapList = t.queryForList(sql, account.toByteArray());
    final AbstractMapToObject<TransactionOutput> toMapToObject = new TransactionOutputMapToObject();
    final AbstractMapToObject<CoinReference> crMapToObject = new CoinReferenceMapToObject();
    final Map<UInt256, Map<TransactionOutput, CoinReference>> assetIdTxoMap = new TreeMap<>();
    for (final Map<String, Object> map : mapList) {
        final TransactionOutput to = toMapToObject.toObject(map);
        final CoinReference cr = crMapToObject.toObject(map);
        if (!assetIdTxoMap.containsKey(to.assetId)) {
            assetIdTxoMap.put(to.assetId, new TreeMap<>());
        }
        assetIdTxoMap.get(to.assetId).put(to, cr);
    }
    return assetIdTxoMap;
}
Also used : CoinReference(neo.model.core.CoinReference) TransactionOutput(neo.model.core.TransactionOutput) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) TreeMap(java.util.TreeMap) JSONObject(org.json.JSONObject) Map(java.util.Map) TreeMap(java.util.TreeMap) UInt256(neo.model.bytes.UInt256)

Example 7 with TransactionOutput

use of neo.model.core.TransactionOutput in project neo-java by coranos.

the class BlockDbH2Impl method getAssetValueMap.

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

Example 8 with TransactionOutput

use of neo.model.core.TransactionOutput in project neo-java by coranos.

the class TransactionOutputFactory method toObject.

@Override
public TransactionOutput toObject(final ByteBuffer bb) {
    bb.getLong();
    final byte[] assetIdBa = ModelUtil.getVariableLengthByteArray(bb);
    final byte[] valueBa = ModelUtil.getVariableLengthByteArray(bb);
    ArrayUtils.reverse(valueBa);
    final byte[] scriptHashBa = ModelUtil.getVariableLengthByteArray(bb);
    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 9 with TransactionOutput

use of neo.model.core.TransactionOutput in project neo-java by coranos.

the class ModelUtil method getTransactionOutput.

/**
 * returns the transaction output for this coin reference.
 *
 * @param blockDb
 *            the block database to ues.
 * @param coinReference
 *            the coin reference to use.
 * @return the TransactionOutput.
 */
public static TransactionOutput getTransactionOutput(final BlockDb blockDb, final CoinReference coinReference) {
    final UInt256 prevHashReversed = coinReference.prevHash.reverse();
    final Transaction tiTx = blockDb.getTransactionWithHash(prevHashReversed);
    final int prevIndex = coinReference.prevIndex.asInt();
    final TransactionOutput ti = tiTx.outputs.get(prevIndex);
    return ti;
}
Also used : TransactionOutput(neo.model.core.TransactionOutput) Transaction(neo.model.core.Transaction) UInt256(neo.model.bytes.UInt256)

Example 10 with TransactionOutput

use of neo.model.core.TransactionOutput 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)

Aggregations

TransactionOutput (neo.model.core.TransactionOutput)25 Transaction (neo.model.core.Transaction)17 JSONObject (org.json.JSONObject)16 UInt256 (neo.model.bytes.UInt256)15 TreeMap (java.util.TreeMap)11 Fixed8 (neo.model.bytes.Fixed8)11 CoinReference (neo.model.core.CoinReference)10 JSONArray (org.json.JSONArray)10 UInt160 (neo.model.bytes.UInt160)9 Block (neo.model.core.Block)9 Map (java.util.Map)8 Test (org.junit.Test)6 BlockDb (neo.model.db.BlockDb)5 UInt16 (neo.model.bytes.UInt16)4 Timestamp (java.sql.Timestamp)3 LocalNodeData (neo.network.model.LocalNodeData)3 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)3 BufferedOutputStream (java.io.BufferedOutputStream)2 DataOutputStream (java.io.DataOutputStream)2 FileOutputStream (java.io.FileOutputStream)2