Fixed problem with send-token command if address wasn't root wallet.

This commit is contained in:
Geoff Taylor 2021-10-08 17:29:06 +01:00
parent 747e9e2006
commit 9be532714f
1 changed files with 8 additions and 3 deletions

View File

@ -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))