Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,14 @@ txs_in_pool: list[MoneroTx] = daemon.get_tx_pool() # get transactions in the poo

# create wallet from mnemonic phrase using Python bindings to monero-project

wallet_config = MoneroWalletConfig()
wallet_config.path = "sample_wallet_full"
wallet_config.password = "supersecretpassword123"
wallet_config.network_type = MoneroNetworkType.STAGENET
wallet_config.server = MoneroRpcConnection("http://localhost:38081", "superuser", "abctesting123")
wallet_config.seed = "hefty value scenic..."
wallet_config.restore_height = 573936
wallet_config = MoneroWalletConfig(
path="sample_wallet_full",
password="supersecretpassword123",
network_type=MoneroNetworkType.STAGENET,
server=MoneroRpcConnection("http://localhost:38081", "superuser", "abctesting123"),
seed="hefty value scenic...",
restore_height=573936,
)
wallet_full: MoneroWallet = MoneroWalletFull.create_wallet(wallet_config)

listener: MoneroWalletListener = MyWalletListener()
Expand All @@ -83,11 +84,12 @@ balance: int = wallet_rpc.get_balance() # 533648366742
txs: list[MoneroTxWallet] = wallet_rpc.get_txs() # get transactions containing transfers to/from the wallet

# send funds from RPC wallet to full wallet
tx_config = MoneroTxConfig()
tx_config.account_index = 0
tx_config.address = wallet_full.get_address(1, 0)
tx_config.amount = 250000000000 # send 0.25 XMR (denominated in atomic units)
tx_config.relay = False # create transaction and relay to the network if true
tx_config = MoneroTxConfig(
account_index=0,
address=wallet_full.get_address(1, 0),
amount=250000000000, # send 0.25 XMR (denominated in atomic units)
relay=False, # create transaction and relay to the network if true
)

created_tx: MoneroTxWallet = wallet_rpc.create_tx(tx_config)
fee: int | None = created_tx.fee # "Are you sure you want to send... ?"
Expand Down
3 changes: 2 additions & 1 deletion bin/check_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ def main() -> int:
for diagnostic in report.get("generalDiagnostics", []):
if diagnostic["severity"] == "information":
continue
start: dict[str, int] = diagnostic["range"]["start"]
# one about a whole file, as a cycle of imports, has no range: it is of its first line, so VS Code lists it too
start: dict[str, int] = diagnostic["range"]["start"] if "range" in diagnostic else {"line": 0, "character": 0}
file: Path = Path(diagnostic["file"])
name: Path = file.relative_to(ROOT) if file.is_relative_to(ROOT) else file
message: str = " ".join(line.strip() for line in diagnostic["message"].splitlines())
Expand Down
3 changes: 1 addition & 2 deletions docs/mkdocs/docs/en/api/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ except MoneroError as e:
print(f"it failed: {e}")

# a method that a wallet does not support raises a MoneroError that says so
config = MoneroWalletConfig()
config.network_type = MoneroNetworkType.MAINNET
config = MoneroWalletConfig(network_type=MoneroNetworkType.MAINNET)
keys = MoneroWalletKeys.create_wallet_random(config)
try:
keys.get_height()
Expand Down
15 changes: 8 additions & 7 deletions docs/mkdocs/docs/en/api/wallet_full.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ and how depends on what the config has:
```python
from monero import MoneroNetworkType, MoneroRpcConnection, MoneroWalletConfig, MoneroWalletFull

config = MoneroWalletConfig()
config.path = "wallets/main"
config.password = "supersecretpassword123"
config.network_type = MoneroNetworkType.STAGENET
config.server = MoneroRpcConnection("http://localhost:38081")
config.seed = "hefty value scenic..."
config.restore_height = 573936 # the height to sync from: without it a restored wallet syncs from the first block
config = MoneroWalletConfig(
path="wallets/main",
password="supersecretpassword123",
network_type=MoneroNetworkType.STAGENET,
server=MoneroRpcConnection("http://localhost:38081"),
seed="hefty value scenic...",
restore_height=573936, # the height to sync from: without it a restored wallet syncs from the first block
)

wallet = MoneroWalletFull.create_wallet(config)
```
Expand Down
3 changes: 1 addition & 2 deletions docs/mkdocs/docs/en/api/wallet_keys.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ Each way of making it has its own function, which takes a [`MoneroWalletConfig`]
```python
from monero import MoneroNetworkType, MoneroWalletConfig, MoneroWalletKeys

config = MoneroWalletConfig()
config.network_type = MoneroNetworkType.MAINNET
config = MoneroWalletConfig(network_type=MoneroNetworkType.MAINNET)
wallet = MoneroWalletKeys.create_wallet_random(config)

print(wallet.get_seed())
Expand Down
9 changes: 5 additions & 4 deletions docs/mkdocs/docs/en/api/wallet_rpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ wallet = MoneroWalletRpc("http://localhost:38083", "rpc_user", "abc123")
wallet.open_wallet("main", "supersecretpassword123")

# or a new one, there: the config is the one of a full wallet, its path is the name of the wallet in the folder
config = MoneroWalletConfig()
config.path = "other"
config.password = "supersecretpassword123"
config.network_type = MoneroNetworkType.STAGENET
config = MoneroWalletConfig(
path="other",
password="supersecretpassword123",
network_type=MoneroNetworkType.STAGENET,
)
wallet.create_wallet(config)
```

