Merge pull request #6380
9127e97
doc: Mention RPC strings for monetary amounts in release notes (Wladimir J. van der Laan)7d226b7
[QA] add testcases for parsing strings as values (Jonas Schnelli)614601b
rpc: Accept strings in AmountFromValue (Wladimir J. van der Laan)
This commit is contained in:
commit
240b30eaf0
3 changed files with 57 additions and 22 deletions
|
@ -19,10 +19,13 @@ https://www.torproject.org/docs/tor-manual.html.en
|
|||
|
||||
This allows running bitcoind without having to do any manual configuration.
|
||||
|
||||
Example header
|
||||
----------------------
|
||||
Low-level RPC API changes
|
||||
--------------------------
|
||||
|
||||
Example content.
|
||||
- Monetary amounts can be provided as strings. This means that for example the
|
||||
argument to sendtoaddress can be "0.0001" instead of 0.0001. This can be an
|
||||
advantage if a JSON library insists on using a lossy floating point type for
|
||||
numbers, which would be dangerous for monetary amounts.
|
||||
|
||||
0.12.0 Change log
|
||||
=================
|
||||
|
|
|
@ -218,5 +218,37 @@ class WalletTest (BitcoinTestFramework):
|
|||
#tx should be added to balance because after restarting the nodes tx should be broadcastet
|
||||
assert_equal(self.nodes[2].getbalance(), Decimal('63.99800000')); #should not be
|
||||
|
||||
#send a tx with value in a string (PR#6380 +)
|
||||
txId = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), "2")
|
||||
txObj = self.nodes[0].gettransaction(txId)
|
||||
assert_equal(txObj['amount'], Decimal('-2.00000000'))
|
||||
|
||||
txId = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), "0.0001")
|
||||
txObj = self.nodes[0].gettransaction(txId)
|
||||
assert_equal(txObj['amount'], Decimal('-0.00010000'))
|
||||
|
||||
#check if JSON parser can handle scientific notation in strings
|
||||
txId = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), "1e-4")
|
||||
txObj = self.nodes[0].gettransaction(txId)
|
||||
assert_equal(txObj['amount'], Decimal('-0.00010000'))
|
||||
|
||||
#this should fail
|
||||
errorString = ""
|
||||
try:
|
||||
txId = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), "1f-4")
|
||||
except JSONRPCException,e:
|
||||
errorString = e.error['message']
|
||||
|
||||
assert_equal("Invalid amount" in errorString, True);
|
||||
|
||||
errorString = ""
|
||||
try:
|
||||
self.nodes[0].generate("2") #use a string to as block amount parameter must fail because it's not interpreted as amount
|
||||
except JSONRPCException,e:
|
||||
errorString = e.error['message']
|
||||
|
||||
assert_equal("not an integer" in errorString, True);
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
WalletTest ().main ()
|
||||
|
|
|
@ -120,8 +120,8 @@ void RPCTypeCheckObj(const UniValue& o,
|
|||
|
||||
CAmount AmountFromValue(const UniValue& value)
|
||||
{
|
||||
if (!value.isNum())
|
||||
throw JSONRPCError(RPC_TYPE_ERROR, "Amount is not a number");
|
||||
if (!value.isNum() && !value.isStr())
|
||||
throw JSONRPCError(RPC_TYPE_ERROR, "Amount is not a number or string");
|
||||
CAmount amount;
|
||||
if (!ParseFixedPoint(value.getValStr(), 8, &amount))
|
||||
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount");
|
||||
|
|
Loading…
Reference in a new issue