Search in sources :

Example 6 with Transaction

use of neo.model.core.Transaction in project neo-java by coranos.

the class AbstractJsonMockBlockDb method getTransactionWithAccountList.

@Override
public List<Transaction> getTransactionWithAccountList(final UInt160 account) {
    final List<Transaction> transactionList = new ArrayList<>();
    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()) {
            boolean transactionHasAccount = false;
            for (final TransactionOutput output : transaction.outputs) {
                if (output.scriptHash.equals(account)) {
                    transactionHasAccount = true;
                }
            }
            if (transactionHasAccount) {
                transactionList.add(transaction);
            }
        }
    }
    return transactionList;
}
Also used : TransactionOutput(neo.model.core.TransactionOutput) Transaction(neo.model.core.Transaction) JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) Block(neo.model.core.Block)

Example 7 with Transaction

use of neo.model.core.Transaction in project neo-java by coranos.

the class AbstractJsonMockBlockDb method getTransactionWithHash.

@Override
public final Transaction getTransactionWithHash(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 transaction;
            }
        }
    }
    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 8 with Transaction

use of neo.model.core.Transaction in project neo-java by coranos.

the class MockUtil method getMockBlock001.

public static Block getMockBlock001() {
    final Block block = getMockBlock000();
    final Transaction transaction = getMockTransaction000();
    transaction.inputs.add(getCoinReference000());
    transaction.outputs.add(getTransactionOutput000());
    transaction.scripts.add(getWitness000());
    block.getTransactionList().add(transaction);
    return block;
}
Also used : Transaction(neo.model.core.Transaction) Block(neo.model.core.Block)

Example 9 with Transaction

use of neo.model.core.Transaction in project neo-java by coranos.

the class TestBlockSerialization method test00ZAllBlocks.

/**
 * pulls all the blocks (slow) to check for full coverage.
 *
 * @throws ClientProtocolException
 *             if an error occurs.
 * @throws IOException
 *             if an error occurs.
 * @throws DecoderException
 *             if an error occurs.
 * @throws InterruptedException
 *             if an error occurs.
 */
@Test
@Ignore
public void test00ZAllBlocks() throws ClientProtocolException, IOException, DecoderException, InterruptedException {
    final BlockDb blockDb = new AbstractJsonMockBlockDb() {

        @Override
        public JSONArray getMockBlockDb() {
            return new JSONArray();
        }
    };
    final long maxBlockIx = blockDb.getHeaderOfBlockWithMaxIndex().getIndexAsLong();
    final Set<TransactionType> knownTypeSet = new TreeSet<>();
    for (long blockIx = 0; blockIx <= maxBlockIx; blockIx++) {
        final Block block = blockDb.getFullBlockFromHeight(blockIx);
        for (int txIx = 0; txIx < block.getTransactionList().size(); txIx++) {
            final Transaction tx = block.getTransactionList().get(txIx);
            if (!knownTypeSet.contains(tx.type)) {
                LOG.error("getBlock {} {} tx {} {}", block.getIndexAsLong(), block.prevHash, txIx, tx.type);
                knownTypeSet.add(tx.type);
            }
        }
    }
    blockDb.close();
}
Also used : TransactionType(neo.model.core.TransactionType) Transaction(neo.model.core.Transaction) TreeSet(java.util.TreeSet) AbstractJsonMockBlockDb(neo.rpc.client.test.util.AbstractJsonMockBlockDb) JSONArray(org.json.JSONArray) Block(neo.model.core.Block) BlockDb(neo.model.db.BlockDb) AbstractJsonMockBlockDb(neo.rpc.client.test.util.AbstractJsonMockBlockDb) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 10 with Transaction

use of neo.model.core.Transaction in project neo-java by coranos.

the class TestCoreToJson method test011Transaction.

/**
 * test Transaction.
 */
@Test
public void test011Transaction() {
    final Transaction transaction = MockUtil.getMockTransaction000();
    final String expectedStrRaw = TestUtil.getJsonTestResourceAsString(TEST_PACKAGE, getClass().getSimpleName(), "test011Transaction");
    final String expectedStr = new JSONObject(expectedStrRaw).toString();
    final String actualStr = transaction.toString();
    Assert.assertEquals(TestUtil.RESPONSES_MUST_MATCH, expectedStr, actualStr);
    final String expectedHexStrRaw = TestUtil.getJsonTestResourceAsString(TEST_PACKAGE, getClass().getSimpleName(), "test011TransactionHex");
    final String expectedHexStr = new JSONObject(expectedHexStrRaw).toString();
    final String actualHexStr = TestUtil.toHexJsonObject(ModelUtil.toHexString(transaction.toByteArray())).toString();
    Assert.assertEquals(TestUtil.RESPONSES_MUST_MATCH, expectedHexStr, actualHexStr);
}
Also used : Transaction(neo.model.core.Transaction) JSONObject(org.json.JSONObject) Test(org.junit.Test)

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