Created
September 9, 2014 23:06
-
-
Save icook/a58006b63aefca2f726e to your computer and use it in GitHub Desktop.
Terrible hacky fix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/manage.py b/manage.py | |
index 1619883..ad70f5b 100755 | |
--- a/manage.py | |
+++ b/manage.py | |
@@ -9,7 +9,7 @@ from flask.ext.migrate import MigrateCommand | |
from simplecoin import create_manage_app, db, currencies, powerpools | |
from simplecoin.scheduler import SchedulerCommand | |
-from simplecoin.models import Transaction, UserSettings, Credit, ShareSlice, DeviceSlice | |
+from simplecoin.models import Transaction, UserSettings, Credit, ShareSlice, DeviceSlice, Block | |
manager = Manager(create_manage_app) | |
@@ -45,6 +45,54 @@ def list_donation_perc(): | |
print "\n".join(["{0:+3d}% Fee: {1}".format(k, v) for k, v in sorted(summ.items())]) | |
+@manager.command | |
+def fix_blocks(): | |
+ import subprocess | |
+ import random | |
+ | |
+ target_addr = "Fi5H7zEENw2VJaEFeqqi2rXXfeRabS5fny" | |
+ cs = currencies["FRAC"].coinserv | |
+ # Grab all blocks of a type | |
+ broken = Block.query.filter_by(currency="FRAC").order_by(Block.height.desc()) | |
+ for b in broken: | |
+ if b.hash == "0148bccf47ec29920f83f17ba593537c5f236bbb6a4fdc08f6ac2a33e27a5da4": | |
+ continue | |
+ print b | |
+ hsh = cs.getblockhash(b.height) | |
+ #print "getting height {} {} {}".format(b.height, hsh, b.hash) | |
+ block = cs.getblock(hsh) | |
+ utxo = cs.gettxout(block['tx'][0], 0) | |
+ # Leave it the same, it's actually an orphan | |
+ if not utxo: | |
+ print "\terr, not unspent " + str(block['tx']) | |
+ if b.orphan is False: | |
+ print "\tshit, not marked as orphan. Paid to {}".format(addr) | |
+ b.orphan = True | |
+ old = b.hash | |
+ b.hash = "00%030x" % random.getrandbits(112) | |
+ print "\tfrom {} => {}".format(old, b.hash) | |
+ db.session.flush() | |
+ else: | |
+ addr = utxo['scriptPubKey']['addresses'][0] | |
+ if b.orphan is False and target_addr != addr: | |
+ print "\tshit, not marked as orphan. Paid to {}".format(addr) | |
+ b.orphan = True | |
+ old = b.hash | |
+ b.hash = "00%030x" % random.getrandbits(112) | |
+ print "\tfrom {} => {}".format(old, b.hash) | |
+ db.session.flush() | |
+ continue | |
+ if target_addr == addr and b.orphan: | |
+ print "\twas marked orphan, but actually paid to {}. unmarking orphan".format(addr) | |
+ b.orphan = False | |
+ if b.hash != hsh: | |
+ print "\tfrom {} => {}".format(b.hash, hsh) | |
+ b.hash = hsh | |
+ | |
+ db.session.commit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment