def broadcast(name, recipient_address, update_hash, private_key, blockchain_client, blockchain_broadcaster=None, tx_only=False, testset=False):
   
    if blockchain_broadcaster is None:
        blockchain_broadcaster = blockchain_client 
    
    nulldata = build(name, testset=testset)
    
    # convert update_hash from a hex string so it looks like an address
    update_hash_b58 = b58check_encode( unhexlify(update_hash) )
    
    # get inputs and from address
    private_key_obj, from_address, inputs = analyze_private_key(private_key, blockchain_client)
    
    # NAME_IMPORT outputs
    outputs = make_outputs(nulldata, inputs, recipient_address, from_address, update_hash_b58, format='hex')
    
    if tx_only:
        
        unsigned_tx = serialize_transaction( inputs, outputs )
        return {"unsigned_tx": unsigned_tx}
    
    else:
        # serialize, sign, and broadcast the tx
        response = serialize_sign_and_broadcast(inputs, outputs, private_key_obj, blockchain_broadcaster)
        
        # response = {'success': True }
        response.update({'data': nulldata})
        
        # return the response
        return response
Exemplo n.º 2
0
def broadcast(name,
              destination_address,
              keepdata,
              consensus_hash,
              private_key,
              blockchain_client,
              testset=False):

    nulldata = build(name, keepdata, consensus_hash, testset=testset)

    # get inputs and from address
    private_key_obj, from_address, inputs = analyze_private_key(
        private_key, blockchain_client)

    # build custom outputs here
    outputs = make_outputs(nulldata,
                           inputs,
                           destination_address,
                           from_address,
                           format='hex')

    # serialize, sign, and broadcast the tx
    response = serialize_sign_and_broadcast(inputs, outputs, private_key_obj,
                                            blockchain_client)

    # response = {'success': True }
    response.update({'data': nulldata})

    # return the response
    return response
Exemplo n.º 3
0
def tx_make_subsidizable( blockstore_tx, fee_cb, max_fee, subsidy_key, utxo_client ):
    """
    Given an unsigned serialized transaction from Blockstore, make it into a subsidized transaction 
    for the client to go sign off on.
    * Add subsidization inputs/outputs
    * Make sure the subsidy does not exceed the maximum subsidy fee
    * Sign our inputs with SIGHASH_ANYONECANPAY
    """
   
    # get subsidizer key info
    private_key_obj, payer_address, payer_utxo_inputs = analyze_private_key(subsidy_key, utxo_client)
    
    tx_inputs, tx_outputs, locktime, version = tx_deserialize( blockstore_tx )

    # what's the fee?  does it exceed the subsidy?
    dust_fee, op_fee = fee_cb( tx_inputs, tx_outputs )
    if dust_fee is None or op_fee is None:
        log.error("Invalid fee structure")
        return None 
    
    if dust_fee + op_fee > max_fee:
        log.error("Op fee (%s) + dust fee (%s) exceeds maximum subsidy %s" % (dust_fee, op_fee, max_fee))
        return None
    
    else:
        log.debug("%s will subsidize %s satoshi" % (pybitcoin.BitcoinPrivateKey( subsidy_key ).public_key().address(), dust_fee + op_fee ))
    
    # calculate how much the dust fee needs to be 
    subsidized_tx = tx_serialize_subsidized_tx( blockstore_tx, private_key_obj.to_hex(), payer_utxo_inputs, payer_address, 0, op_fee )
    dust_fee = tx_dust_fee( subsidized_tx )

    # *now* make the transaction
    subsidized_tx = tx_serialize_subsidized_tx( blockstore_tx, private_key_obj.to_hex(), payer_utxo_inputs, payer_address, dust_fee, op_fee )
    return subsidized_tx
