Validate string amount decimal places.
This commit is contained in:
		
							parent
							
								
									9a0f237019
								
							
						
					
					
						commit
						d6341eceb7
					
				@ -972,6 +972,7 @@ class BasicSwap():
 | 
				
			|||||||
    def postBid(self, offer_id, amount, addr_send_from=None):
 | 
					    def postBid(self, offer_id, amount, addr_send_from=None):
 | 
				
			||||||
        # Bid to send bid.amount * offer.rate of coin_to in exchange for bid.amount of coin_from
 | 
					        # Bid to send bid.amount * offer.rate of coin_to in exchange for bid.amount of coin_from
 | 
				
			||||||
        self.log.debug('postBid %s %s', offer_id.hex(), format8(amount))
 | 
					        self.log.debug('postBid %s %s', offer_id.hex(), format8(amount))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.mxDB.acquire()
 | 
					        self.mxDB.acquire()
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            offer = self.getOffer(offer_id)
 | 
					            offer = self.getOffer(offer_id)
 | 
				
			||||||
@ -1643,7 +1644,7 @@ class BasicSwap():
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        # TODO: Lookup from explorers
 | 
					        # TODO: Lookup from explorers
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if assert_txid != None:
 | 
					        if assert_txid is not None:
 | 
				
			||||||
            try:
 | 
					            try:
 | 
				
			||||||
                ro = self.callcoinrpc(coin_type, 'getmempoolentry', [assert_txid])
 | 
					                ro = self.callcoinrpc(coin_type, 'getmempoolentry', [assert_txid])
 | 
				
			||||||
                self.log.debug('Tx %s found in mempool, fee %s', assert_txid, ro['fee'])
 | 
					                self.log.debug('Tx %s found in mempool, fee %s', assert_txid, ro['fee'])
 | 
				
			||||||
 | 
				
			|||||||
@ -19,6 +19,7 @@ from . import __version__
 | 
				
			|||||||
from .util import (
 | 
					from .util import (
 | 
				
			||||||
    COIN,
 | 
					    COIN,
 | 
				
			||||||
    format8,
 | 
					    format8,
 | 
				
			||||||
 | 
					    makeInt,
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
from .chainparams import (
 | 
					from .chainparams import (
 | 
				
			||||||
    chainparams,
 | 
					    chainparams,
 | 
				
			||||||
@ -88,6 +89,14 @@ def getTxSpendHex(bid, tx_type):
 | 
				
			|||||||
    return obj.spend_txid.hex() + ' {}'.format(obj.spend_n)
 | 
					    return obj.spend_txid.hex() + ' {}'.format(obj.spend_n)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def validateAmountString(amount):
 | 
				
			||||||
 | 
					    if type(amount) != str:
 | 
				
			||||||
 | 
					        return
 | 
				
			||||||
 | 
					    ar = amount.split('.')
 | 
				
			||||||
 | 
					    if len(ar) > 0 and len(ar[1]) > 8:
 | 
				
			||||||
 | 
					        raise ValueError('Too many decimal places in amount {}'.format(amount))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def html_content_start(title, h2=None, refresh=None):
 | 
					def html_content_start(title, h2=None, refresh=None):
 | 
				
			||||||
    content = '<!DOCTYPE html><html lang="en">\n<head>' \
 | 
					    content = '<!DOCTYPE html><html lang="en">\n<head>' \
 | 
				
			||||||
        + '<meta charset="UTF-8">' \
 | 
					        + '<meta charset="UTF-8">' \
 | 
				
			||||||
@ -260,8 +269,14 @@ class HttpHandler(BaseHTTPRequestHandler):
 | 
				
			|||||||
            except Exception:
 | 
					            except Exception:
 | 
				
			||||||
                raise ValueError('Unknown Coin To')
 | 
					                raise ValueError('Unknown Coin To')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            value_from = int(float(form_data[b'amt_from'][0]) * COIN)
 | 
					            value_from = form_data[b'amt_from'][0].decode('utf-8')
 | 
				
			||||||
            value_to = int(float(form_data[b'amt_to'][0]) * COIN)
 | 
					            value_to = form_data[b'amt_to'][0].decode('utf-8')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            validateAmountString(value_from)
 | 
				
			||||||
 | 
					            validateAmountString(value_to)
 | 
				
			||||||
 | 
					            value_from = makeInt(value_from)
 | 
				
			||||||
 | 
					            value_to = makeInt(value_to)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            min_bid = int(value_from)
 | 
					            min_bid = int(value_from)
 | 
				
			||||||
            rate = int((value_to / value_from) * COIN)
 | 
					            rate = int((value_to / value_from) * COIN)
 | 
				
			||||||
            autoaccept = True if b'autoaccept' in form_data else False
 | 
					            autoaccept = True if b'autoaccept' in form_data else False
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user