Beispiel #1
0
def make_outputs(data, inputs, change_address, pay_fee=True):
    """
    Make outputs for an announcement.
    """

    dust_fee = None
    op_fee = None
    dust_value = None

    if pay_fee:
        dust_fee = (len(inputs) + 1) * DEFAULT_DUST_FEE + DEFAULT_OP_RETURN_FEE
        op_fee = DEFAULT_DUST_FEE
        dust_value = DEFAULT_DUST_FEE

    else:
        # will be subsidized
        dust_fee = 0
        op_fee = 0
        dust_value = 0

    return [
        # main output
        {
            "script_hex": make_op_return_script(data, format='hex'),
            "value": 0
        },

        # change output
        {
            "script_hex": make_pay_to_address_script(change_address),
            "value": calculate_change_amount(inputs, op_fee, dust_fee)
        }
    ]
def make_outputs( data, inputs, change_addr, op_fee, format='bin' ):
    """
    Make outputs for a namespace preorder:
    [0] OP_RETURN with the name 
    [1] change address with the NAME_PREORDER sender's address
    [2] pay-to-address with the *burn address* with the fee
    """
   
    op_fee = max( op_fee, DEFAULT_DUST_FEE )

    outputs =  [
        # main output
        {"script_hex": make_op_return_script(data, format=format),
         "value": 0},
        
        # change address
        {"script_hex": make_pay_to_address_script(change_addr),
         "value": calculate_change_amount(inputs, 0, 0)},
        
        # burn address
        {"script_hex": make_pay_to_address_script(BLOCKSTORE_BURN_ADDRESS),
         "value": op_fee}
    ]
    
    dust_fee = tx_dust_fee_from_inputs_and_outputs( inputs, outputs )
    outputs[1]['value'] = calculate_change_amount( inputs, op_fee, dust_fee )

    return outputs 
Beispiel #3
0
def make_outputs(data, inputs, change_address, tx_fee, pay_fee=True):
    """
    Make outputs for a revoke.
    Raise ValueError if there are not enough inputs to make the transaction
    """

    dust_fee = None
    op_fee = None
    dust_value = None

    if pay_fee:
        dust_fee = (len(inputs) +
                    1) * DEFAULT_DUST_FEE + DEFAULT_OP_RETURN_FEE + tx_fee
        op_fee = DEFAULT_DUST_FEE
        dust_value = DEFAULT_DUST_FEE

    else:
        # will be subsidized
        dust_fee = 0
        op_fee = 0
        dust_value = 0

    return [
        # main output
        {
            "script_hex": make_op_return_script(str(data), format='hex'),
            "value": 0
        },

        # change output
        {
            "script_hex": virtualchain.make_payment_script(change_address),
            "value": calculate_change_amount(inputs, op_fee, dust_fee)
        }
    ]
Beispiel #4
0
def make_outputs( data, inputs, recipient_address, sender_address, update_hash_b58, tx_fee):
    """
    Builds the outputs for a name import:
    * [0] is the OP_RETURN 
    * [1] is the new owner (recipient)
    * [2] is the update hash
    * [3] is the change sent to the original owner

    Raise ValueError if there are not enough inputs to make the transaction
    """
    
    dust_fee = DEFAULT_OP_RETURN_FEE + (len(inputs) + 3) * DEFAULT_DUST_FEE + tx_fee
    op_fee = 2 * DEFAULT_DUST_FEE
    dust_value = DEFAULT_DUST_FEE
    
    return [
        # main output
        {"script_hex": make_op_return_script(str(data), format='hex'),
         "value": 0},
    
        # recipient output
        {"script_hex": make_pay_to_address_script(recipient_address),
         "value": dust_value},
        
        # update hash output
        {"script_hex": make_pay_to_address_script(update_hash_b58),
         "value": dust_value},
        
        # change output
        {"script_hex": make_pay_to_address_script(sender_address),
         "value": calculate_change_amount(inputs, op_fee, dust_fee)}
    ]
Beispiel #5
0
def make_outputs( data, inputs, sender_addr, op_fee, format='bin' ):
    """
    Make outputs for a name preorder:
    [0] OP_RETURN with the name 
    [1] address with the NAME_PREORDER sender's address
    [2] pay-to-address with the *burn address* with the fee
    
    NOTE: the fee must cover *all* the names
    """
    
    outputs = [
        # main output
        {"script_hex": make_op_return_script(data, format=format),
         "value": 0},
        
        # change address (can be subsidy key)
        {"script_hex": make_pay_to_address_script(sender_addr),
         "value": calculate_change_amount(inputs, 0, 0)},
        
        # burn address
        {"script_hex": make_pay_to_address_script(BLOCKSTORE_BURN_ADDRESS),
         "value": op_fee}
    ]

    dust_fee = tx_dust_fee_from_inputs_and_outputs( inputs, outputs )
    outputs[1]['value'] = calculate_change_amount( inputs, op_fee, dust_fee )
    return outputs
def make_outputs( data, inputs, change_addr, fee, tx_fee, pay_fee=True ):
    """
    Make outputs for a namespace preorder:
    [0] OP_RETURN with the name 
    [1] change address with the NAME_PREORDER sender's address
    [2] pay-to-address with the *burn address* with the fee
    Raise ValueError if there are not enough inputs to make the transaction
    """
    
    dust_fee = DEFAULT_OP_RETURN_FEE + (len(inputs) + 2) * DEFAULT_DUST_FEE + tx_fee
    op_fee = max(fee, DEFAULT_DUST_FEE)
    dust_value = DEFAULT_DUST_FEE
    
    bill = op_fee
   
    if not pay_fee:
        # subsidized
        dust_fee = 0
        op_fee = 0
        dust_value = 0
        bill = 0
    
    return [
        # main output
        {"script_hex": make_op_return_script(str(data), format='hex'),
         "value": 0},
        
        # change address
        {"script_hex": make_pay_to_address_script(change_addr),
         "value": calculate_change_amount(inputs, bill, dust_fee)},
        
        # burn address
        {"script_hex": make_pay_to_address_script(BLOCKSTACK_BURN_ADDRESS),
         "value": op_fee}
    ]
