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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations