src/TAO/API/utils.cpp
uint8_t GetDecimals(const TAO::Register::Object& object)
        {
            /* Declare the nDecimals to return */
            uint8_t nDecimals = 0;

            /* Get the object standard. */
            uint8_t nStandard = object.Standard();

            /* Check the object standard. */
            switch(nStandard)
            {
                case TAO::Register::OBJECTS::TOKEN:
                {
                    nDecimals = object.get<uint8_t>("decimals");
                    break;
                }

                case TAO::Register::OBJECTS::TRUST:
                {
                    nDecimals = TAO::Ledger::NXS_DIGITS; // NXS token default digits
                    break;
                }

                case TAO::Register::OBJECTS::ACCOUNT:
                {
                    /* If debiting an account we need to look at the token definition in order to get the digits. */
                    TAO::Register::Address nIdentifier = object.get<uint256_t>("token");

                    /* Edge case for NXS token which has identifier 0, so no look up needed */
                    if(nIdentifier == 0)
                        nDecimals = TAO::Ledger::NXS_DIGITS;
                    else
                    {

                        TAO::Register::Object token;
                        if(!LLD::Register->ReadState(nIdentifier, token, TAO::Ledger::FLAGS::MEMPOOL))
                            throw APIException(-125, "Token not found");

                        /* Parse the object register. */
                        if(!token.Parse())
                            throw APIException(-14, "Object failed to parse");

                        nDecimals = token.get<uint8_t>("decimals");
                    }
                    break;
                }

                default:
                {
                    throw APIException(-124, "Unknown token / account.");
                }

            }

            return nDecimals;
        }
/* Retrieves the number of decimals that applies to amounts for this token or account object.
         *  If the object register passed in is a token account then we need to look at the token definition
         *  in order to get the decimals.  The token is obtained by looking at the identifier field,
         *  which contains the register address of the issuing token
         */
Retrieves the number of decimals that applies to amounts for this token or account object.
If the object register passed in is a token account then we need to look at the token definition
in order to get the decimals.  The token is obtained by looking at the identifier field,
which contains the register address of the issuing token
Retrieves the number of decimals that applies to amounts for this token or account object . If the object register passed in is a token account then we need to look at the token definition in order to get the decimals . The token is obtained by looking at the identifier field which contains the register address of the issuing token
uint8_t GetDecimals(const TAO::Register::Object& object)
        {
            uint8_t nDecimals = 0;
            uint8_t nStandard = object.Standard();
            switch(nStandard)
            {
                case TAO::Register::OBJECTS::TOKEN:
                {
                    nDecimals = object.get<uint8_t>("decimals");
                    break;
                }
                case TAO::Register::OBJECTS::TRUST:
                {
                    nDecimals = TAO::Ledger::NXS_DIGITS; 
                    break;
                }
                case TAO::Register::OBJECTS::ACCOUNT:
                {
                    TAO::Register::Address nIdentifier = object.get<uint256_t>("token");
                    if(nIdentifier == 0)
                        nDecimals = TAO::Ledger::NXS_DIGITS;
                    else
                    {
                        TAO::Register::Object token;
                        if(!LLD::Register->ReadState(nIdentifier, token, TAO::Ledger::FLAGS::MEMPOOL))
                            throw APIException(-125, "Token not found");
                        if(!token.Parse())
                            throw APIException(-14, "Object failed to parse");
                        nDecimals = token.get<uint8_t>("decimals");
                    }
                    break;
                }
                default:
                {
                    throw APIException(-124, "Unknown token / account.");
                }
            }
            return nDecimals;
        }
uint8_t GetDecimals ( const TAO :: Register :: Object & object ) { uint8_t nDecimals = 0 ; uint8_t nStandard = object . Standard ( ) ; switch ( nStandard ) { case TAO :: Register :: OBJECTS :: TOKEN : { nDecimals = object . get < uint8_t > ( " " ) ; break ; } case TAO :: Register :: OBJECTS :: TRUST : { nDecimals = TAO :: Ledger :: NXS_DIGITS ; break ; } case TAO :: Register :: OBJECTS :: ACCOUNT : { TAO :: Register :: Address nIdentifier = object . get < uint256_t > ( " " ) ; if ( nIdentifier == 0 ) nDecimals = TAO :: Ledger :: NXS_DIGITS ; else { TAO :: Register :: Object token ; if ( ! LLD :: Register -> ReadState ( nIdentifier , token , TAO :: Ledger :: FLAGS :: MEMPOOL ) ) throw APIException ( -125 , " " ) ; if ( ! token . Parse ( ) ) throw APIException ( -14 , " " ) ; nDecimals = token . get < uint8_t > ( " " ) ; } break ; } default : { throw APIException ( -124 , " " ) ; } } return nDecimals ; }
Retrieves the number of decimals that applies to amounts for this token or account object.
Retrieves the number of decimals that applies to amounts for this token or account object .
/* Declare the nDecimals to return */ /* Get the object standard. */ /* Check the object standard. */ // NXS token default digits /* If debiting an account we need to look at the token definition in order to get the digits. */ /* Edge case for NXS token which has identifier 0, so no look up needed */ /* Parse the object register. */