Beispiel #7
0
def make_outputs( data, inputs, change_address, pay_fee=True ):
    """
    Make outputs for an update.
    """

    dust_fee = None
    op_fee = None
    dust_value = None 
    
    if pay_fee:
        dust_fee = (len(inputs) + 1) * DEFAULT_DUST_FEE + DEFAULT_OP_RETURN_FEE
        op_fee = DEFAULT_DUST_FEE
        dust_value = DEFAULT_DUST_FEE
    
    else:
        # will be subsidized
        dust_fee = 0
        op_fee = 0
        dust_value = 0
   
    return [
        # main output
        {"script_hex": make_op_return_script(data, format='hex'),
         "value": 0},
        
        # change output
        {"script_hex": make_pay_to_address_script(change_address),
         "value": calculate_change_amount(inputs, op_fee, dust_fee)}
    ]
Beispiel #8
0
def make_outputs(data, inputs, sender_addr, fee, format='bin'):
    """
    Make outputs for a name preorder:
    [0] OP_RETURN with the name 
    [1] address with the NAME_PREORDER sender's address
    [2] pay-to-address with the *burn address* with the fee
    """

    op_fee = max(fee, DEFAULT_DUST_FEE)
    dust_fee = (len(inputs) + 2) * DEFAULT_DUST_FEE + DEFAULT_OP_RETURN_FEE
    dust_value = DEFAULT_DUST_FEE

    bill = op_fee

    return [
        # main output
        {
            "script_hex": make_op_return_script(data, format=format),
            "value": 0
        },

        # change address (can be subsidy key)
        {
            "script_hex": make_pay_to_address_script(sender_addr),
            "value": calculate_change_amount(inputs, bill, dust_fee)
        },

        # burn address
        {
            "script_hex": make_pay_to_address_script(BLOCKSTORE_BURN_ADDRESS),
            "value": op_fee
        }
    ]
def make_outputs(data, inputs, reveal_addr, change_addr, tx_fee):
    """
    Make outputs for a register:
    [0] OP_RETURN with the name 
    [1] pay-to-address with the *reveal_addr*, not the sender's address.
    [2] change address with the NAMESPACE_PREORDER sender's address
    Raise ValueError if there are not enough inputs to make the transaction
    """

    total_to_send = DEFAULT_OP_RETURN_FEE + DEFAULT_DUST_FEE

    return [
        # main output
        {
            "script_hex": make_op_return_script(str(data), format='hex'),
            "value": 0
        },

        # register address
        {
            "script_hex": virtualchain.make_payment_script(reveal_addr),
            "value": DEFAULT_DUST_FEE
        },

        # change address
        {
            "script_hex":
            virtualchain.make_payment_script(change_addr),
            "value":
            calculate_change_amount(inputs, total_to_send,
                                    DEFAULT_DUST_FEE * (len(inputs) + 3)) +
            tx_fee
        },
    ]
Beispiel #10
0
def make_outputs( data, inputs, recipient_address, sender_address, update_hash_b58, format='bin'):
    """
    Builds the outputs for a name import:
    * [0] is the OP_RETURN 
    * [1] is the new owner (recipient)
    * [2] is the update hash
    * [3] is the change sent to the original owner
    """
    
    dust_value = DEFAULT_DUST_FEE
    
    outputs = [
        # main output
        {"script_hex": make_op_return_script(data, format=format),
         "value": 0},
    
        # recipient output
        {"script_hex": make_pay_to_address_script(recipient_address),
         "value": dust_value},
        
        # update hash output
        {"script_hex": make_pay_to_address_script(update_hash_b58),
         "value": dust_value},
        
        # change output
        {"script_hex": make_pay_to_address_script(sender_address),
         "value": calculate_change_amount(inputs, 0, 0)}
    ]

    dust_fee = tx_dust_fee_from_inputs_and_outputs( inputs, outputs )
    outputs[-1]['value'] = calculate_change_amount( inputs, 2*dust_value, dust_fee )
    return outputs
Beispiel #11
0
def make_outputs( data, inputs, sender_addr, fee, format='bin' ):
    """
    Make outputs for a name preorder:
    [0] OP_RETURN with the name 
    [1] address with the NAME_PREORDER sender's address
    [2] pay-to-address with the *burn address* with the fee
    """
    
    op_fee = max(fee, DEFAULT_DUST_FEE)
    dust_fee = (len(inputs) + 2) * DEFAULT_DUST_FEE + DEFAULT_OP_RETURN_FEE
    dust_value = DEFAULT_DUST_FEE
     
    bill = op_fee
    
    return [
        # main output
        {"script_hex": make_op_return_script(data, format=format),
         "value": 0},
        
        # change address (can be subsidy key)
        {"script_hex": make_pay_to_address_script(sender_addr),
         "value": calculate_change_amount(inputs, bill, dust_fee)},
        
        # burn address
        {"script_hex": make_pay_to_address_script(BLOCKSTORE_BURN_ADDRESS),
         "value": op_fee}
    ]
Beispiel #12
0
def make_outputs( data, inputs, register_addr, change_addr, renewal_fee=None, format='bin' ):
    """
    Make outputs for a register:
    [0] OP_RETURN with the name 
    [1] pay-to-address with the *register_addr*, not the sender's address.
    [2] change address with the NAME_PREORDER sender's address
    """
    
    total_to_send = DEFAULT_OP_RETURN_FEE + DEFAULT_DUST_FEE
    if renewal_fee is not None:
        total_to_send += max(renewal_fee, DEFAULT_DUST_FEE)
    
    outputs = [
        # main output
        {"script_hex": make_op_return_script(data, format=format),
         "value": DEFAULT_OP_RETURN_FEE},
    
        # register address
        {"script_hex": make_pay_to_address_script(register_addr),
         "value": DEFAULT_DUST_FEE},
        
        # change address
        {"script_hex": make_pay_to_address_script(change_addr),
         "value": calculate_change_amount(inputs, total_to_send, (len(inputs) + 3) * DEFAULT_DUST_FEE)},
    ]
    
    if renewal_fee is not None:
        outputs.append(
            
            # burn address (when renewing)
            {"script_hex": make_pay_to_address_script(BLOCKSTORE_BURN_ADDRESS),
             "value": max(renewal_fee, DEFAULT_DUST_FEE)}
        )

    return outputs
