Skip to content
This repository has been archived by the owner on Jan 18, 2019. It is now read-only.

Submitting large amounts creates a weird temBAD_AMOUNT error #126

Open
irisli opened this issue Sep 30, 2014 · 3 comments
Open

Submitting large amounts creates a weird temBAD_AMOUNT error #126

irisli opened this issue Sep 30, 2014 · 3 comments
Labels

Comments

@irisli
Copy link
Contributor

irisli commented Sep 30, 2014

This transaction works (some information hidden to make things shorter):

curl -X POST https://live.stellar.org:9002 -d '{>   "method": "submit",
>   "params": [
>     {
>       "secret": "secret",
>       "tx_json": {
>         "TransactionType": "OfferCreate",
>         "Account": "gHt7foNVZAjJo8bjd8UMSD669LJpGhiPJk",
>         "TakerGets": {
>           "currency": "SCT",
>           "value": "1",
>           "issuer": "gDSSa75HPagWcvQmwH7D51dT5DPmvsKL4q"
>         },
>         "TakerPays": "100000000000000000"
>       }
>     }
>   ]
> }'
{
   "result" : {
      "engine_result" : "tesSUCCESS",
      "engine_result_code" : 0,
      "engine_result_message" : "The transaction was applied.",
      "status" : "success",
      "tx_blob" : "[hidden for brevity]",
      "tx_json" : {
         "Account" : "gHt7foNVZAjJo8bjd8UMSD669LJpGhiPJk",
         "Fee" : "10",
         "Flags" : 2147483648,
         "Sequence" : 54,
         "SigningPubKey" : "C8CAB98B938F89DBAC4AAA478058BB5664793E29D8764B6C31DD116D4255179D",
         "TakerGets" : {
            "currency" : "SCT",
            "issuer" : "gDSSa75HPagWcvQmwH7D51dT5DPmvsKL4q",
            "value" : "1"
         },
         "TakerPays" : "100000000000000000",
         "TransactionType" : "OfferCreate",
         "TxnSignature" : "425F255DF40A08DF3A31DB9A2FA6AB67AC40E643141B4D683753BFA2892F6240ED64BC0B8AE3B65122BC1832B09B69057D0ED29A1E91860102BF339B48937903",
         "hash" : "1707414A6095B3E19EA1FA067C8EC7040A3B0BD0240CEEC93E827E737D1CE240"
      }
   }
}

But this doesn't work:

curl -X POST https://live.stellar.org:9002 -d '{>   "method": "submit",
>   "params": [
>     {
>       "secret": "secret",
>       "tx_json": {
>         "TransactionType": "OfferCreate",
>         "Account": "gHt7foNVZAjJo8bjd8UMSD669LJpGhiPJk",
>         "TakerGets": {
>           "currency": "SCT",
>           "value": "1",
>           "issuer": "gDSSa75HPagWcvQmwH7D51dT5DPmvsKL4q"
>         },
>         "TakerPays": "100000000000000001"
>       }
>     }
>   ]
> }'
{
   "result" : {
      "engine_result" : "temBAD_AMOUNT",
      "engine_result_code" : -298,
      "engine_result_message" : "Can only send positive amounts.",
      "status" : "success",
      "tx_blob" : "[hidden for brevity]",
      "tx_json" : {
         "Account" : "gHt7foNVZAjJo8bjd8UMSD669LJpGhiPJk",
         "Fee" : "10",
         "Flags" : 2147483648,
         "Sequence" : 55,
         "SigningPubKey" : "C8CAB98B938F89DBAC4AAA478058BB5664793E29D8764B6C31DD116D4255179D",
         "TakerGets" : {
            "currency" : "SCT",
            "issuer" : "gDSSa75HPagWcvQmwH7D51dT5DPmvsKL4q",
            "value" : "1"
         },
         "TakerPays" : "100000000000000001",
         "TransactionType" : "OfferCreate",
         "TxnSignature" : "4F6DE6D965A7A30EF2E845A5BC7EF85CE7452A17293E3EED4828207068ED17EA1FB0167994D7A12F30C00F1BC4E208D0607100C6CEF52DD677CA776098632603",
         "hash" : "BA62147995E337642C53E476066D2DDAE29512799495F4118918CDB4A3B360FB"
      }
   }
}
@irisli irisli added the bug label Sep 30, 2014
@irisli
Copy link
Contributor Author

irisli commented Sep 30, 2014

This is actually similar to #87

@irisli
Copy link
Contributor Author

irisli commented Oct 21, 2014

The issue here is that 100000000000000001 has too much precision. However, the Stellard error message should say something more descriptive than Can only send positive amounts..

However, this is a minor issue.

@nbougalis
Copy link

The issue isn't precision as such. It's that it's largest than the (somewhat arbitrary) largest allowed value for the native currency. The error you are getting comes from code similar to this in the transactor:

if (!saTakerPays.isLegalNet () || !saTakerGets.isLegalNet ())
    return temBAD_AMOUNT;

Tracing through STAmount::isLegalNet you'll find that it determines whether the given amount exceeds the largest allowed value on the network, which happens to be 100000000000000000. You're specifying 100000000000000001 - which is one larger than the maximum allowed value.

The code is correctly returning a "bad amount" because the amount you are trying to represent is one more than the largest allowed value on the network for the native currency.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants