def createcoinbasetx(data, address, msg): nTime = data['curtime'] extranonce_type = '>Q' extranonce_placeholder = struct.pack(extranonce_type, int('f000000ff111111f', 16)) extranonce_size = struct.calcsize(extranonce_type) height = data['height'] flags = data['coinbaseaux']['flags'] extradata = 'NeuralMiner' _time = nTime #in scriptSig_template = (util.ser_number(height) + binascii.unhexlify(flags) + util.ser_number(int(_time)) + chr(extranonce_size), util.ser_string('' + extradata)) scriptSig = scriptSig_template[ 0] + extranonce_placeholder + scriptSig_template[1] prevout_hash = 0L prevout_n = 2**32 - 1 nSequence = 0 txIn = "" txIn += "".zfill(64).decode('hex') txIn += struct.pack("<I", prevout_n) txIn += util.ser_string(scriptSig) txIn += struct.pack("<I", nSequence) #out scriptPubKey = util.script_to_address(address) nVersion = 1 nLockTime = 0 nValue = data['coinbasevalue'] txOut = "" txOut += struct.pack("<q", nValue) txOut += util.ser_string(scriptPubKey) coinbasetx = "" coinbasetx += struct.pack("<i", nVersion) coinbasetx += chr(01) coinbasetx += txIn coinbasetx += chr(01) coinbasetx += txOut coinbasetx += struct.pack("<I", nLockTime) coinbase = binascii.hexlify(coinbasetx) return coinbase
def __init__(self, timestamper, coinbaser, value, flags, height, data, ntime): super(CoinbaseTransaction, self).__init__() #self.extranonce = 0 if len(self.extranonce_placeholder) != self.extranonce_size: raise Exception( "Extranonce placeholder don't match expected length!") tx_in = halfnode.CTxIn() tx_in.prevout.hash = 0L tx_in.prevout.n = 2**32 - 1 tx_in._scriptSig_template = ( util.ser_number(height) + binascii.unhexlify(flags) + util.ser_number(int(timestamper.time())) + \ chr(self.extranonce_size), util.ser_string(coinbaser.get_coinbase_data() + data) ) tx_in.scriptSig = tx_in._scriptSig_template[ 0] + self.extranonce_placeholder + tx_in._scriptSig_template[1] tx_out = halfnode.CTxOut() tx_out.nValue = value tx_out.scriptPubKey = coinbaser.get_script_pubkey() self.nTime = ntime # Coinbase timestamp self.vin.append(tx_in) self.vout.append(tx_out) # Two parts of serialized coinbase, just put part1 + extranonce + part2 to have final serialized tx self._serialized = super(CoinbaseTransaction, self).serialize().split( self.extranonce_placeholder)
def __init__(self, job_id, timestamper, coinbaser, value, flags, height, data): super(CoinbaseTransaction, self).__init__() if len(self.extranonce_placeholder) != self.extranonce_size: raise Exception("Extranonce placeholder don't match expected length!") tx_in = halfnode.CTxInTemplate() tx_in.prevout.hash = 0L tx_in.prevout.n = 2**32-1 tx_in._scriptSig_template = ( util.ser_number(height) + binascii.unhexlify(flags) + util.ser_number(int(timestamper.time())) + chr(self.extranonce_size), util.ser_string("%x" % job_id + "%x" % random.randint(0, 255) + coinbaser.get_coinbase_data() + data) ) tx_in.scriptSig = tx_in._scriptSig_template[0] + self.extranonce_placeholder + tx_in._scriptSig_template[1] tx_out = halfnode.CTxOut() tx_out.nValue = value tx_out.scriptPubKey = coinbaser.get_script_pubkey() self.vin.append(tx_in) self.vout.append(tx_out) # Two parts of serialized coinbase, just put part1 + extranonce + part2 to have final serialized tx self._serialized = super(CoinbaseTransaction, self).serialize().split(self.extranonce_placeholder)
def __init__(self, timestamper, coinbaser, value, flags, height, data, ntime): super(CoinbaseTransaction, self).__init__() log.debug("Got to CoinBaseTX") #self.extranonce = 0 if len(self.extranonce_placeholder) != self.extranonce_size: raise Exception("Extranonce placeholder don't match expected length!") tx_in = halfnode.CTxIn() tx_in.prevout.hash = 0L tx_in.prevout.n = 2**32-1 tx_in._scriptSig_template = ( util.ser_number(height) + binascii.unhexlify(flags) + util.ser_number(int(timestamper.time())) + \ chr(self.extranonce_size), util.ser_string(coinbaser.get_coinbase_data() + data) ) tx_in.scriptSig = tx_in._scriptSig_template[0] + self.extranonce_placeholder + tx_in._scriptSig_template[1] tx_out = halfnode.CTxOut() tx_out.nValue = value tx_out.scriptPubKey = coinbaser.get_script_pubkey() self.nTime = ntime if settings.COINDAEMON_TX_MSG == 'yes': self.strTxComment = settings.Tx_Message self.vin.append(tx_in) self.vout.append(tx_out) # Two parts of serialized coinbase, just put part1 + extranonce + part2 to have final serialized tx self._serialized = super(CoinbaseTransaction, self).serialize().split(self.extranonce_placeholder)
def __init__(self, timestamper, coinbaser, value, flags, height, data): super(CoinbaseTransactionPOW, self).__init__() log.debug("Got to CoinBaseTX") #self.extranonce = 0 if len(self.extranonce_placeholder) != self.extranonce_size: raise Exception( "Extranonce placeholder don't match expected length!") tx_in = halfnode.CTxIn() tx_in.prevout.hash = 0L tx_in.prevout.n = 2**32 - 1 tx_in._scriptSig_template = ( util.ser_number(height) + binascii.unhexlify(flags) + util.ser_number(int(timestamper.time())) + \ chr(self.extranonce_size), util.ser_string(coinbaser.get_coinbase_data() + data) ) tx_in.scriptSig = tx_in._scriptSig_template[ 0] + self.extranonce_placeholder + tx_in._scriptSig_template[1] tx_out = halfnode.CTxOut() tx_out.nValue = value tx_out.scriptPubKey = coinbaser.get_script_pubkey() if settings.COINDAEMON_TX == 'yes': self.strTxComment = "http://github.com/ahmedbodi/stratum-mining" self.vin.append(tx_in) self.vout.append(tx_out) # Two parts of serialized coinbase, just put part1 + extranonce + part2 to have final serialized tx self._serialized = super(CoinbaseTransactionPOW, self).serialize().split( self.extranonce_placeholder)
def __init__(self, timestamper, coinbaser, value, flags, height, data, budget): super(CoinbaseTransaction, self).__init__(nVersion=2, nRefHeight=height) #self.extranonce = 0 if len(self.extranonce_placeholder) != self.extranonce_size: raise Exception("Extranonce placeholder don't match expected length!") tx_in = halfnode.CTxIn() tx_in.prevout.hash = 0L tx_in.prevout.n = 2**32-1 tx_in._scriptSig_template = ( util.ser_number(height) + binascii.unhexlify(flags) + util.ser_number(int(timestamper.time())) + \ chr(self.extranonce_size), util.ser_string(coinbaser.get_coinbase_data() + data) ) tx_in.scriptSig = tx_in._scriptSig_template[0] + self.extranonce_placeholder + tx_in._scriptSig_template[1] tx_out = halfnode.CTxOut() tx_out.nValue = value tx_out.scriptPubKey = coinbaser.get_script_pubkey() self.vin.append(tx_in) self.vout.append(tx_out) for entry in budget: txo = halfnode.CTxOut() txo.nValue = entry['value'] txo.scriptPubKey = entry['scriptPubKey']['hex'].decode('hex') self.vout.append(txo) # Two parts of serialized coinbase, just put part1 + extranonce + part2 to have final serialized tx self._serialized = super(CoinbaseTransaction, self).serialize().split(self.extranonce_placeholder)
def __init__(self, timestamper, coinbaser, value, flags, height, commitment=None, data='', ntime=None): super(CoinbaseTransaction, self).__init__() log.debug('Got to CoinBaseTX') #self.extranonce = 0 if len(self.extranonce_placeholder) != self.extranonce_size: raise Exception( 'Extranonce placeholder don\'t match expected length!') tx_in = halfnode.CTxIn() tx_in.prevout.hash = 0L tx_in.prevout.n = 2**32 - 1 tx_in._scriptSig_template = ( util.ser_number(height) + binascii.unhexlify(flags) + util.ser_number(int(timestamper.time())) + \ chr(self.extranonce_size), util.ser_string(coinbaser.get_coinbase_data() + data) ) tx_in.scriptSig = tx_in._scriptSig_template[ 0] + self.extranonce_placeholder + tx_in._scriptSig_template[1] tx_out = halfnode.CTxOut() tx_out.nValue = value tx_out.scriptPubKey = coinbaser.get_script_pubkey() if settings.COINDAEMON_REWARD == 'POS' and ntime != None: self.nTime = ntime if settings.COINDAEMON_TX != False: self.strTxComment = 'http://github.com/nullivex' self.vin.append(tx_in) self.vout.append(tx_out) if (commitment): txout_commitment = halfnode.CTxOut() txout_commitment.nValue = 0 txout_commitment.scriptPubKey = commitment self.vout.append(txout_commitment) # Two parts of serialized coinbase, just put part1 + extranonce + part2 to have final serialized tx self._serialized = super(CoinbaseTransaction, self).serialize().split( self.extranonce_placeholder)
def __init__(self, timestamper, reward_coinbaser, value, flags, height, data, ntime, coinbase_payload, masternodes): super(CoinbaseTransaction, self).__init__() # self.extranonce = 0 if len(self.extranonce_placeholder) != self.extranonce_size: raise Exception( "Extranonce placeholder don't match expected length!") tx_in = halfnode.CTxIn() tx_in.prevout.hash = 0L tx_in.prevout.n = 2**32 - 1 tx_in._scriptSig_template = ( util.ser_number(height) + binascii.unhexlify(flags) + util.ser_number(int(timestamper.time())) + \ chr(self.extranonce_size), util.ser_string(reward_coinbaser.get_coinbase_data() + data) ) tx_in.scriptSig = tx_in._scriptSig_template[ 0] + self.extranonce_placeholder + tx_in._scriptSig_template[1] # coinbase self.nVersion = 3 self.nType = 5 self.nTime = ntime self.vin.append(tx_in) for masternode in masternodes: master_coinbaser = coinbaser.SimpleCoinbaser( None, masternode['payee']) tx_out = halfnode.CTxOut() tx_out.nValue = masternode['amount'] tx_out.scriptPubKey = master_coinbaser.get_script_pubkey() self.vout.append(tx_out) value -= masternode['amount'] assert (value > 0, "coinbase reward <= 0") tx_out = halfnode.CTxOut() tx_out.nValue = value tx_out.scriptPubKey = reward_coinbaser.get_script_pubkey() self.vout.append(tx_out) # for dashcoin self.vExtraPayload = binascii.unhexlify(coinbase_payload) # Two parts of serialized coinbase, just put part1 + extranonce + part2 to have final serialized tx self._serialized = super(CoinbaseTransaction, self).serialize().split( self.extranonce_placeholder)
def __init__(self, raw_data, extra): super(CoinbaseTransaction, self).__init__() log.debug("Got to CoinBaseTX") if len(self.extranonce_placeholder) != self.extranonce_size: raise Exception( "Extranonce placeholder don't match expected length!") self.deserialize(cStringIO.StringIO(raw_data)) tx_in = self.vin[0] tx_in._scriptSig_template = (tx_in.scriptSig, util.ser_string(extra)) tx_in.scriptSig = tx_in._scriptSig_template[ 0] + self.extranonce_placeholder + tx_in._scriptSig_template[1] self._serialized = super(CoinbaseTransaction, self).serialize().split( self.extranonce_placeholder)
def __init__(self, timestamper, coinbaser, value, charity_value, flags, height, data, ntime): super(CoinbaseTransaction, self).__init__() #self.extranonce = 0 if len(self.extranonce_placeholder) != self.extranonce_size: raise Exception( "Extranonce placeholder don't match expected length!") tx_in = halfnode.CTxIn() tx_in.prevout.hash = 0L tx_in.prevout.n = 2**32 - 1 tx_in._scriptSig_template = ( util.ser_number(height) + binascii.unhexlify(flags) + util.ser_number(int(timestamper.time())) + \ chr(self.extranonce_size), util.ser_string(coinbaser.get_coinbase_data() + data) ) tx_in.scriptSig = tx_in._scriptSig_template[ 0] + self.extranonce_placeholder + tx_in._scriptSig_template[1] # EMC2 Charity Address Requirement charity_value += int(settings.EXTRA_DONATION) if charity_value > value: charity_value = value tx_out_charity = halfnode.CTxOut() tx_out_charity.nValue = charity_value tx_out_charity.scriptPubKey = util.getCharityScript() tx_out = halfnode.CTxOut() tx_out.nValue = value tx_out.scriptPubKey = coinbaser.get_script_pubkey() self.nTime = ntime if settings.COINDAEMON_SHA256_TX == 'yes': self.strTxComment = "" self.vin.append(tx_in) self.vout.append(tx_out_charity) self.vout.append(tx_out) # Two parts of serialized coinbase, just put part1 + extranonce + part2 to have final serialized tx self._serialized = super(CoinbaseTransaction, self).serialize().split( self.extranonce_placeholder)
def __init__(self, timestamper, coinbaser, value, charity_value, flags, height, data, ntime): super(CoinbaseTransactionPOS, self).__init__() log.debug("Got to CoinBaseTX") #self.extranonce = 0 if len(self.extranonce_placeholder) != self.extranonce_size: raise Exception("Extranonce placeholder don't match expected length!") tx_in = halfnode.CTxIn() tx_in.prevout.hash = 0L tx_in.prevout.n = 2**32-1 tx_in._scriptSig_template = ( util.ser_number(height) + binascii.unhexlify(flags) + util.ser_number(int(timestamper.time())) + \ chr(self.extranonce_size), util.ser_string(coinbaser.get_coinbase_data() + data) ) tx_in.scriptSig = tx_in._scriptSig_template[0] + self.extranonce_placeholder + tx_in._scriptSig_template[1] tx_out = halfnode.CTxOut() tx_out.nValue = value tx_out.scriptPubKey = coinbaser.get_script_pubkey() self.nTime = ntime if settings.COINDAEMON_SHA256_TX != False: self.strTxComment = "http://github.com/ahmedbodi/stratum-mining" self.vin.append(tx_in) if settings.CHARITY_ENABLED is True: tx_out_charity = halfnode.CTxOut() tx_out_charity.nValue = charity_value tx_out_charity.scriptPubKey = util.getCharityScript() if settings.CHARITY_ISFIRSTTXOUT is True: self.vout.append(tx_out_charity) self.vout.append(tx_out) else: self.vout.append(tx_out) self.vout.append(tx_out_charity) else: self.vout.append(tx_out) # Two parts of serialized coinbase, just put part1 + extranonce + part2 to have final serialized tx self._serialized = super(CoinbaseTransactionPOS, self).serialize().split(self.extranonce_placeholder)
def __init__(self, timestamper, coinbaser, values, flags, height, commitment, data): super(CoinbaseTransactionPOW, self).__init__() log.debug("Got to CoinBaseTX(POW)") #self.extranonce = 0 if len(self.extranonce_placeholder) != self.extranonce_size: raise Exception("Extranonce placeholder don't match expected length!") tx_in = halfnode.CTxIn() tx_in.prevout.hash = 0L tx_in.prevout.n = 2**32-1 tx_in._scriptSig_template = ( util.ser_number(height) + binascii.unhexlify(flags) + util.ser_number(int(timestamper.time())) + \ chr(self.extranonce_size), util.ser_string(coinbaser.get_coinbase_data() + data) ) tx_in.scriptSig = tx_in._scriptSig_template[0] + self.extranonce_placeholder + tx_in._scriptSig_template[1] tx_out = halfnode.CTxOut() tx_out.nValue = values[0]['nValue'] tx_out.scriptPubKey = coinbaser.get_script_pubkey() self.vin.append(tx_in) self.vout.append(tx_out) values.pop(-1) log.debug("values: %s", values) values.pop(0) for value in values: tx_out = halfnode.CTxOut() tx_out.nValue = value['nValue'] tx_out.scriptPubKey = binascii.unhexlify(value['scriptPubKey']) self.vout.append(tx_out) if(commitment): txout_commitment = halfnode.CTxOut() txout_commitment.nValue = 0 txout_commitment.scriptPubKey = commitment self.vout.append(txout_commitment) # Two parts of serialized coinbase, just put part1 + extranonce + part2 to have final serialized tx self._serialized = super(CoinbaseTransactionPOW, self).serialize().split(self.extranonce_placeholder)
def __init__(self, timestamper, coinbaser, value, charity_value, flags, height, data, ntime): super(CoinbaseTransaction, self).__init__() #self.extranonce = 0 if len(self.extranonce_placeholder) != self.extranonce_size: raise Exception("Extranonce placeholder don't match expected length!") tx_in = halfnode.CTxIn() tx_in.prevout.hash = 0L tx_in.prevout.n = 2**32-1 tx_in._scriptSig_template = ( util.ser_number(height) + binascii.unhexlify(flags) + util.ser_number(int(timestamper.time())) + \ chr(self.extranonce_size), util.ser_string(coinbaser.get_coinbase_data() + data) ) tx_in.scriptSig = tx_in._scriptSig_template[0] + self.extranonce_placeholder + tx_in._scriptSig_template[1] # EMC2 Charity Address Requirement charity_value += int(settings.EXTRA_DONATION) if charity_value > value: charity_value = value tx_out_charity = halfnode.CTxOut() tx_out_charity.nValue = charity_value tx_out_charity.scriptPubKey = util.getCharityScript() tx_out = halfnode.CTxOut() tx_out.nValue = value - charity_value tx_out.scriptPubKey = coinbaser.get_script_pubkey() self.nTime = ntime if settings.COINDAEMON_SHA256_TX == 'yes': self.strTxComment = "" self.vin.append(tx_in) self.vout.append(tx_out) self.vout.append(tx_out_charity) # Two parts of serialized coinbase, just put part1 + extranonce + part2 to have final serialized tx self._serialized = super(CoinbaseTransaction, self).serialize().split(self.extranonce_placeholder)
def __init__(self, coinbasers_value, total_value, flags, height, data): super(CoinbaseTransaction, self).__init__() #self.extranonce = 0 if len(self.extranonce_placeholder) != self.extranonce_size: raise Exception( "Extranonce placeholder don't match expected length!") tx_in = halfnode.CTxIn() tx_in.prevout.hash = 0L tx_in.prevout.n = 2**32 - 1 tx_in._scriptSig_template = ( util.ser_number(height) + binascii.unhexlify(flags) + util.ser_number(int(time.time())) + \ chr(self.extranonce_size), # util.ser_string(coinbaser.get_coinbase_data() + data) util.ser_string(data) ) tx_in.scriptSig = tx_in._scriptSig_template[ 0] + self.extranonce_placeholder + tx_in._scriptSig_template[1] self.vin.append(tx_in) total_value_share = sum([x[1] for x in coinbasers_value]) used_value = 0 for coinbaser, value in coinbasers_value: tx_out = halfnode.CTxOut() current_value = total_value * value / total_value_share tx_out.nValue = current_value used_value += current_value tx_out.scriptPubKey = coinbaser.get_script_pubkey() self.vout.append(tx_out) if used_value < total_value: self.vout[0].nValue += total_value - used_value # Two parts of serialized coinbase, just put part1 + extranonce + part2 to have final serialized tx self._serialized = super(CoinbaseTransaction, self).serialize().split( self.extranonce_placeholder)
def __init__(self, coinbasers_value, total_value, flags, height, data): super(CoinbaseTransaction, self).__init__() #self.extranonce = 0 if len(self.extranonce_placeholder) != self.extranonce_size: raise Exception("Extranonce placeholder don't match expected length!") tx_in = halfnode.CTxIn() tx_in.prevout.hash = 0L tx_in.prevout.n = 2**32-1 tx_in._scriptSig_template = ( util.ser_number(height) + binascii.unhexlify(flags) + util.ser_number(int(time.time())) + \ chr(self.extranonce_size), # util.ser_string(coinbaser.get_coinbase_data() + data) util.ser_string(data) ) tx_in.scriptSig = tx_in._scriptSig_template[0] + self.extranonce_placeholder + tx_in._scriptSig_template[1] self.vin.append(tx_in) total_value_share = sum([x[1] for x in coinbasers_value]) used_value = 0 for coinbaser, value in coinbasers_value: tx_out = halfnode.CTxOut() current_value = total_value * value / total_value_share tx_out.nValue = current_value used_value += current_value tx_out.scriptPubKey = coinbaser.get_script_pubkey() self.vout.append(tx_out) if used_value < total_value: self.vout[0].nValue += total_value - used_value # Two parts of serialized coinbase, just put part1 + extranonce + part2 to have final serialized tx self._serialized = super(CoinbaseTransaction, self).serialize().split(self.extranonce_placeholder)
def __init__(self, timestamper, coinbaser, payee, value, flags, height, data): super(CoinbaseTransactionPOW, self).__init__() log.debug("Got to CoinBaseTX") #self.extranonce = 0 if len(self.extranonce_placeholder) != self.extranonce_size: raise Exception("Extranonce placeholder don't match expected length!") tx_in = halfnode.CTxIn() tx_in.prevout.hash = 0L tx_in.prevout.n = 2**32-1 tx_in._scriptSig_template = ( util.ser_number(height) + binascii.unhexlify(flags) + util.ser_number(int(timestamper.time())) + \ chr(self.extranonce_size), util.ser_string(coinbaser.get_coinbase_data() + data) ) tx_in.scriptSig = tx_in._scriptSig_template[0] + self.extranonce_placeholder + tx_in._scriptSig_template[1] tx_out2 = None if(payee != None): value2 = value / 5 value -= value2 tx_out2 = halfnode.CTxOut() tx_out2.nValue = value2 tx_out2.scriptPubKey = payee tx_out = halfnode.CTxOut() tx_out.nValue = value tx_out.scriptPubKey = coinbaser.get_script_pubkey() if settings.COINDAEMON_TX != False: self.strTxComment = "http://github.com/ahmedbodi/stratum-mining" self.vin.append(tx_in) self.vout.append(tx_out) if tx_out2: self.vout.append(tx_out2) # Two parts of serialized coinbase, just put part1 + extranonce + part2 to have final serialized tx self._serialized = super(CoinbaseTransactionPOW, self).serialize().split(self.extranonce_placeholder)