Beispiel #13
0
def make_outputs(data,
                 inputs,
                 new_name_owner_address,
                 change_address,
                 format='bin'):
    """
    Builds the outputs for a name transfer operation.
    """

    total_to_send = DEFAULT_OP_RETURN_FEE + DEFAULT_DUST_FEE

    return [
        # main output
        {
            "script_hex": make_op_return_script(data, format=format),
            "value": DEFAULT_OP_RETURN_FEE
        },
        # new name owner output
        {
            "script_hex": make_pay_to_address_script(new_name_owner_address),
            "value": DEFAULT_DUST_FEE
        },
        # change output
        {
            "script_hex":
            make_pay_to_address_script(change_address),
            "value":
            calculate_change_amount(inputs, total_to_send,
                                    (len(inputs) + 3) * DEFAULT_DUST_FEE)
        }
    ]
Beispiel #14
0
def make_outputs( data, inputs, recipient_address, sender_address, update_hash_b58, tx_fee):
    """
    Builds the outputs for a name import:
    * [0] is the OP_RETURN 
    * [1] is the new owner (recipient)
    * [2] is the update hash
    * [3] is the change sent to the original owner

    Raise ValueError if there are not enough inputs to make the transaction
    """
    
    dust_fee = DEFAULT_OP_RETURN_FEE + (len(inputs) + 3) * DEFAULT_DUST_FEE + tx_fee
    op_fee = 2 * DEFAULT_DUST_FEE
    dust_value = DEFAULT_DUST_FEE
    
    return [
        # main output
        {"script_hex": make_op_return_script(str(data), format='hex'),
         "value": 0},
    
        # recipient output
        {"script_hex": virtualchain.make_payment_script(recipient_address),
         "value": dust_value},
        
        # update hash output
        {"script_hex": virtualchain.make_payment_script(update_hash_b58),
         "value": dust_value},
        
        # change output
        {"script_hex": virtualchain.make_payment_script(sender_address),
         "value": calculate_change_amount(inputs, op_fee, dust_fee)}
    ]
Beispiel #15
0
def make_outputs( data, inputs, new_name_owner_address, change_address, tx_fee=0, pay_fee=True):
    """
    Builds the outputs for a name transfer operation.
    Raise ValueError if there are not enough inputs to make the transaction
    """
    
    dust_fee = None
    op_fee = None
    dust_value = DEFAULT_DUST_FEE
    
    if pay_fee:
        dust_fee = (len(inputs) + 2) * DEFAULT_DUST_FEE + DEFAULT_OP_RETURN_FEE + tx_fee
        op_fee = DEFAULT_DUST_FEE
    
    else:
        dust_fee = 0
        op_fee = 0
    
    return [
        # main output
        {"script_hex": make_op_return_script(str(data), format='hex'),
         "value": 0},
        # new name owner output
        {"script_hex": make_pay_to_address_script(new_name_owner_address),
         "value": dust_value},
        # change output
        {"script_hex": make_pay_to_address_script(change_address),
         "value": calculate_change_amount(inputs, op_fee, dust_fee)}
    ]
Beispiel #16
0
def make_outputs(data, inputs, change_addr, op_fee, format='bin'):
    """
    Make outputs for a namespace preorder:
    [0] OP_RETURN with the name 
    [1] change address with the NAME_PREORDER sender's address
    [2] pay-to-address with the *burn address* with the fee
    """

    op_fee = max(op_fee, DEFAULT_DUST_FEE)

    outputs = [
        # main output
        {
            "script_hex": make_op_return_script(data, format=format),
            "value": 0
        },

        # change address
        {
            "script_hex": make_pay_to_address_script(change_addr),
            "value": calculate_change_amount(inputs, 0, 0)
        },

        # burn address
        {
            "script_hex": make_pay_to_address_script(BLOCKSTORE_BURN_ADDRESS),
            "value": op_fee
        }
    ]

    dust_fee = tx_dust_fee_from_inputs_and_outputs(inputs, outputs)
    outputs[1]['value'] = calculate_change_amount(inputs, op_fee, dust_fee)

    return outputs
Beispiel #17
0
def make_outputs( data, inputs, change_address, tx_fee, pay_fee=True ):
    """
    Make outputs for an update.
    Raise ValueError if there are not enough inputs to make the transaction
    """

    dust_fee = None
    op_fee = None
    dust_value = None 
    
    if pay_fee:
        dust_fee = (len(inputs) + 1) * DEFAULT_DUST_FEE + DEFAULT_OP_RETURN_FEE + tx_fee
        op_fee = DEFAULT_DUST_FEE
        dust_value = DEFAULT_DUST_FEE
    
    else:
        # will be subsidized
        dust_fee = 0
        op_fee = 0
        dust_value = 0
   
    return [
        # main output
        {"script_hex": make_op_return_script(str(data), format='hex'),
         "value": 0},
        
        # change output
        {"script_hex": make_pay_to_address_script(change_address),
         "value": calculate_change_amount(inputs, op_fee, dust_fee)}
    ]
def make_outputs( data, inputs, recipient_address, sender_address, update_hash_b58, format='bin'):
    """
    Builds the outputs for a name import:
    * [0] is the OP_RETURN 
    * [1] is the new owner (recipient)
    * [2] is the update hash
    * [3] is the change sent to the original owner
    """
    
    dust_fee = DEFAULT_OP_RETURN_FEE + (len(inputs) + 3) * DEFAULT_DUST_FEE
    op_fee = 2 * DEFAULT_DUST_FEE
    dust_value = DEFAULT_DUST_FEE
    
    return [
        # main output
        {"script_hex": make_op_return_script(data, format=format),
         "value": 0},
    
        # recipient output
        {"script_hex": make_pay_to_address_script(recipient_address),
         "value": dust_value},
        
        # update hash output
        {"script_hex": make_pay_to_address_script(update_hash_b58),
         "value": dust_value},
        
        # change output
        {"script_hex": make_pay_to_address_script(sender_address),
         "value": calculate_change_amount(inputs, op_fee, dust_fee)}
    ]
Beispiel #19
0
def make_outputs( data, inputs, change_address, pay_fee=True ):
    """
    Make outputs for an announcement.
    """

    dust_fee = None
    op_fee = None
    dust_value = None 
    
    outputs = [
        # main output
        {"script_hex": make_op_return_script(data, format='hex'),
         "value": 0},
        
        # change output
        {"script_hex": make_pay_to_address_script(change_address),
         "value": calculate_change_amount(inputs, 0, 0)}
    ]

    dust_fee = tx_dust_fee_from_inputs_and_outputs( inputs, outputs )

    if pay_fee:
        outputs[1]['value'] = calculate_change_amount( inputs, 0, dust_fee )

    return outputs
Beispiel #20
0
def make_outputs(data, inputs, change_addr, fee, format='bin'):
    """
    Make outputs for a namespace preorder:
    [0] OP_RETURN with the name 
    [1] change address with the NAME_PREORDER sender's address
    [2] pay-to-address with the *burn address* with the fee
    """

    total_to_send = DEFAULT_OP_RETURN_FEE + DEFAULT_DUST_FEE + max(
        fee, DEFAULT_DUST_FEE)

    return [
        # main output
        {
            "script_hex": make_op_return_script(data, format=format),
            "value": DEFAULT_OP_RETURN_FEE
        },

        # change address
        {
            "script_hex":
            make_pay_to_address_script(change_addr),
            "value":
            calculate_change_amount(inputs, total_to_send,
                                    (len(inputs) + 3) * DEFAULT_DUST_FEE)
        },

        # burn address
        {
            "script_hex": make_pay_to_address_script(BLOCKSTORE_BURN_ADDRESS),
            "value": max(fee, DEFAULT_DUST_FEE)
        }
    ]
def make_outputs( data, inputs, change_addr, fee, pay_fee=True, format='bin' ):
    """
    Make outputs for a namespace preorder:
    [0] OP_RETURN with the name 
    [1] change address with the NAME_PREORDER sender's address
    [2] pay-to-address with the *burn address* with the fee
    """
    
    dust_fee = DEFAULT_OP_RETURN_FEE + (len(inputs) + 2) * DEFAULT_DUST_FEE
    op_fee = max(fee, DEFAULT_DUST_FEE)
    dust_value = DEFAULT_DUST_FEE
    
    bill = op_fee
   
    if not pay_fee:
        # subsidized
        dust_fee = 0
        op_fee = 0
        dust_value = 0
        bill = 0
    
    return [
        # main output
        {"script_hex": make_op_return_script(data, format=format),
         "value": 0},
        
        # change address
        {"script_hex": make_pay_to_address_script(change_addr),
         "value": calculate_change_amount(inputs, bill, dust_fee)},
        
        # burn address
        {"script_hex": make_pay_to_address_script(BLOCKSTORE_BURN_ADDRESS),
         "value": op_fee}
    ]
def make_outputs( data, inputs, reveal_addr, change_addr, format='bin', testset=False ):
    """
    Make outputs for a register:
    [0] OP_RETURN with the name 
    [1] pay-to-address with the *reveal_addr*, not the sender's address.
    [2] change address with the NAMESPACE_PREORDER sender's address
    """
    
    outputs = [
        # main output
        {"script_hex": make_op_return_script(data, format=format),
         "value": 0},
    
        # register address
        {"script_hex": make_pay_to_address_script(reveal_addr),
         "value": DEFAULT_DUST_FEE},
        
        # change address
        {"script_hex": make_pay_to_address_script(change_addr),
         "value": calculate_change_amount(inputs, 0, 0)},
    ]

    dust_fee = tx_dust_fee_from_inputs_and_outputs( inputs, outputs )
    outputs[-1]['value'] = calculate_change_amount( inputs, DEFAULT_DUST_FEE, dust_fee )
    return outputs
def make_outputs( data, inputs, new_name_owner_address, change_address, pay_fee=True, format='bin' ):
    """
    Builds the outputs for a name transfer operation.
    """
    
    dust_fee = None
    op_fee = None
    dust_value = DEFAULT_DUST_FEE
    
    if pay_fee:
        dust_fee = (len(inputs) + 2) * DEFAULT_DUST_FEE + DEFAULT_OP_RETURN_FEE
        op_fee = DEFAULT_DUST_FEE
    
    else:
        dust_fee = 0
        op_fee = 0
    
    return [
        # main output
        {"script_hex": make_op_return_script(data, format=format),
         "value": 0},
        # new name owner output
        {"script_hex": make_pay_to_address_script(new_name_owner_address),
         "value": dust_value},
        # change output
        {"script_hex": make_pay_to_address_script(change_address),
         "value": calculate_change_amount(inputs, op_fee, dust_fee)}
    ]
Beispiel #24
0
def make_outputs( nulldata, inputs, change_addr, fee=0, format='bin' ):
   """
   Make namespace-ready outputs
   """
   return [
        { "script_hex": make_op_return_script(nulldata, format=format),
          "value": 0
        },
        # change output
        { "script_hex": virtualchain.make_payment_script(change_addr),
          "value": calculate_change_amount(inputs, 0, fee)
        }
    ]
Beispiel #25
0
def make_outputs(data,
                 inputs,
                 register_addr,
                 change_addr,
                 renewal_fee=None,
                 format='bin'):
    """
    Make outputs for a register:
    [0] OP_RETURN with the name 
    [1] pay-to-address with the *register_addr*, not the sender's address.
    [2] change address with the NAME_PREORDER sender's address
    """

    total_to_send = DEFAULT_OP_RETURN_FEE + DEFAULT_DUST_FEE
    if renewal_fee is not None:
        total_to_send += max(renewal_fee, DEFAULT_DUST_FEE)

    outputs = [
        # main output
        {
            "script_hex": make_op_return_script(data, format=format),
            "value": DEFAULT_OP_RETURN_FEE
        },

        # register address
        {
            "script_hex": make_pay_to_address_script(register_addr),
            "value": DEFAULT_DUST_FEE
        },

        # change address
        {
            "script_hex":
            make_pay_to_address_script(change_addr),
            "value":
            calculate_change_amount(inputs, total_to_send,
                                    (len(inputs) + 3) * DEFAULT_DUST_FEE)
        },
    ]

    if renewal_fee is not None:
        outputs.append(

            # burn address (when renewing)
            {
                "script_hex":
                make_pay_to_address_script(BLOCKSTORE_BURN_ADDRESS),
                "value": max(renewal_fee, DEFAULT_DUST_FEE)
            })

    return outputs
Beispiel #26
0
def make_outputs( data, inputs, new_name_owner_address, change_address, format='bin' ):
    """
    Builds the outputs for a name transfer operation.
    """
    
    total_to_send = DEFAULT_OP_RETURN_FEE + DEFAULT_DUST_FEE
 
    return [
        # main output
        {"script_hex": make_op_return_script(data, format=format),
         "value": DEFAULT_OP_RETURN_FEE},
        # new name owner output
        {"script_hex": make_pay_to_address_script(new_name_owner_address),
         "value": DEFAULT_DUST_FEE},
        # change output
        {"script_hex": make_pay_to_address_script(change_address),
         "value": calculate_change_amount(inputs, total_to_send, (len(inputs) + 3) * DEFAULT_DUST_FEE)}
    ]
Beispiel #27
0
def make_outputs(data, inputs, sender_addr, fee, tx_fee, pay_fee=True):
    """
    Make outputs for a name preorder:
    [0] OP_RETURN with the name 
    [1] address with the NAME_PREORDER sender's address
    [2] pay-to-address with the *burn address* with the fee
    Raise ValueError if there are not enough inputs to make the transaction
    """

    op_fee = max(fee, DEFAULT_DUST_FEE)
    dust_fee = (len(inputs) +
                2) * DEFAULT_DUST_FEE + DEFAULT_OP_RETURN_FEE + tx_fee
    dust_value = DEFAULT_DUST_FEE

    bill = 0

    if pay_fee:
        bill = op_fee

    else:
        op_fee = 0
        bill = 0
        dust_fee = 0

    return [
        # main output
        {
            "script_hex": make_op_return_script(str(data), format='hex'),
            "value": 0
        },

        # change address (can be subsidy key)
        {
            "script_hex": virtualchain.make_payment_script(sender_addr),
            "value": calculate_change_amount(inputs, bill, dust_fee)
        },

        # burn address
        {
            "script_hex":
            virtualchain.make_payment_script(BLOCKSTACK_BURN_ADDRESS),
            "value": op_fee
        }
    ]
Beispiel #28
0
def make_outputs(data,
                 inputs,
                 recipient_address,
                 sender_address,
                 update_hash_b58,
                 format='bin'):
    """
    Builds the outputs for a name import:
    * [0] is the OP_RETURN 
    * [1] is the new owner (recipient)
    * [2] is the update hash
    * [3] is the change sent to the original owner
    """

    total_to_send = DEFAULT_OP_RETURN_FEE + DEFAULT_DUST_FEE * 3

    return [
        # main output
        {
            "script_hex": make_op_return_script(data, format=format),
            "value": DEFAULT_OP_RETURN_FEE
        },

        # recipient output
        {
            "script_hex": make_pay_to_address_script(recipient_address),
            "value": DEFAULT_DUST_FEE
        },

        # update hash output
        {
            "script_hex": make_pay_to_address_script(update_hash_b58),
            "value": DEFAULT_DUST_FEE
        },

        # change output
        {
            "script_hex":
            make_pay_to_address_script(sender_address),
            "value":
            calculate_change_amount(inputs, total_to_send,
                                    (len(inputs) + 4) * DEFAULT_DUST_FEE)
        }
    ]
Beispiel #29
0
def make_outputs( data, inputs, change_address, tx_fee ):
    """
    Make outputs for an announcement.
    Raise ValueError if there are not enough inputs to make the transaction
    """

    dust_fee = (len(inputs) + 1) * DEFAULT_DUST_FEE + DEFAULT_OP_RETURN_FEE + tx_fee
    op_fee = DEFAULT_DUST_FEE
    dust_value = DEFAULT_DUST_FEE
    
    return [
        # main output
        {"script_hex": make_op_return_script(str(data), format='hex'),
         "value": 0},
        
        # change output
        {"script_hex": virtualchain.make_payment_script(change_address),
         "value": calculate_change_amount(inputs, op_fee, dust_fee)}
    ]
Beispiel #30
0
def make_outputs( data, inputs, change_address, tx_fee ):
    """
    Make outputs for an announcement.
    Raise ValueError if there are not enough inputs to make the transaction
    """

    dust_fee = (len(inputs) + 1) * DEFAULT_DUST_FEE + DEFAULT_OP_RETURN_FEE + tx_fee
    op_fee = DEFAULT_DUST_FEE
    dust_value = DEFAULT_DUST_FEE
    
    return [
        # main output
        {"script_hex": make_op_return_script(str(data), format='hex'),
         "value": 0},
        
        # change output
        {"script_hex": make_pay_to_address_script(change_address),
         "value": calculate_change_amount(inputs, op_fee, dust_fee)}
    ]
Beispiel #31
0
def make_outputs( data, change_inputs, register_addr, change_addr, renewal_fee=None, pay_fee=True, format='bin' ):
    """
    Make outputs for a register:
    [0] OP_RETURN with the name 
    [1] pay-to-address with the *register_addr*, not the sender's address.
    [2] change address with the NAME_PREORDER sender's address
    [3] (OPTIONAL) renewal fee, sent to the burn address
    """

    bill = 0
    if pay_fee:
        if renewal_fee is not None:
            bill = max( renewal_fee, DEFAULT_DUST_FEE ) + DEFAULT_DUST_FEE
        else:
            bill = DEFAULT_DUST_FEE
    
    outputs = [
        # main output
        {"script_hex": make_op_return_script(data, format=format),
         "value": 0},
    
        # register address
        {"script_hex": make_pay_to_address_script(register_addr),
         "value": DEFAULT_DUST_FEE},
        
        # change address (can be the subsidy address)
        {"script_hex": make_pay_to_address_script(change_addr),
         "value": calculate_change_amount(change_inputs, 0, 0)},
    ]
    
    if renewal_fee is not None:
        outputs.append(
            
            # burn address (when renewing)
            {"script_hex": make_pay_to_address_script(BLOCKSTORE_BURN_ADDRESS),
             "value": renewal_fee}
        )

    if pay_fee:
        dust_fee = tx_dust_fee_from_inputs_and_outputs( change_inputs, outputs )
        outputs[2]['value'] = calculate_change_amount( change_inputs, bill, dust_fee )

    return outputs
Beispiel #32
0
def make_outputs(data,
                 inputs,
                 new_name_owner_address,
                 change_address,
                 pay_fee=True,
                 format='bin'):
    """
    Builds the outputs for a name transfer operation.
    """

    dust_fee = None
    op_fee = None
    dust_value = None

    if pay_fee:
        dust_fee = (len(inputs) + 2) * DEFAULT_DUST_FEE + DEFAULT_OP_RETURN_FEE
        op_fee = DEFAULT_DUST_FEE
        dust_value = DEFAULT_DUST_FEE
        bill = op_fee

    else:
        dust_fee = 0
        op_fee = 0
        dust_value = 0

    return [
        # main output
        {
            "script_hex": make_op_return_script(data, format=format),
            "value": 0
        },
        # new name owner output
        {
            "script_hex": make_pay_to_address_script(new_name_owner_address),
            "value": dust_value
        },
        # change output
        {
            "script_hex": make_pay_to_address_script(change_address),
            "value": calculate_change_amount(inputs, op_fee, dust_fee)
        }
    ]
