From 9be532714f214efbb2949a6a235f36461f22c46c Mon Sep 17 00:00:00 2001 From: Geoff Taylor Date: Fri, 8 Oct 2021 17:29:06 +0100 Subject: [PATCH] Fixed problem with send-token command if address wasn't root wallet. --- bin/send-token | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/bin/send-token b/bin/send-token index a172fc3..b8f29ec 100755 --- a/bin/send-token +++ b/bin/send-token @@ -11,7 +11,7 @@ from decimal import Decimal from solana.publickey import PublicKey from solana.rpc.types import TxOpts from spl.token.client import Token -from spl.token.constants import TOKEN_PROGRAM_ID +from spl.token.constants import ACCOUNT_LEN, TOKEN_PROGRAM_ID sys.path.insert(0, os.path.abspath( os.path.join(os.path.dirname(__file__), ".."))) @@ -51,10 +51,15 @@ account_info: typing.Optional[mango.AccountInfo] = mango.AccountInfo.load(contex if account_info is None: raise Exception(f"Could not find account at address {args.address}.") +destination: PublicKey if account_info.owner == mango.SYSTEM_PROGRAM_ADDRESS: # This is a root wallet account - get the token account to use. - destination: PublicKey = mango.TokenAccount.find_or_create_token_address_to_use( - context, wallet, args.address, token) + destination = mango.TokenAccount.find_or_create_token_address_to_use(context, wallet, args.address, token) +elif account_info.owner == mango.TOKEN_PROGRAM_ID and len(account_info.data) == ACCOUNT_LEN: + # This is not a root wallet account, this is an SPL token account. + destination = args.address +else: + raise Exception(f"Account {args.address} is neither a root wallet account nor an SPL token account.") owner = wallet.account amount = int(args.quantity * Decimal(10 ** token.decimals))