Search in sources :

Example 11 with UInt256

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

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

use of neo.model.bytes.UInt256 in project neo-java by coranos.

the class InvPayload method toJSONObject.

@Override
public JSONObject toJSONObject() {
    final JSONObject json = new JSONObject();
    json.put("type", type);
    final JSONArray hashesJson = new JSONArray();
    json.put("hashes", hashesJson);
    for (final UInt256 hash : hashes) {
        hashesJson.put(hash.toHexString());
    }
    return json;
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) UInt256(neo.model.bytes.UInt256)

Example 14 with UInt256

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

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

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