• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python pwallet.PersistentWallet类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中ngcccbase.pwallet.PersistentWallet的典型用法代码示例。如果您正苦于以下问题:Python PersistentWallet类的具体用法?Python PersistentWallet怎么用?Python PersistentWallet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: TestRealP2PTrade

class TestRealP2PTrade(unittest.TestCase):

    def setUp(self):
        from ngcccbase.pwallet import PersistentWallet
        from ngcccbase.wallet_controller import WalletController
        self.pwallet = PersistentWallet(":memory:", True)
        self.pwallet.init_model()
        self.wctrl = WalletController(self.pwallet.wallet_model)

    def test_real(self):
        ewctrl = EWalletController(self.pwallet.get_model(), self.wctrl)
        config = {"offer_expiry_interval": 30,
                  "ep_expiry_interval": 30}
        comm1 = MockComm()
        comm2 = MockComm()
        comm1.add_peer(comm2)
        comm2.add_peer(comm1)
        agent1 = EAgent(ewctrl, config, comm1)
        agent2 = EAgent(ewctrl, config, comm2)

        self.cd0 = "obc:cc8e64cef1a880f5132e73b5a1f52a72565c92afa8ec36c445c635fe37b372fd:0:263370"
        self.cd1 = "obc:caff27b3fe0a826b776906aceafecac7bb34af16971b8bd790170329309391ac:0:265577"

        cv0 = { 'color_spec' : self.cd0, 'value' : 100 }
        cv1 = { 'color_spec' : self.cd1, 'value' : 200 }

        ag1_offer = MyEOffer(None, cv0, cv1)
        ag2_offer = MyEOffer(None, cv0, cv1)
        ag2_offer.auto_post = False

        agent1.register_my_offer(ag1_offer)
        agent2.register_my_offer(ag2_offer)
        for _ in xrange(3):
            agent1._update_state()
            agent2._update_state()
开发者ID:F483,项目名称:ngcccbase,代码行数:35,代码来源:test_real.py


示例2: add_coins

    def add_coins(self):
        self.config['asset_definitions'] = [
            {"color_set": [""], "monikers": ["bitcoin"], "unit": 100000000},  
            {"color_set": [self.cspec], "monikers": ['test'], "unit": 1},]
        self.config['hdwam'] = {
            "genesis_color_sets": [ 
                [self.cspec],
                ],
            "color_set_states": [
                {"color_set": [""], "max_index": 1},
                {"color_set": [self.cspec], "max_index": 7},
                ]
            }
        self.config['bip0032'] = True
        self.pwallet = PersistentWallet(self.path, self.config)
        self.pwallet.init_model()
        self.model = self.pwallet.get_model()
        self.ewc.model = self.model
        self.wc.model = self.model
        # modify model colored coin context, so test runs faster
        ccc = self.model.ccc
        cdbuilder = ColorDataBuilderManager(
            ccc.colormap, ccc.blockchain_state, ccc.cdstore,
            ccc.metastore, AidedColorDataBuilder)

        ccc.colordata = ThinColorData(
            cdbuilder, ccc.blockchain_state, ccc.cdstore, ccc.colormap)

        # need to query the blockchain
        self.model.utxo_man.update_all()

        adm = self.model.get_asset_definition_manager()
        asset = adm.get_asset_by_moniker('test')
        cq = self.model.make_coin_query({"asset": asset})
        utxo_list = cq.get_result()
开发者ID:Andymeows,项目名称:ngcccbase,代码行数:35,代码来源:test_ewctrl.py


示例3: __init__

    def __init__(self, dataDir, isTestNet):
        QtCore.QObject.__init__(self)

        self.lock = threading.Lock()

        self._patching_BaseTxDb()

        self.wallet_path = os.path.join(dataDir, 'wallet.sqlite')
        self._pwallet = PersistentWallet(self.wallet_path, isTestNet)
        self._set_wallet_settings(dataDir, isTestNet)
        self._pwallet.init_model()
        self._wallet = self._pwallet.get_model()
        self._controller = WalletController(self._wallet)
        self._utxo_fetcher = AsyncUTXOFetcher(
            self._wallet, self._pwallet.wallet_config.get('utxo_fetcher', {}))

        self._utxo_fetcher_timer = QtCore.QTimer()
        self._utxo_fetcher_timer.timeout.connect(self._utxo_fetcher.update)
        self._utxo_fetcher_timer.setInterval(1000)

        asset = self.get_asset_definition('bitcoin')
        if len(self._controller.get_all_addresses(asset)) == 0:
            self._controller.get_new_address(asset)

        self._create_club_asset()
