mirror of
https://github.com/Blockstream/satellite-api.git
synced 2025-02-22 13:42:33 +01:00
Add lower limit of one satoshi on bids
Many Lightning wallets do not support payments below 1 sat (in millisatoshis). For wider compliance, set a lower limit of 1 sat on orders, while preserving the minimum bid per byte requirement for orders whose absolute bid exceeds 1 sat.
This commit is contained in:
parent
d27e5152f1
commit
2ae72ccc59
5 changed files with 21 additions and 3 deletions
|
@ -17,6 +17,7 @@ CHARGE_API_TOKEN = ENV['CHARGE_API_TOKEN'] || 'mySecretToken'
|
|||
CHARGE_ROOT = ENV['CHARGE_ROOT'] || "http://api-token:#{CHARGE_API_TOKEN}@localhost:9112"
|
||||
|
||||
MIN_PER_BYTE_BID = Integer(ENV['MIN_PER_BYTE_BID'] || 1) # minimum price per byte in millisatoshis
|
||||
MIN_BID = 1000 # minimum absolute bid in millisatoshis
|
||||
MIN_MESSAGE_SIZE = 1
|
||||
|
||||
UDP_HDR_SIZE = 8
|
||||
|
|
|
@ -53,6 +53,10 @@ module Sinatra
|
|||
halt 400, error_object("Message upload problem", "Message too small. Minimum message size is #{MIN_MESSAGE_SIZE} byte", ERROR::CODES[:MESSAGE_FILE_TOO_SMALL])
|
||||
end
|
||||
|
||||
def bid_below_minimum_error()
|
||||
halt 413, error_object("Bid too low", "Bid cannot be below #{MIN_BID} millisatoshis.", ERROR::CODES[:BID_TOO_SMALL])
|
||||
end
|
||||
|
||||
def bid_too_small_error(min_bid)
|
||||
halt 413, error_object("Bid too low", "Per byte bid cannot be below #{MIN_PER_BYTE_BID} millisatoshis per byte. The minimum bid for this message is #{min_bid} millisatoshis.", ERROR::CODES[:BID_TOO_SMALL])
|
||||
end
|
||||
|
|
6
main.rb
6
main.rb
|
@ -181,8 +181,10 @@ post '/order' do
|
|||
|
||||
order.message_size = message_size
|
||||
order.message_digest = sha256.to_s
|
||||
|
||||
if bid.to_f / order.message_size_with_overhead < MIN_PER_BYTE_BID
|
||||
|
||||
if bid.to_f < MIN_BID
|
||||
bid_below_minimum_error()
|
||||
elsif bid.to_f / order.message_size_with_overhead < MIN_PER_BYTE_BID
|
||||
bid_too_small_error(order.message_size_with_overhead * MIN_PER_BYTE_BID)
|
||||
end
|
||||
|
||||
|
|
|
@ -112,7 +112,7 @@ class Order < ActiveRecord::Base
|
|||
|
||||
def paid_enough?
|
||||
self.adjust_bids
|
||||
self.bid_per_byte >= MIN_PER_BYTE_BID
|
||||
self.bid_per_byte >= MIN_PER_BYTE_BID && self.bid.to_f >= MIN_BID
|
||||
end
|
||||
|
||||
def message_size_with_overhead
|
||||
|
|
|
@ -139,6 +139,17 @@ class MainAppTest < Minitest::Test
|
|||
assert_equal ERROR::CODES[:BID_TOO_SMALL], last_response_error_code
|
||||
end
|
||||
|
||||
def test_bid_below_min_bid
|
||||
post '/order', params={"bid" => (4 + L2_OVERHEAD), "message" => "test"}
|
||||
refute last_response.ok?
|
||||
assert_equal ERROR::CODES[:BID_TOO_SMALL], last_response_error_code
|
||||
post '/order', params={"bid" => (MIN_BID - 1), "message" => "test"}
|
||||
refute last_response.ok?
|
||||
assert_equal ERROR::CODES[:BID_TOO_SMALL], last_response_error_code
|
||||
post '/order', params={"bid" => (MIN_BID), "message" => "test"}
|
||||
assert last_response.ok?
|
||||
end
|
||||
|
||||
def test_bid_too_low
|
||||
post '/order', params={"bid" => 1, "file" => Rack::Test::UploadedFile.new(TEST_FILE, "image/png")}
|
||||
refute last_response.ok?
|
||||
|
|
Loading…
Add table
Reference in a new issue