html: variable contract locktime.
This commit is contained in:
		
							parent
							
								
									c9954bef1a
								
							
						
					
					
						commit
						589e4ca1d6
					
				@ -655,6 +655,14 @@ class BasicSwap():
 | 
			
		||||
        assert(amount_to > chainparams[coin_to][self.chain]['min_amount']), 'To amount below min value for chain'
 | 
			
		||||
        assert(amount_to < chainparams[coin_to][self.chain]['max_amount']), 'To amount above max value for chain'
 | 
			
		||||
 | 
			
		||||
    def validateOfferLockValue(self, coin_from, coin_to, lock_type, lock_value):
 | 
			
		||||
        if lock_type == OfferMessage.SEQUENCE_LOCK_TIME:
 | 
			
		||||
            assert(lock_value >= 2 * 60 * 60 and lock_value <= 96 * 60 * 60), 'Invalid lock_value time'
 | 
			
		||||
        elif lock_type == OfferMessage.SEQUENCE_LOCK_BLOCKS:
 | 
			
		||||
            assert(lock_value >= 5 and lock_value <= 1000), 'Invalid lock_value blocks'
 | 
			
		||||
        else:
 | 
			
		||||
            raise ValueError('Unknown locktype')
 | 
			
		||||
 | 
			
		||||
    def postOffer(self, coin_from, coin_to, amount, rate, min_bid_amount, swap_type,
 | 
			
		||||
                  lock_type=SEQUENCE_LOCK_TIME, lock_value=48 * 60 * 60, auto_accept_bids=False):
 | 
			
		||||
 | 
			
		||||
@ -671,6 +679,7 @@ class BasicSwap():
 | 
			
		||||
            raise ValueError('Unknown coin to type')
 | 
			
		||||
 | 
			
		||||
        self.validateOfferAmounts(coin_from_t, coin_to_t, amount, rate, min_bid_amount)
 | 
			
		||||
        self.validateOfferLockValue(coin_from_t, coin_to_t, lock_type, lock_value)
 | 
			
		||||
 | 
			
		||||
        self.mxDB.acquire()
 | 
			
		||||
        try:
 | 
			
		||||
@ -1811,14 +1820,11 @@ class BasicSwap():
 | 
			
		||||
        assert(offer_data.coin_from != offer_data.coin_to), 'coin_from == coin_to'
 | 
			
		||||
 | 
			
		||||
        self.validateOfferAmounts(coin_from, coin_to, offer_data.amount_from, offer_data.rate, offer_data.min_bid_amount)
 | 
			
		||||
        self.validateOfferLockValue(coin_from, coin_to, offer_data.lock_type, offer_data.lock_value)
 | 
			
		||||
 | 
			
		||||
        assert(offer_data.time_valid >= MIN_OFFER_VALID_TIME and offer_data.time_valid <= MAX_OFFER_VALID_TIME), 'Invalid time_valid'
 | 
			
		||||
        assert(msg['sent'] + offer_data.time_valid >= now), 'Offer expired'
 | 
			
		||||
 | 
			
		||||
        assert(offer_data.lock_type == OfferMessage.SEQUENCE_LOCK_TIME or
 | 
			
		||||
               offer_data.lock_type == OfferMessage.SEQUENCE_LOCK_BLOCKS), 'Unknown locktype'
 | 
			
		||||
        # TODO: lock value valid range
 | 
			
		||||
 | 
			
		||||
        if offer_data.swap_type == SwapTypes.SELLER_FIRST:
 | 
			
		||||
            assert(len(offer_data.proof_address) == 0)
 | 
			
		||||
            assert(len(offer_data.proof_signature) == 0)
 | 
			
		||||
 | 
			
		||||
@ -177,9 +177,10 @@ class HttpHandler(BaseHTTPRequestHandler):
 | 
			
		||||
                min_bid = int(value_from)
 | 
			
		||||
                rate = int((value_to / value_from) * COIN)
 | 
			
		||||
                autoaccept = True if b'autoaccept' in form_data else False
 | 
			
		||||
                lock_seconds = int(form_data[b'lockhrs'][0]) * 60 * 60
 | 
			
		||||
                # TODO: More accurate rate
 | 
			
		||||
                # assert(value_to == (value_from * rate) // COIN)
 | 
			
		||||
                offer_id = swap_client.postOffer(coin_from, coin_to, value_from, rate, min_bid, SwapTypes.SELLER_FIRST, auto_accept_bids=autoaccept)
 | 
			
		||||
                offer_id = swap_client.postOffer(coin_from, coin_to, value_from, rate, min_bid, SwapTypes.SELLER_FIRST, auto_accept_bids=autoaccept, lock_value=lock_seconds)
 | 
			
		||||
                content += '<p><a href="/offer/' + offer_id.hex() + '">Sent Offer ' + offer_id.hex() + '</a><br/>Rate: ' + format8(rate) + '</p>'
 | 
			
		||||
 | 
			
		||||
        coins = []
 | 
			
		||||
@ -193,7 +194,9 @@ class HttpHandler(BaseHTTPRequestHandler):
 | 
			
		||||
        content += '<table>'
 | 
			
		||||
        content += '<tr><td>Coin From</td><td>' + self.make_coin_select('coin_from', coins) + '</td><td>Amount From</td><td><input type="text" name="amt_from"></td></tr>'
 | 
			
		||||
        content += '<tr><td>Coin To</td><td>' + self.make_coin_select('coin_to', coins) + '</td><td>Amount To</td><td><input type="text" name="amt_to"></td></tr>'
 | 
			
		||||
        content += '<tr><td>Auto Accept Bids</td><td><input type="checkbox" name="autoaccept" value="aa" checked></td></tr>'
 | 
			
		||||
 | 
			
		||||
        content += '<tr><td>Contract locked (hrs)</td><td><input type="number" name="lockhrs" min="2" max="96" value="48"></td><td colspan=2>Participate txn will be locked for half the time.</td></tr>'
 | 
			
		||||
        content += '<tr><td>Auto Accept Bids</td><td colspan=3><input type="checkbox" name="autoaccept" value="aa" checked></td></tr>'
 | 
			
		||||
        content += '</table>'
 | 
			
		||||
 | 
			
		||||
        content += '<input type="submit" value="Submit">'
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user