예제 #1
0
    def authorize(self, address):
        """
        Authorize the stake pool for the provided address and network. DecredError
        is raised on failure to authorize.

        Args:
            address (string): The base58-encoded pubkey address that the wallet
                uses to vote.
        """
        try:
            self.getPurchaseInfo()
            self.validate(address)
        except DecredError as e:
            # code 9 is address not set
            addressNotSet = (isinstance(self.err, dict) and "code" in self.err
                             and self.err["code"] == 9)
            if not addressNotSet:
                raise e

            # address is not set
            data = {"UserPubKeyAddr": address}
            res = tinyhttp.post(self.apiPath("address"),
                                data,
                                headers=self.headers(),
                                urlEncode=True)
            if resultIsSuccess(res):
                self.getPurchaseInfo()
                self.validate(address)
            else:
                raise DecredError("unexpected response from 'address': %s" %
                                  repr(res))
예제 #2
0
    def setVoteBits(self, voteBits):
        """
        Set the vote preference on the VotingServiceProvider.

        Returns:
            bool: True on success. DecredError raised on error.
        """
        data = {"VoteBits": voteBits}
        res = tinyhttp.post(self.apiPath("voting"),
                            data,
                            headers=self.headers(),
                            urlEncode=True)
        if resultIsSuccess(res):
            self.purchaseInfo.voteBits = voteBits
            return True
        raise DecredError("unexpected response from 'voting': %s" % repr(res))
예제 #3
0
 def post(self, data):
     return tinyhttp.post(self.getCallsignPath(),
                          data,
                          headers=POST_HEADERS)
예제 #4
0
def test_post(urlopen):
    urlopen("http://example.org/", b'{"a": "b"}', '{"c": "d"}')
    assert tinyhttp.post("http://example.org/", {"a": "b"}) == {"c": "d"}