当前位置: 首页>>代码示例>>Python>>正文


Python ColorSet.get_color_hash方法代码示例

本文整理汇总了Python中coloredcoinlib.ColorSet.get_color_hash方法的典型用法代码示例。如果您正苦于以下问题:Python ColorSet.get_color_hash方法的具体用法?Python ColorSet.get_color_hash怎么用?Python ColorSet.get_color_hash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在coloredcoinlib.ColorSet的用法示例。


在下文中一共展示了ColorSet.get_color_hash方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: AssetDefinition

# 需要导入模块: from coloredcoinlib import ColorSet [as 别名]
# 或者: from coloredcoinlib.ColorSet import get_color_hash [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.colormap = colormap
        self.monikers = params.get('monikers', [])
        # currently only single-color assets are supported
        assert len(params.get('color_set')) == 1
        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_id(self):
        return self.color_set.get_color_hash()

    def get_all_ids(self):
        return [self.get_id()]

    def get_monikers(self):
        """Returns the list of monikers for this asset.
        """
        return self.monikers

    def get_color_id(self):
        return list(self.get_color_set().color_id_set)[0]

    def has_color_id(self, color_id):
        return self.get_color_set().has_color_id(color_id)

    def get_color_set(self):
        """Returns the list of colors for this asset.
        """
        return self.color_set

    def get_color_def(self):
        color_set = self.get_color_set()
        assert len(color_set.color_desc_list) == 1
        return self.colormap.get_color_def(color_set.color_desc_list[0])

    def get_null_colorvalue(self):
        cd = self.get_color_def()
        return SimpleColorValue(colordef=cd, value=0)

    def get_colorvalue(self, utxo):
        """ return colorvalue for a given utxo"""
        if utxo.colorvalues:
            for cv in utxo.colorvalues:
                if self.has_color_id(cv.get_color_id()):
                    return cv
        raise Exception("Cannot get colorvalue for UTXO!")

    def validate_value(self, portion):
        """Returns True if the portion is an exact multiple of the Asset atoms.
        """
        if isinstance(portion, ColorValue) or isinstance(portion, AssetValue):
            portion = portion.get_value()
        atom = Decimal("1") / Decimal(self.unit)
        return Decimal(portion) % atom == Decimal("0")

    def parse_value(self, portion):
        """Returns actual number of Satoshis for this Asset
        given the <portion> of the asset.
        """
        return int(Decimal(portion) * Decimal(self.unit))

    def format_value(self, value):
        """Returns a string representation of the portion of the asset.
        can involve rounding.  doesn't display insignificant zeros
        """
        if isinstance(value, ColorValue) or isinstance(value, AssetValue):
            value = value.get_value()
        return str(Decimal(value) / Decimal(self.unit))

    def get_atom(self):
        return self.format_value(1)

    def get_data(self):
        """Returns a JSON-compatible object that represents this Asset
        """
        return {
            "monikers": self.monikers,
            "assetid" : self.get_color_set().get_color_hash(),
            "color_set": self.color_set.get_data(),
            "unit": self.unit
            }
开发者ID:F483,项目名称:ngcccbase,代码行数:94,代码来源:asset.py

示例2: TestColorSet

# 需要导入模块: from coloredcoinlib import ColorSet [as 别名]
# 或者: from coloredcoinlib.ColorSet import get_color_hash [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))
开发者ID:shadowxxx,项目名称:ngcccbase,代码行数:74,代码来源:test_colorset.py


注:本文中的coloredcoinlib.ColorSet.get_color_hash方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。