diff --git a/counterpartylib/lib/messages/sweep.py b/counterpartylib/lib/messages/sweep.py index 379eede6ea..cedff8ec68 100644 --- a/counterpartylib/lib/messages/sweep.py +++ b/counterpartylib/lib/messages/sweep.py @@ -61,10 +61,25 @@ def validate (db, source, destination, flags, memo, block_index): cursor.execute('''SELECT * FROM balances WHERE (address = ? AND asset = ?)''', (source, 'XCP')) result = cursor.fetchall() - if len(result) == 0: - problems.append('insufficient XCP balance for sweep. Need %s XCP for antispam fee' % ANTISPAM_FEE_DECIMAL) - elif result[0]['quantity'] < ANTISPAM_FEE: - problems.append('insufficient XCP balance for sweep. Need %s XCP for antispam fee' % ANTISPAM_FEE_DECIMAL) + antispamfee = util.get_value_by_block_index("sweep_antispam_fee", block_index)*config.UNIT + total_fee = ANTISPAM_FEE + + if antispamfee > 0: + cursor.execute('''SELECT count(*) cnt FROM balances WHERE address = ?''', (source, )) + balances_count = cursor.fetchall()[0]['cnt'] + + cursor.execute('''SELECT COUNT(DISTINCT(asset)) cnt FROM issuances WHERE issuer = ?''', (source, )) + issuances_count = cursor.fetchall()[0]['cnt'] + + total_fee = int(balances_count * antispamfee * 2 + issuances_count * antispamfee * 4) + + if result[0]['quantity'] < total_fee: + problems.append('insufficient XCP balance for sweep. Need %s XCP for antispam fee' % total_fee) + else: + if len(result) == 0: + problems.append('insufficient XCP balance for sweep. Need %s XCP for antispam fee' % ANTISPAM_FEE_DECIMAL) + elif result[0]['quantity'] < ANTISPAM_FEE: + problems.append('insufficient XCP balance for sweep. Need %s XCP for antispam fee' % ANTISPAM_FEE_DECIMAL) cursor.close() @@ -76,7 +91,7 @@ def validate (db, source, destination, flags, memo, block_index): if memo and len(memo) > MAX_MEMO_LENGTH: problems.append('memo too long') - return problems + return problems, total_fee def compose (db, source, destination, flags, memo): if memo is None: @@ -88,7 +103,7 @@ def compose (db, source, destination, flags, memo): memo = struct.pack(">{}s".format(len(memo)), memo) block_index = util.CURRENT_BLOCK_INDEX - problems = validate(db, source, destination, flags, memo, block_index) + problems, total_fee = validate(db, source, destination, flags, memo, block_index) if problems: raise exceptions.ComposeError(problems) short_address_bytes = address.pack(destination) @@ -149,12 +164,17 @@ def parse (db, tx, message): status = 'invalid: could not unpack, ' + str(err) if status == 'valid': - problems = validate(db, tx['source'], destination, flags, memo_bytes, tx['block_index']) + problems, total_fee = validate(db, tx['source'], destination, flags, memo_bytes, tx['block_index']) if problems: status = 'invalid: ' + '; '.join(problems) if status == 'valid': try: - util.debit(db, tx['source'], 'XCP', fee_paid, action='sweep fee', event=tx['tx_hash']) + antispamfee = util.get_value_by_block_index("sweep_antispam_fee", tx['block_index'])*config.UNIT + + if antispamfee > 0: + util.debit(db, tx['source'], 'XCP', total_fee, action='sweep fee', event=tx['tx_hash']) + else: + util.debit(db, tx['source'], 'XCP', fee_paid, action='sweep fee', event=tx['tx_hash']) except BalanceError: destination, flags, memo_bytes = None, None, None status = 'invalid: insufficient balance for antispam fee for sweep' @@ -174,7 +194,7 @@ def parse (db, tx, message): if util.enabled("zero_balance_ownership_sweep_fix", tx["block_index"]): cursor.execute('''SELECT DISTINCT(asset) FROM issuances WHERE issuer = ?''', (tx['source'],)) assets_issued = cursor.fetchall() - + for next_asset_issued in assets_issued: cursor.execute('''SELECT * FROM issuances \ WHERE (status = ? AND asset = ?) @@ -217,7 +237,7 @@ def parse (db, tx, message): 'flags': flags, 'status': status, 'memo': memo_bytes, - 'fee_paid': fee_paid + 'fee_paid': total_fee if antispamfee > 0 else fee_paid } sql = 'insert into sweeps values(:tx_index, :tx_hash, :block_index, :source, :destination, :flags, :status, :memo, :fee_paid)' cursor.execute(sql, bindings) diff --git a/counterpartylib/protocol_changes.json b/counterpartylib/protocol_changes.json index 8b6f62b710..983cca6b73 100644 --- a/counterpartylib/protocol_changes.json +++ b/counterpartylib/protocol_changes.json @@ -508,5 +508,23 @@ "value":5 } } + }, + "sweep_antispam_fee": { + "mainnet":{ + "1":{ + "value":0 + }, + "825000":{ + "value":0.001 + } + }, + "testnet":{ + "1":{ + "value":0 + }, + "2535092":{ + "value":0.001 + } + } } }