def makeCoinbaseTxn(coinbaseValue, useCoinbaser = True): txn = Txn.new() if useCoinbaser and hasattr(config, 'CoinbaserCmd') and config.CoinbaserCmd: coinbased = 0 try: cmd = config.CoinbaserCmd cmd = cmd.replace('%d', str(coinbaseValue)) p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) nout = int(p.stdout.readline()) for i in range(nout): amount = int(p.stdout.readline()) addr = p.stdout.readline().rstrip(b'\n').decode('utf8') pkScript = BitcoinScript.toAddress(addr) txn.addOutput(amount, pkScript) coinbased += amount except: coinbased = coinbaseValue + 1 if coinbased >= coinbaseValue: logging.getLogger('makeCoinbaseTxn').error('Coinbaser failed!') txn.outputs = [] else: coinbaseValue -= coinbased pkScript = BitcoinScript.toAddress(config.TrackerAddr) txn.addOutput(coinbaseValue, pkScript) # TODO # TODO: red flag on dupe coinbase return txn
def _test(): from binascii import b2a_hex mt = MerkleTree([None] + [bytes.fromhex(a) for a in [ '999d2c8bb6bda0bf784d9ebeb631d711dbbbfe1bc006ea13d6ad0d6a2649a971', '3f92594d5a3d7b4df29d7dd7c46a0dac39a96e751ba0fc9bab5435ea5e22a19d', 'a5633f03855f541d8e60a6340fc491d49709dc821f3acb571956a856637adcb6', '28d97c850eaf917a4c76c02474b05b70a197eaefb468d21c22ed110afe8ec9e0', ]]) assert( b'82293f182d5db07d08acf334a5a907012bbb9990851557ac0ec028116081bd5a' == b2a_hex(mt.withFirst(bytes.fromhex('d43b669fb42cfa84695b844c0402d410213faa4f3e66cb7248f688ff19d5e5f7'))) ) d = b'\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00' dh = b"C\xeczW\x9fUa\xa4*~\x967\xadAVg'5\xa6X\xbe'R\x18\x18\x01\xf7#\xba3\x16\xd2" t = Txn(d) m = MerkleTree([t]) assert m.merkleRoot() == dh u = Txn.new() u.addInput((b' '*32, 0), b'') u.assemble() m.data.append(u) m.recalculate() mr = b"q\xe1\x9a3'\x0f>\xbfTv\xc8\x90\x81\x802\xe3\xb7u\x96\xddjP4\xe3\x19\xf3\xf0\xc5A4\xc0\xdb" assert m.merkleRoot() == mr step = b'\xb0\x91t\x84%\x9dg\x827\xc5\xbf\x94\xf0"\x94\xafN[\x0c\xeelF\xd9\x1b\x13q\xd3\xdf\x83\xe6\x01g' assert m._steps == [step] m.recalculate(detailed=True) assert m.detail == [dh, step, mr] m = MerkleTree([t.txid, u.txid]) assert m.merkleRoot() == mr assert m._steps == [step] m.recalculate(detailed=True) assert m.detail == [dh, step, mr]
def makeCoinbaseTxn(coinbaseValue, useCoinbaser=True, prevBlockHex=None, witness_commitment=NotImplemented): if witness_commitment is NotImplemented: raise NotImplementedError txn = Txn.new() #todo needs get dev rewared from MP pkScript = BitcoinScript.toAddress(config.TrackerAddr) devfeeScript = BitcoinScript.toAddress(config.Coinbaser_fee) txn.addOutput(coinbaseValue - config.Coinbaser_value, pkScript) txn.addOutput(config.Coinbaser_value, devfeeScript) txn.addOutput(config.devreward_value, a2b_hex(config.devreward_pubkey)) # SegWit commitment if not witness_commitment is None: txn.addOutput( 0, BitcoinScript.commitment(WitnessMagic + witness_commitment)) # TODO # TODO: red flag on dupe coinbase return txn
def makeCoinbaseTxn(coinbaseValue, useCoinbaser=True, prevBlockHex=None, witness_commitment=None): txn = Txn.new() txn.addOutput( coinbaseValue, BitcoinScript.commitment(witness_commitment) if witness_commitment else b'') return txn
def makeCoinbaseTxn(coinbaseValue, useCoinbaser=True, prevBlockHex=None, witness_commitment=NotImplemented, rsk_blockhash=None): if witness_commitment is NotImplemented: raise NotImplementedError txn = Txn.new() if useCoinbaser and hasattr(config, 'CoinbaserCmd') and config.CoinbaserCmd: coinbased = 0 try: cmd = config.CoinbaserCmd cmd = cmd.replace('%d', str(coinbaseValue)) cmd = cmd.replace('%p', prevBlockHex or '""') p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) nout = int(p.stdout.readline()) for i in range(nout): amount = int(p.stdout.readline()) addr = p.stdout.readline().rstrip(b'\n').decode('utf8') pkScript = BitcoinScript.toAddress(addr) txn.addOutput(amount, pkScript) coinbased += amount except: coinbased = coinbaseValue + 1 if coinbased >= coinbaseValue: logging.getLogger('makeCoinbaseTxn').error('Coinbaser failed!') txn.outputs = [] else: coinbaseValue -= coinbased pkScript = BitcoinScript.toAddress(config.TrackerAddr) txn.addOutput(coinbaseValue, pkScript) # SegWit commitment if not witness_commitment is None: txn.addOutput( 0, BitcoinScript.commitment(WitnessMagic + witness_commitment)) # RSK merged mining if rsk_blockhash is not None: txn.addOutput(0, rootstock.getRSKTag() + rsk_blockhash) # TODO # TODO: red flag on dupe coinbase return txn
def _test(): if not hasattr(bytes, 'fromhex'): return from binascii import b2a_hex mt = MerkleTree([None] + [ bytes.fromhex(a) for a in [ '999d2c8bb6bda0bf784d9ebeb631d711dbbbfe1bc006ea13d6ad0d6a2649a971', '3f92594d5a3d7b4df29d7dd7c46a0dac39a96e751ba0fc9bab5435ea5e22a19d', 'a5633f03855f541d8e60a6340fc491d49709dc821f3acb571956a856637adcb6', '28d97c850eaf917a4c76c02474b05b70a197eaefb468d21c22ed110afe8ec9e0', ] ]) assert ( b'82293f182d5db07d08acf334a5a907012bbb9990851557ac0ec028116081bd5a' == b2a_hex( mt.withFirst( bytes.fromhex( 'd43b669fb42cfa84695b844c0402d410213faa4f3e66cb7248f688ff19d5e5f7' )))) d = b'\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00' dh = b"C\xeczW\x9fUa\xa4*~\x967\xadAVg'5\xa6X\xbe'R\x18\x18\x01\xf7#\xba3\x16\xd2" t = Txn(d) m = MerkleTree([t]) assert m.merkleRoot() == dh u = Txn.new() u.addInput((b' ' * 32, 0), b'') u.assemble() m.data.append(u) m.recalculate() mr = b"q\xe1\x9a3'\x0f>\xbfTv\xc8\x90\x81\x802\xe3\xb7u\x96\xddjP4\xe3\x19\xf3\xf0\xc5A4\xc0\xdb" assert m.merkleRoot() == mr step = b'\xb0\x91t\x84%\x9dg\x827\xc5\xbf\x94\xf0"\x94\xafN[\x0c\xeelF\xd9\x1b\x13q\xd3\xdf\x83\xe6\x01g' assert m._steps == [step] m.recalculate(detailed=True) assert m.detail == [dh, step, mr] m = MerkleTree([t.txid, u.txid]) assert m.merkleRoot() == mr assert m._steps == [step] m.recalculate(detailed=True) assert m.detail == [dh, step, mr]
def makeCoinbaseTxn(coinbaseValue, useCoinbaser = True, prevBlockHex = None, witness_commitment = NotImplemented): if witness_commitment is NotImplemented: raise NotImplementedError txn = Txn.new() if useCoinbaser and hasattr(config, 'CoinbaserCmd') and config.CoinbaserCmd: coinbased = 0 try: cmd = config.CoinbaserCmd cmd = cmd.replace('%d', str(coinbaseValue)) cmd = cmd.replace('%p', prevBlockHex or '""') p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) nout = int(p.stdout.readline()) for i in range(nout): amount = int(p.stdout.readline()) addr = p.stdout.readline().rstrip(b'\n').decode('utf8') pkScript = BitcoinScript.toAddress(addr) txn.addOutput(amount, pkScript) coinbased += amount except: coinbased = coinbaseValue + 1 if coinbased >= coinbaseValue: logging.getLogger('makeCoinbaseTxn').error('Coinbaser failed!') txn.outputs = [] else: coinbaseValue -= coinbased pkScript = BitcoinScript.toAddress(config.TrackerAddr) txn.addOutput(coinbaseValue, pkScript) # SegWit commitment if not witness_commitment is None: txn.addOutput(0, BitcoinScript.commitment(WitnessMagic + witness_commitment)) # TODO # TODO: red flag on dupe coinbase return txn
def makeCoinbaseTxn(coinbaseValue, useCoinbaser = True, prevBlockHex = None): txn = Txn.new() txn.addOutput(coinbaseValue, b'') return txn
def makeCoinbaseTxn(coinbaseValue, useCoinbaser=True, prevBlockHex=None): txn = Txn.new() txn.addOutput(coinbaseValue, b'') return txn
def makeCoinbaseTxn(coinbaseValue, useCoinbaser = True, prevBlockHex = None, witness_commitment=None): txn = Txn.new() txn.addOutput(coinbaseValue, BitcoinScript.commitment(witness_commitment) if witness_commitment else b'') return txn
def makeCoinbaseTxn(coinbaseValue, useCoinbaser = True): txn = Txn.new() txn.addOutput(coinbaseValue, b'') return txn