Exemplo n.º 4
0
def broadcast(name,
              recipient_address,
              update_hash,
              private_key,
              blockchain_client,
              testset=False):

    nulldata = build(name, testset=testset)

    # get inputs and from address
    private_key_obj, from_address, inputs = analyze_private_key(
        private_key, blockchain_client)

    # convert update_hash from a hex string so it looks like an address
    update_hash_b58 = b58check_encode(unhexlify(update_hash))

    # build custom outputs here
    outputs = make_outputs(nulldata,
                           inputs,
                           recipient_address,
                           from_address,
                           update_hash_b58,
                           format='hex')

    # serialize, sign, and broadcast the tx
    response = serialize_sign_and_broadcast(inputs, outputs, private_key_obj,
                                            blockchain_client)

    # response = {'success': True }
    response.update({'data': nulldata})

    # return the response
    return response
Exemplo n.º 5
0
def broadcast( namespace_id, reveal_addr, lifetime, coeff, base_cost, bucket_exponents, nonalpha_discount, no_vowel_discount, private_key, blockchain_client, testset=False ):
   """
   Propagate a namespace.
   
   Arguments:
   namespace_id         human-readable (i.e. base-40) name of the namespace
   reveal_addr          address to own this namespace until it is ready
   lifetime:            the number of blocks for which names will be valid (pass a negative value for "infinite")
   coeff:               cost multipler
   base_cost:           the base cost (i.e. cost of a 1-character name), in satoshis 
   bucket_exponents:    bucket cost exponents to which to raise the base cost 
   nonalpha_discount:   discount multipler for non-alpha-character names 
   no_vowel_discount:   discount multipler for no-vowel names
   """
   
   nulldata = build( namespace_id, BLOCKSTORE_VERSION, reveal_addr, lifetime, coeff, base_cost, bucket_exponents, nonalpha_discount, no_vowel_discount, testset=testset )
   
   # get inputs and from address
   private_key_obj, from_address, inputs = analyze_private_key(private_key, blockchain_client)
    
   # build custom outputs here
   outputs = make_outputs(nulldata, inputs, reveal_addr, from_address, format='hex')
    
   # serialize, sign, and broadcast the tx
   response = serialize_sign_and_broadcast(inputs, outputs, private_key_obj, blockchain_client)
    
   # response = {'success': True }
   response.update({'data': nulldata})
    
   return response
Exemplo n.º 6
0
def broadcast( namespace_id, register_addr, consensus_hash, private_key, blockchain_client, fee, testset=False ):
   """
   Propagate a namespace.
   
   Arguments:
   namespace_id         human-readable (i.e. base-40) name of the namespace
   register_addr        the addr of the key that will reveal the namespace (mixed into the preorder to prevent name preimage attack races)
   private_key          the Bitcoin address that created this namespace, and can populate it.
   """
    
   script_pubkey = get_script_pubkey( private_key )
   nulldata = build( namespace_id, script_pubkey, register_addr, consensus_hash, testset=testset )
   
   # get inputs and from address
   private_key_obj, from_address, inputs = analyze_private_key(private_key, blockchain_client)
    
   # build custom outputs here
   outputs = make_outputs(nulldata, inputs, from_address, fee, format='hex')
    
   # serialize, sign, and broadcast the tx
   response = serialize_sign_and_broadcast(inputs, outputs, private_key_obj, blockchain_client)
    
   # response = {'success': True }
   response.update({'data': nulldata})
    
   return response
Exemplo n.º 7
0
def broadcast(name, recipient_address, update_hash, private_key, blockchain_client, blockchain_broadcaster=None, tx_only=False, testset=False):
   
    if blockchain_broadcaster is None:
        blockchain_broadcaster = blockchain_client 
    
    nulldata = build(name, testset=testset)
    
    # convert update_hash from a hex string so it looks like an address
    update_hash_b58 = b58check_encode( unhexlify(update_hash) )
    
    # get inputs and from address
    private_key_obj, from_address, inputs = analyze_private_key(private_key, blockchain_client)
    
    # NAME_IMPORT outputs
    outputs = make_outputs(nulldata, inputs, recipient_address, from_address, update_hash_b58, format='hex')
    
    if tx_only:
        
        unsigned_tx = serialize_transaction( inputs, outputs )
        return {"unsigned_tx": unsigned_tx}
    
    else:
        # serialize, sign, and broadcast the tx
        response = serialize_sign_and_broadcast(inputs, outputs, private_key_obj, blockchain_broadcaster)
        
        # response = {'success': True }
        response.update({'data': nulldata})
        
        # return the response
        return response
