Exemplo n.º 1
0
static void parseTX(
    const uint8_t *&p
)
{
    uint8_t *txHash = 0;
    const uint8_t *txStart = p;

    if(gNeedTXHash && !skip) {
        const uint8_t *txEnd = p;
        parseTX<true>(txEnd);
        txHash = allocHash256();
        sha256Twice(txHash, txStart, txEnd - txStart);
    }

    if(!skip) startTX(p, txHash);

        SKIP(uint32_t, version, p);

        parseInputs<skip>(p, txHash);

        if(gNeedTXHash && !skip)
            gTXMap[txHash] = p;

        parseOutputs<skip, false>(p, txHash);

        SKIP(uint32_t, lockTime, p);

    if(!skip) endTX(p);
}
Exemplo n.º 2
0
    virtual void startBlock(
        const Block *b,
        uint64_t
    )
    {
        if(0<=cutoffBlock && cutoffBlock<b->height) wrapup();

        uint8_t blockHash[kSHA256ByteSize];
        sha256Twice(blockHash, b->data, 80);

        const uint8_t *p = b->data;
        SKIP(uint32_t, version, p);
        SKIP(uint256_t, prevBlkHash, p);
        SKIP(uint256_t, blkMerkleRoot, p);
        LOAD(uint32_t, blkTime, p);

        // id BIGINT PRIMARY KEY
        // hash BINARY(32)
        // time BIGINT
        fprintf(blockFile, "%" PRIu64 "\t", (blkID = b->height-1));

        writeEscapedBinaryBuffer(blockFile, blockHash, kSHA256ByteSize);
        fputc('\t', blockFile);

        fprintf(blockFile, "%" PRIu64 "\n", (uint64_t)blkTime);
        if(0==(b->height)%500) {
            fprintf(
                stderr,
                "block=%8" PRIu64 " "
                "nbOutputs=%8" PRIu64 "\n",
                b->height,
                outputMap.size()
            );
        }
    }
Exemplo n.º 3
0
    virtual void startBlock(
        const Block *b,
        uint64_t chainBase
    )
    {
        if (lastBlock >= 0 && lastBlock < b->height - 1) wrapup();
        if (b->height - 1 == firstBlock) active = 1;

        if (active) {
            uint8_t blockHash[kSHA256ByteSize];
            sha256Twice(blockHash, b->data, 80);

            const uint8_t *p = b->data;

            // Total block size is 81 bytes plus transactions
            blkSize = 81;

            totalBlkFees = 0;
            totalBlkOutput = 0;
            numBlkTxs = 0;

            LOAD(uint32_t, version, p);
            SKIP(uint256_t, prevBlkHash, p);
            LOAD(uint256_t, blkMerkleRoot, p);
            LOAD(uint32_t, blkTime, p);
            LOAD(uint32_t, difficultyBits, p);
            LOAD(uint32_t, nonce, p);

            // ID
            fprintf(blockFile, "%" PRIu64 ",", blkID);

            // Hash
            uint8_t buf[1 + 2*kSHA256ByteSize];
            toHex(buf, blockHash);
            fprintf(blockFile, "\"%s\",", buf);

            // Version
            fprintf(blockFile, "%" PRIu32 ",", version);

            // Timestamp
            time_t blockTime = blkTime;
            char tbuf[23];
            strftime(tbuf, sizeof tbuf, "%FT%TZ", gmtime(&blockTime));

            fprintf(blockFile, "\"%s\",", tbuf);

            // Nonce
            fprintf(blockFile, "%" PRIu32 ",", nonce);

            // Difficulty
            fprintf(blockFile, "%f,", difficulty(difficultyBits));

            // Merkle root
            uint8_t buf2[kSHA256ByteSize];
            uint8_t buf3[1 + 2*kSHA256ByteSize];
            memcpy(buf2, &blkMerkleRoot, kSHA256ByteSize);
            toHex(buf3, buf2);
            fprintf(blockFile, "\"%s\",", buf3);
        }
    }