开发者ID:fanatid,项目名称:chromaclub,代码行数:25,代码来源:wallet.py


示例4: __init__

    def __init__(self):
        parser = argparse.ArgumentParser()
        parser.add_argument("--wallet", dest="wallet_path")
        parsed_args = vars(parser.parse_args())

        self.wallet = PersistentWallet(parsed_args.get('wallet_path'))
        self.wallet.init_model()
        self.model = self.wallet.get_model()
        self.controller = WalletController(self.wallet.get_model())
开发者ID:amidvidy,项目名称:ngcccbase,代码行数:9,代码来源:wallet.py


示例5: __init__

    def __init__(self, wallet=None, testnet=False):

        # sanitize inputs
        testnet = sanitize.flag(testnet)

        if not wallet:
            wallet = "%s.wallet" % ("testnet" if testnet else "mainnet")
        self.wallet = PersistentWallet(wallet, testnet)
        self.model_is_initialized = False
开发者ID:killerstorm,项目名称:ngcccbase,代码行数:9,代码来源:api.py


示例6: __init__

    def __init__(self, wallet=None, testnet=False):

        # sanitize inputs
        testnet = sanitize.flag(testnet)

        if not wallet:
            wallet = "%s.wallet" % ("testnet" if testnet else "mainnet")
        self.wallet = PersistentWallet(wallet, testnet)
        self.wallet.init_model()
        self.model = self.wallet.get_model()
        self.controller = WalletController(self.model)
开发者ID:F483,项目名称:ngcccbase,代码行数:11,代码来源:api.py


示例7: __getattribute__

    def __getattribute__(self, name):
        if name in ['controller', 'model', 'wallet']:
            try:
                data = self.data
            except AttributeError:
                self.data = data = {}

                pw = PersistentWallet(self.args.get('wallet_path'))
                pw.init_model()

                wallet_model = pw.get_model()

                data.update({
                    'controller': WalletController(wallet_model)
                    if wallet_model else None,
                    'wallet': pw,
                    'model': wallet_model if pw else None,
                    })
            return data[name]
        return object.__getattribute__(self, name)
开发者ID:elkingtowa,项目名称:alphacoin,代码行数:20,代码来源:ngccc-cli.py


示例8: TestRealP2PTrade

class TestRealP2PTrade(unittest.TestCase):

    def setUp(self):
        from ngcccbase.pwallet import PersistentWallet
        from ngcccbase.wallet_controller import WalletController
        self.pwallet = PersistentWallet()
        self.pwallet.init_model()
        self.wctrl = WalletController(self.pwallet.wallet_model)

    def test_real(self):
        ewctrl = EWalletController(self.pwallet.get_model(), self.wctrl)
        config = {"offer_expiry_interval": 30,
                  "ep_expiry_interval": 30}
        comm1 = MockComm()
        comm2 = MockComm()
        comm1.add_peer(comm2)
        comm2.add_peer(comm1)
        agent1 = EAgent(ewctrl, config, comm1)
        agent2 = EAgent(ewctrl, config, comm2)

        frobla_color_desc = "obc:cc8e64cef1a880f5132e73b5a1f52a72565c92afa8ec36c445c635fe37b372fd:0:263370"
        foo_color_desc = "obc:caff27b3fe0a826b776906aceafecac7bb34af16971b8bd790170329309391ac:0:265577"

        self.cd0 = OBColorDefinition(1, {'txhash': 'cc8e64cef1a880f5132e73b5a1f52a72565c92afa8ec36c445c635fe37b372fd',
                                         'outindex': 0, 'height':263370})

        self.cd1 = OBColorDefinition(1, {'txhash': 'caff27b3fe0a826b776906aceafecac7bb34af16971b8bd790170329309391ac',
                                         'outindex': 0, 'height':265577})

        cv0 = SimpleColorValue(colordef=self.cd0, value=100)
        cv1 = SimpleColorValue(colordef=self.cd1, value=200)

        ag1_offer = MyEOffer(None, cv0, cv1)
        ag2_offer = MyEOffer(None, cv0, cv1, False)

        agent1.register_my_offer(ag1_offer)
        agent2.register_my_offer(ag2_offer)
        for _ in xrange(3):
            agent1._update_state()
            agent2._update_state()
