本文整理汇总了Python中coloredcoinlib.ColorSet.uncolored_only方法的典型用法代码示例。如果您正苦于以下问题:Python ColorSet.uncolored_only方法的具体用法?Python ColorSet.uncolored_only怎么用?Python ColorSet.uncolored_only使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类coloredcoinlib.ColorSet
的用法示例。
在下文中一共展示了ColorSet.uncolored_only方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AssetDefinition
# 需要导入模块: from coloredcoinlib import ColorSet [as 别名]
# 或者: from coloredcoinlib.ColorSet import uncolored_only [as 别名]
class AssetDefinition(object):
"""Stores the definition of a particular asset, including its color set,
it's name (moniker), and the wallet model that represents it.
"""
def __init__(self, colormap, params):
"""Create an Asset for a color map <colormap> and configuration
<params>. Note params has the color definitions used for this
Asset.
"""
self.monikers = params.get('monikers', [])
self.color_set = ColorSet(colormap, params.get('color_set'))
self.unit = int(params.get('unit', 1))
def __repr__(self):
return "%s: %s" % (self.monikers, self.color_set)
def get_monikers(self):
"""Returns the list of monikers for this asset.
"""
return self.monikers
def get_color_set(self):
"""Returns the list of colors for this asset.
"""
return self.color_set
def get_colorvalue(self, utxo):
""" return colorvalue for a given utxo"""
if self.color_set.uncolored_only():
return utxo.value
else:
if utxo.colorvalues:
for cv in utxo.colorvalues:
if cv[0] in self.color_set.color_id_set:
return cv[1]
raise Exception("cannot get colorvalue for UTXO: "
"no colorvalues available")
def parse_value(self, portion):
"""Returns actual number of Satoshis for this Asset
given the <portion> of the asset.
"""
return int(float(portion) * self.unit)
def format_value(self, atoms):
"""Returns a string representation of the portion of the asset.
can involve rounding. doesn't display insignificant zeros
"""
return '{0:g}'.format(atoms / float(self.unit))
def get_data(self):
"""Returns a JSON-compatible object that represents this Asset
"""
return {
"monikers": self.monikers,
"color_set": self.color_set.get_data(),
"unit": self.unit
}
示例2: TestColorSet
# 需要导入模块: from coloredcoinlib import ColorSet [as 别名]
# 或者: from coloredcoinlib.ColorSet import uncolored_only [as 别名]
class TestColorSet(unittest.TestCase):
def setUp(self):
self.colormap = MockColorMap()
d = self.colormap.d
self.colorset0 = ColorSet(self.colormap, [""])
self.colorset1 = ColorSet(self.colormap, [d[1]])
self.colorset2 = ColorSet(self.colormap, [d[2]])
self.colorset3 = ColorSet(self.colormap, [d[1], d[2]])
self.colorset4 = ColorSet(self.colormap, [d[3], d[2]])
self.colorset5 = ColorSet(self.colormap, [d[3], d[1]])
self.colorset6 = ColorSet(self.colormap, [])
def test_repr(self):
self.assertEquals(self.colorset0.__repr__(), "['']")
self.assertEquals(self.colorset1.__repr__(), "['obc:color_desc_1:0:0']")
self.assertEquals(self.colorset3.__repr__(), "['obc:color_desc_1:0:0', 'obc:color_desc_2:0:1']")
def test_uncolored_only(self):
self.assertTrue(self.colorset0.uncolored_only())
self.assertFalse(self.colorset1.uncolored_only())
self.assertFalse(self.colorset3.uncolored_only())
def test_get_data(self):
self.assertEquals(self.colorset0.get_data(), [""])
self.assertEquals(self.colorset1.get_data(), ["obc:color_desc_1:0:0"])
def test_get_hash_string(self):
self.assertEquals(
self.colorset0.get_hash_string(), "055539df4a0b804c58caf46c0cd2941af10d64c1395ddd8e50b5f55d945841e6"
)
self.assertEquals(
self.colorset1.get_hash_string(), "ca90284eaa79e05d5971947382214044fe64f1bdc2e97040cfa9f90da3964a14"
)
self.assertEquals(
self.colorset3.get_hash_string(), "09f731f25cf5bfaad512d4ee6f37cb9481f442df3263b15725dd1624b4678557"
)
def test_get_earliest(self):
self.assertEquals(self.colorset5.get_earliest(), "obc:color_desc_1:0:0")
self.assertEquals(self.colorset4.get_earliest(), "obc:color_desc_2:0:1")
self.assertEquals(self.colorset6.get_earliest(), "\x00\x00\x00\x00")
def test_get_color_string(self):
self.assertEquals(self.colorset1.get_color_hash(), "CP4YWLr8aAe4Hn")
self.assertEquals(self.colorset3.get_color_hash(), "ZUTSoEEwZY6PB")
def test_has_color_id(self):
self.assertTrue(self.colorset0.has_color_id(0))
self.assertTrue(self.colorset3.has_color_id(1))
self.assertFalse(self.colorset1.has_color_id(0))
self.assertFalse(self.colorset4.has_color_id(1))
def test_intersects(self):
self.assertFalse(self.colorset0.intersects(self.colorset1))
self.assertTrue(self.colorset1.intersects(self.colorset3))
self.assertTrue(self.colorset3.intersects(self.colorset1))
self.assertTrue(self.colorset4.intersects(self.colorset3))
self.assertFalse(self.colorset2.intersects(self.colorset0))
self.assertFalse(self.colorset1.intersects(self.colorset4))
def test_equals(self):
self.assertFalse(self.colorset1.equals(self.colorset0))
self.assertTrue(self.colorset3.equals(self.colorset3))
self.assertFalse(self.colorset4.equals(self.colorset5))
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))