本文整理汇总了Python中coloredcoinlib.ColorSet.from_color_ids方法的典型用法代码示例。如果您正苦于以下问题:Python ColorSet.from_color_ids方法的具体用法?Python ColorSet.from_color_ids怎么用?Python ColorSet.from_color_ids使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类coloredcoinlib.ColorSet
的用法示例。
在下文中一共展示了ColorSet.from_color_ids方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_etx_spec
# 需要导入模块: from coloredcoinlib import ColorSet [as 别名]
# 或者: from coloredcoinlib.ColorSet import from_color_ids [as 别名]
def make_etx_spec(self, our, their):
our_color_def = self.resolve_color_spec(our['color_spec'])
our_color_set = ColorSet.from_color_ids(self.model.get_color_map(),
[our_color_def.get_color_id()])
their_color_def = self.resolve_color_spec(their['color_spec'])
their_color_set = ColorSet.from_color_ids(self.model.get_color_map(),
[their_color_def.get_color_id()])
extra_value = 0
if our_color_def == UNCOLORED_MARKER:
# pay fee + padding for one colored outputs
extra_value = 10000 + 8192 * 1
c_utxos, c_change = self.select_inputs(
SimpleColorValue(colordef=our_color_def,
value=our['value'] + extra_value))
inputs = {our['color_spec']:
[utxo.get_outpoint() for utxo in c_utxos]}
wam = self.model.get_address_manager()
our_address = wam.get_change_address(their_color_set)
targets = [(our_address.get_address(),
their['color_spec'], their['value'])]
if c_change > 0:
our_change_address = wam.get_change_address(our_color_set)
targets.append((our_change_address.get_address(),
our['color_spec'], c_change.get_value()))
return ETxSpec(inputs, targets, c_utxos)
示例2: test_from_color_ids
# 需要导入模块: from coloredcoinlib import ColorSet [as 别名]
# 或者: from coloredcoinlib.ColorSet import from_color_ids [as 别名]
def test_from_color_ids(self):
self.assertTrue(self.colorset0.equals(ColorSet.from_color_ids(self.colormap, [0])))
self.assertTrue(self.colorset3.equals(ColorSet.from_color_ids(self.colormap, [1, 2])))
tmp = ColorSet.from_color_ids(self.colormap, [1, 2, 3])
self.assertTrue(tmp.has_color_id(1))
self.assertTrue(tmp.has_color_id(2))
self.assertTrue(tmp.has_color_id(3))
示例3: make_etx_spec
# 需要导入模块: from coloredcoinlib import ColorSet [as 别名]
# 或者: from coloredcoinlib.ColorSet import from_color_ids [as 别名]
def make_etx_spec(self, our, their):
fee = FEE if our.get_colordef() == UNCOLORED_MARKER else 0
c_utxos, c_change = self.select_inputs(our + fee)
inputs = {our.get_colordef():
[utxo.get_outpoint() for utxo in c_utxos]}
wam = self.model.get_address_manager()
our_color_set = ColorSet.from_color_ids(self.model.get_color_map(),
[our.get_color_id()])
their_color_set = ColorSet.from_color_ids(self.model.get_color_map(),
[their.get_color_id()])
our_address = wam.get_change_address(their_color_set)
targets = [ColorTarget(our_address.get_address(), their)]
if c_change > 0:
our_change_address = wam.get_change_address(our_color_set)
targets.append(ColorTarget(our_change_address.get_address(),
c_change))
return ETxSpec(inputs, targets, c_utxos)
示例4: get_asset_value_for_colorvalue
# 需要导入模块: from coloredcoinlib import ColorSet [as 别名]
# 或者: from coloredcoinlib.ColorSet import from_color_ids [as 别名]
def get_asset_value_for_colorvalue(self, colorvalue):
colorset = ColorSet.from_color_ids(self.colormap,
[colorvalue.get_color_id()])
asset = self.find_asset_by_color_set(colorset)
if not asset:
raise Exception('asset not found')
return AdditiveAssetValue(asset=asset,
value=colorvalue.get_value())
示例5: prepare_targets
# 需要导入模块: from coloredcoinlib import ColorSet [as 别名]
# 或者: from coloredcoinlib.ColorSet import from_color_ids [as 别名]
def prepare_targets(self, etx_spec, their):
self.targets = etx_spec.targets
wam = self.model.get_address_manager()
colormap = self.model.get_color_map()
their_color_set = ColorSet.from_color_ids(self.model.get_color_map(),
[their.get_color_id()])
ct = ColorTarget(wam.get_change_address(their_color_set).get_address(),
their)
self.targets.append(ct)
示例6: make_query
# 需要导入模块: from coloredcoinlib import ColorSet [as 别名]
# 或者: from coloredcoinlib.ColorSet import from_color_ids [as 别名]
def make_query(self, query):
"""Create a UTXOQuery from query <query>. Queries are dicts with:
color_set - color associated with this query
"""
color_set = query.get('color_set')
if not color_set:
if 'color_id_set' in query:
color_set = ColorSet.from_color_ids(
self.model.get_color_map(), query['color_id_set'])
elif 'asset' in query:
color_set = query['asset'].get_color_set()
else:
raise Exception('color set is not specified')
return UTXOQuery(self.model, color_set)
示例7: prepare_targets
# 需要导入模块: from coloredcoinlib import ColorSet [as 别名]
# 或者: from coloredcoinlib.ColorSet import from_color_ids [as 别名]
def prepare_targets(self, etx_spec, their):
self.targets = []
for address, color_spec, value in etx_spec.targets:
colordef = self.ewctrl.resolve_color_spec(color_spec)
self.targets.append(ColorTarget(address,
SimpleColorValue(colordef=colordef,
value=value)))
wam = self.model.get_address_manager()
colormap = self.model.get_color_map()
their_colordef = self.ewctrl.resolve_color_spec(their['color_spec'])
their_color_set = ColorSet.from_color_ids(self.model.get_color_map(),
[their_colordef.get_color_id()])
ct = ColorTarget(wam.get_change_address(their_color_set).get_address(),
SimpleColorValue(colordef=their_colordef,
value=their['value']))
self.targets.append(ct)
示例8: get_change_addr
# 需要导入模块: from coloredcoinlib import ColorSet [as 别名]
# 或者: from coloredcoinlib.ColorSet import from_color_ids [as 别名]
def get_change_addr(self, color_def):
"""Get an address associated with color definition <color_def>
that is in the current wallet for receiving change.
"""
color_id = color_def.color_id
wam = self.model.get_address_manager()
color_set = None
if color_def == UNCOLORED_MARKER:
color_set = ColorSet.from_color_ids(self.model.get_color_map(),
[0])
elif self.asset.get_color_set().has_color_id(color_id):
color_set = self.asset.get_color_set()
if color_set is None:
raise InvalidColorIdError('wrong color id')
aw = wam.get_change_address(color_set)
return aw.get_address()
示例9: select_inputs
# 需要导入模块: from coloredcoinlib import ColorSet [as 别名]
# 或者: from coloredcoinlib.ColorSet import from_color_ids [as 别名]
def select_inputs(self, colorvalue):
cs = ColorSet.from_color_ids(self.model.get_color_map(),
[colorvalue.get_color_id()])
cq = self.model.make_coin_query({"color_set": cs})
utxo_list = cq.get_result()
selection = []
csum = SimpleColorValue(colordef=colorvalue.get_colordef(), value=0)
for utxo in utxo_list:
csum += SimpleColorValue.sum(utxo.colorvalues)
selection.append(utxo)
if csum >= colorvalue:
break
if csum < colorvalue:
raise InsufficientFundsError('not enough money')
return selection, (csum - colorvalue)
示例10: make_query
# 需要导入模块: from coloredcoinlib import ColorSet [as 别名]
# 或者: from coloredcoinlib.ColorSet import from_color_ids [as 别名]
def make_query(self, query):
"""Create a CoinQuery from query <query>. Queries are dicts with:
color_set - color associated with this query
"""
query = query.copy()
color_set = query.get('color_set')
if not color_set:
if 'color_id_set' in query:
color_set = ColorSet.from_color_ids(
self.model.get_color_map(), query['color_id_set'])
elif 'asset' in query:
color_set = query['asset'].get_color_set()
else:
raise Exception('Color set is not specified!')
if 'spent' not in query:
query['spent'] = False
return CoinQuery(self.model, color_set, query)
示例11: resolve_color_spec
# 需要导入模块: from coloredcoinlib import ColorSet [as 别名]
# 或者: from coloredcoinlib.ColorSet import from_color_ids [as 别名]
def resolve_color_spec(self, color_spec):
colormap = self.model.get_color_map()
color_id = colormap.resolve_color_desc(color_spec, False)
if color_id is None:
raise Exception("color spec not recognized")
return ColorSet.from_color_ids(self.model.get_color_map(), [color_id])
示例12: get_change_addr
# 需要导入模块: from coloredcoinlib import ColorSet [as 别名]
# 或者: from coloredcoinlib.ColorSet import from_color_ids [as 别名]
def get_change_addr(self, color_def):
color_id = color_def.color_id
cs = ColorSet.from_color_ids(self.model.get_color_map(), [color_id])
wam = self.model.get_address_manager()
return wam.get_change_address(cs).get_address()
示例13: get_asset_by_color_id
# 需要导入模块: from coloredcoinlib import ColorSet [as 别名]
# 或者: from coloredcoinlib.ColorSet import from_color_ids [as 别名]
def get_asset_by_color_id(self, colorid):
colorset = ColorSet.from_color_ids(self.colormap, [colorid])
asset = self.find_asset_by_color_set(colorset)
if not asset:
raise Exception('Asset not found!')
return asset