Exemplo n.º 8
0
def broadcast(name,
              register_addr,
              private_key,
              blockchain_client,
              renewal_fee=None,
              testset=False):

    nulldata = build(name, testset=testset)

    # get inputs and from address
    private_key_obj, from_address, inputs = analyze_private_key(
        private_key, blockchain_client)

    # build custom outputs here
    outputs = make_outputs(nulldata,
                           inputs,
                           register_addr,
                           from_address,
                           renewal_fee=renewal_fee,
                           format='hex')

    # serialize, sign, and broadcast the tx
    response = serialize_sign_and_broadcast(inputs, outputs, private_key_obj,
                                            blockchain_client)

    # response = {'success': True }
    response.update({'data': nulldata})

    return response
Exemplo n.º 9
0
def broadcast(name,
              register_addr,
              consensus_hash,
              private_key,
              blockchain_client,
              fee,
              testset=False):
    """
    Builds and broadcasts a preorder transaction.
    """

    script_pubkey = get_script_pubkey(private_key)

    nulldata = build(name,
                     script_pubkey,
                     register_addr,
                     consensus_hash,
                     testset=testset)

    # get inputs and from address
    private_key_obj, from_address, inputs = analyze_private_key(
        private_key, blockchain_client)

    # build custom outputs here
    outputs = make_outputs(nulldata, inputs, from_address, fee, format='hex')

    # serialize, sign, and broadcast the tx
    response = serialize_sign_and_broadcast(inputs, outputs, private_key_obj,
                                            blockchain_client)

    # response = {'success': True }
    response.update({'data': nulldata})

    return response
Exemplo n.º 10
0
def broadcast(name, private_key, register_addr, blockchain_client, renewal_fee=None, blockchain_broadcaster=None, tx_only=False, user_public_key=None, subsidy_public_key=None, testset=False):
    
    # sanity check 
    if subsidy_public_key is not None:
        # if subsidizing, we're only giving back a tx to be signed
        tx_only = True

    if subsidy_public_key is None and private_key is None:
        raise Exception("Missing both public and private key")
    
    if not tx_only and private_key is None:
        raise Exception("Need private key for broadcasting")
    
    if blockchain_broadcaster is None:
        blockchain_broadcaster = blockchain_client 
    
    from_address = None 
    change_inputs = None
    private_key_obj = None
    subsidized_renewal = False
    
    if subsidy_public_key is not None:
        # subsidizing
        pubk = BitcoinPublicKey( subsidy_public_key )
        
        if user_public_key is not None and renewal_fee is not None:
            # renewing, and subsidizing the renewal
            from_address = BitcoinPublicKey( user_public_key ).address() 
            subsidized_renewal = True

        else:
            # registering or renewing under the subsidy key
            from_address = pubk.address()

        change_inputs = get_unspents( from_address, blockchain_client )

    elif private_key is not None:
        # ordering directly
        pubk = BitcoinPrivateKey( private_key ).public_key()
        public_key = pubk.to_hex()
        
        # get inputs and from address using private key
        private_key_obj, from_address, change_inputs = analyze_private_key(private_key, blockchain_client)
        
    nulldata = build(name, testset=testset)
    outputs = make_outputs(nulldata, change_inputs, register_addr, from_address, renewal_fee=renewal_fee, pay_fee=(not subsidized_renewal), format='hex')
   
    if tx_only:
        
        unsigned_tx = serialize_transaction( change_inputs, outputs )
        return {"unsigned_tx": unsigned_tx}
    
    else:
        
        # serialize, sign, and broadcast the tx
        response = serialize_sign_and_broadcast(change_inputs, outputs, private_key_obj, blockchain_broadcaster)
        response.update({'data': nulldata})
        return response
