|
15 | 15 | from abc import ABCMeta, abstractmethod |
16 | 16 | from typing import Any, Dict, List, Optional, Tuple, Union |
17 | 17 |
|
18 | | -from electroncash import address, token, util |
| 18 | +from electroncash import address, networks, token, util |
19 | 19 | from electroncash.simple_config import SimpleConfig |
20 | 20 | from electroncash.transaction import Transaction |
21 | 21 |
|
@@ -431,10 +431,16 @@ def sanitize(self): |
431 | 431 | self.decimals = int(self.decimals) |
432 | 432 | except (ValueError, TypeError): |
433 | 433 | pass |
434 | | - self.decimals = min(max(0, self.decimals), 19) if isinstance(self.decimals, int) else 0 |
435 | | - self.name = self.name[:30] if isinstance(self.name, str) else "" |
436 | | - self.description = self.description[:160] if isinstance(self.description, str) else "" |
437 | | - self.symbol = self.symbol[:8] if isinstance(self.symbol, str) else "" |
| 434 | + # BCMR spec: "An integer between 0 and 18 (inclusive)" |
| 435 | + self.decimals = min(max(0, self.decimals), 18) if isinstance(self.decimals, int) else 0 |
| 436 | + # BCMR schema: "names should be hidden beyond ... 20 characters until revealed by the user" |
| 437 | + # We allow up to 2 x 20 = 40 characters |
| 438 | + self.name = self.name[:40] if isinstance(self.name, str) else "" |
| 439 | + # BCMR spec: "descriptions should be hidden beyond ... 140 characters until revealed by the user" |
| 440 | + # We allow up to 2 x 140 = 280 characters |
| 441 | + self.description = self.description[:280] if isinstance(self.description, str) else "" |
| 442 | + # BCMR spec: "this standard recommends that... clients accommodate up to 26 characters for full symbols" |
| 443 | + self.symbol = self.symbol[:26] if isinstance(self.symbol, str) else "" |
438 | 444 |
|
439 | 445 |
|
440 | 446 | def _rewrite_if_ipfs(u: str) -> str: |
@@ -471,16 +477,17 @@ def _try_to_dl_icon(icon_url: str, *, timeout=30) -> Optional[Tuple[bytes, str]] |
471 | 477 | return icon, icon_ext |
472 | 478 |
|
473 | 479 |
|
474 | | -PAYTACA_HOST = "bcmr.paytaca.com" |
475 | | - |
476 | 480 |
|
477 | 481 | def _try_to_dl_from_paytaca_indexer(token_id_hex, timeout=30, *, skip_icon=False, |
478 | 482 | nft_hex=None) -> Optional[DownloadedMetaData]: |
479 | 483 | """Download metadata from the paytaca indexer""" |
| 484 | + host = networks.net.PAYTACA_HOST |
| 485 | + if not host: |
| 486 | + return None |
480 | 487 | if not nft_hex: |
481 | | - url = f"https://{PAYTACA_HOST}/api/tokens/{token_id_hex}/" |
| 488 | + url = f"https://{host}/api/tokens/{token_id_hex}/" |
482 | 489 | else: |
483 | | - url = f"https://{PAYTACA_HOST}/api/tokens/{token_id_hex}/{nft_hex}" |
| 490 | + url = f"https://{host}/api/tokens/{token_id_hex}/{nft_hex}" |
484 | 491 | r = requests.get(url, timeout=timeout, allow_redirects=True) |
485 | 492 | if not r.ok: |
486 | 493 | util.print_error(f"Got error requesting url {url}: {r.status_code} {r.reason}") |
@@ -636,7 +643,7 @@ def try_to_download_metadata(wallet, token_id_hex, timeout=30, *, skip_icon=Fals |
636 | 643 | md = _try_to_dl_from_paytaca_indexer(token_id_hex, timeout=timeout, skip_icon=skip_icon, |
637 | 644 | nft_hex=nft_hex) |
638 | 645 | if md is not None: |
639 | | - util.print_error(f"Success in downloading token metadata from {PAYTACA_HOST} for:" |
| 646 | + util.print_error(f"Success in downloading token metadata from {networks.net.PAYTACA_HOST} for:" |
640 | 647 | f" {token_id_hex} ({md.name})") |
641 | 648 | return md |
642 | 649 |
|
|
0 commit comments