Is this json_object() function creating a circular reference? (in bitcoin mining)

13 Views Asked by At

This question is about what the role of the function json_object() used in cpumier

I will show cpuminer code first and Jansson documentation second:

FIRST:

else if (work->txs) {
        char *req;

        for (i = 0; i < ARRAY_SIZE(work->data); i++)
            be32enc(work->data + i, work->data[i]);
        bin2hex(data_str, (unsigned char *)work->data, 80);
        if (work->workid) {
            char *params;
            val = json_object();  //   ============>>>>>>   MY QUESTION !!!!! - THE PROBLEM IS HERE
            json_object_set_new(val, "workid", json_string(work->workid));      // AND HERE
            params = json_dumps(val, 0);
            json_decref(val);
            req = malloc(128 + 2*80 + strlen(work->txs) + strlen(params));
            sprintf(req,
                "{\"method\": \"submitblock\", \"params\": [\"%s%s\", %s], \"id\":1}\r\n",
                data_str, work->txs, params);
            free(params);

SECOND: Read Jansson Documentation:

Circular References

A circular reference is created when an object or an array is, directly or indirectly, inserted inside itself. The direct case is simple:

json_t *obj = json_object();
json_object_set(obj, "foo", obj);

I have tried to find what json_object() is doing there in the cpuminer but I am not even sure whether json_object() is a circular reference or not.

Please explain json_object() function.

0

There are 0 best solutions below