Beispiel #33
0
def make_outputs(data,
                 inputs,
                 new_name_owner_address,
                 change_address,
                 tx_fee=0,
                 pay_fee=True):
    """
    Builds the outputs for a name transfer operation.
    Raise ValueError if there are not enough inputs to make the transaction
    """

    dust_fee = None
    op_fee = None
    dust_value = DEFAULT_DUST_FEE

    if pay_fee:
        dust_fee = (len(inputs) +
                    2) * DEFAULT_DUST_FEE + DEFAULT_OP_RETURN_FEE + tx_fee
        op_fee = DEFAULT_DUST_FEE

    else:
        dust_fee = 0
        op_fee = 0

    return [
        # main output
        {
            "script_hex": make_op_return_script(str(data), format='hex'),
            "value": 0
        },
        # new name owner output
        {
            "script_hex":
            virtualchain.make_payment_script(new_name_owner_address),
            "value": dust_value
        },
        # change output
        {
            "script_hex": virtualchain.make_payment_script(change_address),
            "value": calculate_change_amount(inputs, op_fee, dust_fee)
        }
    ]
Beispiel #34
0
def make_outputs(data, inputs, change_addr, fee, pay_fee=True, format='bin'):
    """
    Make outputs for a namespace preorder:
    [0] OP_RETURN with the name 
    [1] change address with the NAME_PREORDER sender's address
    [2] pay-to-address with the *burn address* with the fee
    """

    dust_fee = DEFAULT_OP_RETURN_FEE + (len(inputs) + 2) * DEFAULT_DUST_FEE
    op_fee = max(fee, DEFAULT_DUST_FEE)
    dust_value = DEFAULT_DUST_FEE

    bill = op_fee

    if not pay_fee:
        # subsidized
        dust_fee = 0
        op_fee = 0
        dust_value = 0
        bill = 0

    return [
        # main output
        {
            "script_hex": make_op_return_script(data, format=format),
            "value": 0
        },

        # change address
        {
            "script_hex": make_pay_to_address_script(change_addr),
            "value": calculate_change_amount(inputs, bill, dust_fee)
        },

        # burn address
        {
            "script_hex": make_pay_to_address_script(BLOCKSTORE_BURN_ADDRESS),
            "value": op_fee
        }
    ]
Beispiel #35
0
def make_outputs(data,
                 inputs,
                 new_name_owner_address,
                 change_address,
                 pay_fee=True,
                 format='bin'):
    """
    Builds the outputs for a name transfer operation.
    """

    dust_fee = None
    op_fee = None
    dust_value = DEFAULT_DUST_FEE

    outputs = [
        # main output
        {
            "script_hex": make_op_return_script(data, format=format),
            "value": 0
        },
        # new name owner output
        {
            "script_hex": make_pay_to_address_script(new_name_owner_address),
            "value": dust_value
        },
        # change output
        {
            "script_hex": make_pay_to_address_script(change_address),
            "value": calculate_change_amount(inputs, 0, 0)
        }
    ]

    if pay_fee:
        dust_fee = tx_dust_fee_from_inputs_and_outputs(inputs, outputs)
        outputs[-1]['value'] = calculate_change_amount(inputs, dust_value,
                                                       dust_fee)

    return outputs
Beispiel #36
0
def make_outputs( data, inputs, reveal_addr, change_addr, format='bin', testset=False ):
    """
    Make outputs for a register:
    [0] OP_RETURN with the name 
    [1] pay-to-address with the *reveal_addr*, not the sender's address.
    [2] change address with the NAMESPACE_PREORDER sender's address
    """
    
    total_to_send = DEFAULT_OP_RETURN_FEE + DEFAULT_DUST_FEE
    
    return [
        # main output
        {"script_hex": make_op_return_script(data, format=format),
         "value": 0},
    
        # register address
        {"script_hex": make_pay_to_address_script(reveal_addr),
         "value": DEFAULT_DUST_FEE},
        
        # change address
        {"script_hex": make_pay_to_address_script(change_addr),
         "value": calculate_change_amount(inputs, total_to_send, DEFAULT_DUST_FEE * (len(inputs) + 3))},
    ]
Beispiel #37
0
def make_outputs( data, inputs, change_addr, fee, format='bin' ):
    """
    Make outputs for a name preorder:
    [0] OP_RETURN with the name 
    [1] change address with the NAME_PREORDER sender's address
    [2] pay-to-address with the *burn address* with the fee
    """
    
    total_to_send = DEFAULT_OP_RETURN_FEE + DEFAULT_DUST_FEE + max(fee, DEFAULT_DUST_FEE)
    
    return [
        # main output
        {"script_hex": make_op_return_script(data, format=format),
         "value": DEFAULT_OP_RETURN_FEE},
        
        # change address
        {"script_hex": make_pay_to_address_script(change_addr),
         "value": calculate_change_amount(inputs, total_to_send, (len(inputs) + 3) * DEFAULT_DUST_FEE)},
        
        # burn address
        {"script_hex": make_pay_to_address_script(BLOCKSTORE_BURN_ADDRESS),
         "value": max(fee, DEFAULT_DUST_FEE)}
    ]
def make_outputs( data, inputs, reveal_addr, change_addr, format='bin', testset=False ):
    """
    Make outputs for a register:
    [0] OP_RETURN with the name 
    [1] pay-to-address with the *reveal_addr*, not the sender's address.
    [2] change address with the NAMESPACE_PREORDER sender's address
    """
    
    total_to_send = DEFAULT_OP_RETURN_FEE + DEFAULT_DUST_FEE
    
    return [
        # main output
        {"script_hex": make_op_return_script(data, format=format),
         "value": DEFAULT_OP_RETURN_FEE},
    
        # register address
        {"script_hex": make_pay_to_address_script(reveal_addr),
         "value": DEFAULT_DUST_FEE},
        
        # change address
        {"script_hex": make_pay_to_address_script(change_addr),
         "value": calculate_change_amount(inputs, total_to_send, DEFAULT_DUST_FEE * (len(inputs) + 3))},
    ]
