Skip to content

Commit

Permalink
Add NFT error category
Browse files Browse the repository at this point in the history
  • Loading branch information
Bushstar committed Apr 3, 2022
1 parent 50fe0d9 commit c948ab0
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 30 deletions.
40 changes: 40 additions & 0 deletions src/omnicore/errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,46 @@ inline std::string error_str(int ec) {
ec_str = "Address is already frozen";
break;

case PKT_ERROR_NFT -20:
ec_str = "Non-fungible tokens are not yet activated";
break;
case PKT_ERROR_NFT -21:
ec_str = "Property %d is of type non-fungible";
break;
case PKT_ERROR_NFT -23:
ec_str = "Type or version not permitted for property";
break;
case PKT_ERROR_NFT -24:
ec_str = "Property is not of type non-fungible";
break;
case PKT_ERROR_NFT -25:
ec_str = "Non-fungible token range start value out of range or zero";
break;
case PKT_ERROR_NFT -26:
ec_str = "Non-fungible token range end value out of range or zero";
break;
case PKT_ERROR_NFT -27:
ec_str = "Non-fungible token range start value is less than or equal to range end value";
break;
case PKT_ERROR_NFT -28:
ec_str = "Non-fungible token range amount out of range or zero";
break;
case PKT_ERROR_NFT -29:
ec_str = "Property does not exist";
break;
case PKT_ERROR_NFT -30:
ec_str = "Sender does not own the range data is being set on";
break;
case PKT_ERROR_NFT -31:
ec_str = "Sender is not the issuer of property";
break;
case PKT_ERROR_NFT -32:
ec_str = "Sender has insufficient balance of property";
break;
case PKT_ERROR_NFT -33:
ec_str = "Sender %s does not own the range being sent";
break;

default:
ec_str = "Unknown error";
}
Expand Down
1 change: 1 addition & 0 deletions src/omnicore/omnicore.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ enum TransactionType {
#define PKT_ERROR_TOKENS (-82000)
#define PKT_ERROR_SEND_ALL (-83000)
#define PKT_ERROR_ANYDATA (-84000)
#define PKT_ERROR_NFT (-85000)

#define OMNI_PROPERTY_BTC 0
#define OMNI_PROPERTY_MSC 1
Expand Down
60 changes: 30 additions & 30 deletions src/omnicore/tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,7 @@ int CMPTransaction::logicMath_SimpleSend(uint256& blockHash)

if (isPropertyNonFungible(property)) {
PrintToLog("%s(): rejected: property %d is of type non-fungible\n", __func__, property);
return (PKT_ERROR_TOKENS -27);
return (PKT_ERROR_NFT -21);
}

if (nValue <= 0 || MAX_INT_8_BYTES < nValue) {
Expand Down Expand Up @@ -1241,7 +1241,7 @@ int CMPTransaction::logicMath_SendToOwners()

if (isPropertyNonFungible(property)) {
PrintToLog("%s(): rejected: property %d is of type non-fungible\n", __func__, property);
return (PKT_ERROR_TOKENS -27);
return (PKT_ERROR_NFT -21);
}

if (nValue <= 0 || MAX_INT_8_BYTES < nValue) {
Expand Down Expand Up @@ -1373,7 +1373,7 @@ int CMPTransaction::logicMath_SendAll()

if (isPropertyNonFungible(property)) {
PrintToLog("%s(): rejected: property %d is of type non-fungible\n", __func__, property);
return (PKT_ERROR_TOKENS -27);
return (PKT_ERROR_NFT -21);
}

// ------------------------------------------
Expand Down Expand Up @@ -1431,38 +1431,38 @@ int CMPTransaction::logicMath_SendNonFungible()
version,
property,
block);
return (PKT_ERROR_SEND -22);
return (PKT_ERROR_NFT -23);
}

if (!isPropertyNonFungible(property)) {
PrintToLog("%s(): rejected: property %d is not of type non-fungible\n", __func__, property);
return (PKT_ERROR_TOKENS -27);
return (PKT_ERROR_NFT -24);
}

if (nonfungible_token_start <= 0 || MAX_INT_8_BYTES < nonfungible_token_start) {
PrintToLog("%s(): rejected: non-fungible token range start value out of range or zero: %d", __func__, nonfungible_token_start);
return (PKT_ERROR_SEND -23);
return (PKT_ERROR_NFT -25);
}

if (nonfungible_token_end <= 0 || MAX_INT_8_BYTES < nonfungible_token_end) {
PrintToLog("%s(): rejected: non-fungible token range end value out of range or zero: %d", __func__, nonfungible_token_end);
return (PKT_ERROR_SEND -23);
return (PKT_ERROR_NFT -26);
}

if (nonfungible_token_start > nonfungible_token_end) {
PrintToLog("%s(): rejected: non-fungible token range start value: %d is less than or equal to range end value: %d", __func__, nonfungible_token_start, nonfungible_token_end);
return (PKT_ERROR_SEND -23);
return (PKT_ERROR_NFT -27);
}

int64_t amount = (nonfungible_token_end - nonfungible_token_start) + 1;
if (amount <= 0) {
PrintToLog("%s(): rejected: non-fungible token range amount out of range or zero: %d", __func__, amount);
return (PKT_ERROR_SEND -23);
return (PKT_ERROR_NFT -28);
}

if (!pDbSpInfo->hasSP(property)) {
PrintToLog("%s(): rejected: property %d does not exist\n", __func__, property);
return (PKT_ERROR_SEND -24);
return (PKT_ERROR_NFT -29);
}

int64_t nBalance = GetAvailableTokenBalance(sender, property);
Expand All @@ -1473,7 +1473,7 @@ int CMPTransaction::logicMath_SendNonFungible()
property,
FormatMP(property, nBalance),
FormatMP(property, amount));
return (PKT_ERROR_SEND -25);
return (PKT_ERROR_NFT -32);
}