Exemplo n.º 4
0
static void getBlockHeader(
    size_t        &size,
    Block        *&prev,
    uint8_t      *&hash,
    size_t        &earlyMissCnt,
    const uint8_t *p
) {

    LOAD(uint32_t, magic, p);
    if(unlikely(gExpectedMagic!=magic)) {
        hash = 0;
        return;
    }

    LOAD(uint32_t, sz, p);
    size = sz;
    prev = 0;

    hash = allocHash256();

    #if defined(DARKCOIN)
        h9(hash, p, gHeaderSize);
    #elif defined(PAYCON) 
        h13(hash, p, gHeaderSize);
    #elif defined(MARTEXCOIN)
        h13(hash, p, gHeaderSize);
    #elif defined(CLAM)
        auto pBis = p;
        LOAD(uint32_t, nVersion, pBis);
        if(6<nVersion) {
            sha256Twice(hash, p, gHeaderSize);
        } else {
            scrypt(hash, p, gHeaderSize);
        }
    #elif defined(JUMBUCKS)
        scrypt(hash, p, gHeaderSize);
    #else
        sha256Twice(hash, p, gHeaderSize);
    #endif

    auto i = gBlockMap.find(p + 4);
    if(likely(gBlockMap.end()!=i)) {
        prev = i->second;
    } else {
        ++earlyMissCnt;
    }
}
Exemplo n.º 5
0
static bool buildBlock(
    const uint8_t *&p,
    const uint8_t *e
)
{
	//litcoin 0xfb, 0xc0, 0xb6, 0xdb
	//unsigned char pchMessageStart[4] = { 0xce, 0xfb, 0xfa, 0xdb };
    static const uint32_t expected =
    #if defined(UVCCOIN)
        0xdbfafbce
    #elif defined(LITECOIN)
        0xdbb6c0fb
    #else
        0xd9b4bef9
    #endif
    ;

    if(unlikely(e<=(8+p))) {
        //printf("end of map, reason : pointer past EOF\n");
        return true;
    }

    LOAD(uint32_t, magic, p);
    if(unlikely(expected!=magic)) {
        //printf("end of map, reason : magic is f****d %d away from EOF\n", (int)(e-p));
        return true;
    }

    LOAD(uint32_t, size, p);
    if(unlikely(e<(p+size))) {
        //printf("end of map, reason : end of block past EOF, %d past EOF\n", (int)((p+size)-e));
        return true;
    }

    Block *block = allocBlock();
    block->height = -1;
    block->data = p;
    block->prev = 0;
    block->next = 0;

    uint8_t *hash = allocHash256();
    sha256Twice(hash, p, 80);
    gBlockMap[hash] = block;
    p += size;
    return false;
}
Exemplo n.º 6
0
static bool buildBlock(
    const uint8_t *&p,
    const uint8_t *e
)
{
    static const uint32_t expected =
    #if defined(REDDCOIN)
        0xdbb6c0fb
    #else
        0xd9b4bef9
    #endif
    ;

    if(unlikely(e<=(8+p))) {
        //printf("end of map, reason : pointer past EOF\n");
        return true;
    }

    LOAD(uint32_t, magic, p);
    if(unlikely(expected!=magic)) {
        //printf("end of map, reason : magic is f****d %d away from EOF\n", (int)(e-p));
        return true;
    }

    LOAD(uint32_t, size, p);
    if(unlikely(e<(p+size))) {
        //printf("end of map, reason : end of block past EOF, %d past EOF\n", (int)((p+size)-e));
        return true;
    }

    Block *block = allocBlock();
    block->height = -1;
    block->data = p;
    block->prev = 0;
    block->next = 0;

    uint8_t *hash = allocHash256();
    sha256Twice(hash, p, 80);
    gBlockMap[hash] = block;
    p += size;
    return false;
}
Exemplo n.º 7
0
    virtual void startBlock(
        const Block *b,
        uint64_t chainSize
    )
    {
        uint8_t blockHash[kSHA256ByteSize];
        sha256Twice(blockHash, b->data, 80);

        const uint8_t *p = b->data;
        SKIP(uint32_t, version, p);
        SKIP(uint256_t, prevBlkHash, p);
        SKIP(uint256_t, blkMerkleRoot, p);
        LOAD(uint32_t, blkTime, p);

        blkID = b->height - 1;

        if (blkID >= cutoffBlock)
        {
            // block_id BIGINT PRIMARY KEY
            // block_hash BINARY(32)
            // time BIGINT
            fprintf(blockFile, "%" PRIu64 "|", blkID);

            writeEscapedBinaryBuffer(blockFile, blockHash, kSHA256ByteSize);
            fputc('|', blockFile);
            fprintf(blockFile, "%" PRIu64 "\n", (uint64_t)blkTime);
        }
        if (0 == (blkID) % 5000)
        {
            fprintf(
                stderr,
                "block=%8" PRIu64 " "
                "nbOutputs=%9" PRIu64 "\n",
                blkID,
                outputMap.size()
            );
        }
    }
