Exemple #1
0
 def test_operational(self):
     self.basic.add_target(self.assettarget0)
     self.basic.add_target(self.assettarget1)
     self.basic.add_target(self.assettarget2)
     op = self.transformer.transform_basic(self.basic, 'operational')
     self.assertTrue(self.transformer.classify_tx_spec(op), 'operational')
     self.assertRaises(InvalidTargetError, op.add_target, 1)
     self.assertEqual(ColorTarget.sum(op.get_targets()),
                      ColorTarget.sum(self.targets))
     self.assertEqual(op.get_change_addr(self.colordef0), self.addr0)
     self.assertEqual(op.get_change_addr(UNCOLORED_MARKER), self.baddr)
     self.assertEqual(op.get_required_fee(1).get_value(), 10000)
     self.assertRaises(InvalidColorIdError, op.get_change_addr,
                       self.colordef1)
     cv = SimpleColorValue(colordef=self.colordef0, value=0)
     self.assertRaises(ZeroSelectError, op.select_coins, cv)
     cv = SimpleColorValue(colordef=self.colordef0, value=5)
     self.assertRaises(InsufficientFundsError, op.select_coins, cv)
     self.add_coins()
     self.assertEqual(op.select_coins(cv)[1].get_value(), 100)
Exemple #2
0
 def test_operational(self):
     self.basic.add_target(self.assettarget0)
     self.basic.add_target(self.assettarget1)
     self.basic.add_target(self.assettarget2)
     op = self.transformer.transform_basic(self.basic, 'operational')
     self.assertTrue(self.transformer.classify_tx_spec(op), 'operational')
     self.assertRaises(InvalidTargetError, op.add_target, 1)
     self.assertEqual(ColorTarget.sum(op.get_targets()),
                      ColorTarget.sum(self.targets))
     self.assertEqual(op.get_change_addr(self.colordef0), self.addr0)
     self.assertEqual(op.get_change_addr(UNCOLORED_MARKER), self.baddr)
     self.assertEqual(op.get_required_fee(1).get_value(), 10000)
     self.assertRaises(InvalidColorIdError, op.get_change_addr,
                       self.colordef1)
     cv = SimpleColorValue(colordef=self.colordef0, value=0)
     self.assertRaises(ZeroSelectError, op.select_coins, cv)
     cv = SimpleColorValue(colordef=self.colordef0, value=5)
     self.assertRaises(InsufficientFundsError, op.select_coins, cv)
     self.add_coins()
     self.assertEqual(op.select_coins(cv)[1].get_value(), 100)
Exemple #3
0
def compose_uncolored_tx(tx_spec):
    """ compose a simple bitcoin transaction """
    targets = tx_spec.get_targets()
    ttotal = ColorTarget.sum(targets)
    fee = tx_spec.get_required_fee(500)
    sel_utxos, sum_sel_coins = tx_spec.select_coins(ttotal + fee)
    change = sum_sel_coins - ttotal - fee
    txouts = [ComposedTxSpec.TxOut(target.get_satoshi(), target.get_address())
              for target in targets]
    # give ourselves the change
    if change > 0:
        change_addr = tx_spec.get_change_addr(UNCOLORED_MARKER)
        txouts.append(
            ComposedTxSpec.TxOut(change.get_satoshi(), change_addr))
    return ComposedTxSpec(sel_utxos, txouts)
Exemple #4
0
def compose_uncolored_tx(tx_spec):
    """ compose a simple bitcoin transaction """
    targets = tx_spec.get_targets()
    ttotal = ColorTarget.sum(targets)
    fee = tx_spec.get_required_fee(500)
    sel_utxos, sum_sel_coins = tx_spec.select_coins(ttotal + fee)
    change = sum_sel_coins - ttotal - fee
    txouts = [ComposedTxSpec.TxOut(target.get_satoshi(), target.get_address())
              for target in targets]
    # give ourselves the change
    if change > 0:
        change_addr = tx_spec.get_change_addr(UNCOLORED_MARKER)
        txouts.append(
            ComposedTxSpec.TxOut(change.get_satoshi(), change_addr))
    return ComposedTxSpec(sel_utxos, txouts)
Exemple #5
0
def compose_uncolored_tx(tx_spec):
    """ compose a simple bitcoin transaction """
    composed_tx_spec = tx_spec.make_composed_tx_spec()
    targets = tx_spec.get_targets()
    composed_tx_spec.add_txouts(targets)
    ttotal = ColorTarget.sum(targets)
    sel_utxos, sum_sel_coins = tx_spec.select_coins(ttotal, composed_tx_spec)
    composed_tx_spec.add_txins(sel_utxos)
    fee = composed_tx_spec.estimate_required_fee()
    change = sum_sel_coins - ttotal - fee
    # give ourselves the change
    if change > tx_spec.get_dust_threshold():
        composed_tx_spec.add_txout(value=change,
                                   target_addr=tx_spec.get_change_addr(UNCOLORED_MARKER),
                                   is_fee_change=True)
    return composed_tx_spec
Exemple #6
0
def compose_uncolored_tx(tx_spec):
    """ compose a simple bitcoin transaction """
    composed_tx_spec = tx_spec.make_composed_tx_spec()
    targets = tx_spec.get_targets()
    composed_tx_spec.add_txouts(targets)
    ttotal = ColorTarget.sum(targets)
    sel_utxos, sum_sel_coins = tx_spec.select_coins(ttotal, composed_tx_spec)
    composed_tx_spec.add_txins(sel_utxos)
    fee = composed_tx_spec.estimate_required_fee()
    change = sum_sel_coins - ttotal - fee
    # give ourselves the change
    if change > tx_spec.get_dust_threshold():
        composed_tx_spec.add_txout(value=change,
                                   target_addr=tx_spec.get_change_addr(UNCOLORED_MARKER),
                                   is_fee_change=True)
    return composed_tx_spec