开发者ID:Andymeows,项目名称:ngcccbase,代码行数:40,代码来源:test_real.py


示例9: __init__

    def __init__(self):
        parser = argparse.ArgumentParser()
        parser.add_argument("--wallet", dest="wallet_path")
        parser.add_argument("--testnet", action='store_true')
        parsed_args = vars(parser.parse_args())

        self.wallet = PersistentWallet(parsed_args.get('wallet_path'),
                                       parsed_args.get('testnet'))
        self.wallet.init_model()
        self.model = self.wallet.get_model()
        self.controller = WalletController(self.wallet.get_model())
        self.async_utxo_fetcher = AsyncUTXOFetcher(
            self.model, self.wallet.wallet_config.get('utxo_fetcher', {}))
开发者ID:Andymeows,项目名称:ngcccbase,代码行数:13,代码来源:wallet.py


示例10: setUp

    def setUp(self):
        self.path = ":memory:"
        self.config = {
            'hdw_master_key':
                '91813223e97697c42f05e54b3a85bae601f04526c5c053ff0811747db77cfdf5f1accb50b3765377c379379cd5aa512c38bf24a57e4173ef592305d16314a0f4',
            'testnet': True,
            'ccc': {'colordb_path' : self.path},
            }
        self.pwallet = PersistentWallet(self.path, self.config)
        self.pwallet.init_model()
        self.model = self.pwallet.get_model()
        self.wc = WalletController(self.model)

        self.ewc = EWalletController(self.model, self.wc)
        self.bcolorset =self.ewc.resolve_color_spec('')
        self.cspec = "obc:03524a4d6492e8d43cb6f3906a99be5a1bcd93916241f759812828b301f25a6c:0:153267"
开发者ID:Andymeows,项目名称:ngcccbase,代码行数:16,代码来源:test_ewctrl.py


示例11: setUp

    def setUp(self):
        self.pwallet = PersistentWallet(None, True)
        self.pwallet.init_model()
        self.model = self.pwallet.get_model()
        adm = self.model.get_asset_definition_manager()

        # make sure you have the asset 'testobc' in your testnet.wallet !!
        self.asset = adm.get_asset_by_moniker('testobc')
        self.color_spec = self.asset.get_color_set().get_data()[0]

        self.wc = WalletController(self.model)
        self.ewc = EWalletController(self.model, self.wc)

        def null(a):
            pass
        self.wc.publish_tx = null
开发者ID:F483,项目名称:ngcccbase,代码行数:16,代码来源:test_ewctrl.py


示例12: setUp

 def setUp(self):
     self.path = ":memory:"
     self.config = {
         'hdw_master_key':
             '91813223e97697c42f05e54b3a85bae601f04526c5c053ff0811747db77cfdf5f1accb50b3765377c379379cd5aa512c38bf24a57e4173ef592305d16314a0f4',
         'testnet': True,
         'ccc': {'colordb_path' : self.path},
         }
     self.pwallet = PersistentWallet(self.path, self.config)
     self.pwallet.init_model()
     self.model = self.pwallet.get_model()
     self.colormap = self.model.get_color_map()
     self.bcolorset = ColorSet(self.colormap, [''])
     self.basset = self.model.get_asset_definition_manager(
         ).get_asset_by_moniker('bitcoin')
     self.cqf = self.model.get_coin_query_factory()
开发者ID:Andymeows,项目名称:ngcccbase,代码行数:16,代码来源:test_wallet_model.py


