Fixed problem with send-token command if address wasn't root wallet.
This commit is contained in:
parent
747e9e2006
commit
9be532714f
|
@ -11,7 +11,7 @@ from decimal import Decimal
|
||||||
from solana.publickey import PublicKey
|
from solana.publickey import PublicKey
|
||||||
from solana.rpc.types import TxOpts
|
from solana.rpc.types import TxOpts
|
||||||
from spl.token.client import Token
|
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(
|
sys.path.insert(0, os.path.abspath(
|
||||||
os.path.join(os.path.dirname(__file__), "..")))
|
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:
|
if account_info is None:
|
||||||
raise Exception(f"Could not find account at address {args.address}.")
|
raise Exception(f"Could not find account at address {args.address}.")
|
||||||
|
|
||||||
|
destination: PublicKey
|
||||||
if account_info.owner == mango.SYSTEM_PROGRAM_ADDRESS:
|
if account_info.owner == mango.SYSTEM_PROGRAM_ADDRESS:
|
||||||
# This is a root wallet account - get the token account to use.
|
# This is a root wallet account - get the token account to use.
|
||||||
destination: PublicKey = mango.TokenAccount.find_or_create_token_address_to_use(
|
destination = mango.TokenAccount.find_or_create_token_address_to_use(context, wallet, args.address, token)
|
||||||
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
|
owner = wallet.account
|
||||||
amount = int(args.quantity * Decimal(10 ** token.decimals))
|
amount = int(args.quantity * Decimal(10 ** token.decimals))
|
||||||
|
|
Loading…
Reference in New Issue