def _mint_to_args( self, dest: PublicKey, mint_authority: Union[Keypair, PublicKey], amount: int, multi_signers: Optional[List[Keypair]], opts: TxOpts, ) -> Tuple[Transaction, List[Keypair], TxOpts]: if isinstance(mint_authority, Keypair): owner_pubkey = mint_authority.public_key signers = [mint_authority] else: owner_pubkey = mint_authority signers = multi_signers if multi_signers else [] txn = Transaction().add( spl_token.mint_to( spl_token.MintToParams( program_id=self.program_id, mint=self.pubkey, dest=dest, mint_authority=owner_pubkey, amount=amount, signers=[signer.public_key for signer in signers], ) ) ) return txn, signers, opts
def test_mint_to(stubbed_reciever): """Test mint to.""" mint, mint_authority = PublicKey(0), PublicKey(1) params = spl_token.MintToParams( program_id=TOKEN_PROGRAM_ID, mint=mint, dest=stubbed_reciever, mint_authority=mint_authority, amount=123, ) instruction = spl_token.mint_to(params) assert spl_token.decode_mint_to(instruction) == params multisig_params = spl_token.MintToParams( program_id=TOKEN_PROGRAM_ID, mint=mint, dest=stubbed_reciever, mint_authority=mint_authority, signers=[PublicKey(i) for i in range(3, 10)], amount=123, ) instruction = spl_token.mint_to(multisig_params) assert spl_token.decode_mint_to(instruction) == multisig_params
def mint_to( self, dest: PublicKey, mint_authority: Union[Account, PublicKey], amount: int, multi_signers: Optional[List[Account]] = None, opts: TxOpts = TxOpts(), ) -> RPCResponse: """Mint new tokens. :param dest: Public key of the account to mint to. :param mint_authority: Public key of the minting authority. :param amount: Amount to mint. :param multi_signers: (optional) Signing accounts if `owner` is a multiSig. :param opts: (optional) Transaction options. If skip confirmation is set to `False`, this method will block for at most 30 seconds or until the transaction is confirmed. """ if isinstance(mint_authority, Account): owner_pubkey = mint_authority.public_key() signers = [mint_authority] else: owner_pubkey = mint_authority signers = multi_signers if multi_signers else [] txn = Transaction().add( spl_token.mint_to( spl_token.MintToParams( program_id=self.program_id, mint=self.pubkey, dest=dest, mint_authority=owner_pubkey, amount=amount, signers=[signer.public_key() for signer in signers], ) ) ) return self._conn.send_transaction(txn, *signers, opts=opts)