Expand Down
33 changes: 18 additions & 15 deletions docs/mkdocs/docs/en/examples/basics/create_local_full_wallet.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ how it works.
```python
from monero import MoneroNetworkType, MoneroRpcConnection, MoneroWalletConfig, MoneroWalletFull

config = MoneroWalletConfig()
config.path = "test_wallet_full" # test_wallet_full and test_wallet_full.keys
config.password = "supersecretpassword123"
config.network_type = MoneroNetworkType.TESTNET
config.server = MoneroRpcConnection("http://localhost:28081")
config = MoneroWalletConfig(
path="test_wallet_full", # test_wallet_full and test_wallet_full.keys
password="supersecretpassword123",
network_type=MoneroNetworkType.TESTNET,
server=MoneroRpcConnection("http://localhost:28081"),
)

wallet = MoneroWalletFull.create_wallet(config)
print(wallet.get_seed()) # write it down: it is the wallet
Expand All @@ -27,13 +28,14 @@ print(wallet.get_seed()) # write it down: it is the w
```python
from monero import MoneroNetworkType, MoneroRpcConnection, MoneroWalletConfig, MoneroWalletFull

config = MoneroWalletConfig()
config.path = "restored_wallet"
config.password = "supersecretpassword123"
config.network_type = MoneroNetworkType.TESTNET
config.server = MoneroRpcConnection("http://localhost:28081")
config.seed = "...the 25 words..."
config.restore_height = 2500000 # a height before the first payment to the wallet
config = MoneroWalletConfig(
path="restored_wallet",
password="supersecretpassword123",
network_type=MoneroNetworkType.TESTNET,
server=MoneroRpcConnection("http://localhost:28081"),
seed="...the 25 words...",
restore_height=2500000, # a height before the first payment to the wallet
)

wallet = MoneroWalletFull.create_wallet(config)
wallet.sync()
Expand Down Expand Up @@ -72,9 +74,10 @@ A wallet with no `path` is not written to disk: its data are taken with
```python
from monero import MoneroNetworkType, MoneroWalletConfig, MoneroWalletFull

config = MoneroWalletConfig()
config.password = "supersecretpassword123"
config.network_type = MoneroNetworkType.TESTNET
config = MoneroWalletConfig(
password="supersecretpassword123",
network_type=MoneroNetworkType.TESTNET,
)
wallet = MoneroWalletFull.create_wallet(config)

keys_data: bytes = wallet.get_keys_file_buffer("supersecretpassword123", False)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ A new wallet, in the `--wallet-dir` of the server:
from monero import MoneroWalletConfig

# build wallet configuration
config = MoneroWalletConfig()
config.path = "wallet_name" # the name of its file, in the folder of the server
config.password = "wallet_password"
config = MoneroWalletConfig(
path="wallet_name", # the name of its file, in the folder of the server
password="wallet_password",
)

# create new wallet file in rpc server
wallet.create_wallet(config)
Expand Down
4 changes: 1 addition & 3 deletions docs/mkdocs/docs/en/examples/basics/multisig.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ def send(participants: list[MoneroWallet], m: int, address: str, amount: int) ->
share_multisig_info(participants)

# one participant creates the transaction, which is not signed enough to be relayed
config = MoneroTxConfig()
config.address = address
config.amount = amount
config = MoneroTxConfig(address=address, amount=amount)
tx = participants[0].create_tx(config)
assert tx.tx_set is not None and tx.tx_set.multisig_tx_hex is not None
tx_hex: str = tx.tx_set.multisig_tx_hex
Expand Down
3 changes: 1 addition & 2 deletions docs/mkdocs/docs/en/examples/basics/proofs_and_signatures.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ A message signed with an address proves that whoever signed it has the keys of t
```python
from monero import MoneroMessageSignatureType, MoneroNetworkType, MoneroWalletConfig, MoneroWalletKeys

