Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: domob on July 02, 2014, 05:52:29 PM



Title: RPC command to get block tree
Post by: domob on July 02, 2014, 05:52:29 PM
Bitcoin Core has the start-up option "-printblocktree" to get information about the blockchain status, in particular, potential chain forks the client knows about.  I think it could be handy to have the possibility to access this same information also via an RPC call - this can be used from within a running daemon, and external services (web applications using the daemon internally, for instance) could use this to detect chain forks.

I've implemented something like this already for Namecoin and originally Huntercoin, see https://github.com/chronokings/huntercoin/pull/19.  This implements a simple new RPC command "getchains" (the name could be changed, obviously) with output like this:
Code:
[
    {
        "height" : 249522,
        "hash" : "458354cbd80c350045076193030d75dbcbb007d76f4960dbc6b00d560b77065d",
        "is_best" : true,
        "branch_len" : 0
    },
    {
        "height" : 249522,
        "hash" : "a18a3d1848e095297b41b9f921f5b86086c165ba9dff7e30d286c36373f334be",
        "is_best" : false,
        "branch_len" : 1,
        "branch" : [
            "7e78dc70d073a164ab66b066f2413578648b4d3ecc0d72ef9be2132faab36b82"
        ]
    },
    {
        "height" : 237894,
        "hash" : "b2274b69cf1e8ebd23c560b8b9811fe17c48720e0fb96e8f3ee5b5f5fffea27a",
        "is_best" : false,
        "branch_len" : 2,
        "branch" : [
            "28d1151f24990831e89bccfa1131a9387013ee3fdc946bf6fe8efa2d0c7a7a34",
            "c1ffb74675d2d23e087f026266d0f90096e4d1d6e7979b5638ed3be024f58543"
        ]
    },
    {
        "height" : 237865,
        "hash" : "0c0509b3d6e30663d7c96a0337d43223ce759b725a124a5892399efa37c9134b",
        "is_best" : false,
        "branch_len" : 3,
        "branch" : [
            "ddb0cb645af22155d652382ae03143401b733eb5b7981a9e9ba8b9f7632f4910",
            "ff6b5f794c08e8ca45682db3fe8ec715d31fb57159b2c90f2a0b7300b5e88b45",
            "6e60b1718f923c888f34d773eee6aa753c7f22e4405a128fc59740f98a8be61c"
        ]
    },
    {
        "height" : 87393,
        "hash" : "fef9f102dc000e0069e3042526032327bc618453b5bc0d8ca25ee5509028e628",
        "is_best" : false,
        "branch_len" : 12,
        "branch" : [
            "50926027c1fe34e43c59d8bf84a475e56bd63e62bf4a2e5756fea68ddbd00910",
            "648927b7b456d36a0a2baa68b57a51ad9878b10b1d708187acfeeb8f8b74ebe2",
            "e0872226a925cbf552557ba3f6a7d072fa6ee4f119da8719acfc5e3fb0477c1b",
            "841df107ac58c51d4ee4346b716e086368c987355cf6b854d8c423f31db4431b",
            "e28701a3bab940f3ec81cd0324ccb47cb34dfd8cc30211b23f3532cabb578d44",
            "9742dbcc4d447054a135255c720c286ff498002cda408f6c5e98d7c8fb4d3454",
            "92b463b45ec5afccfc7dc14a774b681966f9fa4740653bbf520eaa0b25d01049",
            "2c88dae0637e5977ebeb2367675c71e43c259b9ead16ed30fbb3135d989e9266",
            "8aa82978461c0dc812160ffcf4fc89a780f1d67e3a29123c318238eaa9b5facf",
            "f244148b7e02839787452481b9b76cb166718410f082b688b565644e18d3be1e",
            "91d4acdf2a641d7b545b4b73323db69eda60520ec21ba86e885e3a83f886c4e3",
            "497e0d08cef9c85e20fe7d758c3bf6010072105a6a2b33123b524e8413e45b69"
        ]
    }
]

What do you think about adding this or similar functionality also to Bitcoin Core?  Would a pull request be welcome?  I would be interested in working on a patch to implement this for Bitcoin Core.  Of course, the precise output format and other details can be discussed freely, and I will implement them as desired.


Title: Re: RPC command to get block tree
Post by: niceWoman25 on July 02, 2014, 08:50:05 PM
Hello :)

I see you can code in c++, would you do me a favor and code a RPC command to set a Hard Limit for Fee of transactions and reject all RPC sendtoaddress (and sendmany) transactions if the internally calculated Fee is higher than the previously set hardlimitfee like, lets say, 0.02 ?

I posted an thread 5 minutes earlier where i describe it more detailed:
https://bitcointalk.org/index.php?topic=675189.msg7645590#msg7645590