use of neo.model.core.Transaction in project neo-java by coranos.
the class TestVm method test999Vm.
@Test
public void test999Vm() {
LOG.info("STARTED vm");
final LocalNodeData localNodeData = CONTROLLER.getLocalNodeData();
final BlockDb blockDb = localNodeData.getBlockDb();
final long maxIndex = blockDb.getHeaderOfBlockWithMaxIndex().getIndexAsLong();
long startMs = -1;
for (long blockHeight = 0; blockHeight <= maxIndex; blockHeight++) {
LOG.info("STARTED block {} of {} ", blockHeight, maxIndex);
final Block block = blockDb.getFullBlockFromHeight(blockHeight);
final int maxTxIx = block.getTransactionList().size();
for (int txIx = 0; txIx < maxTxIx; txIx++) {
final Transaction tx = block.getTransactionList().get(txIx);
if (tx.type.equals(TransactionType.ISSUE_TRANSACTION)) {
LOG.info("SKIPPED block {} of {} tx {} of {} : {}", blockHeight, maxIndex, txIx, maxTxIx, tx.getHash());
} else {
LOG.info("STARTED block {} of {} tx {} of {} : {} {}", blockHeight, maxIndex, txIx, maxTxIx, tx.type, tx.getHash());
final ScriptVerificationResultEnum verifyScriptsResult = VerifyScriptUtil.verifyScripts(blockDb, tx);
if (!verifyScriptsResult.equals(ScriptVerificationResultEnum.PASS)) {
LOG.error("FAILURE block {} of {} tx {} of {} : {} {} : {}", blockHeight, maxIndex, txIx, maxTxIx, tx.type, tx.getHash(), verifyScriptsResult);
throw new RuntimeException("script failed : " + tx.type + ":" + verifyScriptsResult);
} else {
LOG.info("SUCCESS block {} of {} tx {} of {} : {} {}", blockHeight, maxIndex, txIx, maxTxIx, tx.type, tx.getHash());
}
}
}
final Timestamp blockTs = block.getTimestamp();
if (startMs < 0) {
startMs = blockTs.getTime();
}
final long ms = blockTs.getTime() - startMs;
if (ms > (86400 * 1000)) {
final String targetDateStr = DATE_FORMAT.format(blockTs);
LOG.info("INTERIM vm {} of {}, date {}", INTEGER_FORMAT.format(blockHeight), INTEGER_FORMAT.format(maxIndex), targetDateStr);
startMs = blockTs.getTime();
}
}
LOG.debug("SUCCESS vm");
}
use of neo.model.core.Transaction in project neo-java by coranos.
the class TestMinTx method test001Remark.
@Test
public void test001Remark() {
// final String rpcNode = "http://seed2.neo.org:20332";//
// CityOfZionUtil.getTestNetRpcNode();
final String rpcNode = CityOfZionUtil.getTestNetRpcNode();
LOG.info("test001Remark blockCount:{}:", RpcClientUtil.getBlockCount(1000, rpcNode, false));
final byte[] txBa = new byte[800];
txBa[0] = TransactionType.CONTRACT_TRANSACTION.getTypeByte();
txBa[2] = 1;
txBa[3] = TransactionAttributeUsage.REMARK_00.getTypeByte();
txBa[4] = 4;
final Transaction tx = new Transaction(ByteBuffer.wrap(txBa));
tx.outputs.add(new TransactionOutput(ModelUtil.NEO_HASH, ModelUtil.getFixed8(BigInteger.ONE), ModelUtil.addressToScriptHash("AeKd54zJdgqXy41NgH1PicXTVcz3RdRFdh")));
tx.inputs.add(new CoinReference(ModelUtil.getUInt256(ByteBuffer.wrap(Hex.decode("24ef2db3a509cd065c85ae33b5b905f30699d69237631598c5f182076619acc8"))), new UInt16(1)));
LOG.info("test001Remark tx:{}:", tx.toJSONObject().toString(2));
final JSONArray paramsJson = new JSONArray();
paramsJson.put(Hex.encode(tx.toByteArray()));
final JSONObject inputJson = new JSONObject();
inputJson.put("jsonrpc", "2.0");
inputJson.put("method", "sendrawtransaction");
inputJson.put("params", paramsJson);
inputJson.put("id", 1);
final JSONObject outputJson = RpcClientUtil.post(1000, rpcNode, false, inputJson);
Assert.assertNotNull("outputJson acnnot be null", outputJson);
LOG.info("test001Remark outputJson:{}:", outputJson.toString(2));
}
use of neo.model.core.Transaction 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.Transaction 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.Transaction 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;
}
Aggregations