Ejemplo n.º 1
0
    def withdraw(self):
        """
        Withdraw voucher
        """
        message = otme.withdraw_voucher(
            self.server_id, self.sender_nym._id, self.sender_account._id,
            self.recipient_nym and self.recipient_nym._id or "", self.memo,
            self.amount)
        assert is_message_success(message)
        ledger = opentxs.OTAPI_Wrap_Message_GetLedger(message)
        transaction = opentxs.OTAPI_Wrap_Ledger_GetTransactionByIndex(
            self.server_id, self.sender_nym._id, self.sender_account._id,
            ledger, 0)
        output = opentxs.OTAPI_Wrap_Transaction_GetVoucher(
            self.server_id, self.sender_nym._id, self.sender_account._id,
            transaction)

        if output == '':
            raise ReturnValueError(output)

        self._body = output

        # save a copy for myself in outpayments box, so i can cancel later
        otme.send_user_payment(self.server_id, self.sender_nym._id,
                               self.sender_nym._id, output)

        return output
Ejemplo n.º 2
0
 def send(self, server_id=None, from_nym=None, to_nym=None):
     response = otme.send_user_msg(server_id or self.server_id,
                                   (from_nym and from_nym._id) or self.from_nym._id,
                                   (to_nym and to_nym._id) or self.to_nym._id,
                                   self.content)
     if response == "":
         raise ReturnValueError("Error sending message to {}".format(to_nym))
Ejemplo n.º 3
0
    def create(self):
        if self._id:
            raise ValueError("Can't create the same account twice,\
            to create an account of the same type, create a new Account object first."
                             )
        account_xml = otme.create_asset_acct(self.server_id, self.nym._id,
                                             self.asset._id)
        s = BeautifulSoup(account_xml)
        # new message name
        if s.registeraccountresponse:
            self._id = s.registeraccountresponse['accountid']

        # todo: old message name, remove in due time.
        elif s.createaccountresponse:
            self._id = s.createaccountresponse['accountid']

        else:
            raise ReturnValueError(
                "No account id present in response, account not created.")

        # set the name if any
        if self.name:
            opentxs.OTAPI_Wrap_SetAccountWallet_Name(self._id, self.nym._id,
                                                     self.name)
        return self
Ejemplo n.º 4
0
 def deposit(self, account, purse=None, nym=None, server_id=None):
     deposited = otme.deposit_cash(server_id or account.server_id,
                                   (nym and nym._id) or account.nym._id,
                                   account._id, purse or self.purse)
     if not deposited:
         raise ReturnValueError(
             "Unable to deposit cash: {} from {}.".format(
                 self.amount, account._id))
     return deposited
Ejemplo n.º 5
0
 def send(self, account, amount=None, nym=None, server_id=None):
     nym_id = (nym and nym._id) or account.nym._id
     server_id = server_id or account.server_id
     opentxs.OTAPI_Wrap_getMint(server_id, nym_id, account.asset._id)
     sent = otme.withdraw_and_send_cash(account._id, nym_id, amount
                                        or self.amount)
     if not sent:
         raise ReturnValueError("Unable to send cash: {} from {}.".format(
             self.amount, account._id))
     return sent
Ejemplo n.º 6
0
def get_all():
    """
    Return list of locally stored nyms.
    """
    nym_count = opentxs.OTAPI_Wrap_GetNymCount()
    nyms = []
    for i in range(nym_count):
        nym_id = opentxs.OTAPI_Wrap_GetNym_ID(i)
        if nym_id == '':
            # this is just a guess, a _id should never be an empty string
            raise ReturnValueError(nym_id)
        nyms.append(Nym(_id=nym_id))
    return nyms
Ejemplo n.º 7
0
    def withdraw(self, account, amount=None, nym=None, server_id=None):
        # get the public mint file on the client side
        nym_id = (nym and nym._id) or account.nym._id
        server_id = server_id or account.server_id
        opentxs.OTAPI_Wrap_getMint(server_id, nym_id, account.asset._id)

        self.purse = otme.withdraw_cash(server_id, nym_id, account._id, amount
                                        or self.amount)
        print("Withdrew cash: %s" % self.purse)
        if self.purse == '':
            raise ReturnValueError(
                "Unable to withdraw cash: {} from {}.".format(
                    amount or self.amount, account._id))
