Esempio n. 1
0
    def showOfferByHash(self, offerhash):
        offerlist = self.listDict["offer"]
        identlist = self.listDict["ident"]
        taglist = self.listDict["tags"]
        offer = MM_util.searchlistbyhash(offerlist, offerhash)
        vendor = MM_util.searchlistbyhash(identlist, offer.obj['vendorid'])

        offername = offer.obj['name']
        ratio = offer.obj['ratio']
        locktime = time.asctime(time.localtime(offer.obj['locktime']))
        minrep = offer.obj['minrep']
        desc = offer.obj['description']
        tags = []
        for tag in offer.obj['tags']:
            tags.append(MM_util.searchlistbyhash(taglist, tag))

        self.showViewOfferDlg(offername, vendor, ratio, locktime, minrep, desc,
                              tags)
Esempio n. 2
0
    def login(self, retries=0):
        credentials = self.showLoginDlg()
        if not credentials:
            return

        self.username, self.passphrase = credentials

        hash = hashlib.sha256(self.passphrase).hexdigest()
        pkbytes = scrypt.hash(hash, self.username, N=2**18, buflen=32)
        self.pkstr = pycoin.serialize.b2h(pkbytes)
        se = long(self.pkstr, 16)
        pk = pycoin.key.Key(secret_exponent=se, netcode=self.netcode)

        self.wif = pk.wif()
        self.btcaddr = pk.address()
        try:
            self.bmaddr = MM_util.bm.getDeterministicAddress(
                base64.b64encode(self.pkstr), 4, 1)

            wp = self.input(
                "Please enter your Bitcoin Core wallet encryption passphrase:",
                password=True)
            if not wp:
                return
            MM_util.unlockwallet(wp)

            addrismine = MM_util.btcd.validateaddress(self.btcaddr)['ismine']
        except bitcoinrpc.authproxy.JSONRPCException as jre:
            if jre.error['code'] == -14:
                self.info(
                    "The passphrase was not correct. Please try logging in again."
                )
                return
        except socket.error:
            self.sockErr()
        except httplib.BadStatusLine:
            MM_util.reconnect_btcd(retries)
            return self.login(retries + 1)

        if MM_util.bm.createDeterministicAddresses(base64.b64encode(self.pkstr)) == [] \
            or not addrismine:
            if not self.importkeys():
                return

        myidstr = MM_util.createidentmsgstr(self.btcaddr, self.bmaddr,
                                            self.username)
        self.myid = MM_util.MM_loads(self.btcaddr, myidstr)

        identlist = self.listDict['ident'] = MM_util.loadlist('ident')
        if not MM_util.searchlistbyhash(identlist, self.myid.hash):
            if not self.register(myidstr):
                return

        self.info("You are now logged in as: %s" % self.username)
        self.loggedIn = True
        self.updateUi()
Esempio n. 3
0
    def on_identViewButton_clicked(self):
        selection = self.identTableWidget.selectedItems()
        if not selection:
            return

        identlist = self.listDict["ident"]
        identhash = str(selection[2].text())
        ident = MM_util.searchlistbyhash(identlist, identhash)

        self.showViewIdentDlg(ident.obj['name'], identhash,
                              ident.obj['btcaddr'], ident.obj['bmaddr'])
Esempio n. 4
0
    def on_offerOrderButton_clicked(self):
        selection = self.offerTableWidget.selectedItems()
        if not selection:
            return

        if not self.yorn("Are you sure?"):
            return

        offerlist = self.listDict["offer"]
        identlist = self.listDict["ident"]
        offer = MM_util.searchlistbyhash(offerlist, str(selection[4].text()))
        vendor = MM_util.searchlistbyhash(identlist, offer.obj['vendorid'])

        msgstr = MM_util.createorder( \
                    self.myid.hash, self.btcaddr, offer, self.pkstr, self.getFee() )
        hash = MM_util.MM_writefile(msgstr)
        MM_util.appendindex('order', hash)

        self.do_sendmsgviabm(vendor.obj['bmaddr'], msgstr)
        self.info("Order placed!")
Esempio n. 5
0
    def on_marketViewButton_clicked(self):
        selection = self.marketTableWidget.selectedItems()
        if not selection:
            return

        mktHash = str(selection[2].text())
        market = MM_util.searchlistbyhash(self.listDict["market"], mktHash)

        mktName = market.obj['marketname']
        regfee = market.obj['fee']
        burnmult = market.obj['multiplier']
        downvotemult = 0
        desc = market.obj['description']

        modident = MM_util.searchlistbyhash(self.listDict["ident"],
                                            market.obj['modid'])
        info = {"market": market, "modid": modident}
        mktjson = json.dumps(info, indent=4, sort_keys=True)

        self.showViewMarketDlg(mktName, regfee, burnmult, downvotemult, desc,
                               mktjson)
