예제 #1
0
def get_cost(recommended_fee_per_transaction,
             dust_threshold, satoshi_per_byte, num_outputs):
    # note: assuming 1 input for now
    recommended_fee = recommended_fee_per_transaction * COIN
    min_per_output = dust_threshold * COIN
    txfee = calculate_txfee(satoshi_per_byte, 1, num_outputs, recommended_fee)
    total = calculate_total(min_per_output, num_outputs, txfee)

    return TransactionCosts(min_per_output, fee=txfee, total=total)
예제 #2
0
 def test_create_trx(self):
     cost = TransactionCosts(0.0001, 0.0000275, 3)
     tx_input = Spendable(200, '18eKkAWyU9kvRNHPKxnZb6wwtPMrNmRRRA',
                          h2b('8443b07464c762d7fb404ea918a5ac9b3618d5cd6a0c5ea6e4dd5d7bbe28b154'), 0)
     tx_outs = [trx_utils.create_transaction_output('mgAqW5ZCnEp7fjvpj8RUL3WxsBy8rcDcCi', 0.0000275)]
     tx = trx_utils.create_trx('TEST'.encode('utf-8'), cost, 'mgAqW5ZCnEp7fjvpj8RUL3WxsBy8rcDcCi', tx_outs, tx_input)
     hextx = hexlify(tx.serialize())
     self.assertEquals(hextx,
                       '01000000018443b07464c762d7fb404ea918a5ac9b3618d5cd6a0c5ea6e4dd5d7bbe28b1540000000000ffffffff0300000000000000001976a914072a22e5913cd939904c46bbd0bc56755543384b88acc5000000000000001976a914072a22e5913cd939904c46bbd0bc56755543384b88ac0000000000000000066a045445535400000000')
예제 #3
0
    def test_verify_transaction(self):
        cost = TransactionCosts(0.0001, 0.0000275, 3)
        tx_input = Spendable(200, '18eKkAWyU9kvRNHPKxnZb6wwtPMrNmRRRA',
                             h2b('8443b07464c762d7fb404ea918a5ac9b3618d5cd6a0c5ea6e4dd5d7bbe28b154'), 0)
        tx_outs = [trx_utils.create_transaction_output('mgAqW5ZCnEp7fjvpj8RUL3WxsBy8rcDcCi', 0.0000275)]
        op_return_val = h2b('e9cee71ab932fde863338d08be4de9dfe39ea049bdafb342ce659ec5450b69ae')
        tx = trx_utils.create_trx(op_return_val, cost, 'mgAqW5ZCnEp7fjvpj8RUL3WxsBy8rcDcCi', tx_outs, tx_input)

        hextx = hexlify(tx.serialize())

        trx_utils.verify_transaction(hextx, hexlify(op_return_val))
예제 #4
0
def get_cost(num_outputs):
    """
    Get cost of the transaction:
    :param num_outputs:
    :return:
    """
    if not num_outputs or num_outputs < 1:
        raise ValueError('num_outputs must be greater than or equal to 1')

    tx_fee = calculate_tx_fee(1, num_outputs)
    total = MIN_PER_OUTPUT * num_outputs + tx_fee
    return TransactionCosts(MIN_PER_OUTPUT, fee=tx_fee, total=total)
예제 #5
0
def get_cost_for_certificate_batch(dust_threshold, recommended_fee_per_transaction, satoshi_per_byte, num_certificates,
                                   allow_transfer):
    """Per certificate, we pay 2*min_per_output (which is based on dust) + recommended fee. Note assumes 1 input
    per tx. We may also need to pay additional fees for splitting into temp addresses
    """
    fee_per_transaction = recommended_fee_per_transaction * COIN
    min_per_output = dust_threshold * COIN

    # plus additional fees for splitting
    if allow_transfer:
        split_transfer_fee = calculate_txfee(
            satoshi_per_byte, fee_per_transaction, 1, num_certificates)
    else:
        split_transfer_fee = 0

    return TransactionCosts(min_per_output, fee_per_transaction, num_certificates, split_transfer_fee)
    def test_TransactionCosts_with_split(self):
        issuing_cost = TransactionCosts(10, 4000, 60000)
        issuing_cost.set_transfer_fee(10000)

        self.assertEqual(70000, issuing_cost.total)
예제 #7
0
 def test_TransactionCosts_no_split(self):
     issuing_cost = TransactionCosts(10, 4000, 60000)
     self.assertEqual(60000, issuing_cost.total)
예제 #8
0
    def test_TransactionCosts_with_split(self):
        issuing_cost = TransactionCosts(10, 4000, 60000)
        issuing_cost.set_transfer_fee(10000)

        self.assertEqual(70000, issuing_cost.total)
예제 #9
0
 def test_TotalCosts_no_split(self):
     issuing_cost = TransactionCosts(10, 4000, 60000)
     costs = TotalCosts(1,
                        issuing_transaction_cost=issuing_cost,
                        transfer_cost=None)
     self.assertEqual(60000, costs.total)
예제 #10
0
    def test_TransactionCosts_with_split(self):
        issuing_cost = TransactionCosts(10, 4000, 60000)
        transfer_cost = TransactionCosts(10, 4000, 50000)
        costs = TotalCosts(1, issuing_cost, transfer_cost)

        self.assertEqual(110000, costs.total)
예제 #11
0
 def test_TransactionCosts_no_split(self):
     costs = TransactionCosts(min_per_output=3,
                              fee_per_transaction=1,
                              number_of_transactions=5,
                              transfer_split_fee=0)
     self.assertEqual(35, costs.total)