<p>As you can see from the definition in <a href="https://github.com/bitcoin/bitcoin/blob/master/src/rpc/util.h#L115" rel="nofollow noreferrer">rpc/util.h</a>, <code>RPCResult::Type</code> is just an enumeration, meaning they are numbers to represent different types of values.
As the values returned by the RPC are simply strings, those numbers help describing them in the output (e.g. as 'numeric').
In the <code>enum</code> definition, you can find a description for the values that are less intuitive (such as STR_AMOUNT).</p>

<p>That said, you can map those objects to C++ types by looking at the variables that are converted to such objects.</p>

<p>In your example, the RPC object is built by <code>MempoolInfoToJSON</code>.
If you look at that function (<a href="https://github.com/bitcoin/bitcoin/blob/master/src/rpc/blockchain.cpp#L1398" rel="nofollow noreferrer">here</a>), you will see a number of <code>pushKV</code> operations, which convert the original variables to the corresponding object.
So, you can easily see that:</p>

<p><code>RPCResult::Type::BOOL</code> is a <code>bool</code>  </p>

<p><code>RPCResult::Type::NUM</code> is an <code>int64_t</code> (which is a <code>signed long int</code>)</p>

<p>and so on.</p>

<p>Note that these JSON objects can actually be mapped to more than a type in C++: you can convert a <code>STR</code> to a <code>string</code> or a <code>char*</code>, and you can convert a <code>NUM</code> to an <code>int</code> or to a <code>long</code>, depending on its size.
Similarly, a string hex can be mapped to a string or it can be converted to its numeric value.
So, eventually, it's up to you to decide the actual mapping, depending on your needs.</p>

CC BY-SA 4.0
2020-06-11T11:32:13.940Z
2020-06-11T11:48:23.073Z
2020-06-11T11:48:23.073Z
FedFranz
<p>Sorry for this noob question. I have wrapped some Bitcoin Core JSON RPC APIs. 
The tests I've made so far are working fime but now I have some issues mapping input arguments with the correct C++ data types.</p>

<p>For instance:
<em>bitcoin-cli help getmempoolinfo</em> returns:</p>

<pre><code>{
  "size": xxxxx,               (numeric) Current tx count
  "bytes": xxxxx,              (numeric) Sum of all virtual transaction sizes as defined in BIP 141. Differs from actual serialized size because witness data is discounted
  "usage": xxxxx,              (numeric) Total memory usage for the mempool
  "maxmempool": xxxxx,         (numeric) Maximum memory usage for the mempool
  "mempoolminfee": xxxxx       (numeric) Minimum fee rate in BTC/kB for tx to be accepted. Is the maximum of minrelaytxfee and minimum mempool fee
  "minrelaytxfee": xxxxx       (numeric) Current minimum relay fee for transactions
}
</code></pre>

<p>Numeric is too generic</p>

<p>The file blockchain.cpp defines:</p>

<pre><code>static UniValue getmempoolinfo(const JSONRPCRequest&amp; request)
{
            RPCHelpMan{"getmempoolinfo",
                "\nReturns details on the active state of the TX memory pool.\n",
                {},
                RPCResult{
                    RPCResult::Type::OBJ, "", "",
                    {
                        {RPCResult::Type::BOOL, "loaded", "True if the mempool is fully loaded"},
                        {RPCResult::Type::NUM, "size", "Current tx count"},
                        {RPCResult::Type::NUM, "bytes", "Sum of all virtual transaction sizes as defined in BIP 141. Differs from actual serialized size because witness data is discounted"},
                        {RPCResult::Type::NUM, "usage", "Total memory usage for the mempool"},
                        {RPCResult::Type::NUM, "maxmempool", "Maximum memory usage for the mempool"},
                        {RPCResult::Type::STR_AMOUNT, "mempoolminfee", "Minimum fee rate in " + CURRENCY_UNIT + "/kB for tx to be accepted. Is the maximum of minrelaytxfee and minimum mempool fee"},
                        {RPCResult::Type::STR_AMOUNT, "minrelaytxfee", "Current minimum relay fee for transactions"},
                        {RPCResult::Type::NUM, "unbroadcastcount", "Current number of transactions that haven't passed initial broadcast yet"}
                    }},
                RPCExamples{
                    HelpExampleCli("getmempoolinfo", "")
            + HelpExampleRpc("getmempoolinfo", "")
                },
            }.Check(request);

    return MempoolInfoToJSON(EnsureMemPool(request.context));
}
</code></pre>