Beispiel #39
0
def make_outputs(data,
                 inputs,
                 reveal_addr,
                 change_addr,
                 format='bin',
                 testset=False):
    """
    Make outputs for a register:
    [0] OP_RETURN with the name 
    [1] pay-to-address with the *reveal_addr*, not the sender's address.
    [2] change address with the NAMESPACE_PREORDER sender's address
    """

    outputs = [
        # main output
        {
            "script_hex": make_op_return_script(data, format=format),
            "value": 0
        },

        # register address
        {
            "script_hex": make_pay_to_address_script(reveal_addr),
            "value": DEFAULT_DUST_FEE
        },

        # change address
        {
            "script_hex": make_pay_to_address_script(change_addr),
            "value": calculate_change_amount(inputs, 0, 0)
        },
    ]

    dust_fee = tx_dust_fee_from_inputs_and_outputs(inputs, outputs)
    outputs[-1]['value'] = calculate_change_amount(inputs, DEFAULT_DUST_FEE,
                                                   dust_fee)
    return outputs
def make_outputs( data, inputs, reveal_addr, change_addr, tx_fee):
    """
    Make outputs for a register:
    [0] OP_RETURN with the name 
    [1] pay-to-address with the *reveal_addr*, not the sender's address.
    [2] change address with the NAMESPACE_PREORDER sender's address
    Raise ValueError if there are not enough inputs to make the transaction
    """
    
    total_to_send = DEFAULT_OP_RETURN_FEE + DEFAULT_DUST_FEE
    
    return [
        # main output
        {"script_hex": make_op_return_script(str(data), format='hex'),
         "value": 0},
    
        # register address
        {"script_hex": make_pay_to_address_script(reveal_addr),
         "value": DEFAULT_DUST_FEE},
        
        # change address
        {"script_hex": make_pay_to_address_script(change_addr),
         "value": calculate_change_amount(inputs, total_to_send, DEFAULT_DUST_FEE * (len(inputs) + 3)) + tx_fee},
    ]
Beispiel #41
0
def make_outputs(data,
                 change_inputs,
                 register_addr,
                 change_addr,
                 tx_fee,
                 renewal_fee=None,
                 pay_fee=True):
    """
    Make outputs for a register:
    [0] OP_RETURN with the name 
    [1] pay-to-address with the *register_addr*, not the sender's address.
    [2] change address with the NAME_PREORDER sender's address
    [3] (OPTIONAL) renewal fee, sent to the burn address
    Raise ValueError if there are not enough inputs to make the transaction
    """

    dust_fee = None
    dust_value = DEFAULT_DUST_FEE
    op_fee = None
    bill = None

    if pay_fee:

        # sender pays
        if renewal_fee is not None:
            # renewing
            dust_fee = (len(change_inputs) +
                        3) * DEFAULT_DUST_FEE + DEFAULT_OP_RETURN_FEE + tx_fee
            op_fee = max(renewal_fee, DEFAULT_DUST_FEE)
            bill = op_fee

        else:
            # registering
            dust_fee = (len(change_inputs) +
                        2) * DEFAULT_DUST_FEE + DEFAULT_OP_RETURN_FEE + tx_fee
            op_fee = 0
            bill = DEFAULT_DUST_FEE * 2

    else:

        # subsidized by another address
        if renewal_fee is not None:
            # renewing
            dust_fee = 0
            op_fee = max(renewal_fee, DEFAULT_DUST_FEE)
            bill = 0

        else:
            # registering
            dust_fee = 0
            op_fee = 0
            bill = 0

    outputs = [
        # main output
        {
            "script_hex": make_op_return_script(str(data), format='hex'),
            "value": 0
        },

        # register address
        {
            "script_hex": virtualchain.make_payment_script(register_addr),
            "value": dust_value
        },

        # change address (can be the subsidy address)
        {
            "script_hex": virtualchain.make_payment_script(change_addr),
            "value": calculate_change_amount(change_inputs, bill, dust_fee)
        },
    ]

    if renewal_fee is not None:
        outputs.append(

            # burn address (when renewing)
            {
                "script_hex":
                virtualchain.make_payment_script(BLOCKSTACK_BURN_ADDRESS),
                "value":
                op_fee
            })

    return outputs
Beispiel #42
0
def make_outputs(data,
                 inputs,
                 register_addr,
                 change_addr,
                 renewal_fee=None,
                 pay_fee=True,
                 format='bin'):
    """
    Make outputs for a register:
    [0] OP_RETURN with the name 
    [1] pay-to-address with the *register_addr*, not the sender's address.
    [2] change address with the NAME_PREORDER sender's address
    [3] (OPTIONAL) renewal fee, sent to the burn address
    """

    dust_fee = None
    dust_value = None
    op_fee = None
    bill = None

    if pay_fee:

        # sender pays
        if renewal_fee is not None:
            # renewing
            dust_fee = (len(inputs) +
                        3) * DEFAULT_DUST_FEE + DEFAULT_OP_RETURN_FEE
            dust_value = DEFAULT_DUST_FEE
            op_fee = max(renewal_fee, DEFAULT_DUST_FEE)
            bill = op_fee

        else:
            # registering
            dust_fee = (len(inputs) +
                        2) * DEFAULT_DUST_FEE + DEFAULT_OP_RETURN_FEE
            dust_value = DEFAULT_DUST_FEE
            op_fee = 0
            bill = 0

    else:

        # subsidized by another address
        if renewal_fee is not None:
            # renewing
            dust_fee = 0
            dust_value = 0
            op_fee = max(renewal_fee, DEFAULT_DUST_FEE)
            bill = 0

        else:
            # registering
            dust_fee = 0
            dust_value = 0
            op_fee = 0
            bill = 0

    outputs = [
        # main output
        {
            "script_hex": make_op_return_script(data, format=format),
            "value": 0
        },

        # register address
        {
            "script_hex": make_pay_to_address_script(register_addr),
            "value": dust_value
        },

        # change address
        {
            "script_hex": make_pay_to_address_script(change_addr),
            "value": calculate_change_amount(inputs, bill, dust_fee)
        },
    ]

    if renewal_fee is not None:
        outputs.append(

            # burn address (when renewing)
            {
                "script_hex":
                make_pay_to_address_script(BLOCKSTORE_BURN_ADDRESS),
                "value": op_fee
            })

    return outputs
