def send_op_return(self, lst_of_pushdata, fee=1): """ All-in-one function both generates and sends a rawtx with desired OP_RETURN metadata. Parameters ---------- lst_of_pushdata : a list of tuples (pushdata, encoding) where encoding is either "hex" or "utf-8" fee : sat/byte (defaults to 1 satoshi per byte) Returns ------- broadcasts rawtx Examples -------- lst_of_pushdata = [('6d01','hex'), ('my_new_memocash_name', 'utf-8')] send_op_return(my_key, lst_of_pushdata) """ self.get_unspents() pushdata = op_return.create_pushdata(lst_of_pushdata) rawtx = self.create_transaction([], fee=fee, message=pushdata, custom_pushdata=True) return BitIndex.broadcast_rawtx(rawtx)
def bcat_linker_create_from_txids(self, lst_of_txids, media_type, encoding, file_name, info=' ', flags=' ', utxos=None): """Creates bcat transaction to link up "bcat parts" (with the stored data). This BCAT:// protocol allows for concatenating data > 100kb (up to 310MB uncompressed) to the blockchain. see: https://bcat.bico.media/ returns rawtx""" if utxos is None: utxos = self.filter_utxos_for_bcat() # FIXME - add checks lst_of_pushdata = [ (BCAT, 'utf-8'), (info, "utf-8"), # B:// protocol prefix (media_type, 'utf-8'), (encoding, "utf-8"), (file_name, "utf-8"), # Optional if no filename (flags, "utf-8") ] # Optional lst_of_pushdata.extend([(tx, 'hex') for tx in lst_of_txids]) lst_of_pushdata = op_return.create_pushdata(lst_of_pushdata) return self.create_transaction(outputs=[], message=lst_of_pushdata, combine=False, custom_pushdata=True, unspents=utxos[-1:])
def bcat_parts_send_from_binary(self, binary, utxos=None): """Takes in binary data for upload - returns list of rawtx""" # Get full binary stream = BytesIO(binary) if utxos is None: utxos = self.filter_utxos_for_bcat() txs = [] number_bcat_parts = self.get_number_bcat_parts(len(binary)) if len(utxos) - 1 >= number_bcat_parts: # Leaves one Fresh utxo leftover for linker. pass else: raise ValueError("insufficient 'Fresh' unspent transaction outputs (utxos) to complete the " "BCAT upload. Please generate more 'Fresh' utxos and try again") for i in range(number_bcat_parts): data = stream.read(SPACE_AVAILABLE_PER_TX_BCAT_PART) lst_of_pushdata = [(BCATPART, 'utf-8'), (data.hex(), 'hex')] lst_of_pushdata = op_return.create_pushdata(lst_of_pushdata) # bitsv sorts utxos by amount and then selects first the ones of *lowest* amount # so here we will manually select "Fresh" utxos (with 100,000 satoshis, 1 conf) one at a time fresh_utxo = utxos[i:i+1] txid = self.send(outputs=[], message=lst_of_pushdata, fee=1, combine=False, custom_pushdata=True, unspents=fresh_utxo) txs.append(txid) return txs
def b_create_rawtx_from_binary(self, binary, media_type, encoding=' ', file_name=' '): """Creates rawtx for sending data (<100kb) to the blockchain via the B:// protocol see: https://github.com/unwriter/B or https://b.bitdb.network/ for details""" hex_data = binary.hex() lst_of_pushdata = [(B, "utf-8"), # B:// protocol prefix (hex_data, 'hex'), (media_type, "utf-8"), (encoding, "utf-8"), # Optional if no filename (file_name, "utf-8")] # Optional lst_of_pushdata = op_return.create_pushdata(lst_of_pushdata) return self.create_transaction(outputs=[], message=lst_of_pushdata, combine=False, custom_pushdata=True, unspents=self.filter_utxos_for_bcat())
def create_op_return_rawtx(self, lst_of_pushdata, fee=1): """creates a rawtx with OP_RETURN metadata ready for broadcast. Parameters ---------- lst_of_pushdata : a list of tuples (pushdata, encoding) where encoding is either "hex" or "utf-8" fee : sat/byte (defaults to 1 satoshi per byte) Returns ------- rawtx ready to broadcast """ self.get_unspents() pushdata = op_return.create_pushdata(lst_of_pushdata) rawtx = self.create_transaction([], fee=fee, message=pushdata, custom_pushdata=True) return rawtx
def send_op_return(self, list_of_pushdata, outputs=None, fee=1, unspents=None, leftover=None, combine=False): """Sends a rawtx with OP_RETURN metadata ready for broadcast. Parameters ---------- list_of_pushdata : a list of tuples (pushdata, encoding) where encoding is either "hex" or "utf-8" fee : sat/byte (defaults to 1 satoshi per byte) Returns ------- rawtx Examples -------- list_of_pushdata = [('6d01', 'hex'), ('bitPUSHER', 'utf-8')] as per memo.cash protocol @ https://memo.cash/protocol this results in a "Set name" action to "bitPUSHER" """ if not outputs: outputs = [] self.get_unspents() pushdata = op_return.create_pushdata(list_of_pushdata) tx_hex = self.create_transaction(outputs=outputs, fee=fee, message=pushdata, custom_pushdata=True, combine=combine, unspents=unspents, leftover=leftover) self.network_api.broadcast_tx(tx_hex) return calc_txid(tx_hex)
def create_op_return_tx(self, list_of_pushdata, outputs=None, fee=1, unspents=None, leftover=None, combine=False): """Creates a rawtx with OP_RETURN metadata ready for broadcast. Parameters ---------- list_of_pushdata : a list of tuples (pushdata, encoding) where encoding is either "hex" or "utf-8" fee : sat/byte (defaults to 1 satoshi per byte) Returns ------- rawtx Examples -------- list_of_pushdata = [('6d01', 'hex'), ('bitPUSHER', 'utf-8')] as per memo.cash protocol @ https://memo.cash/protocol this results in a "Set name" action to "bitPUSHER" :param outputs: A sequence of outputs you wish to send in the form ``(destination, amount, currency)``. The amount can be either an int, float, or string as long as it is a valid input to ``decimal.Decimal``. The currency must be :ref:`supported <supported currencies>`. :type outputs: ``list`` of ``tuple`` :param fee: The number of satoshi per byte to pay to miners. By default BitSV will use a fee of 1 sat/byte :type fee: ``int`` :param leftover: The destination that will receive any change from the transaction. By default BitSV will send any change to the same address you sent from. :type leftover: ``str`` :param combine: Whether or not BitSV should use all available UTXOs to make future transactions smaller and therefore reduce fees. By default BitSV will consolidate UTXOs. :type combine: ``bool`` :param unspents: The UTXOs to use as the inputs. By default BitSV will communicate with the blockchain itself. :type unspents: ``list`` of :class:`~bitsv.network.meta.Unspent` :param list_of_pushdata: List indicating pushdata to be included in op_return as e.g.: [('6d01', 'hex'), ('hello', 'utf-8')] :type list_of_pushdata:`list` of `tuples` """ if not outputs: outputs = [] self.get_unspents() pushdata = op_return.create_pushdata(list_of_pushdata) rawtx = self.create_transaction(outputs, fee=fee, message=pushdata, custom_pushdata=True, combine=combine, unspents=unspents, leftover=leftover) return rawtx