Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Jonney/solana-py
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonney committed Dec 12, 2024
2 parents c19e661 + 40c753e commit 4cfba7c
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 1,112 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.35.1
current_version = 0.36.0
commit = True
tag = True

Expand Down
3 changes: 0 additions & 3 deletions docs/core/transaction.md

This file was deleted.

213 changes: 121 additions & 92 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "solana"
version = "0.35.1"
version = "0.36.0"
description = "Solana Python API"
authors = [
"Michael Huang <michaelhly@gmail.com>",
Expand Down Expand Up @@ -32,7 +32,7 @@ construct-typing = "^0.5.2"
httpx = ">=0.23.0"
typing-extensions = ">=4.2.0"
websockets = ">=9.0,<=12.0"
solders = "^0.21.0"
solders = "^0.23.0"

[tool.poetry.dev-dependencies]
pytest = "^7.4.3"
Expand Down
86 changes: 1 addition & 85 deletions src/solana/rpc/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@

from time import sleep, time
from typing import Dict, List, Optional, Sequence, Union
from warnings import warn

from solders.hash import Hash as Blockhash
from solders.keypair import Keypair
from solders.message import VersionedMessage
from solders.pubkey import Pubkey
from solders.rpc.responses import (
Expand Down Expand Up @@ -43,7 +40,6 @@
GetSignatureStatusesResp,
GetSlotLeaderResp,
GetSlotResp,
GetStakeActivationResp,
GetSupplyResp,
GetTokenAccountBalanceResp,
GetTokenAccountsByDelegateJsonParsedResp,
Expand All @@ -67,9 +63,8 @@
from solders.transaction import Transaction, VersionedTransaction

from solana.rpc import types
from solana.transaction import Transaction as LegacyTransaction

from .commitment import Commitment, Finalized
from .commitment import Commitment
from .core import (
_COMMITMENT_TO_SOLDERS,
RPCException,
Expand Down Expand Up @@ -765,29 +760,6 @@ def get_slot_leader(self, commitment: Optional[Commitment] = None) -> GetSlotLea
body = self._get_slot_leader_body(commitment)
return self._provider.make_request(body, GetSlotLeaderResp)

def get_stake_activation(
self,
pubkey: Pubkey,
epoch: Optional[int] = None,
commitment: Optional[Commitment] = None,
) -> GetStakeActivationResp:
"""Returns epoch activation information for a stake account.
Args:
pubkey: Pubkey of stake account to query
epoch: (optional) Epoch for which to calculate activation details. If parameter not provided,
defaults to current epoch.
commitment: Bank state to query. It can be either "finalized", "confirmed" or "processed".
Example:
>>> solana_client = Client("http://localhost:8899")
>>> solana_client.get_stake_activation().value.active # doctest: +SKIP
124429280
"""
warn("get_stake_activation is deprecated. Use get_account_info instead.", DeprecationWarning, stacklevel=1)
body = self._get_stake_activation_body(pubkey, epoch, commitment)
return self._provider.make_request(body, GetStakeActivationResp)

def get_supply(self, commitment: Optional[Commitment] = None) -> GetSupplyResp:
"""Returns information about the current supply.
Expand Down Expand Up @@ -1003,62 +975,6 @@ def send_raw_transaction(self, txn: bytes, opts: Optional[types.TxOpts] = None)
post_send_args = self._send_raw_transaction_post_send_args(resp, opts_to_use)
return self.__post_send_with_confirm(*post_send_args)

def send_legacy_transaction(
self,
txn: LegacyTransaction,
*signers: Keypair,
opts: Optional[types.TxOpts] = None,
recent_blockhash: Optional[Blockhash] = None,
) -> SendTransactionResp:
"""Send a legacy transaction.
Args:
txn: transaction object.
signers: Signers to sign the transaction. Only supported for legacy Transaction.
opts: (optional) Transaction options.
recent_blockhash: (optional) Pass a valid recent blockhash here if you want to
skip fetching the recent blockhash or relying on the cache.
Only supported for legacy Transaction.
Example:
>>> from solders.keypair import Keypair
>>> from solders.pubkey import Pubkey
>>> from solana.rpc.api import Client
>>> from solders.system_program import TransferParams, transfer
>>> from solana.transaction import Transaction
>>> leading_zeros = [0] * 31
>>> sender, receiver = Keypair.from_seed(leading_zeros + [1]), Keypair.from_seed(leading_zeros + [2])
>>> txn = Transaction().add(transfer(TransferParams(
... from_pubkey=sender.pubkey(), to_pubkey=receiver.pubkey(), lamports=1000)))
>>> solana_client = Client("http://localhost:8899")
>>> solana_client.send_transaction(txn, sender).value # doctest: +SKIP
Signature(
1111111111111111111111111111111111111111111111111111111111111111,
)
"""
warn("send_legacy_transaction is deprecated. Use send_transaction instead.", DeprecationWarning, stacklevel=1)

last_valid_block_height = None
if recent_blockhash is None:
blockhash_resp = self.get_latest_blockhash(Finalized)
recent_blockhash = self.parse_recent_blockhash(blockhash_resp)
last_valid_block_height = blockhash_resp.value.last_valid_block_height

txn.recent_blockhash = recent_blockhash

txn.sign(*signers)
opts_to_use = (
types.TxOpts(
preflight_commitment=self._commitment,
last_valid_block_height=last_valid_block_height,
)
if opts is None
else opts
)

txn_resp = self.send_raw_transaction(txn.serialize(), opts=opts_to_use)
return txn_resp

def send_transaction(
self,
txn: Union[VersionedTransaction, Transaction],
Expand Down
83 changes: 1 addition & 82 deletions src/solana/rpc/async_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import asyncio
from time import time
from typing import Dict, List, Optional, Sequence, Union
from warnings import warn

from solders.hash import Hash as Blockhash
from solders.keypair import Keypair
from solders.message import VersionedMessage
from solders.pubkey import Pubkey
from solders.rpc.responses import (
Expand Down Expand Up @@ -42,7 +39,6 @@
GetSignatureStatusesResp,
GetSlotLeaderResp,
GetSlotResp,
GetStakeActivationResp,
GetSupplyResp,
GetTokenAccountBalanceResp,
GetTokenAccountsByDelegateJsonParsedResp,
Expand All @@ -65,9 +61,8 @@
from solders.transaction import Transaction, VersionedTransaction

from solana.rpc import types
from solana.transaction import Transaction as LegacyTransaction

from .commitment import Commitment, Finalized
from .commitment import Commitment
from .core import (
_COMMITMENT_TO_SOLDERS,
TransactionExpiredBlockheightExceededError,
Expand Down Expand Up @@ -776,29 +771,6 @@ async def get_slot_leader(self, commitment: Optional[Commitment] = None) -> GetS
body = self._get_slot_leader_body(commitment)
return await self._provider.make_request(body, GetSlotLeaderResp)

async def get_stake_activation(
self,
pubkey: Pubkey,
epoch: Optional[int] = None,
commitment: Optional[Commitment] = None,
) -> GetStakeActivationResp:
"""Returns epoch activation information for a stake account.
Args:
pubkey: Pubkey of stake account to query
epoch: (optional) Epoch for which to calculate activation details. If parameter not provided,
defaults to current epoch.
commitment: Bank state to query. It can be either "finalized", "confirmed" or "processed".
Example:
>>> solana_client = AsyncClient("http://localhost:8899")
>>> (await solana_client.get_stake_activation()).value.active # doctest: +SKIP
124429280
"""
warn("get_stake_activation is deprecated. Use get_account_info instead.", DeprecationWarning, stacklevel=1)
body = self._get_stake_activation_body(pubkey, epoch, commitment)
return await self._provider.make_request(body, GetStakeActivationResp)

async def get_supply(self, commitment: Optional[Commitment] = None) -> GetSupplyResp:
"""Returns information about the current supply.
Expand Down Expand Up @@ -1016,59 +988,6 @@ async def send_raw_transaction(self, txn: bytes, opts: Optional[types.TxOpts] =
post_send_args = self._send_raw_transaction_post_send_args(resp, opts_to_use)
return await self.__post_send_with_confirm(*post_send_args)

async def send_legacy_transaction(
self,
txn: LegacyTransaction,
*signers: Keypair,
opts: Optional[types.TxOpts] = None,
recent_blockhash: Optional[Blockhash] = None,
) -> SendTransactionResp:
"""Send a legacy transaction.
Args:
txn: transaction object.
signers: Signers to sign the transaction. Only supported for legacy Transaction.
opts: (optional) Transaction options.
recent_blockhash: (optional) Pass a valid recent blockhash here if you want to
skip fetching the recent blockhash or relying on the cache.
Only supported for legacy Transaction.
Example:
>>> from solders.keypair import Keypair
>>> from solders.system_program import TransferParams, transfer
>>> from solana.transaction import Transaction
>>> leading_zeros = [0] * 31
>>> sender, receiver = Keypair.from_seed(leading_zeros + [1]), Keypair.from_seed(leading_zeros + [2])
>>> txn = Transaction().add(transfer(TransferParams(
... from_pubkey=sender.pubkey(), to_pubkey=receiver.pubkey(), lamports=1000)))
>>> solana_client = AsyncClient("http://localhost:8899")
>>> (await solana_client.send_transaction(txn, sender)).value # doctest: +SKIP
Signature(
1111111111111111111111111111111111111111111111111111111111111111,
)
"""
warn("send_legacy_transaction is deprecated. Use send_transaction instead.", DeprecationWarning, stacklevel=1)

last_valid_block_height = None
if recent_blockhash is None:
blockhash_resp = await self.get_latest_blockhash(Finalized)
recent_blockhash = self.parse_recent_blockhash(blockhash_resp)
last_valid_block_height = blockhash_resp.value.last_valid_block_height

txn.recent_blockhash = recent_blockhash

txn.sign(*signers)
opts_to_use = (
types.TxOpts(
preflight_commitment=self._commitment,
last_valid_block_height=last_valid_block_height,
)
if opts is None
else opts
)
txn_resp = await self.send_raw_transaction(txn.serialize(), opts=opts_to_use)
return txn_resp

async def send_transaction(
self,
txn: Union[VersionedTransaction, Transaction],
Expand Down
Loading

0 comments on commit 4cfba7c

Please sign in to comment.