src/TAO/API/types/objects/list.cpp
json::json Objects::List(const json::json& params, uint8_t nRegisterType, uint8_t nObjectType)
        {
            /* JSON return value. */
            json::json ret = json::json::array();

            /* Get the Genesis ID. */
            uint256_t hashGenesis = 0;

            /* Watch for destination genesis. If no specific genesis or username
             * have been provided then fall back to the active sigchain. */
            if(params.find("genesis") != params.end())
                hashGenesis.SetHex(params["genesis"].get<std::string>());

            /* Check for username. */
            else if(params.find("username") != params.end())
                hashGenesis = TAO::Ledger::SignatureChain::Genesis(params["username"].get<std::string>().c_str());

            /* Check for default sessions. */
            else if(!config::fMultiuser.load() && users->LoggedIn())
                hashGenesis = users->GetGenesis(0);
            else
                throw APIException(-111, "Missing genesis / username");

            /* Check for paged parameter. */
            uint32_t nPage = 0;
            if(params.find("page") != params.end())
                nPage = std::stoul(params["page"].get<std::string>());

            /* Check for username parameter. */
            uint32_t nLimit = 100;
            if(params.find("limit") != params.end())
                nLimit = std::stoul(params["limit"].get<std::string>());

            /* Get the list of registers owned by this sig chain */
            std::vector<TAO::Register::Address> vAddresses;
            ListRegisters(hashGenesis, vAddresses);

            /* Get list of tokenized assets owned by this sig chain */
            ListPartial(hashGenesis, vAddresses);
            if(vAddresses.size() == 0)
                throw APIException(-74, "No registers found");

            /* Read all the registers to that they are sorted by creation time */
            std::vector<std::pair<TAO::Register::Address, TAO::Register::State>> vRegisters;
            GetRegisters(vAddresses, vRegisters);

            /* We pass false for fLookupName if the requested type is a name of namesace object,
               as those are the edge case that do not have a Name object themselves */
            bool fLookupName = nObjectType != TAO::Register::OBJECTS::NAME && nObjectType != TAO::Register::OBJECTS::NAMESPACE;

            /* Add the register data to the response */
            uint32_t nTotal = 0;
            for(const auto& state : vRegisters)
            {
                /* Only include requested register type */
                if(state.second.nType != nRegisterType)
                    continue;

                /* Cast to an Object */
                TAO::Register::Object object(state.second);

                /* Handle for object registers. */
                if(object.nType == TAO::Register::REGISTER::OBJECT)
                {
                    /* parse object so that the data fields can be accessed */
                    if(!object.Parse())
                        throw APIException(-36, "Failed to parse object register");

                    /* Only included requested object types. */
                    if((object.Standard() & nObjectType) == 0)
                        continue;
                }

                /* Get the current page. */
                uint32_t nCurrentPage = (nTotal / nLimit) ;

                /* Increment the counter */
                ++nTotal;

                /* Check the paged data. */
                if(nCurrentPage < nPage)
                    continue;

                if(nCurrentPage > nPage)
                    break;

                if(nTotal - (nPage * nLimit) > nLimit)
                    break;

                /* Populate the response JSON */
                json::json json;
                json["created"]  = state.second.nCreated;
                json["modified"] = state.second.nModified;

                json::json data  =TAO::API::ObjectToJSON(params, object, state.first, fLookupName);

                /* Copy the data in to the response after the  */
                json.insert(data.begin(), data.end());

                /* Add this objects json to the response */
                ret.push_back(json);

            }

            return ret;
        }
/* Generic method to list object registers by sig chain*/
Generic method to list object registers by sig chain
Generic method to list object registers by sig chain
json::json Objects::List(const json::json& params, uint8_t nRegisterType, uint8_t nObjectType)
        {
            json::json ret = json::json::array();
            uint256_t hashGenesis = 0;
            if(params.find("genesis") != params.end())
                hashGenesis.SetHex(params["genesis"].get<std::string>());
            else if(params.find("username") != params.end())
                hashGenesis = TAO::Ledger::SignatureChain::Genesis(params["username"].get<std::string>().c_str());
            else if(!config::fMultiuser.load() && users->LoggedIn())
                hashGenesis = users->GetGenesis(0);
            else
                throw APIException(-111, "Missing genesis / username");
            uint32_t nPage = 0;
            if(params.find("page") != params.end())
                nPage = std::stoul(params["page"].get<std::string>());
            uint32_t nLimit = 100;
            if(params.find("limit") != params.end())
                nLimit = std::stoul(params["limit"].get<std::string>());
            std::vector<TAO::Register::Address> vAddresses;
            ListRegisters(hashGenesis, vAddresses);
            ListPartial(hashGenesis, vAddresses);
            if(vAddresses.size() == 0)
                throw APIException(-74, "No registers found");
            std::vector<std::pair<TAO::Register::Address, TAO::Register::State>> vRegisters;
            GetRegisters(vAddresses, vRegisters);
            bool fLookupName = nObjectType != TAO::Register::OBJECTS::NAME && nObjectType != TAO::Register::OBJECTS::NAMESPACE;
            uint32_t nTotal = 0;
            for(const auto& state : vRegisters)
            {
                if(state.second.nType != nRegisterType)
                    continue;
                TAO::Register::Object object(state.second);
                if(object.nType == TAO::Register::REGISTER::OBJECT)
                {
                    if(!object.Parse())
                        throw APIException(-36, "Failed to parse object register");
                    if((object.Standard() & nObjectType) == 0)
                        continue;
                }
                uint32_t nCurrentPage = (nTotal / nLimit) ;
                ++nTotal;
                if(nCurrentPage < nPage)
                    continue;
                if(nCurrentPage > nPage)
                    break;
                if(nTotal - (nPage * nLimit) > nLimit)
                    break;
                json::json json;
                json["created"]  = state.second.nCreated;
                json["modified"] = state.second.nModified;
                json::json data  =TAO::API::ObjectToJSON(params, object, state.first, fLookupName);
                json.insert(data.begin(), data.end());
                ret.push_back(json);
            }
            return ret;
        }
