use of neo.model.core.Block in project neo-java by coranos.
the class AbstractJsonMockBlockDb method getAccountAssetValueMap.
@Override
public final Map<UInt160, Map<UInt256, Fixed8>> getAccountAssetValueMap() {
final Map<UInt160, Map<UInt256, Fixed8>> accountAssetValueMap = new TreeMap<>();
final JSONArray mockBlockDb = getMockBlockDb();
for (int ix = 0; ix < mockBlockDb.length(); ix++) {
final JSONObject mockBlock = mockBlockDb.getJSONObject(ix);
final Block block = getBlock(mockBlock, true);
for (final Transaction transaction : block.getTransactionList()) {
for (final TransactionOutput output : transaction.outputs) {
if (!accountAssetValueMap.containsKey(output.scriptHash)) {
accountAssetValueMap.put(output.scriptHash, new TreeMap<>());
}
final Map<UInt256, Fixed8> assetValueMap = accountAssetValueMap.get(output.scriptHash);
final Fixed8 value = output.value;
if (assetValueMap.containsKey(output.assetId)) {
final Fixed8 oldValue = assetValueMap.get(output.assetId);
final Fixed8 newValue = ModelUtil.add(value, oldValue);
assetValueMap.put(output.assetId, newValue);
} else {
assetValueMap.put(output.assetId, value);
}
}
}
}
return accountAssetValueMap;
}
use of neo.model.core.Block in project neo-java by coranos.
the class AbstractJsonMockBlockDb method getBlockIndexFromTransactionHash.
@Override
public final Long getBlockIndexFromTransactionHash(final UInt256 hash) {
final JSONArray mockBlockDb = getMockBlockDb();
for (int ix = 0; ix < mockBlockDb.length(); ix++) {
final JSONObject mockBlock = mockBlockDb.getJSONObject(ix);
final Block block = getBlock(mockBlock, true);
for (final Transaction transaction : block.getTransactionList()) {
if (transaction.getHash().equals(hash)) {
return block.getIndexAsLong();
}
}
}
throw new RuntimeException("no transaction with hash:" + hash);
}
use of neo.model.core.Block in project neo-java by coranos.
the class AbstractJsonMockBlockDb method getBlockWithMaxIndex.
/**
* return the block with the maximum value in the index column.
*
* @param withTransactions
* if true, add transactions. If false, only return the block header.
* @return the block with the maximum value in the index column.
*/
private Block getBlockWithMaxIndex(final boolean withTransactions) {
Block maxBlock = null;
final JSONArray mockBlockDb = getMockBlockDb();
for (int ix = 0; ix < mockBlockDb.length(); ix++) {
final JSONObject mockBlock = mockBlockDb.getJSONObject(ix);
if (maxBlock == null) {
maxBlock = getBlock(mockBlock, withTransactions);
} else {
if (mockBlock.getLong(INDEX) > maxBlock.getIndexAsLong()) {
maxBlock = getBlock(mockBlock, withTransactions);
}
}
}
return maxBlock;
}
use of neo.model.core.Block in project neo-java by coranos.
the class AbstractJsonMockBlockDb method getUnspentTransactionOutputListMap.
@Override
public Map<UInt256, Map<TransactionOutput, CoinReference>> getUnspentTransactionOutputListMap(final UInt160 account) {
final Map<UInt256, Map<TransactionOutput, CoinReference>> assetIdTxoMap = new TreeMap<>();
final JSONArray mockBlockDb = getMockBlockDb();
for (int ix = 0; ix < mockBlockDb.length(); ix++) {
final JSONObject mockBlock = mockBlockDb.getJSONObject(ix);
final Block block = getBlock(mockBlock, true);
for (int txIx = 0; txIx < block.getTransactionList().size(); txIx++) {
final Transaction transaction = block.getTransactionList().get(txIx);
for (final TransactionOutput output : transaction.outputs) {
if (output.scriptHash.equals(account)) {
if (!assetIdTxoMap.containsKey(output.assetId)) {
assetIdTxoMap.put(output.assetId, new TreeMap<>());
}
final CoinReference cr = new CoinReference(transaction.getHash(), new UInt16(txIx));
assetIdTxoMap.get(output.assetId).put(output, cr);
}
}
}
}
return assetIdTxoMap;
}
use of neo.model.core.Block in project neo-java by coranos.
the class MockUtil method getMockBlock003.
public static Block getMockBlock003() {
final Block block = getMockBlock002();
final Transaction transaction = getMockTransaction000();
transaction.inputs.add(getCoinReference001());
transaction.outputs.add(getTransactionOutput001());
transaction.scripts.add(getWitness000());
block.getTransactionList().add(transaction);
return block;
}
Aggregations