示例13: add_coins

    def add_coins(self):
        self.config['asset_definitions'] = [
            {"color_set": [""], "monikers": ["bitcoin"], "unit": 100000000},  
            {"color_set": [self.cspec], "monikers": ['test'], "unit": 1},]
        self.config['hdwam'] = {
            "genesis_color_sets": [ 
                [self.cspec],
                ],
            "color_set_states": [
                {"color_set": [""], "max_index": 1},
                {"color_set": [self.cspec], "max_index": 7},
                ]
            }
        self.config['bip0032'] = True
        self.pwallet = PersistentWallet(self.path, self.config)
        self.pwallet.init_model()
        self.model = self.pwallet.get_model()
        self.ewc.model = self.model
        self.wc.model = self.model
        def null(a):
            pass
        self.wc.publish_tx = null
        # modify model colored coin context, so test runs faster
        ccc = self.model.ccc
        cdbuilder = ColorDataBuilderManager(
            ccc.colormap, ccc.blockchain_state, ccc.cdstore,
            ccc.metastore, AidedColorDataBuilder)

        ccc.colordata = ThinColorData(
            cdbuilder, ccc.blockchain_state, ccc.cdstore, ccc.colormap)

        # need to query the blockchain
        self.model.utxo_man.update_all()

        adm = self.model.get_asset_definition_manager()
        asset = adm.get_asset_by_moniker('test')
        cq = self.model.make_coin_query({"asset": asset})
        utxo_list = cq.get_result()

        self.cd = ColorDefinition.from_color_desc(1, self.cspec)

        self.cv0 = SimpleColorValue(colordef=UNCOLORED_MARKER, value=100)
        self.cv1 = SimpleColorValue(colordef=self.cd, value=200)

        self.offer0 = MyEOffer(None, self.cv0, self.cv1)
        self.offer1 = MyEOffer(None, self.cv1, self.cv0)
开发者ID:arichnad,项目名称:ngcccbase,代码行数:46,代码来源:test_agent.py


示例14: setUp

    def setUp(self):
        self.path = ":memory:"
        self.config = {'dw_master_key': 'test', 'testnet': True, 'ccc': {
                'colordb_path' : self.path
                }, 'bip0032': False }
        self.pwallet = PersistentWallet(self.path, self.config)
        self.pwallet.init_model()
        self.model = self.pwallet.get_model()
        self.wc = WalletController(self.model)
        self.wc.testing = True
        self.wc.debug = True
        self.colormap = self.model.get_color_map()
        self.bcolorset = ColorSet(self.colormap, [''])
        wam = self.model.get_address_manager()
        self.baddress = wam.get_new_address(self.bcolorset)
        self.baddr = self.baddress.get_address()

        self.blockhash = '00000000c927c5d0ee1ca362f912f83c462f644e695337ce3731b9f7c5d1ca8c'
        self.txhash = '4fe45a5ba31bab1e244114c4555d9070044c73c98636231c77657022d76b87f7'

        script = tools.compile(
            "OP_DUP OP_HASH160 {0} OP_EQUALVERIFY OP_CHECKSIG".format(
                self.baddress.rawPubkey().encode("hex"))).encode("hex")

        self.model.utxo_man.store.add_utxo(self.baddr, self.txhash,
                                           0, 100, script)

        script = tools.compile(
            "OP_DUP OP_HASH160 {0} OP_EQUALVERIFY OP_CHECKSIG".format(
                self.baddress.rawPubkey().encode("hex"))).encode("hex")

        self.model.utxo_man.store.add_utxo(self.baddr, self.txhash,
                                           1, 1000000000, script)

        self.model.ccc.blockchain_state.bitcoind = MockBitcoinD('test')
        def x(s):
            return self.blockhash, True
        self.model.ccc.blockchain_state.get_tx_blockhash = x
        self.moniker = 'test'
        self.wc.issue_coins(self.moniker, 'obc', 10000, 1)
        self.asset = self.model.get_asset_definition_manager(
            ).get_asset_by_moniker(self.moniker)
        self.basset = self.model.get_asset_definition_manager(
            ).get_asset_by_moniker('bitcoin')
        self.color_id = list(self.asset.color_set.color_id_set)[0]
        self.model.ccc.metastore.set_as_scanned(self.color_id, self.blockhash)
