Skip to content
This repository was archived by the owner on Nov 10, 2025. It is now read-only.

fix insufficient networkfee in RpcClient#496

Closed
bettybao1209 wants to merge 4 commits intoneo-project:masterfrom
bettybao1209:fix-netfee
Closed

fix insufficient networkfee in RpcClient#496
bettybao1209 wants to merge 4 commits intoneo-project:masterfrom
bettybao1209:fix-netfee

Conversation

@bettybao1209
Copy link
Copy Markdown
Contributor

The decimal of network fee in RpcClient and RpcServer is different, resulting in insuffient funds exception.

@bettybao1209 bettybao1209 changed the title fix insufficient networkfee fix insufficient networkfee in RpcClient Feb 1, 2021
@erikzhang
Copy link
Copy Markdown
Member

I think use floating-point numbers in JSON is not safe. Especially in the case of expressing prices.

@bettybao1209
Copy link
Copy Markdown
Contributor Author

I think use floating-point numbers in JSON is not safe. Especially in the case of expressing prices.

If not, it may be knida confusing for users when invoking calculatenetworkfee in RPCServer.

@erikzhang
Copy link
Copy Markdown
Member

We should uniformly use long to ensure accuracy.

@bettybao1209
Copy link
Copy Markdown
Contributor Author

We should uniformly use long to ensure accuracy.

But currently we use float value for json output like json["gasconsumed"].

@erikzhang
Copy link
Copy Markdown
Member

But currently we use float value for json output like json["gasconsumed"].

I think we should use long for JSON output.

@bettybao1209
Copy link
Copy Markdown
Contributor Author

So should we uniform both the user input and the JSON output in long type?

@erikzhang
Copy link
Copy Markdown
Member

erikzhang commented Feb 1, 2021

For JSON, I think we should use long for both requests and responses.

@chenzhitong
Copy link
Copy Markdown
Contributor

chenzhitong commented Feb 1, 2021

For JSON, I think we should use long for both requests and responses.

The asset amount(fees and NEP-17 tokens) is now in decimal format in both neo-cli and RpcServer.
e.g.

"sysfee": "0.0900799",
"netfee": "0.0124845",
"amount": "30000046.99999955",
"balance": "30000016.38985890"

neo-cli command:
deploy
invoke
balanceof
totalsupply
transfer
etc.

RpcServer:
calculatenetworkfee
getapplicationlog
getblock
getblockheader
getrawtransaction
getunclaimedgas
getwalletunclaimedgas
invokecontractverify
invokefunction
invokescript
sendfrom
sendmany
sendtoaddress
getnep17balances
getnep17transfers
getwalletbalance

@roman-khimov
Copy link
Copy Markdown
Contributor

I think use floating-point numbers in JSON is not safe.

They really are, we had problems with rounding errors.

For JSON, I think we should use long for both requests and responses.

But we can wrap them into strings, returning "value": "0.12345678" instead of "value": 0.12345678. This representation is much more convenient to me (especially for everything that is not GAS or NEO where the number of decimals is well-known, it's not for $RANDOM_TOKEN). And it avoids any losses when converting to/from JSON.

I mean BigDecimal.ToString() doesn't introduce any rounding errors and neither does TryParse(), so we just need to avoid going through floating point everywhere we're dealing with these values and we'll be fine.

@erikzhang
Copy link
Copy Markdown
Member

Wrapping BigInteger into string in JSON is okay for me.

@Ashuaidehao Ashuaidehao mentioned this pull request Feb 3, 2021
@bettybao1209
Copy link
Copy Markdown
Contributor Author

move to #505

@bettybao1209 bettybao1209 deleted the fix-netfee branch February 3, 2021 10:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants