Ejemplo n.º 1
0
 def load(self):
     """Load masternodes from wallet storage."""
     masternodes = self.wallet.storage.get('masternodes', {})
     self.masternodes = [MasternodeAnnounce.from_dict(d) for d in masternodes.values()]
     proposals = self.wallet.storage.get('budget_proposals', {})
     self.proposals = [BudgetProposal.from_dict(d) for d in proposals.values()]
     self.budget_votes = [BudgetVote.from_dict(d) for d in self.wallet.storage.get('budget_votes', [])]
Ejemplo n.º 2
0
 def newmasternode(self, alias):
     """Create a new masternode."""
     try:
         self.masternode_manager.add_masternode(MasternodeAnnounce(alias=alias))
         return 'Added new masternode "%s".' % alias
     except Exception as e:
         return 'Error: %s' % str(e)
Ejemplo n.º 3
0
    def import_masternode_conf_lines(self, conf_lines, password):
        """Import a list of MasternodeConfLine."""
        def already_have(line):
            for masternode in self.masternodes:
                # Don't let aliases collide.
                if masternode.alias == line.alias:
                    return True
                # Don't let outputs collide.
                if masternode.vin.get('prevout_hash') == line.txid and masternode.vin.get('prevout_n') == line.output_index:
                    return True
            return False

        num_imported = 0
        for conf_line in conf_lines:
            if already_have(conf_line):
                continue
            # Import delegate WIF key for signing last_ping.
            self.import_masternode_delegate(conf_line.wif)
            public_key = bitcoin.public_key_from_private_key(conf_line.wif)

            addr = conf_line.addr.split(':')
            addr = NetworkAddress(ip=addr[0], port=int(addr[1]))
            vin = {'prevout_hash': conf_line.txid, 'prevout_n': conf_line.output_index}
            mn = MasternodeAnnounce(alias=conf_line.alias, vin=vin,  
                    delegate_key = public_key, addr=addr)
            self.add_masternode(mn)
            try:
                self.populate_masternode_output(mn.alias)
            except Exception as e:
                print_error(str(e))
            num_imported += 1

        return num_imported