Exemplo n.º 8
0
  virtual void startBlock(
    const Block *b,
    uint64_t
    ) {
    if (lastBlock < b->height) {
      wrapup();
    }

    auto p = b->chunk->getData();
    uint8_t blockHash[kSHA256ByteSize];
    sha256Twice(blockHash, p, 80);

    SKIP(uint32_t,  version,       p);
    SKIP(uint256_t, prevBlkHash,   p);
    SKIP(uint256_t, blkMerkleRoot, p);
    LOAD(uint32_t, blkTime, p);

    blkID = b->height - 1;

    if (blkID >= firstBlock) {
      fprintf(blockFile, "%" PRIu64 "|", blkID);

      writeHexEscapedBinaryBuffer(blockFile, blockHash, kSHA256ByteSize);
      fputc('|', blockFile);
      fprintf(blockFile, "%" PRIu64 "\n", (uint64_t)blkTime);
    }

    if (0 == blkID % 5000) {
      fprintf(
        stderr,
        "block=%8" PRIu64 " "
        "nbOutputs=%9" PRIu64 "\n",
        blkID,
        outputMap.size()
        );
    }
  }
Exemplo n.º 9
0
static void parseTX(
    const Block   *block,
    const uint8_t *&p
) {
    auto txStart = p;
    uint8_t *txHash = 0;

    if(gNeedTXHash && !skip) {
        auto txEnd = p;
        txHash = allocHash256();
        parseTX<true>(block, txEnd);
        sha256Twice(txHash, txStart, txEnd - txStart);
    }

    if(!skip) {
        startTX(p, txHash);
    }

        #if defined(CLAM)
            LOAD(uint32_t, nVersion, p);
        #else
            SKIP(uint32_t, nVersion, p);
        #endif

        #if defined(PEERCOIN) || defined(CLAM) || defined(JUMBUCKS)
            SKIP(uint32_t, nTime, p);
        #endif

        parseInputs<skip>(block, p, txHash);

        Chunk *txo = 0;
        size_t txoOffset = -1;
        const uint8_t *outputsStart = p;
        if(gNeedTXHash && !skip) {
            txo = Chunk::alloc();
            txoOffset = block->chunk->getOffset() + (p - block->chunk->getData());
            gTXOMap[txHash] = txo;
        }

        parseOutputs<skip, false>(p, txHash);

        if(txo) {
            size_t txoSize = p - outputsStart;
            txo->init(
                block->chunk->getMap(),
                txoSize,
                txoOffset
            );
        }

        SKIP(uint32_t, lockTime, p);

        #if defined(CLAM)
            if(1<nVersion) {
                LOAD_VARINT(strCLAMSpeechLen, p);
                p += strCLAMSpeechLen;
            }
        #endif

    if(!skip) {
        endTX(p);
    }
}