lineage-sdk 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lineage_sdk-1.0.0/LICENSE +21 -0
- lineage_sdk-1.0.0/MANIFEST.in +11 -0
- lineage_sdk-1.0.0/PKG-INFO +251 -0
- lineage_sdk-1.0.0/README.md +197 -0
- lineage_sdk-1.0.0/lineage/__init__.py +54 -0
- lineage_sdk-1.0.0/lineage/blockchain.py +288 -0
- lineage_sdk-1.0.0/lineage/config.py +181 -0
- lineage_sdk-1.0.0/lineage/constants.py +23 -0
- lineage_sdk-1.0.0/lineage/interfaces.py +295 -0
- lineage_sdk-1.0.0/lineage/key_handler.py +554 -0
- lineage_sdk-1.0.0/lineage/py.typed +1 -0
- lineage_sdk-1.0.0/lineage/transaction.py +417 -0
- lineage_sdk-1.0.0/lineage/utils/__init__.py +29 -0
- lineage_sdk-1.0.0/lineage/utils/general_utils.py +94 -0
- lineage_sdk-1.0.0/lineage/validators.py +312 -0
- lineage_sdk-1.0.0/lineage/wallet.py +1307 -0
- lineage_sdk-1.0.0/lineage_sdk.egg-info/PKG-INFO +251 -0
- lineage_sdk-1.0.0/lineage_sdk.egg-info/SOURCES.txt +36 -0
- lineage_sdk-1.0.0/lineage_sdk.egg-info/dependency_links.txt +1 -0
- lineage_sdk-1.0.0/lineage_sdk.egg-info/requires.txt +7 -0
- lineage_sdk-1.0.0/lineage_sdk.egg-info/top_level.txt +1 -0
- lineage_sdk-1.0.0/pyproject.toml +55 -0
- lineage_sdk-1.0.0/requirements-test.txt +5 -0
- lineage_sdk-1.0.0/requirements.txt +7 -0
- lineage_sdk-1.0.0/setup.cfg +4 -0
- lineage_sdk-1.0.0/setup.py +9 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Lineage Foundation
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
include LICENSE
|
|
2
|
+
include README.md
|
|
3
|
+
include requirements.txt
|
|
4
|
+
include requirements-test.txt
|
|
5
|
+
include lineage/py.typed
|
|
6
|
+
|
|
7
|
+
recursive-include lineage *.py
|
|
8
|
+
recursive-include lineage/utils *.py
|
|
9
|
+
recursive-exclude * __pycache__
|
|
10
|
+
recursive-exclude * *.py[cod]
|
|
11
|
+
recursive-exclude tests *
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: lineage-sdk
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Python SDK for interacting with the Lineage blockchain
|
|
5
|
+
Author-email: Lineage Foundation <info@lineage.foundation>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2026 Lineage Foundation
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://github.com/lineage-foundation/sdk-python
|
|
29
|
+
Project-URL: Documentation, https://github.com/lineage-foundation/sdk-python/tree/main/docs
|
|
30
|
+
Project-URL: Bug Tracker, https://github.com/lineage-foundation/sdk-python/issues
|
|
31
|
+
Keywords: blockchain,lineage,cryptocurrency
|
|
32
|
+
Classifier: Development Status :: 4 - Beta
|
|
33
|
+
Classifier: Intended Audience :: Developers
|
|
34
|
+
Classifier: Programming Language :: Python :: 3
|
|
35
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
36
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
37
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
39
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
40
|
+
Classifier: Operating System :: OS Independent
|
|
41
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
42
|
+
Classifier: Topic :: Security :: Cryptography
|
|
43
|
+
Requires-Python: >=3.8
|
|
44
|
+
Description-Content-Type: text/markdown
|
|
45
|
+
License-File: LICENSE
|
|
46
|
+
Requires-Dist: requests>=2.25.1
|
|
47
|
+
Requires-Dist: pynacl>=1.4.0
|
|
48
|
+
Requires-Dist: mnemonic>=0.20
|
|
49
|
+
Requires-Dist: typing-extensions>=4.0.0
|
|
50
|
+
Requires-Dist: base58>=2.1.1
|
|
51
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
52
|
+
Requires-Dist: bip32utils>=0.3.0
|
|
53
|
+
Dynamic: license-file
|
|
54
|
+
|
|
55
|
+
# Lineage Python SDK
|
|
56
|
+
|
|
57
|
+
Python SDK for interacting with the Lineage blockchain. This SDK provides a simple interface for wallet operations and blockchain queries.
|
|
58
|
+
|
|
59
|
+
## Installation
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
pip install lineage-sdk
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
The distribution is published as `lineage-sdk`; the import name is `lineage`:
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
import lineage
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Quick Start
|
|
72
|
+
|
|
73
|
+
### Basic Blockchain Queries
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
from lineage.blockchain import BlockchainClient
|
|
77
|
+
|
|
78
|
+
# Initialize blockchain client. api_key is optional and, when set, is sent
|
|
79
|
+
# as the x-api-key header on every request.
|
|
80
|
+
client = BlockchainClient(
|
|
81
|
+
storage_host='https://storage.aiblock.dev',
|
|
82
|
+
mempool_host='https://mempool.aiblock.dev',
|
|
83
|
+
api_key='your-api-key'
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
# Query blockchain
|
|
87
|
+
latest_block = client.get_latest_block()
|
|
88
|
+
if latest_block.is_ok:
|
|
89
|
+
print(f"Latest block: {latest_block.get_ok()['content']['block_num']}")
|
|
90
|
+
|
|
91
|
+
# Get specific block by number
|
|
92
|
+
block = client.get_block_by_num(1)
|
|
93
|
+
if block.is_ok:
|
|
94
|
+
print(f"Block 1: {block.get_ok()['content']}")
|
|
95
|
+
|
|
96
|
+
# Get blockchain entry by hash
|
|
97
|
+
entry = client.get_blockchain_entry('some_hash')
|
|
98
|
+
|
|
99
|
+
# Get transaction by hash
|
|
100
|
+
transaction = client.get_transaction_by_hash('tx_hash')
|
|
101
|
+
|
|
102
|
+
# Get multiple transactions
|
|
103
|
+
transactions = client.fetch_transactions(['hash1', 'hash2'])
|
|
104
|
+
|
|
105
|
+
# Get supply information (requires mempool host) - returns {total, issued}
|
|
106
|
+
total_supply = client.get_total_supply()
|
|
107
|
+
issued_supply = client.get_issued_supply()
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Wallet Operations
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
from lineage.wallet import Wallet
|
|
114
|
+
|
|
115
|
+
# Create wallet
|
|
116
|
+
wallet = Wallet()
|
|
117
|
+
|
|
118
|
+
# Generate seed phrase
|
|
119
|
+
seed_phrase = wallet.generate_seed_phrase()
|
|
120
|
+
print(f"Seed phrase: {seed_phrase}")
|
|
121
|
+
|
|
122
|
+
# Initialize wallet from seed. apiKey is optional and, when set, is sent
|
|
123
|
+
# as the x-api-key header on every mempool request.
|
|
124
|
+
config = {
|
|
125
|
+
'passphrase': 'your-secure-passphrase',
|
|
126
|
+
'mempoolHost': 'https://mempool.aiblock.dev',
|
|
127
|
+
'storageHost': 'https://storage.aiblock.dev',
|
|
128
|
+
'valenceHost': 'https://valence.aiblock.dev',
|
|
129
|
+
'apiKey': 'your-api-key'
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
result = wallet.from_seed(seed_phrase, config)
|
|
133
|
+
if result.is_ok:
|
|
134
|
+
print(f"Wallet address: {wallet.get_address()}")
|
|
135
|
+
else:
|
|
136
|
+
print(result.error, result.error_message)
|
|
137
|
+
|
|
138
|
+
# Check balance - fetch_balance returns {balance: {address: {...}}}
|
|
139
|
+
balance_result = wallet.fetch_balance([wallet.current_keypair.address])
|
|
140
|
+
if balance_result.is_ok:
|
|
141
|
+
print(balance_result.get_ok())
|
|
142
|
+
|
|
143
|
+
# Create an item asset via POST /v1/items. On success this returns
|
|
144
|
+
# {asset, to_address, tx_hash}.
|
|
145
|
+
item_result = wallet.create_item_asset(
|
|
146
|
+
secret_key=wallet.current_keypair.secret_key,
|
|
147
|
+
public_key=wallet.current_keypair.public_key,
|
|
148
|
+
amount=1
|
|
149
|
+
)
|
|
150
|
+
if item_result.is_ok:
|
|
151
|
+
print(item_result.get_ok())
|
|
152
|
+
|
|
153
|
+
# Send a payment. This builds and signs a real UTXO transaction client-side
|
|
154
|
+
# (the same construction as sdk-js) and submits it via POST /v1/transactions.
|
|
155
|
+
# On success this returns {transaction_hash, payment_address, asset, used_addresses}.
|
|
156
|
+
payment_result = wallet.create_transactions(
|
|
157
|
+
destination_address='recipient-address',
|
|
158
|
+
amount=100
|
|
159
|
+
)
|
|
160
|
+
if payment_result.is_ok:
|
|
161
|
+
print(payment_result.get_ok())
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Features
|
|
165
|
+
|
|
166
|
+
### Blockchain Client
|
|
167
|
+
- **get_latest_block()** - Get the latest block information
|
|
168
|
+
- **get_block_by_num(block_num)** - Get a specific block by number
|
|
169
|
+
- **get_blockchain_entry(hash)** - Get blockchain entry by hash
|
|
170
|
+
- **get_transaction_by_hash(tx_hash)** - Get transaction details
|
|
171
|
+
- **fetch_transactions(tx_hashes)** - Get multiple transactions
|
|
172
|
+
- **get_total_supply()** - Get total token supply
|
|
173
|
+
- **get_issued_supply()** - Get issued token supply
|
|
174
|
+
|
|
175
|
+
### Wallet Operations
|
|
176
|
+
- Generate and manage seed phrases
|
|
177
|
+
- Create and manage keypairs
|
|
178
|
+
- Construct and submit real, client-signed transactions (payments)
|
|
179
|
+
- Create item assets
|
|
180
|
+
- Check balances
|
|
181
|
+
- Two-way payment protocol support (via the separate valence service)
|
|
182
|
+
|
|
183
|
+
All of the above talk to the `/v1` REST API on the mempool/storage hosts.
|
|
184
|
+
Reads and writes go through `lineage/blockchain.py`'s shared transport,
|
|
185
|
+
which maps `application/problem+json` error bodies onto the SDK's
|
|
186
|
+
`IResult` error types. The 2-way payment flow (`make_2way_payment`,
|
|
187
|
+
`fetch_pending_2way_payments`, `accept_2way_payment`, `reject_2way_payment`)
|
|
188
|
+
is unrelated to `/v1` - it talks to the valence node directly and its
|
|
189
|
+
wire format hasn't changed.
|
|
190
|
+
|
|
191
|
+
`create_transactions` now does real work: it fetches the current balance
|
|
192
|
+
for the spending addresses, selects UTXOs, builds and signs a
|
|
193
|
+
`CreateTransaction` the same way sdk-js does, and submits it to
|
|
194
|
+
`POST /v1/transactions`. Previously this only produced a signed payload
|
|
195
|
+
without ever confirming it reached the network - callers who relied on
|
|
196
|
+
the old behaviour should check `payment_result.get_ok()['transaction_hash']`
|
|
197
|
+
to confirm the payment was actually accepted.
|
|
198
|
+
|
|
199
|
+
## Configuration
|
|
200
|
+
|
|
201
|
+
The SDK uses environment variables for configuration. Create a `.env` file:
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
LINEAGE_PASSPHRASE="your-secure-passphrase"
|
|
205
|
+
LINEAGE_STORAGE_HOST="https://storage.aiblock.dev"
|
|
206
|
+
LINEAGE_MEMPOOL_HOST="https://mempool.aiblock.dev"
|
|
207
|
+
LINEAGE_VALENCE_HOST="https://valence.aiblock.dev"
|
|
208
|
+
|
|
209
|
+
# Optional - sent as the x-api-key header on every /v1 request
|
|
210
|
+
LINEAGE_API_KEY="your-api-key"
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
## Error Handling
|
|
214
|
+
|
|
215
|
+
All methods return `IResult` objects with proper error handling:
|
|
216
|
+
|
|
217
|
+
```python
|
|
218
|
+
result = client.get_latest_block()
|
|
219
|
+
if result.is_ok:
|
|
220
|
+
data = result.get_ok()
|
|
221
|
+
print(f"Success: {data}")
|
|
222
|
+
else:
|
|
223
|
+
print(result.error, result.error_message)
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
## Development
|
|
227
|
+
|
|
228
|
+
1. Clone the repository
|
|
229
|
+
2. Install uv (https://docs.astral.sh/uv/)
|
|
230
|
+
3. Run tests: `uv pip install -q pytest requests-mock && uv run pytest -q`
|
|
231
|
+
|
|
232
|
+
The suite is offline by default; tests marked `integration` talk to a live network and are excluded from the default run.
|
|
233
|
+
|
|
234
|
+
## Documentation
|
|
235
|
+
|
|
236
|
+
- [API Reference](docs/api-reference.md) - Complete API documentation
|
|
237
|
+
- [Examples](docs/examples.md) - Usage examples and patterns
|
|
238
|
+
- [Troubleshooting](docs/troubleshooting.md) - Common issues and solutions
|
|
239
|
+
|
|
240
|
+
## Links
|
|
241
|
+
|
|
242
|
+
- [Lineage Foundation](https://lineage.foundation)
|
|
243
|
+
- [Other SDKs](https://github.com/lineage-foundation) – sdk-python, sdk-php, sdk-js, sdk-laravel
|
|
244
|
+
|
|
245
|
+
## Contributing
|
|
246
|
+
|
|
247
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
248
|
+
|
|
249
|
+
## License
|
|
250
|
+
|
|
251
|
+
MIT – see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
# Lineage Python SDK
|
|
2
|
+
|
|
3
|
+
Python SDK for interacting with the Lineage blockchain. This SDK provides a simple interface for wallet operations and blockchain queries.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install lineage-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
The distribution is published as `lineage-sdk`; the import name is `lineage`:
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
import lineage
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
### Basic Blockchain Queries
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
from lineage.blockchain import BlockchainClient
|
|
23
|
+
|
|
24
|
+
# Initialize blockchain client. api_key is optional and, when set, is sent
|
|
25
|
+
# as the x-api-key header on every request.
|
|
26
|
+
client = BlockchainClient(
|
|
27
|
+
storage_host='https://storage.aiblock.dev',
|
|
28
|
+
mempool_host='https://mempool.aiblock.dev',
|
|
29
|
+
api_key='your-api-key'
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
# Query blockchain
|
|
33
|
+
latest_block = client.get_latest_block()
|
|
34
|
+
if latest_block.is_ok:
|
|
35
|
+
print(f"Latest block: {latest_block.get_ok()['content']['block_num']}")
|
|
36
|
+
|
|
37
|
+
# Get specific block by number
|
|
38
|
+
block = client.get_block_by_num(1)
|
|
39
|
+
if block.is_ok:
|
|
40
|
+
print(f"Block 1: {block.get_ok()['content']}")
|
|
41
|
+
|
|
42
|
+
# Get blockchain entry by hash
|
|
43
|
+
entry = client.get_blockchain_entry('some_hash')
|
|
44
|
+
|
|
45
|
+
# Get transaction by hash
|
|
46
|
+
transaction = client.get_transaction_by_hash('tx_hash')
|
|
47
|
+
|
|
48
|
+
# Get multiple transactions
|
|
49
|
+
transactions = client.fetch_transactions(['hash1', 'hash2'])
|
|
50
|
+
|
|
51
|
+
# Get supply information (requires mempool host) - returns {total, issued}
|
|
52
|
+
total_supply = client.get_total_supply()
|
|
53
|
+
issued_supply = client.get_issued_supply()
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Wallet Operations
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
from lineage.wallet import Wallet
|
|
60
|
+
|
|
61
|
+
# Create wallet
|
|
62
|
+
wallet = Wallet()
|
|
63
|
+
|
|
64
|
+
# Generate seed phrase
|
|
65
|
+
seed_phrase = wallet.generate_seed_phrase()
|
|
66
|
+
print(f"Seed phrase: {seed_phrase}")
|
|
67
|
+
|
|
68
|
+
# Initialize wallet from seed. apiKey is optional and, when set, is sent
|
|
69
|
+
# as the x-api-key header on every mempool request.
|
|
70
|
+
config = {
|
|
71
|
+
'passphrase': 'your-secure-passphrase',
|
|
72
|
+
'mempoolHost': 'https://mempool.aiblock.dev',
|
|
73
|
+
'storageHost': 'https://storage.aiblock.dev',
|
|
74
|
+
'valenceHost': 'https://valence.aiblock.dev',
|
|
75
|
+
'apiKey': 'your-api-key'
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
result = wallet.from_seed(seed_phrase, config)
|
|
79
|
+
if result.is_ok:
|
|
80
|
+
print(f"Wallet address: {wallet.get_address()}")
|
|
81
|
+
else:
|
|
82
|
+
print(result.error, result.error_message)
|
|
83
|
+
|
|
84
|
+
# Check balance - fetch_balance returns {balance: {address: {...}}}
|
|
85
|
+
balance_result = wallet.fetch_balance([wallet.current_keypair.address])
|
|
86
|
+
if balance_result.is_ok:
|
|
87
|
+
print(balance_result.get_ok())
|
|
88
|
+
|
|
89
|
+
# Create an item asset via POST /v1/items. On success this returns
|
|
90
|
+
# {asset, to_address, tx_hash}.
|
|
91
|
+
item_result = wallet.create_item_asset(
|
|
92
|
+
secret_key=wallet.current_keypair.secret_key,
|
|
93
|
+
public_key=wallet.current_keypair.public_key,
|
|
94
|
+
amount=1
|
|
95
|
+
)
|
|
96
|
+
if item_result.is_ok:
|
|
97
|
+
print(item_result.get_ok())
|
|
98
|
+
|
|
99
|
+
# Send a payment. This builds and signs a real UTXO transaction client-side
|
|
100
|
+
# (the same construction as sdk-js) and submits it via POST /v1/transactions.
|
|
101
|
+
# On success this returns {transaction_hash, payment_address, asset, used_addresses}.
|
|
102
|
+
payment_result = wallet.create_transactions(
|
|
103
|
+
destination_address='recipient-address',
|
|
104
|
+
amount=100
|
|
105
|
+
)
|
|
106
|
+
if payment_result.is_ok:
|
|
107
|
+
print(payment_result.get_ok())
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Features
|
|
111
|
+
|
|
112
|
+
### Blockchain Client
|
|
113
|
+
- **get_latest_block()** - Get the latest block information
|
|
114
|
+
- **get_block_by_num(block_num)** - Get a specific block by number
|
|
115
|
+
- **get_blockchain_entry(hash)** - Get blockchain entry by hash
|
|
116
|
+
- **get_transaction_by_hash(tx_hash)** - Get transaction details
|
|
117
|
+
- **fetch_transactions(tx_hashes)** - Get multiple transactions
|
|
118
|
+
- **get_total_supply()** - Get total token supply
|
|
119
|
+
- **get_issued_supply()** - Get issued token supply
|
|
120
|
+
|
|
121
|
+
### Wallet Operations
|
|
122
|
+
- Generate and manage seed phrases
|
|
123
|
+
- Create and manage keypairs
|
|
124
|
+
- Construct and submit real, client-signed transactions (payments)
|
|
125
|
+
- Create item assets
|
|
126
|
+
- Check balances
|
|
127
|
+
- Two-way payment protocol support (via the separate valence service)
|
|
128
|
+
|
|
129
|
+
All of the above talk to the `/v1` REST API on the mempool/storage hosts.
|
|
130
|
+
Reads and writes go through `lineage/blockchain.py`'s shared transport,
|
|
131
|
+
which maps `application/problem+json` error bodies onto the SDK's
|
|
132
|
+
`IResult` error types. The 2-way payment flow (`make_2way_payment`,
|
|
133
|
+
`fetch_pending_2way_payments`, `accept_2way_payment`, `reject_2way_payment`)
|
|
134
|
+
is unrelated to `/v1` - it talks to the valence node directly and its
|
|
135
|
+
wire format hasn't changed.
|
|
136
|
+
|
|
137
|
+
`create_transactions` now does real work: it fetches the current balance
|
|
138
|
+
for the spending addresses, selects UTXOs, builds and signs a
|
|
139
|
+
`CreateTransaction` the same way sdk-js does, and submits it to
|
|
140
|
+
`POST /v1/transactions`. Previously this only produced a signed payload
|
|
141
|
+
without ever confirming it reached the network - callers who relied on
|
|
142
|
+
the old behaviour should check `payment_result.get_ok()['transaction_hash']`
|
|
143
|
+
to confirm the payment was actually accepted.
|
|
144
|
+
|
|
145
|
+
## Configuration
|
|
146
|
+
|
|
147
|
+
The SDK uses environment variables for configuration. Create a `.env` file:
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
LINEAGE_PASSPHRASE="your-secure-passphrase"
|
|
151
|
+
LINEAGE_STORAGE_HOST="https://storage.aiblock.dev"
|
|
152
|
+
LINEAGE_MEMPOOL_HOST="https://mempool.aiblock.dev"
|
|
153
|
+
LINEAGE_VALENCE_HOST="https://valence.aiblock.dev"
|
|
154
|
+
|
|
155
|
+
# Optional - sent as the x-api-key header on every /v1 request
|
|
156
|
+
LINEAGE_API_KEY="your-api-key"
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Error Handling
|
|
160
|
+
|
|
161
|
+
All methods return `IResult` objects with proper error handling:
|
|
162
|
+
|
|
163
|
+
```python
|
|
164
|
+
result = client.get_latest_block()
|
|
165
|
+
if result.is_ok:
|
|
166
|
+
data = result.get_ok()
|
|
167
|
+
print(f"Success: {data}")
|
|
168
|
+
else:
|
|
169
|
+
print(result.error, result.error_message)
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## Development
|
|
173
|
+
|
|
174
|
+
1. Clone the repository
|
|
175
|
+
2. Install uv (https://docs.astral.sh/uv/)
|
|
176
|
+
3. Run tests: `uv pip install -q pytest requests-mock && uv run pytest -q`
|
|
177
|
+
|
|
178
|
+
The suite is offline by default; tests marked `integration` talk to a live network and are excluded from the default run.
|
|
179
|
+
|
|
180
|
+
## Documentation
|
|
181
|
+
|
|
182
|
+
- [API Reference](docs/api-reference.md) - Complete API documentation
|
|
183
|
+
- [Examples](docs/examples.md) - Usage examples and patterns
|
|
184
|
+
- [Troubleshooting](docs/troubleshooting.md) - Common issues and solutions
|
|
185
|
+
|
|
186
|
+
## Links
|
|
187
|
+
|
|
188
|
+
- [Lineage Foundation](https://lineage.foundation)
|
|
189
|
+
- [Other SDKs](https://github.com/lineage-foundation) – sdk-python, sdk-php, sdk-js, sdk-laravel
|
|
190
|
+
|
|
191
|
+
## Contributing
|
|
192
|
+
|
|
193
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
194
|
+
|
|
195
|
+
## License
|
|
196
|
+
|
|
197
|
+
MIT – see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Lineage Python SDK
|
|
3
|
+
|
|
4
|
+
A Python SDK for interacting with the Lineage blockchain.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from lineage.blockchain import BlockchainClient
|
|
8
|
+
from lineage.wallet import Wallet
|
|
9
|
+
from lineage.config import get_config, validate_config, get_default_config
|
|
10
|
+
from lineage import utils
|
|
11
|
+
|
|
12
|
+
# Import key functions from key_handler
|
|
13
|
+
from lineage.key_handler import (
|
|
14
|
+
generate_seed_phrase,
|
|
15
|
+
validate_seed_phrase,
|
|
16
|
+
generate_master_key,
|
|
17
|
+
generate_keypair,
|
|
18
|
+
encrypt_master_key,
|
|
19
|
+
decrypt_master_key,
|
|
20
|
+
encrypt_keypair,
|
|
21
|
+
decrypt_keypair,
|
|
22
|
+
validate_address,
|
|
23
|
+
construct_address
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
try:
|
|
27
|
+
from importlib.metadata import version as _pkg_version, PackageNotFoundError as _PkgNotFound
|
|
28
|
+
try:
|
|
29
|
+
__version__ = _pkg_version("lineage-sdk")
|
|
30
|
+
except _PkgNotFound: # running from a source tree that isn't installed
|
|
31
|
+
__version__ = "1.0.0"
|
|
32
|
+
except ImportError: # pragma: no cover - importlib.metadata is stdlib on 3.8+
|
|
33
|
+
__version__ = "1.0.0"
|
|
34
|
+
|
|
35
|
+
__all__ = [
|
|
36
|
+
'BlockchainClient',
|
|
37
|
+
'Wallet',
|
|
38
|
+
'get_config',
|
|
39
|
+
'validate_config',
|
|
40
|
+
'get_default_config',
|
|
41
|
+
'utils',
|
|
42
|
+
# Key handler functions
|
|
43
|
+
'generate_seed_phrase',
|
|
44
|
+
'validate_seed_phrase',
|
|
45
|
+
'generate_master_key',
|
|
46
|
+
'generate_keypair',
|
|
47
|
+
'encrypt_master_key',
|
|
48
|
+
'decrypt_master_key',
|
|
49
|
+
'encrypt_keypair',
|
|
50
|
+
'decrypt_keypair',
|
|
51
|
+
'validate_address',
|
|
52
|
+
'construct_address',
|
|
53
|
+
'__version__'
|
|
54
|
+
]
|