Search in sources :

Example 61 with Block

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

the class TestDBMapDb method test004getHeaderOfBlockWithMaxIndex.

/**
 * test getHeaderOfBlockWithMaxIndex.
 */
@Test
public void test004getHeaderOfBlockWithMaxIndex() {
    try (TestLocalControllerNode controller = getTestLocalControllerNode()) {
        final Block actual = controller.getBlockDb().getHeaderOfBlockWithMaxIndex();
        Assert.assertEquals("getHeaderOfBlockWithMaxIndex should return null with empty db.", null, actual);
    }
}
Also used : Block(neo.model.core.Block) Test(org.junit.Test)

Example 62 with Block

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

the class TestDBMapDb method test011putAndGetHeaderOfBlockFromHash.

/**
 * test put, and getHeaderOfBlockFromHash.
 */
@Test
public void test011putAndGetHeaderOfBlockFromHash() {
    try (TestLocalControllerNode controller = getTestLocalControllerNode()) {
        final Block expectedBlock = MockUtil.getMockBlock003();
        controller.getBlockDb().put(true, GenesisBlockUtil.GENESIS_BLOCK);
        controller.getBlockDb().put(true, expectedBlock);
        expectedBlock.getTransactionList().clear();
        final Block actualBlock = controller.getBlockDb().getHeaderOfBlockFromHash(expectedBlock.hash);
        Assert.assertEquals("blocks should match.", expectedBlock.toString(), actualBlock.toString());
    }
}
Also used : Block(neo.model.core.Block) Test(org.junit.Test)

Example 63 with Block

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

the class TestDBMapDb method test010putAndGetHeaderOfBlockFromHeight.

/**
 * test put, and getHeaderOfBlockFromHeight.
 */
@Test
public void test010putAndGetHeaderOfBlockFromHeight() {
    try (TestLocalControllerNode controller = getTestLocalControllerNode()) {
        final Block expectedBlock = MockUtil.getMockBlock003();
        controller.getBlockDb().put(true, GenesisBlockUtil.GENESIS_BLOCK);
        controller.getBlockDb().put(true, expectedBlock);
        expectedBlock.getTransactionList().clear();
        final Block actualBlock = controller.getBlockDb().getHeaderOfBlockFromHeight(1);
        Assert.assertEquals("blocks should match.", expectedBlock.toString(), actualBlock.toString());
    }
}
Also used : Block(neo.model.core.Block) Test(org.junit.Test)

Example 64 with Block

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

the class TestDBMapDb method test007putAndGetFullBlockFromHash.

/**
 * test put, and getFullBlockFromHash.
 */
@Test
public void test007putAndGetFullBlockFromHash() {
    try (TestLocalControllerNode controller = getTestLocalControllerNode()) {
        final Block expectedBlock = MockUtil.getMockBlock003();
        controller.getBlockDb().put(true, GenesisBlockUtil.GENESIS_BLOCK);
        controller.getBlockDb().put(true, expectedBlock);
        final Block actualBlock = controller.getBlockDb().getFullBlockFromHash(expectedBlock.hash);
        Assert.assertEquals("blocks should match.", expectedBlock.toString(), actualBlock.toString());
    }
}
Also used : Block(neo.model.core.Block) Test(org.junit.Test)

Example 65 with Block

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

the class Message method createPayload.

/**
 * creates a payload.
 *
 * @param cl
 *            the payload class.
 * @param <T>
 *            the payload type.
 * @return the payload.
 */
@SuppressWarnings("unchecked")
private <T extends Payload> T createPayload(final Class<T> cl) {
    if (LOG.isTraceEnabled()) {
        LOG.trace("initPayload payloadBa {}", Hex.encodeHexString(payloadBa));
    }
    final Payload payload;
    switch(command) {
        case "version":
            payload = new VersionPayload(ByteBuffer.wrap(payloadBa));
            break;
        case "inv":
            payload = new InvPayload(ByteBuffer.wrap(payloadBa));
            break;
        case "addr":
            payload = new AddrPayload(ByteBuffer.wrap(payloadBa));
            break;
        case "headers":
            payload = new HeadersPayload(ByteBuffer.wrap(payloadBa));
            break;
        case "verack":
            payload = null;
            break;
        case "getaddr":
            payload = null;
            break;
        case "getdata":
            payload = null;
            break;
        case "getblocks":
            payload = null;
            break;
        case "mempool":
            payload = null;
            break;
        case "":
            payload = null;
            break;
        case "getheaders":
            payload = null;
            break;
        case "consensus":
            payload = null;
            break;
        case "block":
            payload = new Block(ByteBuffer.wrap(payloadBa));
            break;
        case "tx":
            payload = new Transaction(ByteBuffer.wrap(payloadBa));
            break;
        default:
            if (!command.matches(LOWERCASE_ALPHABET)) {
                LOG.debug("unknown payload type for non alphabetic command \"{}\"", command);
                payload = null;
            } else {
                LOG.error("unknown payload type for command \"{}\"", command);
                payload = null;
            }
    }
    return (T) payload;
}
Also used : Transaction(neo.model.core.Transaction) Block(neo.model.core.Block)

Aggregations

Block (neo.model.core.Block)65 Test (org.junit.Test)26 Transaction (neo.model.core.Transaction)25 JSONObject (org.json.JSONObject)24 JSONArray (org.json.JSONArray)16 TransactionOutput (neo.model.core.TransactionOutput)9 BlockDb (neo.model.db.BlockDb)9 IOException (java.io.IOException)8 TreeMap (java.util.TreeMap)8 UInt256 (neo.model.bytes.UInt256)8 LocalNodeData (neo.network.model.LocalNodeData)6 Fixed8 (neo.model.bytes.Fixed8)5 Timestamp (java.sql.Timestamp)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 TreeSet (java.util.TreeSet)4 OutputStream (java.io.OutputStream)3 SQLException (java.sql.SQLException)3 UInt160 (neo.model.bytes.UInt160)3 UInt32 (neo.model.bytes.UInt32)3