Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fairminter v2 #3070

Open
wants to merge 21 commits into
base: migration
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ruff_scanner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- uses: chartboost/ruff-action@v1
with:
args: "format --check"
version: 0.9.9
version: 0.9.10
- uses: chartboost/ruff-action@v1
with:
version: 0.9.9
version: 0.9.10
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.5
rev: v0.9.9
hooks:
- id: ruff
args: [ --fix ]
Expand Down
6,254 changes: 3,784 additions & 2,470 deletions apiary.apib

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions counterparty-core/counterpartycore/lib/ledger/issuances.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,20 @@ def get_fairmint_quantities(db, fairminter_tx_hash):
return (sums["quantity"] or 0) + (sums["commission"] or 0), (sums["paid_quantity"] or 0)


def get_fairmint_by_address(db, fairminter_tx_hash, source):
cursor = db.cursor()
query = """
SELECT
SUM(earn_quantity) AS quantity
FROM fairmints
WHERE fairminter_tx_hash = ? AND status = ? AND source = ?
"""
bindings = (fairminter_tx_hash, "valid", source)
cursor.execute(query, bindings)
sums = cursor.fetchone()
return sums["quantity"] or 0


def get_fairminters_by_soft_cap_deadline(db, block_index):
cursor = db.cursor()
query = """
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE fairminters ADD COLUMN max_mint_per_address INTEGER;
15 changes: 15 additions & 0 deletions counterparty-core/counterpartycore/lib/ledger/other.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,21 @@
return msg_index


def get_issuance_msg_index(db, tx_hash):
cursor = db.cursor()
last_msg_index = cursor.execute(
"""
SELECT MAX(msg_index) as msg_index FROM issuances WHERE tx_hash = ?
""",
(tx_hash,),
).fetchone()
if last_msg_index and last_msg_index["msg_index"] is not None:
msg_index = last_msg_index["msg_index"] + 1

Check warning on line 127 in counterparty-core/counterpartycore/lib/ledger/other.py

View check run for this annotation

Codecov / codecov/patch

counterparty-core/counterpartycore/lib/ledger/other.py#L127

Added line #L127 was not covered by tests
else:
msg_index = 0
return msg_index


#####################
# BETS #
#####################
Expand Down
46 changes: 33 additions & 13 deletions counterparty-core/counterpartycore/lib/messages/fairmint.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from counterpartycore.lib import config, exceptions, ledger
from counterpartycore.lib.messages import fairminter as fairminter_mod
from counterpartycore.lib.parser import protocol
from counterpartycore.lib.utils import helpers

logger = logging.getLogger(config.LOGGER_NAME)

Expand Down Expand Up @@ -37,6 +38,15 @@

asset_supply = ledger.supplies.asset_supply(db, fairminter["asset"])

if fairminter["max_mint_per_address"] is not None and fairminter["max_mint_per_address"] > 0:
alread_minted = ledger.issuances.get_fairmint_by_address(db, fairminter["tx_hash"], source)
if fairminter["price"] > 0:
if alread_minted + quantity > fairminter["max_mint_per_address"]:
problems.append("quantity exceeds maximum allowed by address")

Check warning on line 45 in counterparty-core/counterpartycore/lib/messages/fairmint.py

View check run for this annotation

Codecov / codecov/patch

counterparty-core/counterpartycore/lib/messages/fairmint.py#L44-L45

Added lines #L44 - L45 were not covered by tests
else:
if alread_minted + fairminter["max_mint_per_tx"] > fairminter["max_mint_per_address"]:
problems.append("quantity exceeds maximum allowed by address")

Check warning on line 48 in counterparty-core/counterpartycore/lib/messages/fairmint.py

View check run for this annotation

Codecov / codecov/patch

counterparty-core/counterpartycore/lib/messages/fairmint.py#L48

Added line #L48 was not covered by tests

if fairminter["price"] > 0:
# if the fairminter is not free the quantity is mandatory
if quantity <= 0:
Expand Down Expand Up @@ -82,25 +92,35 @@

# create message
data = struct.pack(config.SHORT_TXTYPE_FORMAT, ID)
# to optimize the data size (avoiding fixed sizes per parameter) we use a simple
# string of characters separated by `|`.
data_content = "|".join(
[
str(value)
for value in [
asset,
quantity,

if protocol.enabled("fairminter_v2"):
asset_id = ledger.issuances.generate_asset_id(asset)
data += helpers.encode_data(asset_id, quantity or "")
else:
data_content = "|".join(

Check warning on line 100 in counterparty-core/counterpartycore/lib/messages/fairmint.py

View check run for this annotation

Codecov / codecov/patch

counterparty-core/counterpartycore/lib/messages/fairmint.py#L100

Added line #L100 was not covered by tests
[
str(value)
for value in [
asset,
quantity,
]
]
]
).encode("utf-8")
data += struct.pack(f">{len(data_content)}s", data_content)
).encode("utf-8")
data += struct.pack(f">{len(data_content)}s", data_content)

Check warning on line 109 in counterparty-core/counterpartycore/lib/messages/fairmint.py

View check run for this annotation

Codecov / codecov/patch

counterparty-core/counterpartycore/lib/messages/fairmint.py#L109

Added line #L109 was not covered by tests

return (source, [], data)


def unpack(message, return_dict=False):
try:
data_content = struct.unpack(f">{len(message)}s", message)[0].decode("utf-8").split("|")
(asset, quantity) = data_content
if protocol.enabled("fairminter_v2"):
asset_id, quantity = helpers.decode_data(message) # pylint: disable=unbalanced-tuple-unpacking
asset = ledger.issuances.generate_asset_name(helpers.bytes_to_int(asset_id))
quantity = helpers.bytes_to_int(quantity or b"\x00")
else:
data_content = struct.unpack(f">{len(message)}s", message)[0].decode("utf-8").split("|")
(asset, quantity) = data_content

Check warning on line 122 in counterparty-core/counterpartycore/lib/messages/fairmint.py

View check run for this annotation

Codecov / codecov/patch

counterparty-core/counterpartycore/lib/messages/fairmint.py#L121-L122

Added lines #L121 - L122 were not covered by tests

if return_dict:
return {"asset": asset, "quantity": int(quantity)}

Expand Down
Loading
Loading