<p>again, what C++ type is <em>RPCResult::Type::NUM</em> ?</p>

<bitcoin-core>
Bitcoin Data Types
Claudio
# Bitcoin Data Types

(Asked by: username_0 on 2020-06-11)

Sorry for this noob question. I have wrapped some Bitcoin Core JSON RPC APIs.
The tests I've made so far are working fime but now I have some issues mapping input arguments with the correct C++ data types.

For instance:
*bitcoin-cli help getmempoolinfo* returns:

```
{
  "size": xxxxx,               (numeric) Current tx count
  "bytes": xxxxx,              (numeric) Sum of all virtual transaction sizes as defined in BIP 141. Differs from actual serialized size because witness data is discounted
  "usage": xxxxx,              (numeric) Total memory usage for the mempool
  "maxmempool": xxxxx,         (numeric) Maximum memory usage for the mempool
  "mempoolminfee": xxxxx       (numeric) Minimum fee rate in BTC/kB for tx to be accepted. Is the maximum of minrelaytxfee and minimum mempool fee
  "minrelaytxfee": xxxxx       (numeric) Current minimum relay fee for transactions
}

```

Numeric is too generic

The file blockchain.cpp defines:

```
static UniValue getmempoolinfo(const JSONRPCRequest& request)
{
            RPCHelpMan{"getmempoolinfo",
                "\nReturns details on the active state of the TX memory pool.\n",
                {},
                RPCResult{
                    RPCResult::Type::OBJ, "", "",
                    {
                        {RPCResult::Type::BOOL, "loaded", "True if the mempool is fully loaded"},
                        {RPCResult::Type::NUM, "size", "Current tx count"},
                        {RPCResult::Type::NUM, "bytes", "Sum of all virtual transaction sizes as defined in BIP 141. Differs from actual serialized size because witness data is discounted"},
                        {RPCResult::Type::NUM, "usage", "Total memory usage for the mempool"},
                        {RPCResult::Type::NUM, "maxmempool", "Maximum memory usage for the mempool"},
                        {RPCResult::Type::STR_AMOUNT, "mempoolminfee", "Minimum fee rate in " + CURRENCY_UNIT + "/kB for tx to be accepted. Is the maximum of minrelaytxfee and minimum mempool fee"},
                        {RPCResult::Type::STR_AMOUNT, "minrelaytxfee", "Current minimum relay fee for transactions"},
                        {RPCResult::Type::NUM, "unbroadcastcount", "Current number of transactions that haven't passed initial broadcast yet"}
                    }},
                RPCExamples{
                    HelpExampleCli("getmempoolinfo", "")
            + HelpExampleRpc("getmempoolinfo", "")
                },
            }.Check(request);

    return MempoolInfoToJSON(EnsureMemPool(request.context));
}

```

again, what C++ type is *RPCResult::Type::NUM* ?

**Tags:** bitcoin-core


---

## 1 answers

### Answer by username_1 on 2020-06-11. Score: 0 | Accepted answer

As you can see from the definition in [rpc/util.h](https://github.com/bitcoin/bitcoin/blob/master/src/rpc/util.h#L115), `RPCResult::Type` is just an enumeration, meaning they are numbers to represent different types of values.
As the values returned by the RPC are simply strings, those numbers help describing them in the output (e.g. as 'numeric').
In the `enum` definition, you can find a description for the values that are less intuitive (such as STR\_AMOUNT).

That said, you can map those objects to C++ types by looking at the variables that are converted to such objects.

In your example, the RPC object is built by `MempoolInfoToJSON`.
If you look at that function ([here](https://github.com/bitcoin/bitcoin/blob/master/src/rpc/blockchain.cpp#L1398)), you will see a number of `pushKV` operations, which convert the original variables to the corresponding object.
So, you can easily see that:

`RPCResult::Type::BOOL` is a `bool`

`RPCResult::Type::NUM` is an `int64_t` (which is a `signed long int`)

and so on.

Note that these JSON objects can actually be mapped to more than a type in C++: you can convert a `STR` to a `string` or a `char*`, and you can convert a `NUM` to an `int` or to a `long`, depending on its size.
Similarly, a string hex can be mapped to a string or it can be converted to its numeric value.
So, eventually, it's up to you to decide the actual mapping, depending on your needs.


---