Exemplo n.º 11
0
def broadcast(name_list, private_key, register_addr_list, consensus_hash, blockchain_client, fee, \
              blockchain_broadcaster=None, subsidy_public_key=None, tx_only=False, testset=False):
    """
    Builds and broadcasts a preorder transaction.

    @subsidy_public_key: if given, the public part of the subsidy key 
    """

    if subsidy_public_key is not None:
        # subsidizing, and only want the tx 
        tx_only = True
    
    # sanity check 
    if subsidy_public_key is None and private_key is None:
        raise Exception("Missing both client public and private key")
    
    if blockchain_broadcaster is None:
        blockchain_broadcaster = blockchain_client 

    from_address = None     # change address
    inputs = None
    private_key_obj = None
    script_pubkey = None    # to be mixed into preorder hash
    
    if subsidy_public_key is not None:
        # subsidizing
        pubk = BitcoinPublicKey( subsidy_public_key )
        
        from_address = BitcoinPublicKey( subsidy_public_key ).address()

        inputs = get_unspents( from_address, blockchain_client )
        script_pubkey = get_script_pubkey( subsidy_public_key )

    else:
        # ordering directly
        pubk = BitcoinPrivateKey( private_key ).public_key()
        public_key = pubk.to_hex()
        script_pubkey = get_script_pubkey( public_key )
        
        # get inputs and from address using private key
        private_key_obj, from_address, inputs = analyze_private_key(private_key, blockchain_client)
        
    nulldata = build( name_list, script_pubkey, register_addr_list, consensus_hash, testset=testset)
    outputs = make_outputs(nulldata, inputs, from_address, fee, format='hex')
    
    if tx_only:

        unsigned_tx = serialize_transaction( inputs, outputs )
        return {"unsigned_tx": unsigned_tx}
    
    else:
        # serialize, sign, and broadcast the tx
        response = serialize_sign_and_broadcast(inputs, outputs, private_key_obj, blockchain_client)
        response.update({'data': nulldata})
        return response
Exemplo n.º 12
0
def broadcast(namespace_id,
              reveal_addr,
              lifetime,
              coeff,
              base_cost,
              bucket_exponents,
              nonalpha_discount,
              no_vowel_discount,
              private_key,
              blockchain_client,
              testset=False):
    """
   Propagate a namespace.
   
   Arguments:
   namespace_id         human-readable (i.e. base-40) name of the namespace
   reveal_addr          address to own this namespace until it is ready
   lifetime:            the number of blocks for which names will be valid (pass a negative value for "infinite")
   coeff:               cost multipler
   base_cost:           the base cost (i.e. cost of a 1-character name), in satoshis 
   bucket_exponents:    bucket cost exponents to which to raise the base cost 
   nonalpha_discount:   discount multipler for non-alpha-character names 
   no_vowel_discount:   discount multipler for no-vowel names
   """

    nulldata = build(namespace_id,
                     BLOCKSTORE_VERSION,
                     reveal_addr,
                     lifetime,
                     coeff,
                     base_cost,
                     bucket_exponents,
                     nonalpha_discount,
                     no_vowel_discount,
                     testset=testset)

    # get inputs and from address
    private_key_obj, from_address, inputs = analyze_private_key(
        private_key, blockchain_client)

    # build custom outputs here
    outputs = make_outputs(nulldata,
                           inputs,
                           reveal_addr,
                           from_address,
                           format='hex')

    # serialize, sign, and broadcast the tx
    response = serialize_sign_and_broadcast(inputs, outputs, private_key_obj,
                                            blockchain_client)

    # response = {'success': True }
    response.update({'data': nulldata})

    return response
