Skip to content

Commit

Permalink
Version 0.6.7.6
Browse files Browse the repository at this point in the history
  • Loading branch information
MrNaif2018 committed Jun 8, 2022
1 parent 8a30a09 commit 049db3f
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 8 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

## Latest changes

## 0.6.7.6

Added ability to configure number of hours eth-based daemons can be left down (default: 1 hour). Configurable via `COIN_MAX_SYNC_HOURS` env variable.

For ETH, BNB and all the contracts the maximum number of decimal digits is artificially decreased to 8 decimals. That's because most exchanges and software doesn't support more than 8 decimals (noone's following the specs except for us), so to make it possible to send from i.e. binance this change was made.

Daemon is almost unmodified - it stores and returns balances in original 18 decimals precision, just that invoice amounts generation algorithm will use at max 8 decimals. As for the merchants API, the output formatting decimals were indeed changed to 8 (from 18), so checkout page now has 8 decimals, which is more readable.

## 0.6.7.5

Better UI for final statuses on invoice page
Expand Down
4 changes: 3 additions & 1 deletion api/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from bitcart import COINS as _COINS

VERSION = "0.6.7.5" # Version, used for openapi schemas and update checks
VERSION = "0.6.7.6" # Version, used for openapi schemas and update checks
WEBSITE = "https://bitcartcc.com" # BitcartCC official site
GIT_REPO_URL = "https://github.com/bitcartcc/bitcart" # BitcartCC github repository
DOCKER_REPO_URL = "https://github.com/bitcartcc/bitcart-docker" # BitcartCC Docker Packaging repository
Expand All @@ -28,3 +28,5 @@
"no": False,
"0": False,
} # common str -> bool conversions
# due to many exchanges lacking more than 8 digits, we limit eth-based divisibility for invoices to 8
MAX_CONTRACT_DIVISIBILITY = 8
3 changes: 2 additions & 1 deletion api/crud/invoices.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from starlette.datastructures import CommaSeparatedStrings

from api import events, invoices, models, schemes, settings, utils
from api.constants import MAX_CONTRACT_DIVISIBILITY
from api.ext.moneyformat import currency_table, truncate
from api.logger import get_exception_message, get_logger
from api.utils.database import safe_db_write
Expand Down Expand Up @@ -58,7 +59,7 @@ async def _create_payment_method(invoice, wallet, product, store, discounts, pro
symbol = await coin.server.readcontract(wallet.contract, "symbol") if wallet.contract else wallet.currency
divisibility = currency_table.get_currency_data(wallet.currency)["divisibility"]
if wallet.contract: # pragma: no cover
divisibility = await coin.server.readcontract(wallet.contract, "decimals")
divisibility = min(MAX_CONTRACT_DIVISIBILITY, await coin.server.readcontract(wallet.contract, "decimals"))
rate = currency_table.normalize(
invoice.currency, await utils.wallets.get_rate(wallet, invoice.currency, store.default_currency)
)
Expand Down
6 changes: 3 additions & 3 deletions api/ext/moneyformat/currencies.json
Original file line number Diff line number Diff line change
Expand Up @@ -303,17 +303,17 @@
},
"ETH": {
"name": "Ethereum",
"divisibility": 18,
"divisibility": 8,
"crypto": true
},
"BNB": {
"name": "Binance Coin",
"divisibility": 18,
"divisibility": 8,
"crypto": true
},
"SBCH": {
"name": "Smart Bitcoin Cash",
"divisibility": 18,
"divisibility": 8,
"crypto": true
}
}
2 changes: 1 addition & 1 deletion daemons/bnb.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class BNBDaemon(eth.ETHDaemon):
DEFAULT_PORT = 5006

EIP1559_SUPPORTED = False
MAX_SYNC_BLOCKS = 1200 # (60/3)=20*60 (a block every 3 seconds, max normal expiry time 60 minutes)
DEFAULT_MAX_SYNC_BLOCKS = 1200 # (60/3)=20*60 (a block every 3 seconds, max normal expiry time 60 minutes)
FIAT_NAME = "binancecoin"

ABI = BEP20_ABI
Expand Down
9 changes: 7 additions & 2 deletions daemons/eth.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,8 @@ def generate_unique_amount(self, amount: Decimal):
add_low = 1
add_high = 2
cur_amount = amount
AMOUNTGEN_PRECISION = Decimal(10) ** (-self.divisibility)
divisibility = min(self.divisibility, daemon.AMOUNTGEN_DIVISIBILITY)
AMOUNTGEN_PRECISION = Decimal(10) ** (-divisibility)
while cur_amount in self.used_amounts:
cur_amount = amount + random.randint(add_low, add_high) * AMOUNTGEN_PRECISION
if add_high < AMOUNTGEN_LIMIT:
Expand Down Expand Up @@ -527,9 +528,11 @@ class ETHDaemon(BaseDaemon):
TOKENS = ERC20_TOKENS
# modern transactions with maxPriorityFeePerGas
EIP1559_SUPPORTED = True
MAX_SYNC_BLOCKS = 300 # (60/12)=5*60 (a block every 12 seconds, max normal expiry time 60 minutes)
DEFAULT_MAX_SYNC_BLOCKS = 300 # (60/12)=5*60 (a block every 12 seconds, max normal expiry time 60 minutes)
# from coingecko API
FIAT_NAME = "ethereum"
# Max number of decimal places to use for amounts generation
AMOUNTGEN_DIVISIBILITY = 8

latest_height = StoredProperty("latest_height", -1)

Expand Down Expand Up @@ -562,6 +565,8 @@ def __init__(self):
def load_env(self):
super().load_env()
self.SERVER = self.env("SERVER", default=get_default_http_endpoint())
max_sync_hours = self.env("MAX_SYNC_HOURS", cast=int, default=1)
self.MAX_SYNC_BLOCKS = max_sync_hours * self.DEFAULT_MAX_SYNC_BLOCKS

async def on_startup(self, app):
await super().on_startup(app)
Expand Down

0 comments on commit 049db3f

Please sign in to comment.