开发者ID:MattFaus,项目名称:ngcccbase,代码行数:46,代码来源:test_wallet_controller.py


示例15: setUp

 def setUp(self):
     self.path = ":memory:"
     self.config = {
         "hdw_master_key": "91813223e97697c42f05e54b3a85bae601f04526c5c053ff0811747db77cfdf5f1accb50b3765377c379379cd5aa512c38bf24a57e4173ef592305d16314a0f4",
         "testnet": True,
         "ccc": {"colordb_path": self.path},
     }
     self.pwallet = PersistentWallet(self.path, self.config)
     self.pwallet.init_model()
     self.model = self.pwallet.get_model()
     self.wc = WalletController(self.model)
     self.ewc = EWalletController(self.model, self.wc)
     self.econfig = {"offer_expiry_interval": 30, "ep_expiry_interval": 30}
     self.comm0 = MockComm()
     self.comm1 = MockComm()
     self.comm0.add_peer(self.comm1)
     self.comm1.add_peer(self.comm0)
     self.agent0 = EAgent(self.ewc, self.econfig, self.comm0)
     self.agent1 = EAgent(self.ewc, self.econfig, self.comm1)
     self.cspec = "obc:03524a4d6492e8d43cb6f3906a99be5a1bcd93916241f759812828b301f25a6c:0:153267"
开发者ID:uwecerron,项目名称:ngcccbase,代码行数:20,代码来源:test_agent.py


示例16: test_get_history

    def test_get_history(self):
        self.config['asset_definitions'] = [
            {"color_set": [""], "monikers": ["bitcoin"], "unit": 100000000},  
            {"color_set": ["obc:03524a4d6492e8d43cb6f3906a99be5a1bcd93916241f759812828b301f25a6c:0:153267"], "monikers": ['test'], "unit": 1},]
        self.config['hdwam'] = {
            "genesis_color_sets": [ 
                ["obc:03524a4d6492e8d43cb6f3906a99be5a1bcd93916241f759812828b301f25a6c:0:153267"],
                ],
            "color_set_states": [
                {"color_set": [""], "max_index": 1},
                {"color_set": ["obc:03524a4d6492e8d43cb6f3906a99be5a1bcd93916241f759812828b301f25a6c:0:153267"], "max_index": 7},
                ]
            }
        self.config['bip0032'] = True
        self.pwallet = PersistentWallet(self.path, self.config)
        self.pwallet.init_model()
        self.model = self.pwallet.get_model()
        # modify model colored coin context, so test runs faster
        ccc = self.model.ccc
        cdbuilder = ColorDataBuilderManager(
            ccc.colormap, ccc.blockchain_state, ccc.cdstore,
            ccc.metastore, AidedColorDataBuilder)

        ccc.colordata = ThinColorData(
            cdbuilder, ccc.blockchain_state, ccc.cdstore, ccc.colormap)

        wc = WalletController(self.model)

        adm = self.model.get_asset_definition_manager()
        asset = adm.get_asset_by_moniker('test')
        self.model.utxo_man.update_all()
        cq = self.model.make_coin_query({"asset": asset})
        utxo_list = cq.get_result()

        # send to the second address so the mempool has something
        addrs = wc.get_all_addresses(asset)
        wc.send_coins(asset, [addrs[1].get_color_address()], [1000])

        history = self.model.get_history_for_asset(asset)
        self.assertTrue(len(history) > 30)
开发者ID:Andymeows,项目名称:ngcccbase,代码行数:40,代码来源:test_wallet_model.py