std::string rangeStartOwner = pDbNFT->GetNonFungibleTokenOwner(property, nonfungible_token_start);
Expand All @@ -1483,7 +1483,7 @@ int CMPTransaction::logicMath_SendNonFungible()
PrintToLog("%s(): rejected: sender %s does not own the range being sent\n",
__func__,
sender);
return (PKT_ERROR_SEND -26);
return (PKT_ERROR_NFT -33);
}

// ------------------------------------------
Expand Down Expand Up @@ -1517,7 +1517,7 @@ int CMPTransaction::logicMath_TradeOffer()

if (isPropertyNonFungible(property)) {
PrintToLog("%s(): rejected: property %d is of type non-fungible\n", __func__, property);
return (PKT_ERROR_TOKENS -27);
return (PKT_ERROR_NFT -21);
}

if (MAX_INT_8_BYTES < nValue) {
Expand Down Expand Up @@ -1621,7 +1621,7 @@ int CMPTransaction::logicMath_AcceptOffer_BTC()

if (isPropertyNonFungible(property)) {
PrintToLog("%s(): rejected: property %d is of type non-fungible\n", __func__, property);
return (PKT_ERROR_TOKENS -27);
return (PKT_ERROR_NFT -21);
}

if (nValue <= 0 || MAX_INT_8_BYTES < nValue) {
Expand Down Expand Up @@ -1652,7 +1652,7 @@ int CMPTransaction::logicMath_MetaDExTrade()

if (isPropertyNonFungible(property) || isPropertyNonFungible(desired_property)) {
PrintToLog("%s(): rejected: property %d or %d is of type non-fungible\n", __func__, property, desired_property);
return (PKT_ERROR_TOKENS -27);
return (PKT_ERROR_NFT -21);
}

if (property == desired_property) {
Expand Down Expand Up @@ -1733,7 +1733,7 @@ int CMPTransaction::logicMath_MetaDExCancelPrice()

if (isPropertyNonFungible(property) || isPropertyNonFungible(desired_property)) {
PrintToLog("%s(): rejected: property %d or %d is of type non-fungible\n", __func__, property, desired_property);
return (PKT_ERROR_TOKENS -27);
return (PKT_ERROR_NFT -21);
}

if (property == desired_property) {
Expand Down Expand Up @@ -1794,7 +1794,7 @@ int CMPTransaction::logicMath_MetaDExCancelPair()

if (isPropertyNonFungible(property) || isPropertyNonFungible(desired_property)) {
PrintToLog("%s(): rejected: property %d or %d is of type non-fungible\n", __func__, property, desired_property);
return (PKT_ERROR_TOKENS -27);
return (PKT_ERROR_NFT -21);
}

if (property == desired_property) {
Expand Down Expand Up @@ -2036,7 +2036,7 @@ int CMPTransaction::logicMath_CloseCrowdsale(CBlockIndex* pindex)

if (isPropertyNonFungible(property)) {
PrintToLog("%s(): rejected: property %d is of type non-fungible\n", __func__, property);
return (PKT_ERROR_TOKENS -27);
return (PKT_ERROR_NFT -21);
}

if (!IsPropertyIdValid(property)) {
Expand Down Expand Up @@ -2112,7 +2112,7 @@ int CMPTransaction::logicMath_CreatePropertyManaged(CBlockIndex* pindex)

if (MSC_PROPERTY_TYPE_NONFUNGIBLE == prop_type && !IsFeatureActivated(FEATURE_NONFUNGIBLE, block)) {
PrintToLog("%s(): rejected: non-fungible tokens are not yet activated (property type: %d)\n", __func__, prop_type);
return (PKT_ERROR_SP -22);
return (PKT_ERROR_NFT -20);
}

if ('\0' == name[0]) {
Expand Down Expand Up @@ -2277,7 +2277,7 @@ int CMPTransaction::logicMath_RevokeTokens(CBlockIndex* pindex)

if (isPropertyNonFungible(property)) {
PrintToLog("%s(): rejected: property %d is of type non-fungible\n", __func__, property);
return (PKT_ERROR_TOKENS -27);
return (PKT_ERROR_NFT -21);
}

if (nValue <= 0 || MAX_INT_8_BYTES < nValue) {
Expand Down Expand Up @@ -2346,7 +2346,7 @@ int CMPTransaction::logicMath_ChangeIssuer(CBlockIndex* pindex)

if (isPropertyNonFungible(property)) {
PrintToLog("%s(): rejected: property %d is of type non-fungible\n", __func__, property);
return (PKT_ERROR_TOKENS -27);
return (PKT_ERROR_NFT -21);
}

if (!IsPropertyIdValid(property)) {
Expand Down Expand Up @@ -2757,38 +2757,38 @@ int CMPTransaction::logicMath_NonFungibleData()
version,
property,
block);
return (PKT_ERROR_SEND -22);
return (PKT_ERROR_NFT -23);
}

if (!isPropertyNonFungible(property)) {
PrintToLog("%s(): rejected: property %d is not of type non-fungible\n", __func__, property);
return (PKT_ERROR_TOKENS -27);
return (PKT_ERROR_NFT -24);
}

if (nonfungible_token_start <= 0 || MAX_INT_8_BYTES < nonfungible_token_start) {
PrintToLog("%s(): rejected: non-fungible token range start value out of range or zero: %d", __func__, nonfungible_token_start);
return (PKT_ERROR_SEND -23);
return (PKT_ERROR_NFT -25);
}

if (nonfungible_token_end <= 0 || MAX_INT_8_BYTES < nonfungible_token_end) {
PrintToLog("%s(): rejected: non-fungible token range end value out of range or zero: %d", __func__, nonfungible_token_end);
return (PKT_ERROR_SEND -23);
return (PKT_ERROR_NFT -26);
}

if (nonfungible_token_start > nonfungible_token_end) {
PrintToLog("%s(): rejected: non-fungible token range start value: %d is less than or equal to range end value: %d", __func__, nonfungible_token_start, nonfungible_token_end);
return (PKT_ERROR_SEND -23);
return (PKT_ERROR_NFT -27);
}

int64_t amount = (nonfungible_token_end - nonfungible_token_start) + 1;
if (amount <= 0) {
PrintToLog("%s(): rejected: non-fungible token range amount out of range or zero: %d", __func__, amount);
return (PKT_ERROR_SEND -23);
return (PKT_ERROR_NFT -28);
}

if (!pDbSpInfo->hasSP(property)) {
PrintToLog("%s(): rejected: property %d does not exist\n", __func__, property);
return (PKT_ERROR_SEND -24);
return (PKT_ERROR_NFT -29);
}

NonFungibleStorage type = nonfungible_data_type ? NonFungibleStorage::IssuerData : NonFungibleStorage::HolderData;
Expand All @@ -2802,7 +2802,7 @@ int CMPTransaction::logicMath_NonFungibleData()
PrintToLog("%s(): rejected: sender %s does not own the range data is being set on\n",
__func__,
sender);
return (PKT_ERROR_SEND -26);
return (PKT_ERROR_NFT -30);
}
}
else
Expand All @@ -2816,7 +2816,7 @@ int CMPTransaction::logicMath_NonFungibleData()
property);

if (IsFeatureActivated(FEATURE_NONFUNGIBLE_ISSUER, block)) {
return (PKT_ERROR_SP -22);
return (PKT_ERROR_NFT -31);
}
}
}
Expand Down

0 comments on commit c948ab0

Please sign in to comment.