add RPC method to return changed/removed claims in a block #267

Closed
opened 2019-05-08 17:15:10 +02:00 by BrannonKing · 1 comment
BrannonKing commented 2019-05-08 17:15:10 +02:00 (Migrated from github.com)

I was thinking something like this:

extern bool UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex *pindex);

UniValue getchangesinblock(const JSONRPCRequest& request) {
    if (request.fHelp || request.params.size() > 1)
        throw std::runtime_error(
                "getchangesinblock\n"
                "Return the list of claims added, updated, and removed in a block\n"
                "or doesn't.\n"
                "Arguments:\n"
                "1. \"blockhash\"      (string, optional) the hash of the block in question\n"
                "Result: \n"
                "{\n"
                "  \"claims_added_or_updated\":   (array of string) claimIDs added or updated in the trie\n"
                "  \"claims_removed\":            (array of string) claimIDs that were removed from the trie.\n"
                "  \"supports_added_or_updated\": (array of string) IDs of supports added or updated\n"
                "  \"supports_removed\":          (array of string) IDs that were removed from the trie.\n"
                "}\n");

    CBlockUndo undo;
    {
        LOCK(cs_main);
        auto index = chainActive.Tip();
        if (request.params.size() > 0) {
            index = BlockHashIndex(ParseHashV(request.params[0], "blockhash (optional parameter)"));
        }

        if (!UndoReadFromDisk(undo, index))
            throw JSONRPCError(RPC_INTERNAL_ERROR,
                               "Unable to read the undo block for height " + std::to_string(index->nHeight));
    }
    UniValue added(UniValue::VARR);
    for (auto& u: undo.insertUndo)
        added.push_back(ClaimIdHash(u.outPoint.hash, u.outPoint.n).ToString());

    UniValue removed(UniValue::VARR);
    for (auto& u: undo.expireUndo)
        added.push_back(u.second.claimId.ToString());

//    UniValue sremoved(UniValue::VARR);
//    for (auto& u: undo.expireSupportUndo)
//        added.push_back(u.second..ToString());


    UniValue result(UniValue::VOBJ);
    result.pushKV("claims_added_or_updated", added);
    return result;
}

Also, make sure that the other RPC methods return the takeover height.

I was thinking something like this: ```c++ extern bool UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex *pindex); UniValue getchangesinblock(const JSONRPCRequest& request) { if (request.fHelp || request.params.size() > 1) throw std::runtime_error( "getchangesinblock\n" "Return the list of claims added, updated, and removed in a block\n" "or doesn't.\n" "Arguments:\n" "1. \"blockhash\" (string, optional) the hash of the block in question\n" "Result: \n" "{\n" " \"claims_added_or_updated\": (array of string) claimIDs added or updated in the trie\n" " \"claims_removed\": (array of string) claimIDs that were removed from the trie.\n" " \"supports_added_or_updated\": (array of string) IDs of supports added or updated\n" " \"supports_removed\": (array of string) IDs that were removed from the trie.\n" "}\n"); CBlockUndo undo; { LOCK(cs_main); auto index = chainActive.Tip(); if (request.params.size() > 0) { index = BlockHashIndex(ParseHashV(request.params[0], "blockhash (optional parameter)")); } if (!UndoReadFromDisk(undo, index)) throw JSONRPCError(RPC_INTERNAL_ERROR, "Unable to read the undo block for height " + std::to_string(index->nHeight)); } UniValue added(UniValue::VARR); for (auto& u: undo.insertUndo) added.push_back(ClaimIdHash(u.outPoint.hash, u.outPoint.n).ToString()); UniValue removed(UniValue::VARR); for (auto& u: undo.expireUndo) added.push_back(u.second.claimId.ToString()); // UniValue sremoved(UniValue::VARR); // for (auto& u: undo.expireSupportUndo) // added.push_back(u.second..ToString()); UniValue result(UniValue::VOBJ); result.pushKV("claims_added_or_updated", added); return result; } ``` Also, make sure that the other RPC methods return the takeover height.
BrannonKing commented 2019-09-06 22:14:09 +02:00 (Migrated from github.com)

Merged via https://github.com/lbryio/lbrycrd/pull/303. It doesn't report all changes, but it does report the ones that were queued for that block.

Merged via https://github.com/lbryio/lbrycrd/pull/303. It doesn't report all changes, but it does report the ones that were queued for that block.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: LBRYCommunity/lbrycrd#267
No description provided.