Exemplo n.º 13
0
def broadcast(namespace_id,
              register_addr,
              consensus_hash,
              private_key,
              blockchain_client,
              fee,
              pay_fee=True,
              tx_only=False,
              testset=False,
              blockchain_broadcaster=None):
    """
   Propagate a namespace.
   
   Arguments:
   namespace_id         human-readable (i.e. base-40) name of the namespace
   register_addr        the addr of the key that will reveal the namespace (mixed into the preorder to prevent name preimage attack races)
   private_key          the Bitcoin address that created this namespace, and can populate it.
   """

    if blockchain_broadcaster is None:
        blockchain_broadcaster = blockchain_client

    pubkey_hex = BitcoinPrivateKey(private_key).public_key().to_hex()

    script_pubkey = get_script_pubkey(pubkey_hex)
    nulldata = build(namespace_id,
                     script_pubkey,
                     register_addr,
                     consensus_hash,
                     testset=testset)

    # get inputs and from address
    private_key_obj, from_address, inputs = analyze_private_key(
        private_key, blockchain_client)

    # build custom outputs here
    outputs = make_outputs(nulldata, inputs, from_address, fee, format='hex')

    if tx_only:

        unsigned_tx = serialize_transaction(inputs, outputs)
        return {"unsigned_tx": unsigned_tx}

    else:
        # serialize, sign, and broadcast the tx
        response = serialize_sign_and_broadcast(inputs, outputs,
                                                private_key_obj,
                                                blockchain_broadcaster)

        # response = {'success': True }
        response.update({'data': nulldata})

        return response
Exemplo n.º 14
0
def tx_make_subsidizable(blockstack_tx, fee_cb, max_fee, subsidy_key,
                         utxo_client):
    """
    Given an unsigned serialized transaction from Blockstack, make it into a subsidized transaction 
    for the client to go sign off on.
    * Add subsidization inputs/outputs
    * Make sure the subsidy does not exceed the maximum subsidy fee
    * Sign our inputs with SIGHASH_ANYONECANPAY
    """

    # get subsidizer key info
    private_key_obj, payer_address, payer_utxo_inputs = analyze_private_key(
        subsidy_key, utxo_client)

    tx_inputs, tx_outputs, locktime, version = tx_deserialize(blockstack_tx)

    # what's the fee?  does it exceed the subsidy?
    dust_fee, op_fee = fee_cb(tx_inputs, tx_outputs)
    if dust_fee is None or op_fee is None:
        log.error("Invalid fee structure")
        return None

    if dust_fee + op_fee > max_fee:
        log.error("Op fee (%s) + dust fee (%s) exceeds maximum subsidy %s" %
                  (dust_fee, op_fee, max_fee))
        return None

    else:
        log.debug(
            "%s will subsidize %s satoshi" %
            (pybitcoin.BitcoinPrivateKey(subsidy_key).public_key().address(),
             dust_fee + op_fee))

    subsidy_output = tx_make_subsidization_output(payer_utxo_inputs,
                                                  payer_address, op_fee,
                                                  dust_fee)

    # add our inputs and output
    subsidized_tx = tx_extend(blockstack_tx, payer_utxo_inputs,
                              [subsidy_output])

    # sign each of our inputs with our key, but use SIGHASH_ANYONECANPAY so the client can sign its inputs
    for i in xrange(0, len(payer_utxo_inputs)):
        idx = i + len(tx_inputs)
        subsidized_tx = bitcoin.sign(subsidized_tx,
                                     idx,
                                     private_key_obj.to_hex(),
                                     hashcode=bitcoin.SIGHASH_ANYONECANPAY)

    return subsidized_tx
Exemplo n.º 15
0
def broadcast(name, private_key, register_addr, consensus_hash, blockchain_client, fee, blockchain_broadcaster=None, tx_only=False, pay_fee=True, public_key=None, testset=False):
    """
    Builds and broadcasts a preorder transaction.
    """
    
    # sanity check 
    if public_key is None and private_key is None:
        raise Exception("Missing both public and private key")
    
    if not tx_only and private_key is None:
        raise Exception("Need private key for broadcasting")
    
    if blockchain_broadcaster is None:
        blockchain_broadcaster = blockchain_client 
    
    from_address = None 
    inputs = None
    private_key_obj = None
    
    if private_key is not None:
        # ordering directly 
        pubk = BitcoinPrivateKey( private_key ).public_key()
        public_key = pubk.to_hex()
        
        # get inputs and from address using private key
        private_key_obj, from_address, inputs = analyze_private_key(private_key, blockchain_client)
        
    elif public_key is not None:
        # subsidizing 
        pubk = BitcoinPublicKey( public_key )
        from_address = pubk.address()
        
        # get inputs from utxo provider 
        inputs = get_unspents( from_address, blockchain_client )
        
    script_pubkey = get_script_pubkey( public_key )
    nulldata = build( name, script_pubkey, register_addr, consensus_hash, testset=testset)
    
    # build custom outputs here
    outputs = make_outputs(nulldata, inputs, from_address, fee, pay_fee=pay_fee, format='hex')
    
    if tx_only:
        unsigned_tx = serialize_transaction( inputs, outputs )
        return {"unsigned_tx": unsigned_tx}
    
    else:
        # serialize, sign, and broadcast the tx
        response = serialize_sign_and_broadcast(inputs, outputs, private_key_obj, blockchain_client)
        response.update({'data': nulldata})
        return response
def broadcast(
    namespace_id,
    register_addr,
    consensus_hash,
    private_key,
    blockchain_client,
    fee,
    pay_fee=True,
    tx_only=False,
    testset=False,
    blockchain_broadcaster=None,
):
    """
   Propagate a namespace.
   
   Arguments:
   namespace_id         human-readable (i.e. base-40) name of the namespace
   register_addr        the addr of the key that will reveal the namespace (mixed into the preorder to prevent name preimage attack races)
   private_key          the Bitcoin address that created this namespace, and can populate it.
   """

    if blockchain_broadcaster is None:
        blockchain_broadcaster = blockchain_client

    pubkey_hex = BitcoinPrivateKey(private_key).public_key().to_hex()

    script_pubkey = get_script_pubkey(pubkey_hex)
    nulldata = build(namespace_id, script_pubkey, register_addr, consensus_hash, testset=testset)

    # get inputs and from address
    private_key_obj, from_address, inputs = analyze_private_key(private_key, blockchain_client)

    # build custom outputs here
    outputs = make_outputs(nulldata, inputs, from_address, fee, format="hex")

    if tx_only:

        unsigned_tx = serialize_transaction(inputs, outputs)
        return {"unsigned_tx": unsigned_tx}

    else:
        # serialize, sign, and broadcast the tx
        response = serialize_sign_and_broadcast(inputs, outputs, private_key_obj, blockchain_broadcaster)

        # response = {'success': True }
        response.update({"data": nulldata})

        return response
Exemplo n.º 17
0
def broadcast(name, register_addr, private_key, blockchain_client, renewal_fee=None, testset=False):
    
    nulldata = build(name, testset=testset)
    
    # get inputs and from address
    private_key_obj, from_address, inputs = analyze_private_key(private_key, blockchain_client)
    
    # build custom outputs here
    outputs = make_outputs(nulldata, inputs, register_addr, from_address, renewal_fee=renewal_fee, format='hex')
    
    # serialize, sign, and broadcast the tx
    response = serialize_sign_and_broadcast(inputs, outputs, private_key_obj, blockchain_client)
    
    # response = {'success': True }
    response.update({'data': nulldata})
    
    return response
Exemplo n.º 18
0
def tx_make_subsidizable(blockstore_tx, fee_cb, max_fee, subsidy_key,
                         utxo_client):
    """
    Given an unsigned serialized transaction from Blockstore, make it into a subsidized transaction 
    for the client to go sign off on.
    * Add subsidization inputs/outputs
    * Make sure the subsidy does not exceed the maximum subsidy fee
    * Sign our inputs with SIGHASH_ANYONECANPAY
    """

    # get subsidizer key info
    private_key_obj, payer_address, payer_utxo_inputs = analyze_private_key(
        subsidy_key, utxo_client)

    tx_inputs, tx_outputs, locktime, version = tx_deserialize(blockstore_tx)

    # what's the fee?  does it exceed the subsidy?
    dust_fee, op_fee = fee_cb(tx_inputs, tx_outputs)
    if dust_fee is None or op_fee is None:
        log.error("Invalid fee structure")
        return None

    if dust_fee + op_fee > max_fee:
        log.error("Op fee (%s) + dust fee (%s) exceeds maximum subsidy %s" %
                  (dust_fee, op_fee, max_fee))
        return None

    else:
        log.debug(
            "%s will subsidize %s satoshi" %
            (pybitcoin.BitcoinPrivateKey(subsidy_key).public_key().address(),
             dust_fee + op_fee))

    # calculate how much the dust fee needs to be
    subsidized_tx = tx_serialize_subsidized_tx(blockstore_tx,
                                               private_key_obj.to_hex(),
                                               payer_utxo_inputs,
                                               payer_address, 0, op_fee)
    dust_fee = tx_dust_fee(subsidized_tx)

    # *now* make the transaction
    subsidized_tx = tx_serialize_subsidized_tx(blockstore_tx,
                                               private_key_obj.to_hex(),
                                               payer_utxo_inputs,
                                               payer_address, dust_fee, op_fee)
    return subsidized_tx
Exemplo n.º 19
0
def broadcast(name, destination_address, keepdata, consensus_hash, private_key, blockchain_client, testset=False):
   
    nulldata = build(name, keepdata, consensus_hash, testset=testset)
    
    # get inputs and from address
    private_key_obj, from_address, inputs = analyze_private_key(private_key, blockchain_client)
    
    # build custom outputs here
    outputs = make_outputs(nulldata, inputs, destination_address, from_address, format='hex')
    
    # serialize, sign, and broadcast the tx
    response = serialize_sign_and_broadcast(inputs, outputs, private_key_obj, blockchain_client)
    
    # response = {'success': True }
    response.update({'data': nulldata})
    
    # return the response
    return response
Exemplo n.º 20
0
def broadcast(name, recipient_address, update_hash, private_key, blockchain_client, testset=False):
   
    nulldata = build(name, testset=testset)
    
    # get inputs and from address
    private_key_obj, from_address, inputs = analyze_private_key(private_key, blockchain_client)
    
    # convert update_hash from a hex string so it looks like an address
    update_hash_b58 = b58check_encode( unhexlify(update_hash) )
    
    # build custom outputs here
    outputs = make_outputs(nulldata, inputs, recipient_address, from_address, update_hash_b58, format='hex')
    
    # serialize, sign, and broadcast the tx
    response = serialize_sign_and_broadcast(inputs, outputs, private_key_obj, blockchain_client)
    
    # response = {'success': True }
    response.update({'data': nulldata})
    
    # return the response
    return response
Exemplo n.º 21
0
def tx_make_subsidizable( blockstack_tx, fee_cb, max_fee, subsidy_key, utxo_client, tx_fee=0 ):
    """
    Given an unsigned serialized transaction from Blockstack, make it into a subsidized transaction 
    for the client to go sign off on.
    * Add subsidization inputs/outputs
    * Make sure the subsidy does not exceed the maximum subsidy fee
    * Sign our inputs with SIGHASH_ANYONECANPAY

    Raise ValueError if there are not enough inputs to subsidize
    """
   
    # get subsidizer key info
    private_key_obj, payer_address, payer_utxo_inputs = pybitcoin.analyze_private_key(subsidy_key, utxo_client)
    
    tx_inputs, tx_outputs, locktime, version = tx_deserialize( blockstack_tx )

    # what's the fee?  does it exceed the subsidy?
    dust_fee, op_fee = fee_cb( tx_inputs, tx_outputs )
    if dust_fee is None or op_fee is None:
        log.error("Invalid fee structure")
        return None 
    
    if dust_fee + op_fee + tx_fee > max_fee:
        log.error("Op fee (%s) + dust fee (%s) exceeds maximum subsidy %s" % (dust_fee, op_fee, max_fee))
        return None
    
    else:
        log.debug("%s will subsidize %s satoshi" % (pybitcoin.BitcoinPrivateKey( subsidy_key ).public_key().address(), dust_fee + op_fee ))
    
    subsidy_output = tx_make_subsidization_output( payer_utxo_inputs, payer_address, op_fee, dust_fee + tx_fee )
    
    # add our inputs and output
    subsidized_tx = tx_extend( blockstack_tx, payer_utxo_inputs, [subsidy_output] )
   
    # sign each of our inputs with our key, but use SIGHASH_ANYONECANPAY so the client can sign its inputs
    for i in xrange( 0, len(payer_utxo_inputs)):
        idx = i + len(tx_inputs)
        subsidized_tx = bitcoin.sign( subsidized_tx, idx, private_key_obj.to_hex(), hashcode=bitcoin.SIGHASH_ANYONECANPAY )
    
    return subsidized_tx
