Skip to content

Instantly share code, notes, and snippets.

@Magicking
Created March 7, 2016 21:24
Show Gist options
  • Save Magicking/4dd951f630d92443d5b5 to your computer and use it in GitHub Desktop.
Save Magicking/4dd951f630d92443d5b5 to your computer and use it in GitHub Desktop.
Cold minting spending
#using the neucoin_wip branch https://github.com/NeuCoin/pycoin/tree/neucoin_wip
from pycoin.tx.pay_to import address_for_pay_to_script, build_hash160_lookup
from pycoin.tx.pay_to.ScriptColdminting import ScriptColdminting
from pycoin.tx.tx_utils import create_tx
from pycoin.tx import Spendable
from pycoin.key import Key
from pycoin.serialize import h2b, h2b_rev
from pycoin.encoding import wif_to_secret_exponent
from time import time
class LazySecretExponentDB(object):
def __init__(self, wif_iterable, secret_exponent_db_cache, allowable_wif_prefixes):
self.wif_iterable = iter(wif_iterable)
self.secret_exponent_db_cache = secret_exponent_db_cache
self.allowable_wif_prefixes = allowable_wif_prefixes
def get(self, v):
if v in self.secret_exponent_db_cache:
return self.secret_exponent_db_cache[v]
for wif in self.wif_iterable:
secret_exponent = wif_to_secret_exponent(wif.wif(), self.allowable_wif_prefixes)
d = build_hash160_lookup([secret_exponent])
self.secret_exponent_db_cache.update(d)
if v in self.secret_exponent_db_cache:
return self.secret_exponent_db_cache[v]
self.wif_iterable = []
return None
se = wif_to_secret_exponent('8jCzsrfeKUt3jDGHMBPmUEWTLHah4zVFSyoXbpvWcmr2YdaS9qHT', [b'\x34', b'\x44'])
spend_wif = Key(secret_exponent=se, netcode='NEU')
hash160_lookup = LazySecretExponentDB([spend_wif], {}, [b'\x34', b'\x44'])
script = '76a9c063141d41fa3592e7a3ff5f62247309338c2a3ba9071b67149f952c529ded949ea10f2ae20488fb1a1d65cd876888ac'
txid = '40baa43d4f902bddbed987a16950e57993223c492ca6678cba346e0b6671d185'
pts = ScriptColdminting.from_script(h2b(script))
txin = Spendable(64900000, pts.script(), h2b_rev(txid), 0)
address = address_for_pay_to_script(pts.script(), netcode='NEU')
tx = create_tx([txin], [address], time=int(time()))
tx.sign(hash160_lookup=hash160_lookup)
print(tx.as_hex())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment