Example #1
0
    def issue(self, amount, to, memo=None, **kwargs):
        """ Issue new shares of an asset

            :param float amount: Amount to issue
            :param str to: Recipient
            :param str memo: (optional) Memo message
        """
        from .memo import Memo
        from .account import Account

        to = Account(to)
        account = Account(self["issuer"])
        memoObj = Memo(from_account=account,
                       to_account=to,
                       blockchain_instance=self)

        # append operation
        op = operations.Asset_issue(
            **{
                "fee": {
                    "amount": 0,
                    "asset_id": "1.3.0",
                },  # Will be filled in automatically
                "issuer": account["id"],  # the Issuer account
                "asset_to_issue": {
                    "amount": int(amount * 10**self["precision"]),
                    "asset_id": self["id"],
                },
                "issue_to_account": to["id"],
                "memo": memoObj.encrypt(memo),
                "extensions": [],
            })
        return self.exbet.finalizeOp(op, self["issuer"], "active", **kwargs)
Example #2
0
 def test_asset_issue(self):
     message = "abcdefgABCDEFG0123456789"
     nonce = "5862723643998573708"
     pub = format(account.PrivateKey(wif).pubkey, prefix)
     encrypted_memo = memo.encode_memo(
         account.PrivateKey(wif),
         account.PublicKey(pub, prefix=prefix),
         nonce,
         message,
     )
     self.op = operations.Asset_issue(
         **{
             "fee": {
                 "amount": 0,
                 "asset_id": "1.3.0"
             },
             "issuer": "1.2.0",
             "asset_to_issue": {
                 "amount": 0,
                 "asset_id": "1.3.0"
             },
             "memo": {
                 "from": pub,
                 "to": pub,
                 "nonce": nonce,
                 "message": encrypted_memo,
             },
             "issue_to_account": "1.2.0",
             "extensions": [],
             "prefix": prefix,
         })
     self.cm = ("f68585abf4dce7c80457010e000000000000000000000000000"
                "00000000000000102c0ded2bc1f1305fb0faac5e6c03ee3a192"
                "4234985427b6167ca569d13df435cf02c0ded2bc1f1305fb0fa"
                "ac5e6c03ee3a1924234985427b6167ca569d13df435cf8c94d1"
                "9817945c5120fa5b6e83079a878e499e2e52a76a7739e9de409"
                "86a8e3bd8a68ce316cee50b210000012055139900ea2ae7db9d"
                "4ef0d5d4015d2d993d0590ad32662bda94daba74a5e13411aef"
                "4de6f847e9e4300e5c8c36aa8e5f9032d25fd8ca01abd58c7e9"
                "528677e4")
     self.doit()
Example #3
0
def issue_asset(inst,
                issue_to_account,
                to_issue_asset,
                amount,
                memo=None,
                account=None,
                **kwargs):
    """ issue_asset


       :param str account: the account to cancel
           to (defaults to ``default_account``)
   """
    if not account:
        if "default_account" in inst.config:
            account = inst.config["default_account"]
    if not account:
        raise ValueError("You need to provide an account")
    account = Account(account)

    if 'extensions' in kwargs:
        extensions = kwargs['extensions']
    else:
        extensions = Set([])
    print(extensions)
    asset_to_issue = {"amount": amount, "asset_id": to_issue_asset}
    kwargs = {
        'fee': {
            "amount": 0,
            "asset_id": "1.3.0"
        },
        'issuer': account["id"],
        'asset_to_issue': asset_to_issue,
        'issue_to_account': issue_to_account,
        'memo': memo,
        'extensions': extensions
    }

    op = operations.Asset_issue(**kwargs)

    return inst.finalizeOp(op, account, "active")
    def issue(self, amount: Decimal, address: str, memo: str = None, trigger_data=None) -> dict:
        """
        Issue (create/print) tokens to a given address/account, optionally specifying a memo if desired.
        The network transaction fee for issuance will be paid by the issuing account in BTS.

        Example - Issue 5.10 SGTK to @privex

            >>> s = BitsharesManager('SGTK')
            >>> s.issue(address='privex', amount=Decimal('5.10'))

        :param Decimal amount:      Amount of tokens to issue, as a Decimal
        :param address:             Account to issue the tokens to (which is also the issuer account)
        :param memo:                Optional memo for the issuance transaction
        :raises IssuerKeyError:     Cannot issue because we don't have authority to (missing key etc.)
        :raises TokenNotFound:      When the requested token `symbol` does not exist
        :raises AccountNotFound:    The requested account doesn't exist
        :raises ArithmeticError:    When the amount is lower than the lowest amount allowed by the token's precision
        :return dict: Result Information

        Format::

          {
              txid:str - Transaction ID - None if not known,
              coin:str - Symbol that was sent,
              amount:Decimal - The amount that was issued,
              fee:Decimal    - TX Fee that was taken from the amount (will be 0 if fee is in BTS rather than the issuing token),
              from:str       - The account/address the coins were issued from,
              send_type:str       - Should be statically set to "issue"
          }

        """
        asset_obj = self.get_asset_obj(self.symbol)
        if asset_obj is None:
            raise exceptions.TokenNotFound(f'Failed to issue because {self.symbol} is an invalid token symbol.')

        # trim input amount to the token's precision just to be safe
        str_amount = ('{0:.' + str(asset_obj['precision']) + 'f}').format(amount)
        amount = Decimal(str_amount)

        if not self.is_amount_above_minimum(amount, asset_obj['precision']):
            raise ArithmeticError(f'Failed to issue because {amount} is less than the minimum amount allowed for {self.symbol} tokens.')

        to_account = self.get_account_obj(address)
        if to_account is None:
            raise exceptions.AccountNotFound(f'Failed to issue because issuing account {address} could not be found.')

        amount_obj = Amount(str_amount, self.symbol, blockchain_instance=self.bitshares)

        try:
            # make sure we have the necessary private keys loaded (memo key for encrypting memo, active key for issuing coins)
            self.set_wallet_keys(address, [ 'memo', 'active' ])

            if memo is None:
                memo = ''
            memo_obj = Memo(from_account=to_account, to_account=to_account, blockchain_instance=self.bitshares)
            encrypted_memo = memo_obj.encrypt(memo)

            # construct the transaction - note that transaction fee for issuance will be paid in BTS, but we retain the
            # flexibility to add support for paying the fee in the issuing token if deemed necessary
            op = operations.Asset_issue(
                **{
                    "fee": {"amount": 0, "asset_id": "1.3.0"},
                    "issuer": to_account["id"],
                    "asset_to_issue": {"amount": int(amount_obj), "asset_id": amount_obj.asset["id"]},
                    "memo": encrypted_memo,
                    "issue_to_account": to_account["id"],
                    "extensions": [],
                    "prefix": self.bitshares.prefix,
                }
            )

            log.debug('doing token issuance - address[%s], amount[%s %s], memo[%s]', address, str_amount, self.symbol, memo)

            # broadcast the transaction
            self.bitshares.finalizeOp(op, to_account, "active")
            result = self.bitshares.broadcast()
        except KeyNotFound as e:
            raise exceptions.IssuerKeyError(str(e))
        except exceptions.AuthorityMissing as e:
            raise exceptions.IssuerKeyError(str(e))

        return {
            'txid': None,     # transaction ID is not readily available from the Bitshares API
            'coin': self.orig_symbol,
            'amount': self.get_decimal_from_amount(amount_obj),
            'fee': Decimal(0),     # fee is in BTS, not the issuing token
            'from': address,
            'send_type': 'issue'
        }