示例17: setUp

    def setUp(self):
        self.pwallet = PersistentWallet(None, True)
        self.pwallet.init_model()
        self.model = self.pwallet.get_model()
        adm = self.model.get_asset_definition_manager()

        # make sure you have the asset 'testobc' in your testnet.wallet !!
        self.asset = adm.get_asset_by_moniker('testobc')
        self.color_spec = self.asset.get_color_set().get_data()[0]

        self.comm0 = MockComm()
        self.comm1 = MockComm()
        self.comm0.add_peer(self.comm1)
        self.comm1.add_peer(self.comm0)
        self.wc = WalletController(self.model)
        self.ewc = EWalletController(self.model, self.wc)
        self.econfig = {"offer_expiry_interval": 30, "ep_expiry_interval": 30}
        self.agent0 = EAgent(self.ewc, self.econfig, self.comm0)
        self.agent1 = EAgent(self.ewc, self.econfig, self.comm1)

        self.cv0 = { 'color_spec' : "", 'value' : 100 }
        self.cv1 = { 'color_spec' : self.color_spec, 'value' : 200 }
        self.offer0 = MyEOffer(None, self.cv0, self.cv1)
        self.offer1 = MyEOffer(None, self.cv1, self.cv0)
开发者ID:F483,项目名称:ngcccbase,代码行数:24,代码来源:test_agent.py


示例18: Ngccc

