Пример #1
0
    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()
Пример #2
0
    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
Пример #3
0
 def setUpClass(cls):
     import signal
     signal.signal(signal.SIGINT, signal.SIG_DFL)
     #cls.tempdir = tempfile.mkdtemp()
     cls.tempdir = '/path/to/folder'
     cls.pwallet = PersistentWallet(
         os.path.join(cls.tempdir, 'testnet.wallet'), True)
     cls.pwallet.init_model()
     cls.vbs = VerifierBlockchainState(cls.tempdir, ChromaBlockchainState())
Пример #4
0
    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())
Пример #5
0
    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)
    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)
Пример #7
0
    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', {}))
Пример #8
0
    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()
Пример #9
0
 def __getattribute__(self, name):
     if name in ['controller', 'model', 'wallet']:
         if name in self.data:
             return self.data[name]
         if name == 'wallet':
             wallet = PersistentWallet(self.args.get('wallet_path'),
                                       self.args.get('testnet'))
             self.data['wallet'] = wallet
             return wallet
         else:
             self.wallet.init_model()
             self.data['model'] = self.data['wallet'].get_model()
             self.data['controller'] = WalletController(self.data['model'])
             return self.data[name]
     return object.__getattribute__(self, name)
Пример #10
0
 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()
Пример #11
0
    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
Пример #12
0
    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"
Пример #13
0
    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)
Пример #14
0
    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)
Пример #15
0
 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"
Пример #16
0
    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)
Пример #17
0
 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)
Пример #18
0
 def command_import_config(self, **kwargs):
     """Special command for importing a JSON config.
     """
     pw = PersistentWallet(kwargs.get('wallet_path'), kwargs['path'])
Пример #19
0
    def setUp(self):
        self.path = ":memory:"
        self.pwallet = PersistentWallet(self.path)
        self.config = {
            'dw_master_key': 'test',
            'testnet': True,
            'ccc': {
                'colordb_path': self.path
            },
            'bip0032': False
        }
        self.pwallet.wallet_config = self.config
        self.pwallet.init_model()
        self.model = self.pwallet.get_model()
        self.colormap = self.model.get_color_map()

        self.colordesc0 = "obc:color0:0:0"
        self.colordesc1 = "obc:color1:0:0"
        self.colordesc2 = "obc:color2:0:0"

        # add some colordescs
        self.colorid0 = self.colormap.resolve_color_desc(self.colordesc0)
        self.colorid1 = self.colormap.resolve_color_desc(self.colordesc1)
        self.colorid2 = self.colormap.resolve_color_desc(self.colordesc2)

        self.colordef0 = OBColorDefinition(self.colorid0, {
            'txhash': 'color0',
            'outindex': 0
        })
        self.colordef1 = OBColorDefinition(self.colorid1, {
            'txhash': 'color1',
            'outindex': 0
        })
        self.colordef2 = OBColorDefinition(self.colorid2, {
            'txhash': 'color2',
            'outindex': 0
        })

        self.asset_config = {
            'monikers': ['blue'],
            'color_set': [self.colordesc0],
        }
        self.basset_config = {
            'monikers': ['bitcoin'],
            'color_set': [''],
        }
        self.asset = AssetDefinition(self.colormap, self.asset_config)
        self.basset = AssetDefinition(self.colormap, self.basset_config)
        self.basic = BasicTxSpec(self.model)
        self.bbasic = BasicTxSpec(self.model)

        wam = self.model.get_address_manager()
        self.address0 = wam.get_new_address(self.asset.get_color_set())
        self.addr0 = self.address0.get_address()

        self.bcolorset = ColorSet(self.colormap, [''])
        self.baddress = wam.get_new_address(self.bcolorset)
        self.baddr = self.baddress.get_address()

        self.assetvalue0 = AdditiveAssetValue(asset=self.asset, value=5)
        self.assetvalue1 = AdditiveAssetValue(asset=self.asset, value=6)
        self.assetvalue2 = AdditiveAssetValue(asset=self.asset, value=7)
        self.bassetvalue = AdditiveAssetValue(asset=self.basset, value=8)
        self.assettarget0 = AssetTarget(self.addr0, self.assetvalue0)
        self.assettarget1 = AssetTarget(self.addr0, self.assetvalue1)
        self.assettarget2 = AssetTarget(self.addr0, self.assetvalue2)
        self.bassettarget = AssetTarget(self.baddr, self.bassetvalue)

        self.atargets = [
            self.assettarget0, self.assettarget1, self.assettarget2
        ]

        # add some targets
        self.colorvalue0 = SimpleColorValue(colordef=self.colordef0, value=5)
        self.colortarget0 = ColorTarget(self.addr0, self.colorvalue0)
        self.colorvalue1 = SimpleColorValue(colordef=self.colordef0, value=6)
        self.colortarget1 = ColorTarget(self.addr0, self.colorvalue1)
        self.colorvalue2 = SimpleColorValue(colordef=self.colordef0, value=7)
        self.colortarget2 = ColorTarget(self.addr0, self.colorvalue2)
        self.bcolorvalue = SimpleColorValue(colordef=UNCOLORED_MARKER, value=8)
        self.bcolortarget = ColorTarget(self.baddr, self.bcolorvalue)

        self.targets = [
            self.colortarget0, self.colortarget1, self.colortarget2
        ]
        self.transformer = TransactionSpecTransformer(self.model, self.config)
        self.blockhash = '00000000c927c5d0ee1ca362f912f83c462f644e695337ce3731b9f7c5d1ca8c'
        self.txhash = '4fe45a5ba31bab1e244114c4555d9070044c73c98636231c77657022d76b87f7'
Пример #20
0
    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)