stellard icon indicating copy to clipboard operation
stellard copied to clipboard

Submitting large amounts creates a weird temBAD_AMOUNT error

Open irisli opened this issue 10 years ago • 3 comments

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 avatar Sep 30 '14 21:09 irisli

This is actually similar to https://github.com/stellar/stellard/issues/87

irisli avatar Sep 30 '14 21:09 irisli

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.

irisli avatar Oct 21 '14 21:10 irisli

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.

nbougalis avatar Nov 01 '14 06:11 nbougalis