Skip to content

Commit

Permalink
Merge branch 'master' into amm
Browse files Browse the repository at this point in the history
  • Loading branch information
khancode committed Jul 10, 2023
2 parents 31aee69 + 4fc8c36 commit 259f60a
Show file tree
Hide file tree
Showing 107 changed files with 1,679 additions and 1,251 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/snippet_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Snippets

on:
push:
branches: [ master ]
pull_request:
workflow_dispatch:

env:
POETRY_VERSION: 1.4.2

jobs:
snippet-test:
name: Snippet test
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Load cached .local
id: cache-poetry
uses: actions/cache@v3
with:
path: /home/runner/.local
key: dotlocal-${{ env.POETRY_VERSION }}

- name: Install poetry
if: steps.cache-poetry.outputs.cache-hit != 'true'
run: |
curl -sSL https://install.python-poetry.org/ | python - --version ${{ env.POETRY_VERSION }}
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Install Python + Retrieve Poetry dependencies from cache
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'poetry'

- name: Display Python version
run: |
python -c "import sys; print(sys.version)"
- name: Install poetry dependencies
run: poetry install


- name: Run Snippets
run: (for i in snippets/*.py; do echo "Running $i" && poetry run python $i || exit 1; done)
12 changes: 6 additions & 6 deletions .github/workflows/unit_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Unit test

on:
push:
branches: [ master ]
branches: [master]
pull_request:
workflow_dispatch:

Expand Down Expand Up @@ -38,7 +38,7 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: 'poetry'
cache: "poetry"

- name: Display Python version
run: |
Expand All @@ -49,18 +49,18 @@ jobs:

- name: Lint
run: |
poetry run flake8 xrpl tests --darglint-ignore-regex="^_(.*)"
poetry run flake8 xrpl tests snippets --darglint-ignore-regex="^_(.*)"
- name: Type-check
run: |
poetry run mypy --strict --implicit-reexport xrpl
poetry run mypy --strict --implicit-reexport xrpl snippets
unit-test:
name: Unit test
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]

steps:
- name: Checkout code
Expand All @@ -83,7 +83,7 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'poetry'
cache: "poetry"

- name: Display Python version
run: |
Expand Down
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
"aiounittest",
"altnet",
"asyncio",
"autofills",
"binarycodec",
"keypair",
"keypairs",
"multisign",
"nftoken",
"rippletest",
"ripplex",
Expand Down
45 changes: 44 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,60 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [[Unreleased]]

## [2.0.0] - 2023-07-05
### Added:
- Wallet support for regular key compatibility
- Added new ways of wallet generation: `from_seed`, `from_secret`, `from_entropy`, `from_secret_numbers`
- Added `address` alias to `Wallet.classic_address`
- Replaced `Wallet.classic_address` with `Wallet.address` to avoid confusion. (`classic_address` is the same as your XRPL account `address`, and is only called classic since it's an older standard than `x-address`)
- Added `network_id` to clients in order to use the `Client` with networks beyond mainnet

### Changed:
- Updated params for `Wallet` class constructor
- `Wallet.address` is now readonly
- Removed `sequence` from `Wallet` class
- Core keypairs generate seed must take in hexstring instead of bytestring
- Core keypairs formatting for `ED25519` is now padded with zeros if length of keystring is less than 64
- Removed deprecated request wrappers (the preferred method is to directly do client.request instead)
- `AccountSetFlagInterface` now operates on transaction `tf` flags (as opposed to `asf` flags)
- `sign` is now synchronous instead of async (done by removing the optional `check_fee` param & moving checks up to other functions)
- In order to be internally consistent, all signing/submitting functions will follow the parameter order of `transaction`, `client`, `wallet`, and then other parameters. (This is because `wallet` is optional for `submit_and_wait` and so must come after `client`)
- `XRP.to_amount` now converts from XRP to drops, instead of expecting a drops amount

### Fixed:
- Added a sort of the account IDs in `multisign`, so that the `multisign` always works.
- Add `ledger_hash` and `ledger_index` to `account_nfts`, `nft_buy_offers`, and `nft_sell_offers` requests.
- Add `nft_page` to `ledger_entry` request.

### Removed:
- `send_reliable_submission` has been replaced by `submit_and_wait`
- Longer aliases for signing/submitting functions have been removed. Specifically
- `submit_transaction` is now `submit`
- `safe_sign_transaction` is now `sign`
- `safe_sign_and_submit_transaction` is now `sign_and_submit`
- The param order for `sign_and_submit` moves `wallet` after `client` to be consistent with `submit_and_wait`
- `safe_sign_and_autofill_transaction` is now `autofill_and_sign`
- The param order for `autofill_and_sign` moves `wallet` after `client` to be consistent with `submit_and_wait`
- Removed deprecated request functions which were just wrappers around `Client.request()`. Specifically this includes:
- `get_account_info`
- `get_account_transactions`
- `get_account_payment_transactions`
- `get_transaction_from_hash`

## [1.9.0] - 2023-06-13
### Added:
- Added `submit_and_wait` to sign (if needed), autofill, submit a transaction and wait for its final outcome
- `submit` and `send_reliable_submission` now accept an optional boolean param `fail_hard` (if `True` halt the submission if it's not immediately validated)
- Added sidechain devnet support to faucet generation
- Added `user_agent` and `usage_context` to `generate_faucet_wallet`

### Changed:
- Allowed keypairs.sign to take a hex string in addition to bytes

### Fixed:
- Refactored `does_account_exist` and `get_balance` to avoid deprecated methods and use `ledger_index` parameter
- Fixed crashes in the SignerListSet validation
- Fixed crashes in the `SignerListSet` validation
- Improved error messages in `send_reliable_submission`
- Better error handling in reliable submission

Expand Down
45 changes: 20 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ test_wallet = generate_faucet_wallet(client)
print(test_wallet)
public_key: ED3CC1BBD0952A60088E89FA502921895FC81FBD79CAE9109A8FE2D23659AD5D56
private_key: -HIDDEN-
classic_address: rBtXmAdEYcno9LWRnAGfT9qBxCeDvuVRZo
address: rBtXmAdEYcno9LWRnAGfT9qBxCeDvuVRZo

# look up account info
from xrpl.models.requests.account_info import AccountInfo
from xrpl.models import AccountInfo
acct_info = AccountInfo(
account="rBtXmAdEYcno9LWRnAGfT9qBxCeDvuVRZo",
ledger_index="current",
Expand Down Expand Up @@ -103,18 +103,18 @@ Use the [`xrpl.wallet`](https://xrpl-py.readthedocs.io/en/stable/source/xrpl.wal
To create a wallet from a seed (in this case, the value generated using [`xrpl.keypairs`](#xrpl-keypairs)):

```py
wallet_from_seed = xrpl.wallet.Wallet(seed, 0)
wallet_from_seed = xrpl.wallet.Wallet.from_seed(seed)
print(wallet_from_seed)
# pub_key: ED46949E414A3D6D758D347BAEC9340DC78F7397FEE893132AAF5D56E4D7DE77B0
# priv_key: -HIDDEN-
# classic_address: rG5ZvYsK5BPi9f1Nb8mhFGDTNMJhEhufn6
# address: rG5ZvYsK5BPi9f1Nb8mhFGDTNMJhEhufn6
```

To create a wallet from a Testnet faucet:

```py
test_wallet = generate_faucet_wallet(client)
test_account = test_wallet.classic_address
test_account = test_wallet.address
print("Classic address:", test_account)
# Classic address: rEQB2hhp3rg7sHj6L8YyR4GG47Cb7pfcuw
```
Expand Down Expand Up @@ -157,34 +157,33 @@ Use the [`xrpl.transaction`](https://xrpl-py.readthedocs.io/en/stable/source/xrp

* [`sign`](https://xrpl-py.readthedocs.io/en/stable/source/xrpl.transaction.html#xrpl.transaction.sign) — Signs a transaction locally. This method **does not** submit the transaction to the XRP Ledger.

* [`send_reliable_submission`](https://xrpl-py.readthedocs.io/en/stable/source/xrpl.transaction.html#xrpl.transaction.send_reliable_submission) — An implementation of the [reliable transaction submission guidelines](https://xrpl.org/reliable-transaction-submission.html#reliable-transaction-submission), this method submits a signed transaction to the XRP Ledger and then verifies that it has been included in a validated ledger (or has failed to do so). Use this method to submit transactions for production purposes.
* [`submit_and_wait`](https://xrpl-py.readthedocs.io/en/stable/source/xrpl.transaction.html#xrpl.transaction.submit_and_wait) — An implementation of the [reliable transaction submission guidelines](https://xrpl.org/reliable-transaction-submission.html#reliable-transaction-submission), this method submits a signed transaction to the XRP Ledger and then verifies that it has been included in a validated ledger (or has failed to do so). Use this method to submit transactions for production purposes.


```py
from xrpl.models.transactions import Payment
from xrpl.transaction import sign, send_reliable_submission
from xrpl.transaction import sign, submit_and_wait
from xrpl.ledger import get_latest_validated_ledger_sequence
from xrpl.account import get_next_valid_seq_number

current_validated_ledger = get_latest_validated_ledger_sequence(client)
wallet_sequence = get_next_valid_seq_number(test_wallet.classic_address, client)

# prepare the transaction
# the amount is expressed in drops, not XRP
# see https://xrpl.org/basic-data-types.html#specifying-currency-amounts
my_tx_payment = Payment(
account=test_wallet.classic_address,
account=test_wallet.address,
amount="2200000",
destination="rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe",
last_ledger_sequence=current_validated_ledger + 20,
sequence=wallet_sequence,
sequence=get_next_valid_seq_number(test_wallet.address, client),
fee="10",
)
# sign the transaction
my_tx_payment_signed = sign(my_tx_payment,test_wallet)

# submit the transaction
tx_response = send_reliable_submission(my_tx_payment_signed, client)
tx_response = submit_and_wait(my_tx_payment_signed, client)
```

#### Get fee from the XRP Ledger
Expand All @@ -205,19 +204,19 @@ The `xrpl-py` library automatically populates the `fee`, `sequence` and `last_le

```py
from xrpl.models.transactions import Payment
from xrpl.transaction import send_reliable_submission, autofill_and_sign
from xrpl.transaction import submit_and_wait, autofill_and_sign
# prepare the transaction
# the amount is expressed in drops, not XRP
# see https://xrpl.org/basic-data-types.html#specifying-currency-amounts
my_tx_payment = Payment(
account=test_wallet.classic_address,
account=test_wallet.address,
amount="2200000",
destination="rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe"
)

# sign the transaction with the autofill method
# (this will auto-populate the fee, sequence, and last_ledger_sequence)
my_tx_payment_signed = autofill_and_sign(my_tx_payment, test_wallet, client)
my_tx_payment_signed = autofill_and_sign(my_tx_payment, client, test_wallet)
print(my_tx_payment_signed)
# Payment(
# account='rMPUKmzmDWEX1tQhzQ8oGFNfAEhnWNFwz',
Expand All @@ -242,7 +241,7 @@ print(my_tx_payment_signed)
# )

# submit the transaction
tx_response = send_reliable_submission(my_tx_payment_signed, client)
tx_response = submit_and_wait(my_tx_payment_signed, client)
```


Expand All @@ -253,7 +252,7 @@ You can send `subscribe` and `unsubscribe` requests only using the WebSocket net
```py
from xrpl.clients import WebsocketClient
url = "wss://s.altnet.rippletest.net/"
from xrpl.models.requests import Subscribe, StreamParameter
from xrpl.models import Subscribe, StreamParameter
req = Subscribe(streams=[StreamParameter.LEDGER])
# NOTE: this code will run forever without a timeout, until the process is killed
with WebsocketClient(url) as client:
Expand All @@ -276,7 +275,7 @@ This sample code is the asynchronous equivalent of the above section on submitti
```py
import asyncio
from xrpl.models.transactions import Payment
from xrpl.asyncio.transaction import sign, send_reliable_submission
from xrpl.asyncio.transaction import sign, submit_and_wait
from xrpl.asyncio.ledger import get_latest_validated_ledger_sequence
from xrpl.asyncio.account import get_next_valid_seq_number
from xrpl.asyncio.clients import AsyncJsonRpcClient
Expand All @@ -285,24 +284,20 @@ async_client = AsyncJsonRpcClient(JSON_RPC_URL)

async def submit_sample_transaction():
current_validated_ledger = await get_latest_validated_ledger_sequence(async_client)
wallet_sequence = await get_next_valid_seq_number(test_wallet.classic_address, async_client)

# prepare the transaction
# the amount is expressed in drops, not XRP
# see https://xrpl.org/basic-data-types.html#specifying-currency-amounts
my_tx_payment = Payment(
account=test_wallet.classic_address,
account=test_wallet.address,
amount="2200000",
destination="rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe",
last_ledger_sequence=current_validated_ledger + 20,
sequence=wallet_sequence,
sequence=await get_next_valid_seq_number(test_wallet.address, async_client),
fee="10",
)
# sign the transaction
my_tx_payment_signed = await sign(my_tx_payment,test_wallet)

# submit the transaction
tx_response = await send_reliable_submission(my_tx_payment_signed, async_client)
# sign and submit the transaction
tx_response = await submit_and_wait(my_tx_payment_signed, async_client, test_wallet)

asyncio.run(submit_sample_transaction())
```
Expand Down
Loading

0 comments on commit 259f60a

Please sign in to comment.