class Ngccc(apigen.Definition):
    """Next-Generation Colored Coin Client interface."""

    def __init__(self, wallet=None, testnet=False):

        # sanitize inputs
        testnet = sanitize.flag(testnet)

        if not wallet:
            wallet = "%s.wallet" % ("testnet" if testnet else "mainnet")
        self.wallet = PersistentWallet(wallet, testnet)
        self.model_is_initialized = False

    def __getattribute__(self, name):
        if name in ['controller', 'model']:
            if not self.model_is_initialized:
                self.wallet.init_model()
                self.model = self.wallet.get_model()
                self.controller = WalletController(self.model)
                slef.model_is_initialized = True
        return object.__getattribute__(self, name)


    @apigen.command()
    def setconfigval(self, key, value): # FIXME behaviour ok?
        """Sets a value in the configuration.
        Key is expressed as: key.subkey.subsubkey
        """

        # sanitize inputs
        key = sanitize.cfgkey(key)
        value = sanitize.cfgvalue(value)

        kpath = key.split('.')
        value = json.loads(value)

        # traverse the path until we get to the value we need to set
        if len(kpath) > 1:
            branch = self.wallet.wallet_config[kpath[0]]
            cdict = branch
            for k in kpath[1:-1]:
                cdict = cdict[k]
            cdict[kpath[-1]] = value
            value = branch
        if kpath[0] in self.wallet.wallet_config:
            self.wallet.wallet_config[kpath[0]] = value
        else:
            raise KeyNotFound(key)

    @apigen.command()
    def getconfigval(self, key):
        """Returns the value for a given key in the config.
        Key is expressed as: key.subkey.subsubkey
        """

        # sanitize inputs
        key = sanitize.cfgkey(key)

        if not key:
            raise KeyNotFound(key)
        keys = key.split('.')
        config = self.wallet.wallet_config
        # traverse the path until we get the value
        for key in keys:
            config = config[key]
        return _print(config)

    @apigen.command()
    def dumpconfig(self):
        """Returns a dump of the current configuration."""
        dict_config = dict(self.wallet.wallet_config.iteritems())
        return _print(dict_config)

    @apigen.command()
    def importconfig(self, path): # FIXME what about subkeys and removed keys?
        """Import JSON config."""
        with open(path, 'r') as fp:
            config = json.loads(fp.read())
            wallet_config = self.wallet.wallet_config
            for k in config:
                wallet_config[k] = config[k]

    @apigen.command()
    def issueasset(self, moniker, quantity, unit="100000000", scheme="epobc"):
        """ Issue <quantity> of asset with name <moniker> and <unit> atoms,
        based on <scheme (epobc|obc)>."""

        # sanitize inputs
        moniker = sanitize.moniker(moniker)
        quantity = sanitize.quantity(quantity)
        unit = sanitize.unit(unit)
        scheme = sanitize.scheme(scheme)

        self.controller.issue_coins(moniker, scheme, quantity, unit)
        return self.getasset(moniker)

    @apigen.command()
    def addassetjson(self, data):
        """Add a json asset definition.
        Enables the use of colors/assets issued by others.
#.........这里部分代码省略.........
开发者ID:killerstorm,项目名称:ngcccbase,代码行数:101,代码来源:api.py


示例19: TestEWalletController

class TestEWalletController(unittest.TestCase):

    def setUp(self):
        self.pwallet = PersistentWallet(None, True)
        self.pwallet.init_model()
        self.model = self.pwallet.get_model()
        adm = self.model.get_asset_definition_manager()

        # make sure you have the asset 'testobc' in your testnet.wallet !!
        self.asset = adm.get_asset_by_moniker('testobc')
        self.color_spec = self.asset.get_color_set().get_data()[0]

        self.wc = WalletController(self.model)
        self.ewc = EWalletController(self.model, self.wc)

        def null(a):
            pass
        self.wc.publish_tx = null

    def test_resolve_color_spec(self):
        self.cd =self.ewc.resolve_color_spec('')
        self.assertRaises(KeyError, self.ewc.resolve_color_spec, 'nonexistent')
        self.assertTrue(isinstance(self.cd, ColorDefinition))
        self.assertEqual(self.cd.get_color_id(), 0)

    def test_select_inputs(self):
        cv = SimpleColorValue(colordef=UNCOLORED_MARKER, value=10000000000000)
        self.assertRaises(InsufficientFundsError, self.ewc.select_inputs, cv)
        
    def test_tx_spec(self):
        alice_cv = { 'color_spec' : self.color_spec, 'value' : 10 }
        bob_cv = { 'color_spec' : "", 'value' : 500 }
        alice_offer = MyEOffer(None, alice_cv, bob_cv)
        bob_offer = MyEOffer(None, bob_cv, alice_cv)
        bob_etx = self.ewc.make_etx_spec(bob_cv, alice_cv)
        self.assertTrue(isinstance(bob_etx, ETxSpec))
        for target in bob_etx.targets:
            # check address
            address = target[0]
            self.assertTrue(isinstance(address, type(u"unicode")))
            # TODO check address is correct format

            # check color_spec
            color_spec = target[1]
            self.assertTrue(isinstance(color_spec, type("str")))
            color_spec_parts = len(color_spec.split(":"))
            self.assertTrue(color_spec_parts == 4 or color_spec_parts == 1)

            # check value
            value = target[2]
            self.assertTrue(isinstance(value, type(10)))
        signed = self.ewc.make_reply_tx(bob_etx, alice_cv, bob_cv)
        self.assertTrue(isinstance(signed, RawTxSpec))

        self.ewc.publish_tx(signed, alice_offer)

        alice_etx = self.ewc.make_etx_spec(alice_cv, bob_cv)
        self.assertTrue(isinstance(alice_etx, ETxSpec))
        for target in alice_etx.targets:
            # check address
            address = target[0]
            self.assertTrue(isinstance(address, type(u"unicode")))
            # TODO check address is correct format

            # check color_spec
            color_spec = target[1]
            self.assertTrue(isinstance(color_spec, type("str")))
            color_spec_parts = len(color_spec.split(":"))
            self.assertTrue(color_spec_parts == 4 or color_spec_parts == 1)

            # check value
            value = target[2]
            self.assertTrue(isinstance(value, type(10)))
        signed = self.ewc.make_reply_tx(alice_etx, bob_cv, alice_cv)
        self.assertTrue(isinstance(signed, RawTxSpec))

        oets = OperationalETxSpec(self.model, self.ewc)
        oets.set_our_value_limit(bob_cv)
        oets.prepare_inputs(alice_etx)
        zero = SimpleColorValue(colordef=UNCOLORED_MARKER, value=0)
        self.assertRaises(ZeroSelectError, oets.select_coins, zero)
        toomuch = SimpleColorValue(colordef=UNCOLORED_MARKER, value=10000000000000)
        self.assertRaises(InsufficientFundsError, oets.select_coins, toomuch)
开发者ID:F483,项目名称:ngcccbase,代码行数:83,代码来源:test_ewctrl.py


示例20: Wallet

class Wallet(QtCore.QObject):
    balanceUpdated = QtCore.pyqtSignal(name='balanceUpdated')

    def __init__(self, dataDir, isTestNet):
        QtCore.QObject.__init__(self)

        self.lock = threading.Lock()

        self._patching_BaseTxDb()

        self.wallet_path = os.path.join(dataDir, 'wallet.sqlite')
        self._pwallet = PersistentWallet(self.wallet_path, isTestNet)
        self._set_wallet_settings(dataDir, isTestNet)
        self._pwallet.init_model()
        self._wallet = self._pwallet.get_model()
        self._controller = WalletController(self._wallet)
        self._utxo_fetcher = AsyncUTXOFetcher(
            self._wallet, self._pwallet.wallet_config.get('utxo_fetcher', {}))

        self._utxo_fetcher_timer = QtCore.QTimer()
        self._utxo_fetcher_timer.timeout.connect(self._utxo_fetcher.update)
        self._utxo_fetcher_timer.setInterval(1000)

        asset = self.get_asset_definition('bitcoin')
        if len(self._controller.get_all_addresses(asset)) == 0:
            self._controller.get_new_address(asset)

        self._create_club_asset()

    def _patching_BaseTxDb(self):
        original_add_tx = BaseTxDb.add_tx
        def new_add_tx(baseTxDb, txhash, txdata, raw_tx, *args, **kwargs):
            retval = original_add_tx(baseTxDb, txhash, txdata, raw_tx, *args, **kwargs)

            if retval:
                ctxs = raw_tx.composed_tx_spec
                coinStore = self._wallet.get_coin_manager().store
                all_addresses = [a.get_address() for a in
                    self._wallet.get_address_manager().get_all_addresses()]
                lookup_moniker_by_address = {}
                for asset in self._controller.get_all_assets():
                    monikers = asset.get_monikers()
                    for address in self._controller.get_all_addresses(asset):
                        lookup_moniker_by_address[address.get_address()] = monikers
                # txin
                for txin in ctxs.txins:
                    prev_txhash, prev_outindex = txin.get_outpoint()
                    coin_id = coinStore.find_coin(prev_txhash, prev_outindex)
                    if coin_id:
                        address = coinStore.get_coin(coin_id)['address']
                        self.balanceUpdated.emit()
                # txout
                for txout in ctxs.txouts:
                    target_addr = txout.target_addr
                    if target_addr in all_addresses:
                        self.balanceUpdated.emit()

            return retval
        BaseTxDb.add_tx = new_add_tx

    def _set_wallet_settings(self, dataDir, isTestNet):
        self._pwallet.wallet_config['testnet'] = isTestNet

        ccc = self._pwallet.wallet_config.get('ccc', {})
        ccc['colordb_path'] = os.path.join(dataDir, 'color_db.sqlite')
        self._pwallet.wallet_config['ccc'] = ccc

    def _create_club_asset(self):
        for asset in self._wallet.get_asset_definition_manager().get_all_assets():
            for color in asset.get_color_set().get_data():
                if color in clubAsset['color_set']:
                    return
        self._wallet.get_asset_definition_manager().add_asset_definition(clubAsset)
        asset = self.get_asset_definition(clubAsset['monikers'][0])
        if len(self._controller.get_all_addresses(asset)) == 0:
            self._controller.get_new_address(asset).get_color_address()

    def sync_start(self):
        self._utxo_fetcher.start_thread()
        self._utxo_fetcher_timer.start()

    def sync_stop(self):
        self._utxo_fetcher.stop()
        self._utxo_fetcher_timer.stop()

    def get_asset_definition(self, moniker):
        if isinstance(moniker, AssetDefinition):
            return moniker
        adm = self._wallet.get_asset_definition_manager()
        asset = adm.get_asset_by_moniker(moniker)
        if not asset:
            raise Exception("asset not found")
        return asset

    def get_address(self, moniker):
        asset = self.get_asset_definition(moniker)
        return self._controller.get_all_addresses(asset)[0].get_color_address()

    def get_bitcoin_address(self, moniker):
        asset = self.get_asset_definition(moniker)
#.........这里部分代码省略.........
开发者ID:fanatid,项目名称:chromaclub,代码行数:101,代码来源:wallet.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python config.get_ngeo_config函数代码示例发布时间:2022-05-27
下一篇:
Python utils.Utils类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap