Ejemplo n.º 1
0
    virtual void edge(
        uint64_t      value,
        const uint8_t *upTXHash,
        uint64_t      outputIndex,
        const uint8_t *outputScript,
        uint64_t      outputScriptSize,
        const uint8_t *downTXHash,
        uint64_t      inputIndex,
        const uint8_t *inputScript,
        uint64_t      inputScriptSize
    )
    {
        uint8_t addrType[3];
        uint160_t pubKeyHash;
        int type = solveOutputScript(pubKeyHash.v, outputScript, outputScriptSize, addrType);
        if(unlikely(type<0)) return;

        uint64_t a;
        auto i = addrMap.find(pubKeyHash.v);
        if(unlikely(addrMap.end()!=i))
            a = i->second;
        else {
            Addr *addr = (Addr*)allocHash160();
            memcpy(addr->v, pubKeyHash.v, kRIPEMD160ByteSize);
            addrMap[addr->v] = a = allAddrs.size();
            allAddrs.push_back(addr);
        }

        vertices.push_back(a);
    }
Ejemplo n.º 2
0
    void move(
        const uint8_t *script,
        uint64_t      scriptSize,
        const uint8_t *txHash,
        uint64_t       value,
        bool           add,
        const uint8_t *downTXHash = 0
    )
    {
        uint8_t addrType[3];
        uint160_t pubKeyHash;
        int type = solveOutputScript(pubKeyHash.v, script, scriptSize, addrType);
        if(unlikely(type<0)) return;

        int64_t newSum = sum + value*(add ? 1 : -1);

        fwrite(&bTime, sizeof(uint64_t), 1, stdout);

        fwrite(pubKeyHash.v, sizeof(uint8_t), kRIPEMD160ByteSize, stdout); 

        const uint8_t *hash = downTXHash ? downTXHash : txHash;  
        fwrite(hash, sizeof(uint8_t), kSHA256ByteSize, stdout);

        fwrite(&add, sizeof(uint8_t), 1, stdout);
        fwrite(&value, sizeof(uint64_t), 1, stdout);

        (add ? adds : subs) += value;
        sum = newSum;
        ++nbTX;
    }
Ejemplo n.º 3
0
    virtual void endOutput(
        const uint8_t *p,
        uint64_t      value,
        const uint8_t *txHash,
        uint64_t      outputIndex,
        const uint8_t *outputScript,
        uint64_t      outputScriptSize
    )
    {
        if (active)
        {
            numTxOutputs++;
            totalTxOutput += value;

            // Script
            uint8_t script[1 + 2*outputScriptSize];
            toHex(script, outputScript, outputScriptSize);

            // Receiving address
            uint8_t address[40];
            address[0] = 'X';
            address[1] = 0;
            uint8_t addrType[3];
            uint160_t pubKeyHash;
            int type = solveOutputScript(pubKeyHash.v, outputScript, outputScriptSize, addrType);
            if(likely(0<=type)) hash160ToAddr(address, pubKeyHash.v);

            // N.B. Input hash and index are NULL at this stage
            fprintf(outputFile, "%" PRIu64 ",%" PRIu64 ",%" PRIu64 ",\"%s\",\"%s\",,\n", txID, outputIndex, value, script, address);
        }
    }
Ejemplo n.º 4
0
  virtual void endOutput(
    const uint8_t *p,
    uint64_t       value,
    const uint8_t *txHash,
    uint64_t       outputIndex,
    const uint8_t *outputScript,
    uint64_t       outputScriptSize
    ) {
    uint8_t address[40];

    address[0] = 'X';
    address[1] = 0;

    uint8_t   addrType[3];
    uint160_t pubKeyHash;
    int type = solveOutputScript(
      pubKeyHash.v,
      outputScript,
      outputScriptSize,
      addrType
      );

    if (likely(0 <= type)) {
      hash160ToAddr(
        address,
        pubKeyHash.v,
        false,
        addrType[0]
        );
    }

    if (blkID >= firstBlock) {
      fprintf(
        outputFile,
        "%" PRIu64 "|"
        "%s|"
        "%" PRIu64 "|"
        "%" PRIu64 "|"
        "%" PRIu32 "\n"
        ,
        outputID,
        address,
        value,
        txID,
        (uint32_t)outputIndex
        );
    }

    uint32_t oi = outputIndex;
    uint8_t *h  = allocHash256();
    memcpy(h, txHash, kSHA256ByteSize);

    uintptr_t ih  = reinterpret_cast<uintptr_t>(h);
    uint32_t *h32 = reinterpret_cast<uint32_t *>(ih);
    h32[0] ^= oi;

    outputMap[h] = outputID++;
  }