Exemplo n.º 22
0
def broadcast(name, register_addr, consensus_hash, private_key, blockchain_client, fee, testset=False):
    """
    Builds and broadcasts a preorder transaction.
    """
    
    script_pubkey = get_script_pubkey( private_key )
    
    nulldata = build( name, script_pubkey, register_addr, consensus_hash, testset=testset)
    
    # get inputs and from address
    private_key_obj, from_address, inputs = analyze_private_key(private_key, blockchain_client)
    
    # build custom outputs here
    outputs = make_outputs(nulldata, inputs, from_address, fee, format='hex')
    
    # serialize, sign, and broadcast the tx
    response = serialize_sign_and_broadcast(inputs, outputs, private_key_obj, blockchain_client)
    
    # response = {'success': True }
    response.update({'data': nulldata})
    
    return response
Exemplo n.º 23
0
def broadcast(namespace_id,
              register_addr,
              consensus_hash,
              private_key,
              blockchain_client,
              fee,
              testset=False):
    """
   Propagate a namespace.
   
   Arguments:
   namespace_id         human-readable (i.e. base-40) name of the namespace
   register_addr        the addr of the key that will reveal the namespace (mixed into the preorder to prevent name preimage attack races)
   private_key          the Bitcoin address that created this namespace, and can populate it.
   """

    script_pubkey = get_script_pubkey(private_key)
    nulldata = build(namespace_id,
                     script_pubkey,
                     register_addr,
                     consensus_hash,
                     testset=testset)

    # get inputs and from address
    private_key_obj, from_address, inputs = analyze_private_key(
        private_key, blockchain_client)

    # build custom outputs here
    outputs = make_outputs(nulldata, inputs, from_address, fee, format='hex')

    # serialize, sign, and broadcast the tx
    response = serialize_sign_and_broadcast(inputs, outputs, private_key_obj,
                                            blockchain_client)

    # response = {'success': True }
    response.update({'data': nulldata})

    return response
Exemplo n.º 24
0
def broadcast(name,
              destination_address,
              keepdata,
              consensus_hash,
              private_key,
              blockchain_client,
              blockchain_broadcaster=None,
              tx_only=False,
              user_public_key=None,
              testset=False):

    # sanity check
    pay_fee = True
    if user_public_key is not None:
        pay_fee = False
        tx_only = True

    if user_public_key is None and private_key is None:
        raise Exception("Missing both public and private key")

    if not tx_only and private_key is None:
        raise Exception("Need private key for broadcasting")

    if blockchain_broadcaster is None:
        blockchain_broadcaster = blockchain_client

    from_address = None
    inputs = None
    private_key_obj = None

    if user_public_key is not None:
        # subsidizing
        pubk = BitcoinPublicKey(user_public_key)

        from_address = pubk.address()
        inputs = get_unspents(from_address, blockchain_client)

    elif private_key is not None:
        # ordering directly
        pubk = BitcoinPrivateKey(private_key).public_key()
        public_key = pubk.to_hex()

        # get inputs and from address using private key
        private_key_obj, from_address, inputs = analyze_private_key(
            private_key, blockchain_client)

    nulldata = build(name, keepdata, consensus_hash, testset=testset)
    outputs = make_outputs(nulldata,
                           inputs,
                           destination_address,
                           from_address,
                           pay_fee=pay_fee,
                           format='hex')

    if tx_only:

        unsigned_tx = serialize_transaction(inputs, outputs)
        return {"unsigned_tx": unsigned_tx}

    else:
        # serialize, sign, and broadcast the tx
        response = serialize_sign_and_broadcast(inputs, outputs,
                                                private_key_obj,
                                                blockchain_broadcaster)
        response.update({'data': nulldata})
        return response