Esempio n. 6
0
    def on_orderCancelButton_clicked(self):
        selection = self.orderTableWidget.selectedItems()
        if not selection:
            return

        index = self.indexFromOrderStatus()
        prevmsg = MM_util.searchlistbyhash(self.listDict[index],
                                           str(selection[4].text()))

        conf = None
        order = None
        if index == 'order':
            order = prevmsg
            for ver in self.listDict['conf']:
                if ver.obj['orderhash'] == order.hash:
                    conf = ver
        elif index == 'conf':
            conf = prevmsg
            order = MM_util.searchlistbyhash(self.listDict['order'],
                                             conf.obj['orderhash'])

        if conf:
            for ver in self.listDict['pay']:
                if ver.obj['confhash'] == conf.hash:
                    self.info("We cannot cancel this Order, " + \
                                "as a Payment has already been sent.")
                    return

        if not self.yorn("Are you sure?"):
            return

        msgstr = MM_util.createcancel(self.myid.hash, self.btcaddr, \
                                    "buyer", self.listDict['conf'], order)

        hash = MM_util.MM_writefile(msgstr)
        MM_util.appendindex('cancel', hash)

        self.do_sendmsgviabm(vendor.obj['bmaddr'], msgstr)
        self.info("Order cancellation message sent to Vendor!")
Esempio n. 7
0
    def on_identBurnButton_clicked(self, amount=None):
        mod = MM_util.searchlistbyhash(self.listDict["ident"],
                                       self.currentMarket.obj['modid'])

        amount = self.value_input("How much BTC would you like to BURN?")
        if not amount or not self.yorn("Are you sure?"):
            return

        msgstr = MM_util.createburn( self.myid.hash, self.btcaddr, \
                            amount, self.getFee(), self.conf_wait, self.conf_end )

        hash = MM_util.MM_writefile(msgstr)
        MM_util.appendindex('burn', hash)

        self.do_sendmsgviabm(mod.obj['bmaddr'], msgstr)
        self.info("Proof of BURN sent!")
Esempio n. 8
0
    def on_identRegButton_clicked(self):
        if not self.yorn("Are you sure you would like to register your identity at %s?" \
                            % self.currentMarket.obj['markename']):
            return

        identlist = self.listDict['ident']
        mod = MM_util.searchlistbyhash(identlist,
                                       self.currentMarket.obj['modid'])
        amount = self.currentMarket.obj['fee']

        msgstr = MM_util.createreg( \
                    self.myid.hash, self.btcaddr, amount, mod, self.getFee() )
        hash = MM_util.MM_writefile(msgstr)
        MM_util.appendindex('reg', hash)

        self.do_sendmsgviabm(mod.obj['bmaddr'], msgstr)
        self.info("Registered!")
Esempio n. 9
0
    def on_orderProcessButton_clicked(self):
        selection = self.orderTableWidget.selectedItems()
        if not selection:
            return

        index = self.indexFromOrderStatus()
        prevmsg = MM_util.searchlistbyhash(self.listDict[index],
                                           str(selection[4].text()))
        offer = self.do_offerfromordermsg(prevmsg)
        vendor = MM_util.searchlistbyhash(self.listDict['ident'],
                                          prevmsg.obj['vendorid'])

        if index == 'conf':
            # Send pay based on this conf
            replyindex = 'pay'
            if not self.yorn("Are you sure?"):
                return

            for ver in self.listDict['pay']:
                if ver.obj['confhash'] == prevmsg.hash:
                    self.info("This Order is already Paid.")
                    return

            order = MM_util.searchlistbyhash(self.listDict['order'],
                                             prevmsg.obj['orderhash'])
            msgstr = MM_util.createpay(self.myid.hash, self.btcaddr, prevmsg,
                                       order, offer, self.getFee())

        elif index == 'rec':
            # Send final based on this rec
            replyindex = 'final'
            flag = self.yorn("Click Yes to Finalize this purchase, " + \
                                "or click No to collect the refund.")
            if not self.yorn("Are you sure?"):
                return

            for ver in self.listDict['final']:
                if ver.obj['rechash'] == prevmsg.hash:
                    self.info("This Order has already been Finalized.")
                    return

            price = decimal.Decimal(offer.obj['price'])
            msgstr = MM_util.createfinal(self.myid.hash, self.btcaddr, \
                                    flag, prevmsg, vendor, offer, price)

        elif index == 'final':
            # Send feedback based on this final
            replyindex = 'feedback'
            flag = self.yorn("Click Yes to give positive feedback on this purchase, " + \
                                "or click No to give negative feedback.")
            if not self.yorn("Are you sure?"):
                return

            for ver in self.listDict['feedback']:
                if ver.obj['finalhash'] == prevmsg.hash:
                    self.info("You've already given feedback on this Order.")
                    return

            message = self.input("Leave a message with your feedback.")
            order = None
            for ver in self.listDict['order']:
                if ver.obj['offerhash'] == offer.hash:
                    order = ver
                    break
            msgstr = MM_util.createfeedback(self.btcaddr, \
                                    "buyer", flag, message, prevmsg, offer, order)

        else:
            self.info("Buyers cannot process this type of message.")
            return

        hash = MM_util.MM_writefile(msgstr)
        MM_util.appendindex(replyindex, hash)

        self.do_sendmsgviabm(vendor.obj['bmaddr'], msgstr)
        self.info("Message sent to Vendor!")