Ejemplo n.º 5
0
    void move(
        const uint8_t *script,
        uint64_t      scriptSize,
        const uint8_t *txHash,
        int64_t        value,
        const uint8_t *downTXHash = 0
    )
    {
        uint8_t addrType[3];
        uint160_t pubKeyHash;
        int type = solveOutputScript(pubKeyHash.v, script, scriptSize, addrType);
        if(unlikely(type<0)) return;

        Addr *addr;
        auto i = addrMap.find(pubKeyHash.v);
        if(unlikely(addrMap.end()!=i))
            addr = i->second;
        else {
            addr = allocAddr();
            memcpy(addr->hash.v, pubKeyHash.v, kRIPEMD160ByteSize);
            addr->sum = 0;

            addrMap[addr->hash.v] = addr;
            allAddrs.push_back(addr);
        }

        addr->lastTouched = blockTime;
        addr->sum += value;

        static uint64_t cnt = 0;
        if(unlikely(0==((cnt++)&0xFFFFF))) {

            if(
                curBlock   &&
                lastBlock  &&
                firstBlock
            )
            {
                double progress = curBlock->height/(double)lastBlock->height;
                info(
                    "%8" PRIu64 " blocks, "
                    "%8.3f MegaMoves , "
                    "%8.3f MegaAddrs , "
                    "%5.2f%%",
                    curBlock->height,
                    cnt*1e-6,
                    addrMap.size()*1e-6,
                    100.0*progress
                );
            }
        }
    }
Ejemplo n.º 6
0
    static void showScriptInfo(
        const uint8_t   *outputScript,
        uint64_t        outputScriptSize
    )
    {
        uint8_t type[128];
        const char *typeName = "unknown";
        uint8_t pubKeyHash[kSHA256ByteSize];
        int r = solveOutputScript(pubKeyHash, outputScript, outputScriptSize, type);
        switch(r) {
        case 0: {
            typeName = "pays to hash160(pubKey)";
            break;
        }
        case 1: {
            typeName = "pays to explicit uncompressed pubKey";
            break;
        }
        case 2: {
            typeName = "pays to explicit compressed pubKey";
            break;
        }
        case 3: {
            typeName = "pays to hash160(script)";
            break;
        }
        case 4: {
            typeName = "pays to hash160(script)";
            break;
        }
        case -2: {
            typeName = "broken script generated by p2pool - coins lost";
            break;
        }
        case -1: {
            typeName = "couldn't parse script";
            break;
        }
        }
        printf("\n");
        printf("        script type = %s\n", typeName);

        if(0<=r) {
            uint8_t btcAddr[64];
            hash160ToAddr(btcAddr, pubKeyHash);
            printf("        script pays to address %s\n", btcAddr);
        }
    }
Ejemplo n.º 7
0
    virtual void endOutput(
        const uint8_t *p,
        uint64_t      value,
        const uint8_t *txHash,
        uint64_t      outputIndex,
        const uint8_t *outputScript,
        uint64_t      outputScriptSize
    )
    {
        uint8_t address[40];
        address[0] = 'X';
        address[1] = 0;

        uint8_t addrType[3];
        uint160_t pubKeyHash;
        int type = solveOutputScript(pubKeyHash.v, outputScript, outputScriptSize, addrType);
        if(likely(0<=type)) hash160ToAddr(address, pubKeyHash.v);

        // id BIGINT PRIMARY KEY
        // dstAddress CHAR(36)
        // value BIGINT
        // txID BIGINT
        // offset INT
        fprintf(
            outputFile,
            "%" PRIu64 "\t"
            "%s\t"
            "%" PRIu64 "\t"
            "%" PRIu64 "\t"
            "%" PRIu32 "\n"
            ,
            outputID,
            address,
            value,
            txID,
            (uint32_t)outputIndex
        );

        uint32_t oi = outputIndex;
        uint8_t *h = allocHash256();
        memcpy(h, txHash, kSHA256ByteSize);

        uintptr_t ih = reinterpret_cast<uintptr_t>(h);
        uint32_t *h32 = reinterpret_cast<uint32_t*>(ih);
        h32[0] ^= oi;

        outputMap[h] = outputID++;
    }
Ejemplo n.º 8
0
    void move(
        const uint8_t *script,
        uint64_t      scriptSize,
        const uint8_t *txHash,
        uint64_t       value,
        bool           add,
        const uint8_t *downTXHash = 0
    )
    {
        uint8_t addrType[3];
        uint160_t pubKeyHash;
        int type = solveOutputScript(pubKeyHash.v, script, scriptSize, addrType);
        if(unlikely(type<0)) return;

        bool match = (addrMap.end() != addrMap.find(pubKeyHash.v));
        if(unlikely(match)) {

            int64_t newSum = sum + value*(add ? 1 : -1);

            if(csv) {
                printf("%6" PRIu64 ", \"", bTime/86400 + 25569);
                showHex(pubKeyHash.v, kRIPEMD160ByteSize, false);
                printf("\", \"");
                showHex(downTXHash ? downTXHash : txHash);
                printf(
                    "\",%17.08f,%17.08f\n",
                    (add ? 1e-8 : -1e-8)*value,
                    newSum*1e-8
                );
            } else {

                struct tm gmTime;
                time_t blockTime = bTime;
                gmtime_r(&blockTime, &gmTime);

                char timeBuf[256];
                asctime_r(&gmTime, timeBuf);

                size_t sz =strlen(timeBuf);
                if(0<sz) timeBuf[sz-1] = 0;

                printf("    %s    ", timeBuf);
                showHex(pubKeyHash.v, kRIPEMD160ByteSize, false);

                printf("    ");
                showHex(downTXHash ? downTXHash : txHash);

                printf(
                    " %24.08f %c %24.08f = %24.08f\n",
                    sum*1e-8,
                    add ? '+' : '-',
                    value*1e-8,
                    newSum*1e-8
                );
            }

            (add ? adds : subs) += value;
            sum = newSum;
            ++nbTX;
        }
    }
Ejemplo n.º 9
0
    void move(
        const uint8_t *script,
        uint64_t      scriptSize,
        const uint8_t *upTXHash,
        int64_t       outputIndex,
        int64_t       value,
        const uint8_t *downTXHash = 0,
        uint64_t      inputIndex = -1
    )
    {
        uint8_t addrType[3];
        uint160_t pubKeyHash;
        int type = solveOutputScript(pubKeyHash.v, script, scriptSize, addrType);
        if(unlikely(type<0)) return;

        if(0!=restrictMap.size()) {
            auto r = restrictMap.find(pubKeyHash.v);
            if(restrictMap.end()==r) {
                return;
            }
        }

        Addr *addr;
        auto i = addrMap.find(pubKeyHash.v);
        if(unlikely(addrMap.end()!=i)) {
            addr = i->second;
        } else {

            addr = allocAddr();

            memcpy(addr->hash.v, pubKeyHash.v, kRIPEMD160ByteSize);
            addr->outputVec = 0;
            addr->nbOut = 0;
            addr->nbIn = 0;
            addr->sum = 0;

            if(detailed) {
                addr->outputVec = new OutputVec;
            }

            addrMap[addr->hash.v] = addr;
            allAddrs.push_back(addr);
        }

        if(0<value) {
            addr->lastIn = blockTime;
            ++(addr->nbIn);
        } else {
            addr->lastOut = blockTime;
            ++(addr->nbOut);
        }
        addr->sum += value;

        if(detailed) {
            struct Output output;
            output.value = value;
            output.time = blockTime;
            output.upTXHash = upTXHash;
            output.downTXHash = downTXHash;
            output.inputIndex = inputIndex;
            output.outputIndex = outputIndex;
            addr->outputVec->push_back(output);
        }
    }