config = MoneroWalletConfig()
config.network_type = MoneroNetworkType.MAINNET
config = MoneroWalletConfig(network_type=MoneroNetworkType.MAINNET)
wallet = MoneroWalletKeys.create_wallet_random(config)

message = "I am the owner of this address"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,16 @@ wallet = MoneroWalletRpc("http://wallet_rpc_uri:18083")
wallet.open_wallet("wallet_name", "wallet_password")

# create and setup a new tx query to filter txs with
query = MoneroTxQuery()

# fetch only outgoing txs
query.is_incoming = False
query.is_outgoing = True

# include outputs in tx data
query.include_outputs = True

# filter tx by height range
query.min_height = 150000
query.max_height = 300000
query = MoneroTxQuery(
# fetch only outgoing txs
is_incoming=False,
is_outgoing=True,
# include outputs in tx data
include_outputs=True,
# filter tx by height range
min_height=150000,
max_height=300000,
)

# fetch the txs that match the query
txs: list[MoneroTxWallet] = wallet.get_txs(query)
Expand All @@ -59,14 +57,13 @@ wallet = MoneroWalletRpc("http://wallet_rpc_uri:18083")
wallet.open_wallet("wallet_name", "wallet_password")

# create and setup a new transfer query
query = MoneroTransferQuery()

# fetch only incoming transfers
query.incoming = True

# filter by account and subaddress index
query.account_index = 1
query.subaddress_indices = [0, 1, 2, 3]
query = MoneroTransferQuery(
# fetch only incoming transfers
incoming=True,
# filter by account and subaddress index
account_index=1,
subaddress_indices=[0, 1, 2, 3],
)

# fetch the transfers that match the query
transfers: list[MoneroTransfer] = wallet.get_transfers(query)
Expand All @@ -81,10 +78,11 @@ Example of fetching the outputs of the wallet with a `MoneroOutputQuery`, the on
```python
from monero import MoneroOutputQuery, MoneroOutputWallet, MoneroUtils

query = MoneroOutputQuery()
query.is_spent = False
query.is_frozen = False
query.account_index = 0
query = MoneroOutputQuery(
is_spent=False,
is_frozen=False,
account_index=0,
)

outputs: list[MoneroOutputWallet] = wallet.get_outputs(query)
for output in outputs:
Expand Down
39 changes: 19 additions & 20 deletions docs/mkdocs/docs/en/examples/basics/sending_payments.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@ wallet = MoneroWalletRpc("http://wallet_rpc_uri:18083")
wallet.open_wallet("wallet_name", "wallet_password")

# create and setup transaction configuration
tx_config = MoneroTxConfig()

# specify source account index
tx_config.account_index = 0

# specify address and destination amount
tx_config.address = "...destination address..."
tx_config.amount = 1000000000

# relay tx to the network
tx_config.relay = True
tx_config = MoneroTxConfig(
# specify source account index
account_index=0,
# specify address and destination amount
address="...destination address...",
amount=1000000000,
# relay tx to the network
relay=True,
)

# create txs with configuration
txs: list[MoneroTxWallet] = wallet.create_txs(tx_config)
Expand All @@ -41,15 +39,16 @@ A transaction can pay more destinations at once, up to 15: a transaction has at
```python
from monero import MoneroDestination, MoneroTxConfig