json :: json Objects :: List ( const json :: json & params , uint8_t nRegisterType , uint8_t nObjectType ) { json :: json ret = json :: json :: array ( ) ; uint256_t hashGenesis = 0 ; if ( params . find ( " " ) != params . end ( ) ) hashGenesis . SetHex ( params [ " " ] . get < std :: string > ( ) ) ; else if ( params . find ( " " ) != params . end ( ) ) hashGenesis = TAO :: Ledger :: SignatureChain :: Genesis ( params [ " " ] . get < std :: string > ( ) . c_str ( ) ) ; else if ( ! config :: fMultiuser . load ( ) && users -> LoggedIn ( ) ) hashGenesis = users -> GetGenesis ( 0 ) ; else throw APIException ( -111 , " " ) ; uint32_t nPage = 0 ; if ( params . find ( " " ) != params . end ( ) ) nPage = std :: stoul ( params [ " " ] . get < std :: string > ( ) ) ; uint32_t nLimit = 100 ; if ( params . find ( " " ) != params . end ( ) ) nLimit = std :: stoul ( params [ " " ] . get < std :: string > ( ) ) ; std :: vector < TAO :: Register :: Address > vAddresses ; ListRegisters ( hashGenesis , vAddresses ) ; ListPartial ( hashGenesis , vAddresses ) ; if ( vAddresses . size ( ) == 0 ) throw APIException ( -74 , " " ) ; std :: vector < std :: pair < TAO :: Register :: Address , TAO :: Register :: State > > vRegisters ; GetRegisters ( vAddresses , vRegisters ) ; bool fLookupName = nObjectType != TAO :: Register :: OBJECTS :: NAME && nObjectType != TAO :: Register :: OBJECTS :: NAMESPACE ; uint32_t nTotal = 0 ; for ( const auto & state : vRegisters ) { if ( state . second . nType != nRegisterType ) continue ; TAO :: Register :: Object object ( state . second ) ; if ( object . nType == TAO :: Register :: REGISTER :: OBJECT ) { if ( ! object . Parse ( ) ) throw APIException ( -36 , " " ) ; if ( ( object . Standard ( ) & nObjectType ) == 0 ) continue ; } uint32_t nCurrentPage = ( nTotal / nLimit ) ; ++ nTotal ; if ( nCurrentPage < nPage ) continue ; if ( nCurrentPage > nPage ) break ; if ( nTotal - ( nPage * nLimit ) > nLimit ) break ; json :: json json ; json [ " " ] = state . second . nCreated ; json [ " " ] = state . second . nModified ; json :: json data = TAO :: API :: ObjectToJSON ( params , object , state . first , fLookupName ) ; json . insert ( data . begin ( ) , data . end ( ) ) ; ret . push_back ( json ) ; } return ret ; }
Generic method to list object registers by sig chain
Generic method to list object registers by sig chain
/* JSON return value. */ /* Get the Genesis ID. */ /* Watch for destination genesis. If no specific genesis or username
             * have been provided then fall back to the active sigchain. */ /* Check for username. */ /* Check for default sessions. */ /* Check for paged parameter. */ /* Check for username parameter. */ /* Get the list of registers owned by this sig chain */ /* Get list of tokenized assets owned by this sig chain */ /* Read all the registers to that they are sorted by creation time */ /* We pass false for fLookupName if the requested type is a name of namesace object,
               as those are the edge case that do not have a Name object themselves */ /* Add the register data to the response */ /* Only include requested register type */ /* Cast to an Object */ /* Handle for object registers. */ /* parse object so that the data fields can be accessed */ /* Only included requested object types. */ /* Get the current page. */ /* Increment the counter */ /* Check the paged data. */ /* Populate the response JSON */ /* Copy the data in to the response after the  */ /* Add this objects json to the response */