Ejemplo n.º 8
0
    def balance(self):
        """
        refresh local account files from server and return account balance
        """
        assert self._id, "Account must be created first."

        if hasattr(opentxs, 'OTAPI_Wrap_getAccountData'):  # new api name
            res = opentxs.OTAPI_Wrap_getAccountData(self.server_id, self.nym._id, self._id)
        else:  # todo: old api name, remove in due time
            res = opentxs.OTAPI_Wrap_getAccountFiles(self.server_id, self.nym._id, self._id)
        if res < 0:
            raise ReturnValueError(res)
        return opentxs.OTAPI_Wrap_GetAccountWallet_Balance(self._id)
Ejemplo n.º 9
0
 def delete(self):
     if hasattr(opentxs, 'OTAPI_Wrap_unregisterNym'):  # new api name
         deleted = opentxs.OTAPI_Wrap_unregisterNym(self.server_id,
                                                    self._id)
     elif hasattr(opentxs, 'OTAPI_Wrap_deleteNym'
                  ):  # todo: old api name, remove in due time
         deleted = opentxs.OTAPI_Wrap_deleteNym(self.server_id, self._id)
     else:  # todo: old api name, remove in due time
         deleted = opentxs.OTAPI_Wrap_deleteUserAccount(
             self.server_id, self._id)
     if deleted <= 0:
         raise ReturnValueError(
             "Unable to delete nym {}, return code {}".format(
                 self._id, deleted))
Ejemplo n.º 10
0
 def export(self, account, nym=None, amount=None):
     """Returns an exported cash purse string, which can be imported later.
        nym = the nym to export the cash to (encrypted to his public key)"""
     nym_id = (nym and nym._id) or account.nym._id
     withdrawn = otme.easy_withdraw_cash(account._id, amount or self.amount)
     if not withdrawn:
         raise ReturnValueError(
             "Unable to withdraw cash: {} from {}".format(
                 self.amount, account._id))
     purses = otme.export_cash(account.server_id, account.nym._id,
                               account.asset._id, nym_id, "0", False)
     self.purse = purses[0]
     self.backup_purse = purses[1]
     return self.purse
Ejemplo n.º 11
0
    def create(self):
        if self._id:
            raise ValueError("Can't create the same account twice,\
            to create an account of the same type, create a new Account object first.")
        account_xml = otme.create_asset_acct(self.server_id, self.nym._id, self.asset._id)
        if account_xml == "":
            raise ReturnValueError("Empty response, account not created.")

        self._id = opentxs.OTAPI_Wrap_Message_GetNewAcctID(account_xml)

        # set the name if any
        if self.name:
            opentxs.OTAPI_Wrap_SetAccountWallet_Name(self._id, self.nym._id, self.name)
        return self
Ejemplo n.º 12
0
    def create(self, keybits=1024, nym_id_source="", alt_location=""):
        """
        Create a new nym in the local wallet.

        Crashes with OT_FAIL if keysize is invalid.

        Returns the nym object
        """
        retval = otme.create_nym(keybits, nym_id_source, alt_location)

        if retval == '':
            # the nym id should be a 43-byte hash
            raise ReturnValueError(retval)
        self._id = retval
        return self
Ejemplo n.º 13
0
    def name(self):
        """
        Return the nym name for a given id.

        Attention: If the nym for the id cannot be found, an empty string is
        returned.
        """

        # FIXME: test and fix crash for empty _id
        # FIXME: discern between "empty name" and "nym not found"
        assert self._id, "Can't get name of an empty Nym'"
        nym_name = opentxs.OTAPI_Wrap_GetNym_Name(self._id)

        if nym_name == '':
            raise ReturnValueError(nym_name)

        return nym_name
Ejemplo n.º 14
0
 def set_name(self, name, signer_nym_id=None):
     success = opentxs.OTAPI_Wrap_SetNym_Name(self._id, signer_nym_id
                                              or self._id, name)
     if not success:
         raise ReturnValueError("Could not set nym name to {}")
Ejemplo n.º 15
0
def check(server, nym, target_nym):
    checked = otme.check_nym(server, nym, target_nym)
    if checked == "":
        raise ReturnValueError("Could not check nym {} as {}".format(
            target_nym, nym))