batch = MoneroTxConfig()
batch.account_index = 0
batch.destinations = [
MoneroDestination("...destination address 1...", 1000000000),
MoneroDestination("...destination address 2...", 2500000000),
MoneroDestination("...destination address 3...", 500000000),
]
batch.can_split = True # more transactions, if one is not enough
batch.relay = True
batch = MoneroTxConfig(
account_index=0,
destinations=[
MoneroDestination("...destination address 1...", 1000000000),
MoneroDestination("...destination address 2...", 2500000000),
MoneroDestination("...destination address 3...", 500000000),
],
can_split=True, # more transactions, if one is not enough
relay=True,
)
txs = wallet.create_txs(batch)
```

Expand Down
23 changes: 11 additions & 12 deletions docs/mkdocs/docs/en/examples/basics/using_keys_only_wallet.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ A new wallet, with a random seed:
```python
from monero import MoneroNetworkType, MoneroWalletConfig, MoneroWalletKeys

config = MoneroWalletConfig()
config.network_type = MoneroNetworkType.TESTNET
config.language = "English" # the language of the words of the seed
config = MoneroWalletConfig(
network_type=MoneroNetworkType.TESTNET,
language="English", # the language of the words of the seed
)

wallet = MoneroWalletKeys.create_wallet_random(config)
print(wallet.get_seed())
Expand All @@ -26,9 +27,7 @@ The same wallet, restored from its seed:
```python
from monero import MoneroNetworkType, MoneroWalletConfig, MoneroWalletKeys

config = MoneroWalletConfig()
config.network_type = MoneroNetworkType.TESTNET
config.seed = "...wallet seed..."
config = MoneroWalletConfig(network_type=MoneroNetworkType.TESTNET, seed="...wallet seed...")

wallet = MoneroWalletKeys.create_wallet_from_seed(config)
```
Expand All @@ -38,10 +37,11 @@ Or from its keys: with the view key and no spend key it is a view-only wallet:
```python
from monero import MoneroNetworkType, MoneroWalletConfig, MoneroWalletKeys

config = MoneroWalletConfig()
config.network_type = MoneroNetworkType.TESTNET
config.primary_address = "...wallet primary address..."
config.private_view_key = "...wallet private view key..."
config = MoneroWalletConfig(
network_type=MoneroNetworkType.TESTNET,
primary_address="...wallet primary address...",
private_view_key="...wallet private view key...",
)

wallet = MoneroWalletKeys.create_wallet_from_keys(config)
print(wallet.is_view_only()) # True
Expand All @@ -52,8 +52,7 @@ print(wallet.is_view_only()) # True
```python
from monero import MoneroNetworkType, MoneroWalletConfig, MoneroWalletKeys

config = MoneroWalletConfig()
config.network_type = MoneroNetworkType.TESTNET
config = MoneroWalletConfig(network_type=MoneroNetworkType.TESTNET)
wallet = MoneroWalletKeys.create_wallet_random(config)

print(wallet.get_primary_address())
Expand Down
15 changes: 7 additions & 8 deletions docs/mkdocs/docs/en/examples/scenarios/accepting_payments.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ def new_order(wallet: MoneroWallet, order_id: str, price_xmr: float) -> tuple[Or
order = Order(order_id, MoneroUtils.xmr_to_atomic_units(price_xmr), subaddress.index, subaddress.address)

# monero:<address>?tx_amount=...&recipient_name=...&tx_description=...
request = MoneroTxConfig()
request.address = order.address
request.amount = order.amount
request.recipient_name = "The Shop"
request.note = f"order {order_id}"
request = MoneroTxConfig(
address=order.address,
amount=order.amount,
recipient_name="The Shop",
note=f"order {order_id}",
)
return order, wallet.get_payment_uri(request)
```

Expand Down Expand Up @@ -104,9 +105,7 @@ class Paid:

def amount_paid(wallet: MoneroWallet, order: Order) -> Paid:
"""What the order received, by state."""
query = MoneroTransferQuery()
query.account_index = ACCOUNT
query.subaddress_index = order.subaddress_index
query = MoneroTransferQuery(account_index=ACCOUNT, subaddress_index=order.subaddress_index)
transfers: list[MoneroIncomingTransfer] = wallet.get_incoming_transfers(query)

paid = Paid()
Expand Down
Loading
Loading