Skip to content

Commit

Permalink
fix: versions, update: docs
Browse files Browse the repository at this point in the history
  • Loading branch information
GitBolt committed Nov 16, 2024
1 parent cc146bd commit ce609b9
Show file tree
Hide file tree
Showing 12 changed files with 450 additions and 336 deletions.
46 changes: 43 additions & 3 deletions docs/pages/clients/client_async.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ import Callout from 'nextra-theme-docs/callout'
- [get_transaction](#get_transaction)
- [request_airdrop](#request_airdrop)
- [send_transaction](#send_transaction)
- [get_signature_statuses](#get_signature_statuses)
- [get_slot](#get_slot)


#### Attributes
Expand Down Expand Up @@ -394,10 +396,14 @@ Returns balance of tokens held in the specified token account.

<Code>
```python
def get_token_account_balance(public_key: PublicKey | str, **kwargs)
async def get_token_account_balance(token_account: PublicKey | str, commitment: Optional[Commitment]=None)
```
</Code>

Parameters:
- `token_account`: The public key of the token account
- `commitment` (optional): The level of commitment desired when querying state

Example:

<Code>
Expand All @@ -416,14 +422,17 @@ print(tokens)
</Code>

#### .get_transaction
Sends a request to the Solana RPC endpoint to retrieve a transaction by its signature.
Returns transaction details for a confirmed transaction signature.

<Code>
```python
async def get_transaction(self, signature: Text, commitment: Optional[Commitment]=None) -> RPCResponse[TransactionElementType] | TransactionElement
async def get_transaction(signature: Text) -> RPCResponse
```
</Code>

Parameters:
- `signature`: Transaction signature as base-58 encoded string

#### .request_airdrop
Requests the amount of lamport specified to be airdropped to the public key.

Expand Down Expand Up @@ -480,6 +489,37 @@ asyncio.run(main())
```
</Code>

#### .get_signature_statuses
Returns signature statuses for confirmed transactions that include the given address in their accountKeys list. Returns signatures backwards in time from the provided signature or most recent confirmed block

<Code>
```python
async def get_signature_statuses()
```
</Code>

#### .get_slot
Returns the current slot of the node.

<Code>
```python
async def get_slot()
```
</Code>

#### .build_and_send_request_async
Internal method used to construct and send RPC requests to the Solana network.

<Code>
```python
async def build_and_send_request_async(method: Text, params: List[Any]) -> RPCResponse
```
</Code>

Parameters:
- `method`: The RPC method name to call
- `params`: List of parameters to pass to the RPC method


## Attributes
#### .endpoint
Expand Down
42 changes: 29 additions & 13 deletions docs/pages/models/keypair.mdx
Original file line number Diff line number Diff line change
@@ -1,54 +1,70 @@
import { Code } from '/components/Code';

# Keypair
**Keypair is the combination of a public key and private key, any authorized action requires this.**
**Keypair is the combination of a public key and private key. It handles key generation, signing, and key management.**

<Code>
```python
class Keypair(value: NaclPrivateKey | None = None)
```
```python
class Keypair(value: NaclPrivateKey | None = None)
```
</Code>

> The value is required to initialise the object with an existing [nacl.Public.PrivateKey](https://pynacl.readthedocs.io/en/latest/public/#nacl.public.PrivateKey) object. To initialize with a private key as a string or bytes, use [from_private_key](#from_private_key) class method. Without the value a new keypair is generated.
> The value is optional. Without a value, a new keypair is generated. If provided, it must be a [nacl.public.PrivateKey](https://pynacl.readthedocs.io/en/latest/public/#nacl.public.PrivateKey) object. To initialize with a private key as a string or bytes, use [from_private_key](#from_private_key) class method.

#### Methods
- [sign](#sign)
- [from_private_key](#from_private_key)
- [from_file](#from_file)

#### Attributes
- [public_key](#public_key)
- [private_key](#private_key)
- [key_pair](#key_pair)


## Methods

#### .sign
Signs a message which can be either a string or bytes.
Signs a message using the keypair's private key.

<Code>
```python
def sign(message: str | bytes)
def sign(message: str | bytes) -> SignedMessage
```
</Code>

> Returns a SignedMessage object from PyNaCl. The message can be either a UTF-8 string or bytes.

#### .from_private_key
Initializes the keypair object using a private key, which can be either a string or bytes.
Class method that creates a Keypair from an existing private key.

<Code>
```python
@classmethod
def from_private_key(cls, private_key: str | List[int]) -> Keypair
```
</Code>

> Accepts either a base58-encoded string or a list of integers representing the private key. Returns a new Keypair instance.

#### .from_file
Class method that loads a Keypair from a JSON file containing the private key.

<Code>
```python
def from_private_key(private_key: str | bytes)
@staticmethod
def from_file(file_path: str) -> Keypair
```
</Code>

> Reads a JSON file containing the private key data and returns a new Keypair instance.

## Attributes

#### .public_key
Returns the keypair object's public key.
The keypair's public key as a PublicKey instance.

#### .private_key
Returns the keypair object's private key.
The keypair's private key as a PrivateKey instance.

#### .key_pair
Returns the keypair value itself in bytes.
The underlying NaclPrivateKey object used in bytes
2 changes: 1 addition & 1 deletion docs/pages/models/publickey.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Code } from '/components/Code';
```
</Code>

> The class requires one value argument to initialize which can be string, bytes, bytearray or int array form of the public key.
> The class requires one value argument to initialize which can be string, bytes, bytearray or int array form of the public key. The public key must be exactly 32 bytes in length.

#### Methods
- [base58_encode](#base58_encode)
Expand Down
24 changes: 13 additions & 11 deletions docs/pages/models/transaction/instructions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ from solathon.core.instructions import *

## Instructions
#### create_account
Creates a program account. When sending the transaction, both existing account and new account keypairs need to be passed in the signers argument of the `Transaction` object.
Creates a new program account. Both the funding account and new account must sign the transaction.

<Code>
```python
Expand All @@ -31,7 +31,7 @@ def create_account(
lamports: int,
space: int,
program_id: PublicKey
)
) -> Instruction
```
</Code>

Expand Down Expand Up @@ -64,7 +64,7 @@ print("Transaction response: ", result)
</Code>

#### create_account_with_seed
Creates a program account using seed
Creates a new program account at an address derived from a base public key and seed string.

<Code>
```python
Expand All @@ -76,12 +76,14 @@ def create_account_with_seed(
lamports: int,
space: int,
program_id: PublicKey
)
) -> Instruction
```
</Code>

> Note: If base_public_key is different from from_public_key, the base public key must also sign the transaction.

#### allocate
Allocates bytes for an account, this can only be used once for an account without any space already.
Allocates space in an account without transferring lamports.

<Code>
```python
Expand Down Expand Up @@ -117,7 +119,7 @@ print("Transaction response: ", result)
</Code>

#### allocate_with_seed
Allocates bytes for an account with seed.
Allocates space in an account at an address derived from a base public key and seed string.

<Code>
```python
Expand All @@ -127,19 +129,19 @@ def allocate_with_seed(
seed: str,
space: int,
program_id: PublicKey
)
) -> Instruction
```
</Code>

#### assign
Assigns an existing account to a program.
Assigns an account to a program.

<Code>
```python
def assign(
account_public_key: PublicKey,
program_id: PublicKey
)
) -> Instruction
```
</Code>

Expand Down Expand Up @@ -170,15 +172,15 @@ print("Transaction response: ", result)


#### transfer
Transfers lamports between accounts
Transfers lamports between accounts. The sender must sign the transaction.

<Code>
```python
def transfer(
from_public_key: PublicKey | str,
to_public_key: PublicKey | str,
lamports: int
)
) -> Instruction
```
</Code>

Expand Down
8 changes: 4 additions & 4 deletions docs/pages/models/transaction/transaction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { Code } from '/components/Code';
import Callout from 'nextra-theme-docs/callout'

# Transaction
**Class representing a transaction model. This object is passed in [send_transaction](/models/client#send_transaction) method**
**Class representing a Solana transaction. This object is used in [send_transaction](/models/client#send_transaction) method**

<Code>
```python
class Transaction(self, **config)
```
```python
class Transaction(**config)
```
</Code>

> A completely empty transaction can be initialized without any config, the table below shows the available config options
Expand Down
Loading

0 comments on commit ce609b9

Please sign in to comment.