Search in sources :

Example 31 with Transaction

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");
}
Also used : LocalNodeData(neo.network.model.LocalNodeData) Transaction(neo.model.core.Transaction) ScriptVerificationResultEnum(neo.model.ScriptVerificationResultEnum) Block(neo.model.core.Block) BlockDb(neo.model.db.BlockDb) Timestamp(java.sql.Timestamp) Test(org.junit.Test)

Example 32 with Transaction

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));
}
Also used : CoinReference(neo.model.core.CoinReference) TransactionOutput(neo.model.core.TransactionOutput) Transaction(neo.model.core.Transaction) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) UInt16(neo.model.bytes.UInt16) Test(org.junit.Test)

Example 33 with Transaction

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;
}
Also used : TransactionOutput(neo.model.core.TransactionOutput) JSONArray(org.json.JSONArray) TreeMap(java.util.TreeMap) JSONObject(org.json.JSONObject) Transaction(neo.model.core.Transaction) UInt160(neo.model.bytes.UInt160) Fixed8(neo.model.bytes.Fixed8) Block(neo.model.core.Block) TreeMap(java.util.TreeMap) Map(java.util.Map) UInt256(neo.model.bytes.UInt256)

Example 34 with Transaction

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);
}
Also used : JSONObject(org.json.JSONObject) Transaction(neo.model.core.Transaction) JSONArray(org.json.JSONArray) Block(neo.model.core.Block)

Example 35 with Transaction

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;
}
Also used : CoinReference(neo.model.core.CoinReference) TransactionOutput(neo.model.core.TransactionOutput) JSONArray(org.json.JSONArray) TreeMap(java.util.TreeMap) JSONObject(org.json.JSONObject) Transaction(neo.model.core.Transaction) Block(neo.model.core.Block) UInt16(neo.model.bytes.UInt16) TreeMap(java.util.TreeMap) Map(java.util.Map) UInt256(neo.model.bytes.UInt256)

Aggregations

Transaction (neo.model.core.Transaction)49 JSONObject (org.json.JSONObject)26 Block (neo.model.core.Block)25 JSONArray (org.json.JSONArray)19 TransactionOutput (neo.model.core.TransactionOutput)17 Test (org.junit.Test)14 UInt256 (neo.model.bytes.UInt256)13 TreeMap (java.util.TreeMap)12 BlockDb (neo.model.db.BlockDb)9 Map (java.util.Map)8 Fixed8 (neo.model.bytes.Fixed8)8 UInt160 (neo.model.bytes.UInt160)8 CoinReference (neo.model.core.CoinReference)8 ArrayList (java.util.ArrayList)6 IOException (java.io.IOException)5 LocalNodeData (neo.network.model.LocalNodeData)5 Timestamp (java.sql.Timestamp)4 UInt16 (neo.model.bytes.UInt16)4 List (java.util.List)3 TreeSet (java.util.TreeSet)3