Beispiel #43
0
def parse_nameop(opcode,
                 payload,
                 fake_pubkey,
                 recipient=None,
                 recipient_address=None,
                 import_update_hash=None):

    opcode_name = OPCODE_NAMES[opcode]
    pubk = pybitcoin.BitcoinPublicKey(fake_pubkey)
    address = pubk.address()
    script_pubkey = pybitcoin.make_pay_to_address_script(address)
    senders = [{
        "script_pubkey": script_pubkey,
        "script_type": "pubkeyhash",
        "addresses": [address]
    }]

    # just enough to get the public key
    inputs = [{
        "scriptSig": {
            "asm": "ignored %s" % fake_pubkey,
        }
    }]

    script = "OP_RETURN %s" % payload

    try:
        scripthex = pybitcoin.make_op_return_script(payload)
    except:
        if len(payload) == 0:
            scripthex = "6a"
        else:
            raise

    outputs = [{
        "scriptPubKey": {
            "asm": script,
            "hex": scripthex,
            "addresses": []
        }
    }]

    if recipient_address is not None:
        script = "OP_DUP OP_HASH160 %s OP_EQUALVERIFY OP_CHECKSIG" % binascii.hexlify(
            pybitcoin.bin_double_sha256(fake_pubkey))
        scripthex = pybitcoin.make_pay_to_address_script(recipient_address)
        outputs.append({
            "scriptPubKey": {
                "asm": script,
                "hex": scripthex,
                "addresses": [recipient_address]
            }
        })

    if import_update_hash is not None:
        script = "OP_DUP OP_HASH160 %s OP_EQUALVERIFY OP_CHECKSIG" % import_update_hash
        scripthex = pybitcoin.make_pay_to_address_script(
            pybitcoin.hex_hash160_to_address(import_update_hash))
        outputs.append({
            "scriptPubKey": {
                "asm": script,
                "hex": scripthex,
                "addresses":
                [pybitcoin.hex_hash160_to_address(import_update_hash)]
            }
        })

    try:
        op = op_extract(opcode_name, payload, senders, inputs, outputs, 373601,
                        0, "00" * 64)
    except AssertionError, ae:
        # failed to parse
        return None
def parse_nameop( opcode, payload, fake_pubkey, recipient=None, recipient_address=None, import_update_hash=None ):

    opcode_name = OPCODE_NAMES[opcode]
    pubk = pybitcoin.BitcoinPublicKey(fake_pubkey)
    address = pubk.address()
    script_pubkey = pybitcoin.make_pay_to_address_script( address )
    senders = [{
        "script_pubkey": script_pubkey,
        "script_type": "pubkeyhash",
        "addresses": [ address ]
    }]

    # just enough to get the public key
    inputs = [{
        "scriptSig": {
            "asm": "ignored %s" % fake_pubkey,
        }
    }]

    script = "OP_RETURN %s" % payload

    try:
        scripthex = pybitcoin.make_op_return_script( payload )
    except:
        if len(payload) == 0:
            scripthex = "6a"
        else:
            raise

    outputs = [{
        "scriptPubKey": {
            "asm": script,
            "hex": scripthex,
            "addresses": []
        }}]

    if recipient_address is not None:
        script = "OP_DUP OP_HASH160 %s OP_EQUALVERIFY OP_CHECKSIG" % binascii.hexlify( pybitcoin.bin_double_sha256( fake_pubkey ) )
        scripthex = pybitcoin.make_pay_to_address_script( recipient_address )
        outputs.append( {
            "scriptPubKey": {
                "asm": script,
                "hex": scripthex,
                "addresses": [ recipient_address ]
            }
        })

    if import_update_hash is not None:
        script = "OP_DUP OP_HASH160 %s OP_EQUALVERIFY OP_CHECKSIG" % import_update_hash
        scripthex = pybitcoin.make_pay_to_address_script( pybitcoin.hex_hash160_to_address( import_update_hash ) )
        outputs.append( {
            "scriptPubKey": {
                "asm": script,
                "hex": scripthex,
                "addresses": [ pybitcoin.hex_hash160_to_address(import_update_hash) ]
            }
        })
   
    try:
        op = op_extract( opcode_name, payload, senders, inputs, outputs, 373601, 0, "00" * 64 )  
    except AssertionError, ae:
        # failed to parse
        return None
Beispiel #45
0
def make_outputs(data, change_inputs, register_addr, change_addr, renewal_fee=None, pay_fee=True, format="bin"):
    """
    Make outputs for a register:
    [0] OP_RETURN with the name 
    [1] pay-to-address with the *register_addr*, not the sender's address.
    [2] change address with the NAME_PREORDER sender's address
    [3] (OPTIONAL) renewal fee, sent to the burn address
    """

    dust_fee = None
    dust_value = None
    op_fee = None
    bill = None

    if pay_fee:

        # sender pays
        if renewal_fee is not None:
            # renewing
            dust_fee = (len(change_inputs) + 3) * DEFAULT_DUST_FEE + DEFAULT_OP_RETURN_FEE
            dust_value = DEFAULT_DUST_FEE
            op_fee = max(renewal_fee, DEFAULT_DUST_FEE)
            bill = op_fee

        else:
            # registering
            dust_fee = (len(change_inputs) + 2) * DEFAULT_DUST_FEE + DEFAULT_OP_RETURN_FEE
            dust_value = DEFAULT_DUST_FEE
            op_fee = 0
            bill = DEFAULT_DUST_FEE * 2

    else:

        # subsidized by another address
        if renewal_fee is not None:
            # renewing
            dust_fee = 0
            dust_value = 0
            op_fee = max(renewal_fee, DEFAULT_DUST_FEE)
            bill = 0

        else:
            # registering
            dust_fee = 0
            dust_value = 0
            op_fee = 0
            bill = 0

    outputs = [
        # main output
        {"script_hex": make_op_return_script(data, format=format), "value": 0},
        # register address
        {"script_hex": make_pay_to_address_script(register_addr), "value": dust_fee},
        # change address (can be the subsidy address)
        {
            "script_hex": make_pay_to_address_script(change_addr),
            "value": calculate_change_amount(change_inputs, bill, dust_fee),
        },
    ]

    if renewal_fee is not None:
        outputs.append(
            # burn address (when renewing)
            {"script_hex": make_pay_to_address_script(BLOCKSTORE_BURN_ADDRESS), "value": op_fee}
        )

    return outputs