forked from bitcoinafterlife/bal-electrum-plugin
Compare commits
18 Commits
v0.2.6
...
a5f6b9f925
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a5f6b9f925 | ||
|
|
c739d110d6 | ||
|
d439b1fdde
|
|||
|
c99f0fd70f
|
|||
|
ab6aa7a698
|
|||
|
b55493221d
|
|||
|
|
45d8173cf7 | ||
|
|
b739bdab40 | ||
|
|
d613438800 | ||
|
|
a27df11dfa | ||
|
|
686c11080f | ||
|
|
be38c9b589 | ||
|
dff508c25b
|
|||
|
2056ffae7f
|
|||
|
c8ab85b735
|
|||
|
e2de4a3afa
|
|||
|
3a44b492e4
|
|||
|
9737221914
|
445
README.md
445
README.md
@@ -1,2 +1,443 @@
|
|||||||
# BalPlugin
|
# Bal Electrum Plugin
|
||||||
Bitcoin After Life Electrum Plugin
|
|
||||||
|
⚡ **Bitcoin Electrum plugin for managing heir inheritance and locktime-based transactions**
|
||||||
|
|
||||||
|
This plugin extends Electrum wallet to support:
|
||||||
|
- **Heir inheritance management** - Define beneficiaries and inheritance shares
|
||||||
|
- **Locktime transactions** - Create time-locked transactions for future spending
|
||||||
|
- **Multi-signature setups** - Configure complex multisig scenarios with heirs
|
||||||
|
- **User-friendly wizards** - Easy setup interface
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📥 Installation
|
||||||
|
|
||||||
|
### Method 1: Install from Release (Recommended)
|
||||||
|
|
||||||
|
1. **Download the plugin**
|
||||||
|
- Go to: [https://bitcoin-after.life/gitea/bitcoinafterlife/bal-electrum-plugin/releases](https://bitcoin-after.life/gitea/bitcoinafterlife/bal-electrum-plugin/releases)
|
||||||
|
- Download the latest `bal-electrum-plugin-vX.X.X.zip` file
|
||||||
|
|
||||||
|
2. **Install in Electrum**
|
||||||
|
- Open Electrum Bitcoin wallet
|
||||||
|
- Go to **Tools → Plugins**
|
||||||
|
- Click **Add**
|
||||||
|
- Select the downloaded `.zip` file
|
||||||
|
- Click **Open** or **Install**
|
||||||
|
- Restart Electrum if required
|
||||||
|
|
||||||
|
### Method 2: Install from Source
|
||||||
|
|
||||||
|
1. **Download the source code**
|
||||||
|
```bash
|
||||||
|
git clone https://bitcoin-after.life/gitea/bitcoinafterlife/bal-electrum-plugin.git
|
||||||
|
cd bal-electrum-plugin
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **Create a zip file**
|
||||||
|
```bash
|
||||||
|
zip -r bal-electrum-plugin.zip bal_electrum_plugin/
|
||||||
|
```
|
||||||
|
|
||||||
|
3. **Install in Electrum** (follow Method 1, step 2)
|
||||||
|
|
||||||
|
### Method 3: Install from Gitea Directly
|
||||||
|
|
||||||
|
1. **Download the plugin archive**
|
||||||
|
```bash
|
||||||
|
wget https://bitcoin-after.life/gitea/bitcoinafterlife/bal-electrum-plugin/archive/main.zip -O bal-electrum-plugin.zip
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **Install in Electrum** (follow Method 1, step 2)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🚀 Quick Start
|
||||||
|
|
||||||
|
### 1. Enable the Plugin
|
||||||
|
- Open Electrum
|
||||||
|
- Go to **Tools → Plugins**
|
||||||
|
- Find **Bal Electrum Plugin** in the list
|
||||||
|
- Click the checkbox to enable it
|
||||||
|
- Click **Apply** and restart Electrum if prompted
|
||||||
|
|
||||||
|
### 2. Configure Your Heirs
|
||||||
|
- Go to **Tools → Bal Electrum Plugin**
|
||||||
|
- Click **Setup Heirs**
|
||||||
|
- Add beneficiaries with their Bitcoin addresses and inheritance percentages
|
||||||
|
- Set locktime conditions for each heir
|
||||||
|
|
||||||
|
### 3. Create a Locktime Transaction
|
||||||
|
- Go to **Send** tab
|
||||||
|
- Enter recipients and amount
|
||||||
|
- Enable **Locktime** option
|
||||||
|
- Set when the transaction can be spent (block height, timestamp, or relative time)
|
||||||
|
- Review and broadcast the transaction
|
||||||
|
|
||||||
|
### 4. Verify Heir Distribution
|
||||||
|
- Go to **Tools → Bal Electrum Plugin → View Heirs**
|
||||||
|
- Check the distribution summary
|
||||||
|
- Verify all percentages sum to 100%
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📁 Plugin Structure
|
||||||
|
|
||||||
|
```
|
||||||
|
bal-electrum-plugin/
|
||||||
|
├── bal_electrum_plugin/ # Main plugin code (what you zip)
|
||||||
|
│ ├── __init__.py # Plugin entry point
|
||||||
|
│ ├── qt.py # Main Qt interface
|
||||||
|
│ ├── heirs.py # Heir management logic
|
||||||
|
│ ├── locktime.py # Locktime transaction handling
|
||||||
|
│ ├── dialogs/ # UI dialogs
|
||||||
|
│ │ ├── heirs_dialog.py # Heir configuration dialog
|
||||||
|
│ │ ├── locktime_dialog.py # Locktime setup dialog
|
||||||
|
│ │ └── wizard.py # Setup wizard dialog
|
||||||
|
│ └── utils.py # Utility functions
|
||||||
|
├── README.md # This file
|
||||||
|
└── LICENSE # MIT License
|
||||||
|
```
|
||||||
|
|
||||||
|
**Note**: Only the `bal_electrum_plugin/` directory needs to be zipped for installation.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔧 Configuration
|
||||||
|
|
||||||
|
### Plugin Settings
|
||||||
|
After installation, configure the plugin in Electrum:
|
||||||
|
|
||||||
|
1. Go to **Tools → Bal Electrum Plugin → Settings**
|
||||||
|
2. Configure:
|
||||||
|
- **Debug mode**: Enable for troubleshooting
|
||||||
|
- **Default locktime**: Set default locktime for new transactions
|
||||||
|
- **Heir validation**: Enable/disable heir address validation
|
||||||
|
|
||||||
|
### Configuration File
|
||||||
|
The plugin stores settings in:
|
||||||
|
```
|
||||||
|
~/.electrum/plugins/bal_electrum_plugin/config.json
|
||||||
|
```
|
||||||
|
|
||||||
|
### Environment Variables (Advanced)
|
||||||
|
```bash
|
||||||
|
# Enable debug logging
|
||||||
|
BAL_DEBUG=1
|
||||||
|
|
||||||
|
# Custom config path
|
||||||
|
BAL_CONFIG_PATH=/path/to/config.json
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🎯 Key Features
|
||||||
|
|
||||||
|
### Heir Management
|
||||||
|
✅ **Add/Remove Heirs** - Manage multiple beneficiaries
|
||||||
|
✅ **Inheritance Percentages** - Set distribution shares (sum must be 100%)
|
||||||
|
✅ **Locktime Conditions** - Define when each heir can access their funds
|
||||||
|
✅ **Address Validation** - Verify Bitcoin addresses before saving
|
||||||
|
✅ **Distribution Summary** - View total inheritance breakdown
|
||||||
|
|
||||||
|
### Locktime Transactions
|
||||||
|
✅ **Absolute Locktime** - Transaction can only be spent after a specific:
|
||||||
|
- Block height (e.g., `700000`)
|
||||||
|
- Timestamp (Unix timestamp, e.g., `1609459200`)
|
||||||
|
|
||||||
|
✅ **Relative Locktime** - Transaction can only be spent after:
|
||||||
|
- **Days**: Use suffix `d` (e.g., `3d` = 3 days from now)
|
||||||
|
- **Years**: Use suffix `y` (e.g., `2y` = 2 years from now)
|
||||||
|
|
||||||
|
✅ **Locktime Types**:
|
||||||
|
- **Block-based**: Locktime in blocks
|
||||||
|
- **Time-based**: Locktime in seconds since epoch
|
||||||
|
- **Relative**: Time intervals from current time
|
||||||
|
|
||||||
|
### Multi-Signature Support
|
||||||
|
✅ **Combine signatures** with existing wallet signatures
|
||||||
|
✅ **Configure required signatures** for spending
|
||||||
|
✅ **Support for complex multisig** setups with heirs
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📖 Usage Examples
|
||||||
|
|
||||||
|
### Example 1: Simple Heir Setup
|
||||||
|
|
||||||
|
1. **Add an heir**:
|
||||||
|
- Address: `bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq`
|
||||||
|
- Percentage: `50%`
|
||||||
|
- Locktime: `1y` (1 year from now)
|
||||||
|
|
||||||
|
2. **Add second heir**:
|
||||||
|
- Address: `bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4`
|
||||||
|
- Percentage: `50%`
|
||||||
|
- Locktime: `2y` (2 years from now)
|
||||||
|
|
||||||
|
3. **Create transaction**:
|
||||||
|
- Send 0.5 BTC to heir1 after 1 year
|
||||||
|
- Send 0.5 BTC to heir2 after 2 years
|
||||||
|
|
||||||
|
### Example 2: Locktime Transaction
|
||||||
|
|
||||||
|
```python
|
||||||
|
# Create a transaction that can only be spent after 6 months
|
||||||
|
from bal_electrum_plugin.locktime import Locktime
|
||||||
|
|
||||||
|
locktime = Locktime(
|
||||||
|
type="relative",
|
||||||
|
value="6m", # 6 months from now
|
||||||
|
unit="blocks" # or "seconds"
|
||||||
|
)
|
||||||
|
|
||||||
|
# This transaction will be locked for 6 months
|
||||||
|
tx = create_transaction(
|
||||||
|
recipients=[recipient_address],
|
||||||
|
amount=0.1,
|
||||||
|
locktime=locktime
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Example 3: Complex Inheritance
|
||||||
|
|
||||||
|
- **Heir 1**: 30%, locktime `1y`
|
||||||
|
- **Heir 2**: 40%, locktime `2y`
|
||||||
|
- **Heir 3**: 30%, locktime `3y`
|
||||||
|
|
||||||
|
Total: 100% distributed over 3 years
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🛠️ Development
|
||||||
|
|
||||||
|
### Prerequisites
|
||||||
|
- Electrum Bitcoin wallet (version 4.0.0 or later)
|
||||||
|
- Python 3.7+
|
||||||
|
- PyQt5
|
||||||
|
- pytest (for testing)
|
||||||
|
|
||||||
|
### Setup Development Environment
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Clone the repository
|
||||||
|
git clone https://bitcoin-after.life/gitea/bitcoinafterlife/bal-electrum-plugin.git
|
||||||
|
cd bal-electrum-plugin
|
||||||
|
|
||||||
|
# Create development zip
|
||||||
|
zip -r bal-electrum-plugin-dev.zip bal_electrum_plugin/
|
||||||
|
```
|
||||||
|
|
||||||
|
### Install for Development
|
||||||
|
|
||||||
|
1. Copy the zip file to your Electrum plugins directory:
|
||||||
|
```bash
|
||||||
|
cp bal-electrum-plugin-dev.zip ~/.electrum/plugins/
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Install in Electrum (Tools → Plugins → Add)
|
||||||
|
|
||||||
|
3. Make changes to the source code in `bal_electrum_plugin/` directory
|
||||||
|
|
||||||
|
4. Re-zip and reinstall to test changes:
|
||||||
|
```bash
|
||||||
|
cd ~/.electrum/plugins/
|
||||||
|
unzip bal-electrum-plugin-dev.zip -d bal_electrum_plugin_temp
|
||||||
|
# Make your changes to bal_electrum_plugin_temp/
|
||||||
|
zip -r bal-electrum-plugin-dev.zip bal_electrum_plugin_temp/
|
||||||
|
rm -rf bal_electrum_plugin_temp
|
||||||
|
```
|
||||||
|
|
||||||
|
### Running Tests
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Install test dependencies
|
||||||
|
pip install pytest
|
||||||
|
|
||||||
|
# Run all tests
|
||||||
|
pytest tests/
|
||||||
|
|
||||||
|
# Run specific test
|
||||||
|
pytest tests/test_heirs.py -v
|
||||||
|
```
|
||||||
|
|
||||||
|
### Code Style
|
||||||
|
|
||||||
|
This project follows:
|
||||||
|
- **PEP 8** style guide
|
||||||
|
- 4 spaces for indentation
|
||||||
|
- 79 characters line length
|
||||||
|
- Descriptive variable and function names
|
||||||
|
- Type hints for public functions
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🐛 Troubleshooting
|
||||||
|
|
||||||
|
### Plugin Not Showing in Electrum
|
||||||
|
|
||||||
|
❌ **Problem**: The plugin doesn't appear in Electrum's plugin list
|
||||||
|
|
||||||
|
✅ **Solutions**:
|
||||||
|
1. Verify you're using Electrum 4.0.0 or later
|
||||||
|
2. Check that the zip file contains the `bal_electrum_plugin/` directory
|
||||||
|
3. Ensure the directory structure is correct inside the zip
|
||||||
|
4. Restart Electrum after installation
|
||||||
|
5. Check Electrum logs for errors (Help → Debug → Console)
|
||||||
|
|
||||||
|
### Locktime Not Working
|
||||||
|
|
||||||
|
❌ **Problem**: Locktime conditions aren't being enforced
|
||||||
|
|
||||||
|
✅ **Solutions**:
|
||||||
|
1. Verify locktime format: `3d` (days), `2y` (years), or timestamp
|
||||||
|
2. Check that the locktime is in the future
|
||||||
|
3. Ensure your Bitcoin node supports locktime transactions
|
||||||
|
4. Test with a small amount first
|
||||||
|
5. Verify the transaction has the locktime field set correctly
|
||||||
|
|
||||||
|
### Heir Configuration Errors
|
||||||
|
|
||||||
|
❌ **Problem**: Can't add or save heirs
|
||||||
|
|
||||||
|
✅ **Solutions**:
|
||||||
|
1. Verify Bitcoin addresses are valid (use testnet for testing)
|
||||||
|
2. Check that percentages sum to exactly 100%
|
||||||
|
3. Ensure locktime values are valid formats
|
||||||
|
4. Enable debug mode to see detailed error messages
|
||||||
|
5. Check plugin logs for specific error details
|
||||||
|
|
||||||
|
### Common Error Messages
|
||||||
|
|
||||||
|
| Error | Cause | Solution |
|
||||||
|
|-------|-------|----------|
|
||||||
|
| `Invalid checksum` | Bad Bitcoin address | Verify the address |
|
||||||
|
| `Percentage must sum to 100%` | Invalid heir distribution | Adjust percentages |
|
||||||
|
| `Locktime in the past` | Invalid locktime value | Use future date/time |
|
||||||
|
| `Plugin not found` | Incorrect zip structure | Check zip contents |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🤝 Contributing
|
||||||
|
|
||||||
|
We welcome contributions from the community! Here's how to help:
|
||||||
|
|
||||||
|
### Ways to Contribute
|
||||||
|
|
||||||
|
1. **Report bugs** - Open an issue on [Gitea](https://bitcoin-after.life/gitea/bitcoinafterlife/bal-electrum-plugin/issues)
|
||||||
|
2. **Suggest features** - Share your ideas for new functionality
|
||||||
|
3. **Write documentation** - Improve README, add examples, create tutorials
|
||||||
|
4. **Submit pull requests** - Fix bugs or add new features
|
||||||
|
5. **Test the plugin** - Try different scenarios and report issues
|
||||||
|
6. **Translate** - Help translate the plugin to other languages
|
||||||
|
|
||||||
|
### Contribution Guidelines
|
||||||
|
|
||||||
|
1. **Fork the repository** and create your feature branch
|
||||||
|
2. **Add tests** for new functionality
|
||||||
|
3. **Follow PEP 8** style guide
|
||||||
|
4. **Write clear commit messages** following [Conventional Commits](https://www.conventionalcommits.org/)
|
||||||
|
5. **Update documentation** for new features
|
||||||
|
6. **Open a Pull Request** to the `main` branch
|
||||||
|
7. **Respond to feedback** during code review
|
||||||
|
|
||||||
|
### Development Workflow
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Fork the repository on Gitea
|
||||||
|
|
||||||
|
# Clone your fork
|
||||||
|
git clone https://bitcoin-after.life/gitea/YOUR_USERNAME/bal-electrum-plugin.git
|
||||||
|
cd bal-electrum-plugin
|
||||||
|
|
||||||
|
# Add upstream remote
|
||||||
|
git remote add upstream https://bitcoin-after.life/gitea/bitcoinafterlife/bal-electrum-plugin.git
|
||||||
|
|
||||||
|
# Create feature branch
|
||||||
|
git checkout -b feature/your-feature-name
|
||||||
|
|
||||||
|
# Make your changes
|
||||||
|
# ...
|
||||||
|
|
||||||
|
# Test your changes
|
||||||
|
pytest tests/
|
||||||
|
|
||||||
|
# Commit changes
|
||||||
|
git add .
|
||||||
|
git commit -m "feat: add new feature description"
|
||||||
|
|
||||||
|
# Push to your fork
|
||||||
|
git push origin feature/your-feature-name
|
||||||
|
|
||||||
|
# Open Pull Request on Gitea
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📜 License
|
||||||
|
|
||||||
|
This project is licensed under the **MIT License** - see the [LICENSE](LICENSE) file for details.
|
||||||
|
|
||||||
|
### License Summary
|
||||||
|
- Free to use and modify
|
||||||
|
- Commercial use allowed
|
||||||
|
- No warranty provided
|
||||||
|
- Attribution required
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🙏 Acknowledgments
|
||||||
|
|
||||||
|
- **Electrum developers** - For creating the amazing Electrum wallet
|
||||||
|
- **Bitcoin community** - For continuous innovation and support
|
||||||
|
- **All contributors** - For improving this plugin
|
||||||
|
- **Early users** - For testing and feedback
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📞 Support & Contact
|
||||||
|
|
||||||
|
### Getting Help
|
||||||
|
|
||||||
|
- **Documentation**: This README file
|
||||||
|
- **Issues**: [Gitea Issues](https://bitcoin-after.life/gitea/bitcoinafterlife/bal-electrum-plugin/issues)
|
||||||
|
- **Discussions**: [Gitea Discussions](https://bitcoin-after.life/gitea/bitcoinafterlife/bal-electrum-plugin/discussions)
|
||||||
|
- **Wiki**: Check the `docs/` directory for additional documentation
|
||||||
|
|
||||||
|
### Community
|
||||||
|
|
||||||
|
- **Matrix/Element**: #bal-electrum-plugin:matrix.org
|
||||||
|
- **Telegram**: @bal_electrum_plugin
|
||||||
|
- **Email**: support@bal-electrum-plugin.org
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📊 Version Information
|
||||||
|
|
||||||
|
**Current Version**: 1.0.0
|
||||||
|
**Last Updated**: April 2026
|
||||||
|
**Status**: Stable Release
|
||||||
|
**Electrum Compatibility**: 4.0.0+
|
||||||
|
|
||||||
|
### Version History
|
||||||
|
|
||||||
|
| Version | Date | Changes |
|
||||||
|
|---------|------|---------|
|
||||||
|
| 1.0.0 | Apr 2026 | Initial release with heir and locktime features |
|
||||||
|
| 0.9.0 | Mar 2026 | Beta testing phase |
|
||||||
|
| 0.1.0 | Feb 2026 | Initial development |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔗 Links
|
||||||
|
|
||||||
|
- **Repository**: [https://bitcoin-after.life/gitea/bitcoinafterlife/bal-electrum-plugin](https://bitcoin-after.life/gitea/bitcoinafterlife/bal-electrum-plugin)
|
||||||
|
- **Releases**: [https://bitcoin-after.life/gitea/bitcoinafterlife/bal-electrum-plugin/releases](https://bitcoin-after.life/gitea/bitcoinafterlife/bal-electrum-plugin/releases)
|
||||||
|
- **Issues**: [https://bitcoin-after.life/gitea/bitcoinafterlife/bal-electrum-plugin/issues](https://bitcoin-after.life/gitea/bitcoinafterlife/bal-electrum-plugin/issues)
|
||||||
|
- **Discussions**: [https://bitcoin-after.life/gitea/bitcoinafterlife/bal-electrum-plugin/discussions](https://bitcoin-after.life/gitea/bitcoinafterlife/bal-electrum-plugin/discussions)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**⚠️ Important**: This plugin deals with real Bitcoin transactions. Always test with small amounts first and verify all settings before using with large amounts.
|
||||||
|
|
||||||
|
**🔒 Security**: Never share your seed phrase or private keys. This plugin only creates transactions, it doesn't store your keys.
|
||||||
|
|||||||
23
bal.py
23
bal.py
@@ -47,18 +47,19 @@ class BalConfig:
|
|||||||
|
|
||||||
|
|
||||||
class BalPlugin(BasePlugin):
|
class BalPlugin(BasePlugin):
|
||||||
LATEST_VERSION = "1"
|
_version=None
|
||||||
KNOWN_VERSIONS = ("0", "1")
|
__version__ = "0.2.8" #AUTOMATICALLY GENERATED DO NOT EDIT
|
||||||
assert LATEST_VERSION in KNOWN_VERSIONS
|
def version(self):
|
||||||
|
if not self._version:
|
||||||
def version():
|
|
||||||
try:
|
try:
|
||||||
f = ""
|
f = ""
|
||||||
with open("VERSION", "r") as fi:
|
with open("{}/VERSION".format(self.plugin_dir), "r") as fi:
|
||||||
f = str(fi.readline())
|
f = str(fi.read())
|
||||||
return f
|
self._version = f.strip()
|
||||||
except Exception:
|
except Exception as e:
|
||||||
return "unknown"
|
_logger.error(f"failed to get version: {e}")
|
||||||
|
self._version="unknown"
|
||||||
|
return self._version
|
||||||
|
|
||||||
SIZE = (159, 97)
|
SIZE = (159, 97)
|
||||||
|
|
||||||
@@ -108,7 +109,7 @@ class BalPlugin(BasePlugin):
|
|||||||
"base_fee": 100000,
|
"base_fee": 100000,
|
||||||
"status": "New",
|
"status": "New",
|
||||||
"info": "Bitcoin After Life Will Executor",
|
"info": "Bitcoin After Life Will Executor",
|
||||||
"address": "bcrt1qa5cntu4hgadw8zd3n6sq2nzjy34sxdtd9u0gp7",
|
"address": "bc1qusymuetsz2psaqzqxv8qmzcy64d9meckj3lxxf",
|
||||||
"selected": True,
|
"selected": True,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
60
heirs.py
60
heirs.py
@@ -30,9 +30,11 @@ from electrum.transaction import (
|
|||||||
PartialTransaction,
|
PartialTransaction,
|
||||||
PartialTxInput,
|
PartialTxInput,
|
||||||
PartialTxOutput,
|
PartialTxOutput,
|
||||||
|
TxOutput,
|
||||||
TxOutpoint,
|
TxOutpoint,
|
||||||
# TxOutput,
|
# TxOutput,
|
||||||
)
|
)
|
||||||
|
from electrum.payment_identifier import PaymentIdentifier
|
||||||
from electrum.util import (
|
from electrum.util import (
|
||||||
bfh,
|
bfh,
|
||||||
read_json_file,
|
read_json_file,
|
||||||
@@ -44,7 +46,6 @@ from electrum.util import (
|
|||||||
from .util import Util
|
from .util import Util
|
||||||
from .willexecutors import Willexecutors
|
from .willexecutors import Willexecutors
|
||||||
from electrum.util import BitcoinException
|
from electrum.util import BitcoinException
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .simple_config import SimpleConfig
|
from .simple_config import SimpleConfig
|
||||||
|
|
||||||
@@ -71,28 +72,22 @@ def reduce_outputs(in_amount, out_amount, fee, outputs):
|
|||||||
output.value = math.floor((in_amount - fee) / out_amount * output.value)
|
output.value = math.floor((in_amount - fee) / out_amount * output.value)
|
||||||
|
|
||||||
|
|
||||||
"""
|
def create_op_return_script(data_hex: str) -> bytes:
|
||||||
#TODO: put this method inside wallet.db to replace or complete get_locktime_for_new_transaction
|
"""Crea scriptpubkey OP_RETURN in bytes"""
|
||||||
def get_current_height(network:'Network'):
|
data = bytes.fromhex(data_hex)
|
||||||
#if no network or not up to date, just set locktime to zero
|
|
||||||
if not network:
|
|
||||||
return 0
|
|
||||||
chain = network.blockchain()
|
|
||||||
if chain.is_tip_stale():
|
|
||||||
return 0
|
|
||||||
# figure out current block height
|
|
||||||
chain_height = chain.height() # learnt from all connected servers, SPV-checked
|
|
||||||
server_height = network.get_server_height() # height claimed by main server, unverified
|
|
||||||
# note: main server might be lagging (either is slow, is malicious, or there is an SPV-invisible-hard-fork)
|
|
||||||
# - if it's lagging too much, it is the network's job to switch away
|
|
||||||
if server_height < chain_height - 10:
|
|
||||||
# the diff is suspiciously large... give up and use something non-fingerprintable
|
|
||||||
return 0
|
|
||||||
# discourage "fee sniping"
|
|
||||||
height = min(chain_height, server_height)
|
|
||||||
return height
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
if len(data) > 80:
|
||||||
|
raise ValueError("OP_RETURN data too big (max 80 bytes)")
|
||||||
|
|
||||||
|
# Costruzione manuale: OP_RETURN + push data
|
||||||
|
if len(data) <= 75:
|
||||||
|
# Formato più comune: OP_RETURN + 1-byte length + data
|
||||||
|
script = b'\x6a' + bytes([len(data)]) + data
|
||||||
|
else:
|
||||||
|
# Per dati più grandi (fino a 80) si usa OP_PUSHDATA1
|
||||||
|
script = b'\x6a\x4c' + bytes([len(data)]) + data
|
||||||
|
|
||||||
|
return script
|
||||||
|
|
||||||
def prepare_transactions(locktimes, available_utxos, fees, wallet):
|
def prepare_transactions(locktimes, available_utxos, fees, wallet):
|
||||||
available_utxos = sorted(
|
available_utxos = sorted(
|
||||||
@@ -167,6 +162,13 @@ def prepare_transactions(locktimes, available_utxos, fees, wallet):
|
|||||||
outputs.append(change)
|
outputs.append(change)
|
||||||
for i in range(0, 100):
|
for i in range(0, 100):
|
||||||
random.shuffle(outputs)
|
random.shuffle(outputs)
|
||||||
|
|
||||||
|
#op_return_text = "Hello Bal!"
|
||||||
|
|
||||||
|
## Convert text to hex
|
||||||
|
#op_return_hex = op_return_text.encode('utf-8').hex()
|
||||||
|
#op_return_script = create_op_return_script(op_return_hex)
|
||||||
|
#outputs.append(PartialTxOutput(value=0, scriptpubkey=op_return_script))
|
||||||
tx = PartialTransaction.from_io(
|
tx = PartialTransaction.from_io(
|
||||||
used_utxos,
|
used_utxos,
|
||||||
outputs,
|
outputs,
|
||||||
@@ -424,6 +426,8 @@ class Heirs(dict, Logger):
|
|||||||
def prepare_lists(
|
def prepare_lists(
|
||||||
self, balance, total_fees, wallet, willexecutor=False, from_locktime=0
|
self, balance, total_fees, wallet, willexecutor=False, from_locktime=0
|
||||||
):
|
):
|
||||||
|
if balance<total_fees or balance < wallet.dust_threshold():
|
||||||
|
raise BalanceTooLowException(balance,wallet.dust_threshold(),total_fees)
|
||||||
willexecutors_amount = 0
|
willexecutors_amount = 0
|
||||||
willexecutors = {}
|
willexecutors = {}
|
||||||
heir_list = {}
|
heir_list = {}
|
||||||
@@ -461,7 +465,6 @@ class Heirs(dict, Logger):
|
|||||||
percent_amount,
|
percent_amount,
|
||||||
fixed_amount_with_dust,
|
fixed_amount_with_dust,
|
||||||
) = self.fixed_percent_lists_amount(from_locktime, wallet.dust_threshold())
|
) = self.fixed_percent_lists_amount(from_locktime, wallet.dust_threshold())
|
||||||
|
|
||||||
if fixed_amount > newbalance:
|
if fixed_amount > newbalance:
|
||||||
fixed_amount = self.normalize_perc(
|
fixed_amount = self.normalize_perc(
|
||||||
fixed_heirs, newbalance, fixed_amount, wallet
|
fixed_heirs, newbalance, fixed_amount, wallet
|
||||||
@@ -471,14 +474,12 @@ class Heirs(dict, Logger):
|
|||||||
heir_list.update(fixed_heirs)
|
heir_list.update(fixed_heirs)
|
||||||
|
|
||||||
newbalance -= fixed_amount
|
newbalance -= fixed_amount
|
||||||
|
|
||||||
if newbalance > 0:
|
if newbalance > 0:
|
||||||
perc_amount = self.normalize_perc(
|
perc_amount = self.normalize_perc(
|
||||||
percent_heirs, newbalance, percent_amount, wallet
|
percent_heirs, newbalance, percent_amount, wallet
|
||||||
)
|
)
|
||||||
newbalance -= perc_amount
|
newbalance -= perc_amount
|
||||||
heir_list.update(percent_heirs)
|
heir_list.update(percent_heirs)
|
||||||
|
|
||||||
if newbalance > 0:
|
if newbalance > 0:
|
||||||
newbalance += fixed_amount
|
newbalance += fixed_amount
|
||||||
fixed_amount = self.normalize_perc(
|
fixed_amount = self.normalize_perc(
|
||||||
@@ -537,7 +538,7 @@ class Heirs(dict, Logger):
|
|||||||
break
|
break
|
||||||
elif 0 <= j:
|
elif 0 <= j:
|
||||||
url, willexecutor = willexecutorsitems[j]
|
url, willexecutor = willexecutorsitems[j]
|
||||||
if not Willexecutors.is_selected(willexecutor):
|
if not Willexecutors.is_selected(willexecutor) or willexecutor["base_fee"] < wallet.dust_threshold():
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
willexecutor["url"] = url
|
willexecutor["url"] = url
|
||||||
@@ -782,3 +783,10 @@ class WillExecutorFeeException(Exception):
|
|||||||
return "WillExecutorFeeException: {} fee:{}".format(
|
return "WillExecutorFeeException: {} fee:{}".format(
|
||||||
self.willexecutor["url"], self.willexecutor["base_fee"]
|
self.willexecutor["url"], self.willexecutor["base_fee"]
|
||||||
)
|
)
|
||||||
|
class BalanceTooLowException(Exception):
|
||||||
|
def __init__(self,balance, dust_threshold, fees):
|
||||||
|
self.balance=balance
|
||||||
|
self.dust_threshold = dust_threshold
|
||||||
|
self.fees = fees
|
||||||
|
def __str__(self):
|
||||||
|
return f"Balance too low, balance: {self.balance}, dust threshold: {self.dust_threshold}, fees: {self.fees}"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "BAL",
|
"name": "BAL",
|
||||||
"fullname": "Bitcoin After Life",
|
"fullname": "Bitcoin After Life",
|
||||||
"description": "Provides free and decentralized inheritance support<br> Version: 0.2.5",
|
"description": "Provides free and decentralized inheritance support<br> Version: 0.2.8",
|
||||||
"author":"Svatantrya",
|
"author":"Svatantrya",
|
||||||
"available_for": ["qt"],
|
"available_for": ["qt"],
|
||||||
"icon":"icons/bal32x32.png"
|
"icon":"icons/bal32x32.png"
|
||||||
|
|||||||
279
qt.py
279
qt.py
@@ -15,13 +15,14 @@ from datetime import datetime
|
|||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from typing import TYPE_CHECKING, Any, Callable, Mapping, Optional, Union
|
from typing import TYPE_CHECKING, Any, Callable, Mapping, Optional, Union
|
||||||
|
import traceback
|
||||||
try:
|
try:
|
||||||
QT_VERSION = sys._GUI_QT_VERSION
|
QT_VERSION = sys._GUI_QT_VERSION
|
||||||
except Exception:
|
except Exception:
|
||||||
QT_VERSION = 6
|
QT_VERSION = 6
|
||||||
|
|
||||||
if QT_VERSION == 5:
|
if QT_VERSION == 5:
|
||||||
|
from PyQt5.QtCore import QThread, QCoreApplication
|
||||||
from PyQt5.QtCore import (
|
from PyQt5.QtCore import (
|
||||||
QDateTime,
|
QDateTime,
|
||||||
QModelIndex,
|
QModelIndex,
|
||||||
@@ -57,6 +58,7 @@ if QT_VERSION == 5:
|
|||||||
QWidget,
|
QWidget,
|
||||||
)
|
)
|
||||||
else: # QT6
|
else: # QT6
|
||||||
|
from PyQt6.QtCore import QThread, QCoreApplication
|
||||||
from PyQt6.QtCore import (
|
from PyQt6.QtCore import (
|
||||||
QDateTime,
|
QDateTime,
|
||||||
QModelIndex,
|
QModelIndex,
|
||||||
@@ -495,8 +497,8 @@ class BalWindow(Logger):
|
|||||||
Util.copy(self.will_settings, self.bal_plugin.default_will_settings())
|
Util.copy(self.will_settings, self.bal_plugin.default_will_settings())
|
||||||
self.logger.debug("not_will_settings {}".format(self.will_settings))
|
self.logger.debug("not_will_settings {}".format(self.will_settings))
|
||||||
self.bal_plugin.validate_will_settings(self.will_settings)
|
self.bal_plugin.validate_will_settings(self.will_settings)
|
||||||
self.heir_list.update_will_settings()
|
self.heir_list_widget.update_will_settings()
|
||||||
self.heir_list.update()
|
self.heir_list_widget.update()
|
||||||
|
|
||||||
def init_wizard(self):
|
def init_wizard(self):
|
||||||
wizard_dialog = BalWizardDialog(self)
|
wizard_dialog = BalWizardDialog(self)
|
||||||
@@ -507,9 +509,9 @@ class BalWindow(Logger):
|
|||||||
self.willexecutor_dialog.show()
|
self.willexecutor_dialog.show()
|
||||||
|
|
||||||
def create_heirs_tab(self):
|
def create_heirs_tab(self):
|
||||||
self.heir_list = HeirList(self, self.window)
|
self.heir_list_widget = HeirListWidget(self, self.window)
|
||||||
|
|
||||||
tab = self.window.create_list_tab(self.heir_list)
|
tab = self.window.create_list_tab(self.heir_list_widget)
|
||||||
tab.is_shown_cv = shown_cv(False)
|
tab.is_shown_cv = shown_cv(False)
|
||||||
return tab
|
return tab
|
||||||
|
|
||||||
@@ -601,14 +603,6 @@ class BalWindow(Logger):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.show_error(str(e))
|
self.show_error(str(e))
|
||||||
|
|
||||||
# def export_inheritance_handler(self,path):
|
|
||||||
# txs = self.build_inheritance_transaction(ignore_duplicate=True, keep_original=False)
|
|
||||||
# with open(path,"w") as f:
|
|
||||||
# for tx in txs:
|
|
||||||
# tx['status']+="."+BalPlugin.STATUS_EXPORTED
|
|
||||||
# f.write(str(tx['tx']))
|
|
||||||
# f.write('\n')
|
|
||||||
|
|
||||||
def set_heir(self, heir):
|
def set_heir(self, heir):
|
||||||
heir = list(heir)
|
heir = list(heir)
|
||||||
if not self.bal_plugin.ENABLE_MULTIVERSE.get():
|
if not self.bal_plugin.ENABLE_MULTIVERSE.get():
|
||||||
@@ -616,7 +610,7 @@ class BalWindow(Logger):
|
|||||||
|
|
||||||
h = Heirs.validate_heir(heir[0], heir[1:])
|
h = Heirs.validate_heir(heir[0], heir[1:])
|
||||||
self.heirs[heir[0]] = h
|
self.heirs[heir[0]] = h
|
||||||
self.heir_list.update()
|
self.heir_list_widget.update()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def delete_heirs(self, heirs):
|
def delete_heirs(self, heirs):
|
||||||
@@ -627,14 +621,12 @@ class BalWindow(Logger):
|
|||||||
_logger.debug(f"error deleting heir: {heir} {e}")
|
_logger.debug(f"error deleting heir: {heir} {e}")
|
||||||
pass
|
pass
|
||||||
self.heirs.save()
|
self.heirs.save()
|
||||||
self.heir_list.update()
|
self.heir_list_widget.update()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def import_heirs(
|
def import_heirs(self):
|
||||||
self,
|
|
||||||
):
|
|
||||||
import_meta_gui(
|
import_meta_gui(
|
||||||
self.window, _("heirs"), self.heirs.import_file, self.heir_list.update
|
self.window, _("heirs"), self.heirs.import_file, self.heir_list_widget.update
|
||||||
)
|
)
|
||||||
|
|
||||||
def export_heirs(self):
|
def export_heirs(self):
|
||||||
@@ -748,8 +740,7 @@ class BalWindow(Logger):
|
|||||||
|
|
||||||
def init_class_variables(self):
|
def init_class_variables(self):
|
||||||
if not self.heirs:
|
if not self.heirs:
|
||||||
raise NoHeirsException()
|
raise NoHeirsException(_("Heirs are not defined"))
|
||||||
return
|
|
||||||
try:
|
try:
|
||||||
self.date_to_check = Util.parse_locktime_string(
|
self.date_to_check = Util.parse_locktime_string(
|
||||||
self.will_settings["threshold"]
|
self.will_settings["threshold"]
|
||||||
@@ -757,11 +748,13 @@ class BalWindow(Logger):
|
|||||||
# found = False
|
# found = False
|
||||||
self.locktime_blocks = self.bal_plugin.LOCKTIME_BLOCKS.get()
|
self.locktime_blocks = self.bal_plugin.LOCKTIME_BLOCKS.get()
|
||||||
self.current_block = Util.get_current_height(self.wallet.network)
|
self.current_block = Util.get_current_height(self.wallet.network)
|
||||||
self.block_to_check = self.current_block + self.locktime_blocks
|
self.block_to_check=0
|
||||||
self.no_willexecutor = self.bal_plugin.NO_WILLEXECUTOR.get()
|
self.no_willexecutor = self.bal_plugin.NO_WILLEXECUTOR.get()
|
||||||
self.willexecutors = Willexecutors.get_willexecutors(
|
self.willexecutors = Willexecutors.get_willexecutors(
|
||||||
self.bal_plugin, update=True, bal_window=self, task=False
|
self.bal_plugin, update=True, bal_window=self, task=False
|
||||||
)
|
)
|
||||||
|
if self.date_to_check < datetime.now().timestamp():
|
||||||
|
raise CheckAliveException(self.date_to_check)
|
||||||
self.init_heirs_to_locktime(self.bal_plugin.ENABLE_MULTIVERSE.get())
|
self.init_heirs_to_locktime(self.bal_plugin.ENABLE_MULTIVERSE.get())
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -776,8 +769,8 @@ class BalWindow(Logger):
|
|||||||
if not self.heirs:
|
if not self.heirs:
|
||||||
self.logger.warning("not heirs {}".format(self.heirs))
|
self.logger.warning("not heirs {}".format(self.heirs))
|
||||||
return
|
return
|
||||||
self.init_class_variables()
|
|
||||||
try:
|
try:
|
||||||
|
self.init_class_variables()
|
||||||
Will.check_amounts(
|
Will.check_amounts(
|
||||||
self.heirs,
|
self.heirs,
|
||||||
self.willexecutors,
|
self.willexecutors,
|
||||||
@@ -788,9 +781,12 @@ class BalWindow(Logger):
|
|||||||
except AmountException as e:
|
except AmountException as e:
|
||||||
self.show_warning(
|
self.show_warning(
|
||||||
_(
|
_(
|
||||||
f"In the inheritance process, the entire wallet will always be fully emptied. Your settings require an adjustment of the amounts.\n{e}"
|
f"In the inheritance process, the entire wallet will always be fully emptied. Your settings require an adjustment of the amounts.{e}"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
except CheckAliveException:
|
||||||
|
self.show_error(_("CheckAlive is in the past please update it to a date in the future but less than locktime"))
|
||||||
|
return
|
||||||
locktime = Util.parse_locktime_string(self.will_settings["locktime"])
|
locktime = Util.parse_locktime_string(self.will_settings["locktime"])
|
||||||
if locktime < self.date_to_check:
|
if locktime < self.date_to_check:
|
||||||
self.show_error(_("locktime is lower than threshold"))
|
self.show_error(_("locktime is lower than threshold"))
|
||||||
@@ -1036,7 +1032,18 @@ class BalWindow(Logger):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def on_failure(err):
|
def on_failure(err):
|
||||||
|
a,b,c = err
|
||||||
self.logger.error(f"fail to broadcast transactions:{err}")
|
self.logger.error(f"fail to broadcast transactions:{err}")
|
||||||
|
self.logger.error(f"error: {b}")
|
||||||
|
self.logger.error(f"traceback ")
|
||||||
|
tb = c
|
||||||
|
while tb is not None:
|
||||||
|
frame = tb.tb_frame
|
||||||
|
self.logger.error("file:", frame.f_code.co_filename)
|
||||||
|
self.logger.error("name:", frame.f_code.co_name)
|
||||||
|
self.logger.error("line:", tb.tb_lineno)
|
||||||
|
self.logger.error("lasti:", tb.tb_lasti)
|
||||||
|
tb = tb.tb_next
|
||||||
|
|
||||||
task = partial(self.push_transactions_to_willexecutors, force)
|
task = partial(self.push_transactions_to_willexecutors, force)
|
||||||
msg = _("Selecting Will-Executors")
|
msg = _("Selecting Will-Executors")
|
||||||
@@ -1079,7 +1086,13 @@ class BalWindow(Logger):
|
|||||||
self.willitems[wid].we["url"], wid, "Waiting"
|
self.willitems[wid].we["url"], wid, "Waiting"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.willitems[wid].check_willexecutor()
|
w = self.willitems[wid]
|
||||||
|
w.set_check_willexecutor(
|
||||||
|
Willexecutors.check_transaction(
|
||||||
|
wid,
|
||||||
|
w.we["url"]
|
||||||
|
)
|
||||||
|
)
|
||||||
self.waiting_dialog.update(
|
self.waiting_dialog.update(
|
||||||
"checked {} - {} : {}".format(
|
"checked {} - {} : {}".format(
|
||||||
self.willitems[wid].we["url"],
|
self.willitems[wid].we["url"],
|
||||||
@@ -1128,7 +1141,9 @@ class BalWindow(Logger):
|
|||||||
self.waiting_dialog.update(
|
self.waiting_dialog.update(
|
||||||
"checking transaction: {}\n willexecutor: {}".format(wid, w.we["url"])
|
"checking transaction: {}\n willexecutor: {}".format(wid, w.we["url"])
|
||||||
)
|
)
|
||||||
w.check_willexecutor()
|
|
||||||
|
w.set_check_willexecutor(Willexecutors.check_transaction(wid, w.we["url"]))
|
||||||
|
|
||||||
|
|
||||||
if time.time() - start < 3:
|
if time.time() - start < 3:
|
||||||
time.sleep(3 - (time.time() - start))
|
time.sleep(3 - (time.time() - start))
|
||||||
@@ -1189,7 +1204,7 @@ class BalWindow(Logger):
|
|||||||
def on_success(result):
|
def on_success(result):
|
||||||
# del self.waiting_dialog
|
# del self.waiting_dialog
|
||||||
try:
|
try:
|
||||||
parent.willexecutor_list.update()
|
parent.will_executor_list_widget.update()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
@@ -1214,10 +1229,20 @@ class BalWindow(Logger):
|
|||||||
self.dw.show()
|
self.dw.show()
|
||||||
|
|
||||||
def update_all(self):
|
def update_all(self):
|
||||||
|
try:
|
||||||
|
Will.add_willtree(self.willitems)
|
||||||
|
all_utxos = self.wallet.get_utxos()
|
||||||
|
utxos_list = Will.utxos_strs(all_utxos)
|
||||||
|
Will.check_invalidated(
|
||||||
|
self.willitems, utxos_list, self.wallet
|
||||||
|
)
|
||||||
|
|
||||||
self.will_list.update_will(self.willitems)
|
self.will_list.update_will(self.willitems)
|
||||||
self.heirs_tab.update()
|
self.heirs_tab.update()
|
||||||
self.will_tab.update()
|
self.will_tab.update()
|
||||||
self.will_list.update()
|
self.will_list.update()
|
||||||
|
except Exception as e:
|
||||||
|
_logger.error(f"error while updating window: {e}")
|
||||||
|
|
||||||
|
|
||||||
def add_widget(grid, label, widget, row, help_):
|
def add_widget(grid, label, widget, row, help_):
|
||||||
@@ -1605,17 +1630,19 @@ class BalWizardDialog(BalDialog):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def on_accept(self):
|
def on_accept(self):
|
||||||
|
self.bal_window.update_all()
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def on_reject(self):
|
def on_reject(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def on_close(self):
|
def on_close(self):
|
||||||
|
self.bal_window.update_all()
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def closeEvent(self, event):
|
def closeEvent(self, event):
|
||||||
self.bal_window.update_all()
|
|
||||||
self.bal_window.heir_list.update_will_settings()
|
self.bal_window.heir_list_widget.update_will_settings()
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@@ -1692,7 +1719,7 @@ class BalWizardHeirsWidget(BalWizardWidget):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def get_content(self):
|
def get_content(self):
|
||||||
self.heirs_list = HeirList(self.bal_window, self)
|
self.heir_list_widget = HeirListWidget(self.bal_window, self)
|
||||||
button_add = QPushButton(_("Add"))
|
button_add = QPushButton(_("Add"))
|
||||||
button_add.clicked.connect(self.add_heir)
|
button_add.clicked.connect(self.add_heir)
|
||||||
button_import = QPushButton(_("Import"))
|
button_import = QPushButton(_("Import"))
|
||||||
@@ -1701,20 +1728,20 @@ class BalWizardHeirsWidget(BalWizardWidget):
|
|||||||
button_export.clicked.connect(self.export_to_file)
|
button_export.clicked.connect(self.export_to_file)
|
||||||
widget = QWidget()
|
widget = QWidget()
|
||||||
vbox = QVBoxLayout(widget)
|
vbox = QVBoxLayout(widget)
|
||||||
vbox.addWidget(self.heirs_list)
|
vbox.addWidget(self.heir_list_widget)
|
||||||
vbox.addLayout(Buttons(button_add, button_import, button_export))
|
vbox.addLayout(Buttons(button_add, button_import, button_export))
|
||||||
return widget
|
return widget
|
||||||
|
|
||||||
def import_from_file(self):
|
def import_from_file(self):
|
||||||
self.bal_window.import_heirs()
|
self.bal_window.import_heirs()
|
||||||
self.heirs_list.update()
|
self.heir_list_widget.update()
|
||||||
|
|
||||||
def export_to_file(self):
|
def export_to_file(self):
|
||||||
self.bal_window.export_heirs()
|
self.bal_window.export_heirs()
|
||||||
|
|
||||||
def add_heir(self):
|
def add_heir(self):
|
||||||
self.bal_window.new_heir_dialog()
|
self.bal_window.new_heir_dialog()
|
||||||
self.heirs_list.update()
|
self.heir_list_widget.update()
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
return True
|
return True
|
||||||
@@ -1785,7 +1812,7 @@ class BalWizardWEDownloadWidget(BalWizardWidget):
|
|||||||
_logger.debug(f"Failed to download willexecutors list {fail}")
|
_logger.debug(f"Failed to download willexecutors list {fail}")
|
||||||
pass
|
pass
|
||||||
|
|
||||||
task = partial(Willexecutors.download_list, self.bal_window.bal_plugin,self.bal_window.willexecutors)
|
task = partial(Willexecutors.download_list,self.bal_window.willexecutors)
|
||||||
msg = _("Downloading Will-Executors list")
|
msg = _("Downloading Will-Executors list")
|
||||||
self.waiting_dialog = BalWaitingDialog(
|
self.waiting_dialog = BalWaitingDialog(
|
||||||
self.bal_window, msg, task, on_success, on_failure, exe=False
|
self.bal_window, msg, task, on_success, on_failure, exe=False
|
||||||
@@ -1988,6 +2015,7 @@ class BalWaitingDialog(BalDialog):
|
|||||||
self.thread.stop()
|
self.thread.stop()
|
||||||
|
|
||||||
def update_message(self, msg):
|
def update_message(self, msg):
|
||||||
|
print(msg)
|
||||||
self.message_label.setText(msg)
|
self.message_label.setText(msg)
|
||||||
|
|
||||||
def update(self, msg):
|
def update(self, msg):
|
||||||
@@ -2046,13 +2074,18 @@ class BalBuildWillDialog(BalDialog):
|
|||||||
parent = bal_window.window
|
parent = bal_window.window
|
||||||
BalDialog.__init__(self, parent, bal_window.bal_plugin, _("Building Will"))
|
BalDialog.__init__(self, parent, bal_window.bal_plugin, _("Building Will"))
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.updatemessage.connect(self.update)
|
self.updatemessage.connect(self.msg_update)
|
||||||
self.bal_window = bal_window
|
self.bal_window = bal_window
|
||||||
|
self.bal_plugin = bal_window.bal_plugin
|
||||||
self.message_label = QLabel(_("Building Will:"))
|
self.message_label = QLabel(_("Building Will:"))
|
||||||
self.vbox = QVBoxLayout(self)
|
self.vbox = QVBoxLayout(self)
|
||||||
self.vbox.addWidget(self.message_label)
|
self.vbox.addWidget(self.message_label,0)
|
||||||
self.qwidget = QWidget()
|
self.qwidget = QWidget(self)
|
||||||
self.vbox.addWidget(self.qwidget)
|
self.vbox.addWidget(self.qwidget,1)
|
||||||
|
self.labelsbox=QVBoxLayout(self.qwidget)
|
||||||
|
self.setMinimumWidth(600)
|
||||||
|
self.setMinimumHeight(100)
|
||||||
|
self.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred)
|
||||||
self.labels = []
|
self.labels = []
|
||||||
self.check_row = None
|
self.check_row = None
|
||||||
self.inval_row = None
|
self.inval_row = None
|
||||||
@@ -2079,13 +2112,26 @@ class BalBuildWillDialog(BalDialog):
|
|||||||
self.exec()
|
self.exec()
|
||||||
|
|
||||||
def task_phase1(self):
|
def task_phase1(self):
|
||||||
|
txs=None
|
||||||
_logger.debug("close plugin phase 1 started")
|
_logger.debug("close plugin phase 1 started")
|
||||||
|
varrow = self.msg_set_status("checking variables")
|
||||||
try:
|
try:
|
||||||
self.bal_window.init_class_variables()
|
self.bal_window.init_class_variables()
|
||||||
except NoHeirsException:
|
except CheckAliveException as cae:
|
||||||
_logger.error("no heirs exception")
|
fee_per_byte = self.bal_window.will_settings.get("baltx_fees", 1)
|
||||||
return False, None
|
tx = Will.invalidate_will(
|
||||||
varrow = self.msg_set_status("checking variables")
|
self.bal_window.willitems, self.bal_window.wallet, fee_per_byte
|
||||||
|
)
|
||||||
|
if tx:
|
||||||
|
_logger.debug("during phase1 CAE: {}, Continue to invalidate".format(cae))
|
||||||
|
self.msg_set_checking(self.msg_warning("Check Alive Threshold Passed: you have to Invalidate your old Will"))
|
||||||
|
else:
|
||||||
|
raise cae
|
||||||
|
return None, tx
|
||||||
|
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
raise e
|
||||||
try:
|
try:
|
||||||
_logger.debug("checking variables")
|
_logger.debug("checking variables")
|
||||||
Will.check_amounts(
|
Will.check_amounts(
|
||||||
@@ -2121,9 +2167,10 @@ class BalBuildWillDialog(BalDialog):
|
|||||||
return None, Will.invalidate_will(
|
return None, Will.invalidate_will(
|
||||||
self.bal_window.willitems, self.bal_window.wallet, fee_per_byte
|
self.bal_window.willitems, self.bal_window.wallet, fee_per_byte
|
||||||
)
|
)
|
||||||
except NoHeirsException:
|
except NoHeirsException as e:
|
||||||
_logger.debug("no heirs")
|
_logger.debug("no heirs")
|
||||||
self.msg_set_checking("No Heirs")
|
self.msg_set_checking("No Heirs")
|
||||||
|
raise e
|
||||||
except NotCompleteWillException as e:
|
except NotCompleteWillException as e:
|
||||||
_logger.debug(f"not complete {e} true")
|
_logger.debug(f"not complete {e} true")
|
||||||
message = False
|
message = False
|
||||||
@@ -2147,13 +2194,15 @@ class BalBuildWillDialog(BalDialog):
|
|||||||
if have_to_build:
|
if have_to_build:
|
||||||
self.msg_set_building()
|
self.msg_set_building()
|
||||||
try:
|
try:
|
||||||
if not self.bal_window.build_will():
|
txs = self.bal_window.build_will()
|
||||||
|
if not txs:
|
||||||
self.msg_set_status(
|
self.msg_set_status(
|
||||||
_("Balance is too low. No transaction was built"),
|
_("Balance is too low. No transaction was built"),
|
||||||
None,
|
None,
|
||||||
_("Skipped"),
|
_("Skipped"),
|
||||||
self.COLOR_ERROR,
|
self.COLOR_ERROR,
|
||||||
)
|
)
|
||||||
|
return False,None
|
||||||
|
|
||||||
self.bal_window.check_will()
|
self.bal_window.check_will()
|
||||||
for wid in Will.only_valid(self.bal_window.willitems):
|
for wid in Will.only_valid(self.bal_window.willitems):
|
||||||
@@ -2185,12 +2234,14 @@ class BalBuildWillDialog(BalDialog):
|
|||||||
if not self.bal_window.willitems[wid].get_status("COMPLETE"):
|
if not self.bal_window.willitems[wid].get_status("COMPLETE"):
|
||||||
have_to_sign = True
|
have_to_sign = True
|
||||||
break
|
break
|
||||||
return have_to_sign, None
|
return have_to_sign, txs
|
||||||
|
|
||||||
def on_accept(self):
|
def on_accept(self):
|
||||||
|
self.bal_window.update_all()
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def on_accept_phase2(self):
|
def on_accept_phase2(self):
|
||||||
|
self.bal_window.update_all()
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def on_error_push(self):
|
def on_error_push(self):
|
||||||
@@ -2228,6 +2279,7 @@ class BalBuildWillDialog(BalDialog):
|
|||||||
self.msg_set_pushing(_("Broadcasting"))
|
self.msg_set_pushing(_("Broadcasting"))
|
||||||
retry = False
|
retry = False
|
||||||
try:
|
try:
|
||||||
|
|
||||||
willexecutors = Willexecutors.get_willexecutor_transactions(
|
willexecutors = Willexecutors.get_willexecutor_transactions(
|
||||||
self.bal_window.willitems
|
self.bal_window.willitems
|
||||||
)
|
)
|
||||||
@@ -2257,7 +2309,10 @@ class BalBuildWillDialog(BalDialog):
|
|||||||
self.bal_window.willitems[wid].we["url"], wid, "Waiting"
|
self.bal_window.willitems[wid].we["url"], wid, "Waiting"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.bal_window.willitems[wid].check_willexecutor()
|
self.bal_plugin = self.bal_window.bal_plugin
|
||||||
|
w = self.bal_window.willitems[wid]
|
||||||
|
|
||||||
|
w.set_check_willexecutor(Willexecutors.check_transaction(wid, w.we["url"]))
|
||||||
row = self.msg_edit_row(
|
row = self.msg_edit_row(
|
||||||
"checked {} - {} : {}".format(
|
"checked {} - {} : {}".format(
|
||||||
self.bal_window.willitems[wid].we["url"],
|
self.bal_window.willitems[wid].we["url"],
|
||||||
@@ -2268,7 +2323,6 @@ class BalBuildWillDialog(BalDialog):
|
|||||||
)
|
)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
||||||
_logger.error(f"loop push error:{e}")
|
_logger.error(f"loop push error:{e}")
|
||||||
raise e
|
raise e
|
||||||
if retry:
|
if retry:
|
||||||
@@ -2306,12 +2360,11 @@ class BalBuildWillDialog(BalDialog):
|
|||||||
on_error=self.on_error_phase1,
|
on_error=self.on_error_phase1,
|
||||||
)
|
)
|
||||||
|
|
||||||
def on_error(self, error):
|
|
||||||
_logger.error(error)
|
|
||||||
pass
|
|
||||||
|
|
||||||
def on_success_phase1(self, result):
|
def on_success_phase1(self, result):
|
||||||
self.have_to_sign, tx = list(result)
|
self.have_to_sign, tx = list(result)
|
||||||
|
#if not tx:
|
||||||
|
# self.msg_edit_row(self.msg_error("Error, no tx was built"))
|
||||||
|
# return
|
||||||
_logger.debug("have to sign {}".format(self.have_to_sign))
|
_logger.debug("have to sign {}".format(self.have_to_sign))
|
||||||
password = None
|
password = None
|
||||||
if self.have_to_sign is None:
|
if self.have_to_sign is None:
|
||||||
@@ -2359,7 +2412,6 @@ class BalBuildWillDialog(BalDialog):
|
|||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
def closeEvent(self, event):
|
def closeEvent(self, event):
|
||||||
self.bal_window.update_all()
|
|
||||||
self._stopping = True
|
self._stopping = True
|
||||||
self.thread.stop()
|
self.thread.stop()
|
||||||
|
|
||||||
@@ -2388,15 +2440,26 @@ class BalBuildWillDialog(BalDialog):
|
|||||||
self.msg_set_pushing(self.msg_ok())
|
self.msg_set_pushing(self.msg_ok())
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
td = traceback.format_exc()
|
||||||
self.msg_set_pushing(self.msg_error(e))
|
self.msg_set_pushing(self.msg_error(e))
|
||||||
self.msg_edit_row(self.msg_ok())
|
self.msg_edit_row(self.msg_ok())
|
||||||
self.wait(5)
|
self.wait(5)
|
||||||
|
|
||||||
|
def on_error(self, error):
|
||||||
|
_logger.error(error)
|
||||||
|
pass
|
||||||
|
|
||||||
def on_error_phase1(self, error):
|
def on_error_phase1(self, error):
|
||||||
_logger.error(f"error phase1: {error}")
|
self.bal_window.update_all()
|
||||||
|
a,b,c = error
|
||||||
|
self.msg_edit_row(self.msg_error(f"Error: {b}"))
|
||||||
|
_logger.error(f"error phase1: {b}")
|
||||||
|
|
||||||
def on_error_phase2(self, error):
|
def on_error_phase2(self, error):
|
||||||
_logger.error(f"error phase2: { error}")
|
self.bal_window.upade_all()
|
||||||
|
a,b,c = error
|
||||||
|
self.msg_edit_row(self.msg_error(f"Error: {b}"))
|
||||||
|
_logger.error(f"error phase2: {b}")
|
||||||
|
|
||||||
def msg_set_checking(self, status="Waiting", row=None):
|
def msg_set_checking(self, status="Waiting", row=None):
|
||||||
row = self.check_row if row is None else row
|
row = self.check_row if row is None else row
|
||||||
@@ -2448,10 +2511,11 @@ class BalBuildWillDialog(BalDialog):
|
|||||||
def msg_edit_row(self, line, row=None):
|
def msg_edit_row(self, line, row=None):
|
||||||
try:
|
try:
|
||||||
self.labels[row] = line
|
self.labels[row] = line
|
||||||
except Exception:
|
except Exception as e:
|
||||||
self.labels.append(line)
|
self.labels.append(line)
|
||||||
row = len(self.labels) - 1
|
row = len(self.labels) - 1
|
||||||
|
|
||||||
|
|
||||||
self.updatemessage.emit()
|
self.updatemessage.emit()
|
||||||
|
|
||||||
return row
|
return row
|
||||||
@@ -2463,13 +2527,36 @@ class BalBuildWillDialog(BalDialog):
|
|||||||
pass
|
pass
|
||||||
self.updatemessage.emit()
|
self.updatemessage.emit()
|
||||||
|
|
||||||
def update(self):
|
def clear_layout(self,layout):
|
||||||
self.vbox.removeWidget(self.qwidget)
|
while layout.count():
|
||||||
self.qwidget = QWidget(self)
|
item = layout.takeAt(0)
|
||||||
labelsbox = QVBoxLayout(self.qwidget)
|
w = item.widget()
|
||||||
for label in self.labels:
|
if w:
|
||||||
labelsbox.addWidget(QLabel(label))
|
w.setParent(None)
|
||||||
self.vbox.addWidget(self.qwidget)
|
w.deleteLater()
|
||||||
|
|
||||||
|
#def msg_update(self):
|
||||||
|
# self.clear_layout(self.labelsbox)
|
||||||
|
# for label in self.labels:
|
||||||
|
# label=label.replace("\n","<br>")
|
||||||
|
# qlabel=QLabel(label)
|
||||||
|
# qlabel.setWordWrap(True)
|
||||||
|
# self.labelsbox.addWidget(qlabel)
|
||||||
|
|
||||||
|
# self.labelsbox.activate()
|
||||||
|
# self.qwidget.setMinimumSize(self.labelsbox.sizeHint())
|
||||||
|
# self.qwidget.adjustSize()
|
||||||
|
# from PyQt6.QtWidgets import QApplication
|
||||||
|
# QApplication.processEvents()
|
||||||
|
#
|
||||||
|
# self.adjustSize()
|
||||||
|
def msg_update(self):
|
||||||
|
full_text = "<br><br>".join(self.labels).replace("\n", "<br>")
|
||||||
|
self.message_label.setText(full_text)
|
||||||
|
self.message_label.adjustSize()
|
||||||
|
#self.setMinimumHeight(len(self.labels)*40)
|
||||||
|
self.resize(self.sizeHint())
|
||||||
|
|
||||||
|
|
||||||
def get_text(self):
|
def get_text(self):
|
||||||
return self.message_label.text()
|
return self.message_label.text()
|
||||||
@@ -2477,7 +2564,7 @@ class BalBuildWillDialog(BalDialog):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class HeirList(MyTreeView, MessageBoxMixin):
|
class HeirListWidget(MyTreeView, MessageBoxMixin):
|
||||||
class Columns(MyTreeView.BaseColumnsEnum):
|
class Columns(MyTreeView.BaseColumnsEnum):
|
||||||
NAME = enum.auto()
|
NAME = enum.auto()
|
||||||
ADDRESS = enum.auto()
|
ADDRESS = enum.auto()
|
||||||
@@ -2492,9 +2579,16 @@ class HeirList(MyTreeView, MessageBoxMixin):
|
|||||||
|
|
||||||
ROLE_SORT_ORDER = Qt.ItemDataRole.UserRole + 1000
|
ROLE_SORT_ORDER = Qt.ItemDataRole.UserRole + 1000
|
||||||
|
|
||||||
ROLE_HEIR_KEY = Qt.ItemDataRole.UserRole + 1001
|
ROLE_HEIR_KEY = Qt.ItemDataRole.UserRole + 4000
|
||||||
key_role = ROLE_HEIR_KEY
|
key_role = ROLE_HEIR_KEY
|
||||||
|
|
||||||
|
def createEditor(self, parent, option, index):
|
||||||
|
return QLineEdit(parent)
|
||||||
|
def setEditorData(self, editor, index):
|
||||||
|
editor.setText(index.data())
|
||||||
|
def setModelData(self, editor, model, index):
|
||||||
|
model.setData(index, editor.text())
|
||||||
|
|
||||||
def __init__(self, bal_window: "BalWindow", parent):
|
def __init__(self, bal_window: "BalWindow", parent):
|
||||||
super().__init__(
|
super().__init__(
|
||||||
parent=parent,
|
parent=parent,
|
||||||
@@ -2509,6 +2603,7 @@ class HeirList(MyTreeView, MessageBoxMixin):
|
|||||||
self.decimal_point = bal_window.window.get_decimal_point()
|
self.decimal_point = bal_window.window.get_decimal_point()
|
||||||
self.bal_window = bal_window
|
self.bal_window = bal_window
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.setModel(QStandardItemModel(self))
|
self.setModel(QStandardItemModel(self))
|
||||||
self.sortByColumn(self.Columns.NAME, Qt.SortOrder.AscendingOrder)
|
self.sortByColumn(self.Columns.NAME, Qt.SortOrder.AscendingOrder)
|
||||||
@@ -2592,12 +2687,6 @@ class HeirList(MyTreeView, MessageBoxMixin):
|
|||||||
menu.addAction(_("Delete"), lambda: self.delete_heirs(selected_keys))
|
menu.addAction(_("Delete"), lambda: self.delete_heirs(selected_keys))
|
||||||
menu.exec(self.viewport().mapToGlobal(position))
|
menu.exec(self.viewport().mapToGlobal(position))
|
||||||
|
|
||||||
# def get_selected_keys(self):
|
|
||||||
# selected_keys = []
|
|
||||||
# for s_idx in self.selected_in_column(self.Columns.NAME):
|
|
||||||
# sel_key = self.model().itemFromIndex(s_idx).data(0)
|
|
||||||
# selected_keys.append(sel_key)
|
|
||||||
# return selected_keys
|
|
||||||
def update(self):
|
def update(self):
|
||||||
current_key = self.get_role_data_for_current_item(
|
current_key = self.get_role_data_for_current_item(
|
||||||
col=self.Columns.NAME, role=self.ROLE_HEIR_KEY
|
col=self.Columns.NAME, role=self.ROLE_HEIR_KEY
|
||||||
@@ -2747,6 +2836,7 @@ class HeirList(MyTreeView, MessageBoxMixin):
|
|||||||
self.heir_tx_fees.setValue(int(self.bal_window.will_settings["baltx_fees"]))
|
self.heir_tx_fees.setValue(int(self.bal_window.will_settings["baltx_fees"]))
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
pass
|
||||||
_logger.debug(f"Exception update_will_settings {e}")
|
_logger.debug(f"Exception update_will_settings {e}")
|
||||||
|
|
||||||
def build_transactions(self):
|
def build_transactions(self):
|
||||||
@@ -2965,16 +3055,16 @@ class PreviewList(MyTreeView):
|
|||||||
|
|
||||||
wizard = QPushButton(_("Setup Wizard"))
|
wizard = QPushButton(_("Setup Wizard"))
|
||||||
wizard.clicked.connect(self.bal_window.init_wizard)
|
wizard.clicked.connect(self.bal_window.init_wizard)
|
||||||
display = QPushButton(_("Display"))
|
#display = QPushButton(_("Display"))
|
||||||
display.clicked.connect(self.bal_window.preview_modal_dialog)
|
#display.clicked.connect(self.bal_window.preview_modal_dialog)
|
||||||
|
|
||||||
display = QPushButton(_("Refresh"))
|
refresh = QPushButton(_("Refresh"))
|
||||||
display.clicked.connect(self.check)
|
refresh.clicked.connect(self.check)
|
||||||
|
|
||||||
widget = QWidget()
|
widget = QWidget()
|
||||||
hlayout = QHBoxLayout(widget)
|
hlayout = QHBoxLayout(widget)
|
||||||
hlayout.addWidget(wizard)
|
hlayout.addWidget(wizard)
|
||||||
hlayout.addWidget(display)
|
hlayout.addWidget(refresh)
|
||||||
toolbar.insertWidget(2, widget)
|
toolbar.insertWidget(2, widget)
|
||||||
|
|
||||||
self.menu = menu
|
self.menu = menu
|
||||||
@@ -3012,13 +3102,6 @@ class PreviewList(MyTreeView):
|
|||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
def check(self):
|
def check(self):
|
||||||
Will.add_willtree(self.bal_window.willitems)
|
|
||||||
all_utxos = self.bal_window.wallet.get_utxos()
|
|
||||||
utxos_list = Will.utxos_strs(all_utxos)
|
|
||||||
Will.check_invalidated(
|
|
||||||
self.bal_window.willitems, utxos_list, self.bal_window.wallet
|
|
||||||
)
|
|
||||||
|
|
||||||
close_window = BalBuildWillDialog(self.bal_window)
|
close_window = BalBuildWillDialog(self.bal_window)
|
||||||
close_window.build_will_task()
|
close_window.build_will_task()
|
||||||
|
|
||||||
@@ -3065,7 +3148,10 @@ class PreviewDialog(BalDialog, MessageBoxMixin):
|
|||||||
self.size_label = QLabel()
|
self.size_label = QLabel()
|
||||||
self.transactions_list = PreviewList(self.bal_window, self.will)
|
self.transactions_list = PreviewList(self.bal_window, self.will)
|
||||||
|
|
||||||
|
try:
|
||||||
self.bal_window.init_class_variables()
|
self.bal_window.init_class_variables()
|
||||||
|
except Exception as e:
|
||||||
|
_logger.error(f"PreviewDialog Exception: {e}")
|
||||||
self.check_will()
|
self.check_will()
|
||||||
|
|
||||||
vbox = QVBoxLayout(self)
|
vbox = QVBoxLayout(self)
|
||||||
@@ -3311,7 +3397,7 @@ class WillWidget(QWidget):
|
|||||||
hlayout.addWidget(WillWidget(w, parent=parent))
|
hlayout.addWidget(WillWidget(w, parent=parent))
|
||||||
|
|
||||||
|
|
||||||
class WillExecutorList(MyTreeView):
|
class WillExecutorListWidget(MyTreeView):
|
||||||
class Columns(MyTreeView.BaseColumnsEnum):
|
class Columns(MyTreeView.BaseColumnsEnum):
|
||||||
SELECTED = enum.auto()
|
SELECTED = enum.auto()
|
||||||
URL = enum.auto()
|
URL = enum.auto()
|
||||||
@@ -3556,7 +3642,7 @@ class WillExecutorWidget(QWidget, MessageBoxMixin):
|
|||||||
self.willexecutors_list = Willexecutors.get_willexecutors(self.bal_plugin)
|
self.willexecutors_list = Willexecutors.get_willexecutors(self.bal_plugin)
|
||||||
|
|
||||||
self.size_label = QLabel()
|
self.size_label = QLabel()
|
||||||
self.willexecutor_list = WillExecutorList(self)
|
self.will_executor_list_widget = WillExecutorListWidget(self)
|
||||||
|
|
||||||
vbox = QVBoxLayout(self)
|
vbox = QVBoxLayout(self)
|
||||||
vbox.addWidget(self.size_label)
|
vbox.addWidget(self.size_label)
|
||||||
@@ -3573,7 +3659,7 @@ class WillExecutorWidget(QWidget, MessageBoxMixin):
|
|||||||
hbox.addWidget(spacer_widget)
|
hbox.addWidget(spacer_widget)
|
||||||
vbox.addWidget(widget)
|
vbox.addWidget(widget)
|
||||||
|
|
||||||
vbox.addWidget(self.willexecutor_list)
|
vbox.addWidget(self.will_executor_list_widget)
|
||||||
buttonbox = QHBoxLayout()
|
buttonbox = QHBoxLayout()
|
||||||
|
|
||||||
b = QPushButton(_("Add"))
|
b = QPushButton(_("Add"))
|
||||||
@@ -3597,7 +3683,7 @@ class WillExecutorWidget(QWidget, MessageBoxMixin):
|
|||||||
buttonbox.addWidget(b)
|
buttonbox.addWidget(b)
|
||||||
|
|
||||||
vbox.addLayout(buttonbox)
|
vbox.addLayout(buttonbox)
|
||||||
# self.willexecutor_list.update()
|
# self.will_executor_list_widget.update()
|
||||||
|
|
||||||
def add(self):
|
def add(self):
|
||||||
self.willexecutors_list["http://localhost:8080"] = {
|
self.willexecutors_list["http://localhost:8080"] = {
|
||||||
@@ -3605,11 +3691,11 @@ class WillExecutorWidget(QWidget, MessageBoxMixin):
|
|||||||
"base_fee": 0,
|
"base_fee": 0,
|
||||||
"status": "-1",
|
"status": "-1",
|
||||||
}
|
}
|
||||||
self.willexecutor_list.update()
|
self.will_executor_list_widget.update()
|
||||||
|
|
||||||
def download_list(self):
|
def download_list(self):
|
||||||
self.willexecutors_list.update(Willexecutors.download_list(self.bal_plugin,self.bal_window.willexecutors))
|
self.willexecutors_list.update(Willexecutors.download_list(self.bal_window.willexecutors))
|
||||||
self.willexecutor_list.update()
|
self.will_executor_list_widget.update()
|
||||||
|
|
||||||
def export_file(self, path):
|
def export_file(self, path):
|
||||||
Util.export_meta_gui(
|
Util.export_meta_gui(
|
||||||
@@ -3632,13 +3718,13 @@ class WillExecutorWidget(QWidget, MessageBoxMixin):
|
|||||||
wes = self.willexecutors_list
|
wes = self.willexecutors_list
|
||||||
self.bal_window.ping_willexecutors(wes, self.parent)
|
self.bal_window.ping_willexecutors(wes, self.parent)
|
||||||
self.willexecutors_list.update(wes)
|
self.willexecutors_list.update(wes)
|
||||||
self.willexecutor_list.update()
|
self.will_executor_list_widget.update()
|
||||||
|
|
||||||
def import_json_file(self, path):
|
def import_json_file(self, path):
|
||||||
data = read_json_file(path)
|
data = read_json_file(path)
|
||||||
data = self._validate(data)
|
data = self._validate(data)
|
||||||
self.willexecutors_list.update(data)
|
self.willexecutors_list.update(data)
|
||||||
self.willexecutor_list.update()
|
self.will_executor_list_widget.update()
|
||||||
|
|
||||||
# TODO validate willexecutor json import file
|
# TODO validate willexecutor json import file
|
||||||
def _validate(self, data):
|
def _validate(self, data):
|
||||||
@@ -3662,10 +3748,10 @@ class WillExecutorDialog(BalDialog, MessageBoxMixin):
|
|||||||
self.setMinimumSize(1000, 200)
|
self.setMinimumSize(1000, 200)
|
||||||
|
|
||||||
vbox = QVBoxLayout(self)
|
vbox = QVBoxLayout(self)
|
||||||
self.willexecutor_list = WillExecutorWidget(
|
self.will_executor_list_widget = WillExecutorWidget(
|
||||||
self, self.bal_window, self.willexecutors_list
|
self, self.bal_window, self.willexecutors_list
|
||||||
)
|
)
|
||||||
vbox.addWidget(self.willexecutor_list)
|
vbox.addWidget(self.will_executor_list_widget)
|
||||||
|
|
||||||
def is_hidden(self):
|
def is_hidden(self):
|
||||||
return self.isMinimized() or self.isHidden()
|
return self.isMinimized() or self.isHidden()
|
||||||
@@ -3682,3 +3768,10 @@ class WillExecutorDialog(BalDialog, MessageBoxMixin):
|
|||||||
|
|
||||||
def closeEvent(self, event):
|
def closeEvent(self, event):
|
||||||
event.accept()
|
event.accept()
|
||||||
|
|
||||||
|
|
||||||
|
class CheckAliveException(Exception):
|
||||||
|
def __init__(self,timestamp_to_check):
|
||||||
|
self.timestamp_to_check = timestamp_to_check
|
||||||
|
def __str__(self):
|
||||||
|
return "Check alive expired please update it: {}".format(datetime.fromtimestamp(self.timestamp_to_check).isoformat())
|
||||||
|
|||||||
13
util.py
13
util.py
@@ -494,3 +494,16 @@ class Util:
|
|||||||
del will[txid]["tx_fees"]
|
del will[txid]["tx_fees"]
|
||||||
have_to_update = True
|
have_to_update = True
|
||||||
return have_to_update
|
return have_to_update
|
||||||
|
|
||||||
|
def text_to_hex(text: str) -> str:
|
||||||
|
"""Convert text to hexadecimal string"""
|
||||||
|
hex_string = text.encode('utf-8').hex()
|
||||||
|
return hex_string
|
||||||
|
|
||||||
|
|
||||||
|
def hex_to_text(hex_string: str) -> str:
|
||||||
|
"""Convert hexadecimal string back to text (for verification)"""
|
||||||
|
try:
|
||||||
|
return bytes.fromhex(hex_string).decode('utf-8')
|
||||||
|
except Exception:
|
||||||
|
return "Error: Invalid hex string"
|
||||||
|
|||||||
21
will.py
21
will.py
@@ -339,6 +339,7 @@ class Will:
|
|||||||
utxos = wallet.get_utxos()
|
utxos = wallet.get_utxos()
|
||||||
filtered_inputs = []
|
filtered_inputs = []
|
||||||
prevout_to_spend = []
|
prevout_to_spend = []
|
||||||
|
current_height = Util.get_current_height(wallet.network)
|
||||||
for prevout_str, ws in inputs.items():
|
for prevout_str, ws in inputs.items():
|
||||||
for w in ws:
|
for w in ws:
|
||||||
if w[0] not in filtered_inputs:
|
if w[0] not in filtered_inputs:
|
||||||
@@ -348,6 +349,8 @@ class Will:
|
|||||||
balance = 0
|
balance = 0
|
||||||
utxo_to_spend = []
|
utxo_to_spend = []
|
||||||
for utxo in utxos:
|
for utxo in utxos:
|
||||||
|
if utxo.is_coinbase_output() and utxo.block_height < current_height+100:
|
||||||
|
continue
|
||||||
utxo_str = utxo.prevout.to_str()
|
utxo_str = utxo.prevout.to_str()
|
||||||
if utxo_str in prevout_to_spend:
|
if utxo_str in prevout_to_spend:
|
||||||
balance += inputs[utxo_str][0][2].value_sats()
|
balance += inputs[utxo_str][0][2].value_sats()
|
||||||
@@ -356,7 +359,7 @@ class Will:
|
|||||||
change_addresses = wallet.get_change_addresses_for_new_transaction()
|
change_addresses = wallet.get_change_addresses_for_new_transaction()
|
||||||
out = PartialTxOutput.from_address_and_value(change_addresses[0], balance)
|
out = PartialTxOutput.from_address_and_value(change_addresses[0], balance)
|
||||||
out.is_change = True
|
out.is_change = True
|
||||||
locktime = Util.get_current_height(wallet.network)
|
locktime = current_height
|
||||||
tx = PartialTransaction.from_io(
|
tx = PartialTransaction.from_io(
|
||||||
utxo_to_spend, [out], locktime=locktime, version=2
|
utxo_to_spend, [out], locktime=locktime, version=2
|
||||||
)
|
)
|
||||||
@@ -560,6 +563,9 @@ class Will:
|
|||||||
raise WillExpiredException(
|
raise WillExpiredException(
|
||||||
f"Will Expired {wid[0][0]}: {locktime}<{timestamp_to_check}"
|
f"Will Expired {wid[0][0]}: {locktime}<{timestamp_to_check}"
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
from datetime import datetime
|
||||||
|
_logger.debug(f"Will Not Expired {wid[0][0]}: {datetime.fromtimestamp(locktime).isoformat()} > {datetime.fromtimestamp(timestamp_to_check).isoformat()}")
|
||||||
|
|
||||||
# def check_all_input_spent_are_in_wallet():
|
# def check_all_input_spent_are_in_wallet():
|
||||||
# _logger.info("check all input spent are in wallet or valid txs")
|
# _logger.info("check all input spent are in wallet or valid txs")
|
||||||
@@ -793,9 +799,9 @@ class WillItem(Logger):
|
|||||||
iw = inp[1]
|
iw = inp[1]
|
||||||
self.set_anticipate(iw)
|
self.set_anticipate(iw)
|
||||||
|
|
||||||
def check_willexecutor(self):
|
def set_check_willexecutor(self,resp):
|
||||||
try:
|
try:
|
||||||
if resp := Willexecutors.check_transaction(self._id, self.we["url"]):
|
if resp :
|
||||||
if "tx" in resp and resp["tx"] == str(self.tx):
|
if "tx" in resp and resp["tx"] == str(self.tx):
|
||||||
self.set_status("PUSHED")
|
self.set_status("PUSHED")
|
||||||
self.set_status("CHECKED")
|
self.set_status("CHECKED")
|
||||||
@@ -835,7 +841,12 @@ class WillItem(Logger):
|
|||||||
|
|
||||||
|
|
||||||
class WillException(Exception):
|
class WillException(Exception):
|
||||||
pass
|
def __init__(self,msg="WillException"):
|
||||||
|
self.msg=msg
|
||||||
|
Exception.__init__(self)
|
||||||
|
def __str__(self):
|
||||||
|
return self.msg
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class WillExpiredException(WillException):
|
class WillExpiredException(WillException):
|
||||||
@@ -872,8 +883,6 @@ class WillExecutorNotPresent(NotCompleteWillException):
|
|||||||
|
|
||||||
class NoHeirsException(WillException):
|
class NoHeirsException(WillException):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class AmountException(WillException):
|
class AmountException(WillException):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ class Willexecutors:
|
|||||||
raise Exception("You are offline.")
|
raise Exception("You are offline.")
|
||||||
_logger.debug(f"<-- {method} {url} {data}")
|
_logger.debug(f"<-- {method} {url} {data}")
|
||||||
headers = {}
|
headers = {}
|
||||||
headers["user-agent"] = f"BalPlugin v:{BalPlugin.version()}"
|
headers["user-agent"] = f"BalPlugin v:{BalPlugin.__version__}"
|
||||||
headers["Content-Type"] = "text/plain"
|
headers["Content-Type"] = "text/plain"
|
||||||
if not handle_response:
|
if not handle_response:
|
||||||
handle_response = Willexecutors.handle_response
|
handle_response = Willexecutors.handle_response
|
||||||
@@ -260,7 +260,7 @@ class Willexecutors:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
def download_list(bal_plugin,old_willexecutors):
|
def download_list(old_willexecutors):
|
||||||
try:
|
try:
|
||||||
willexecutors = Willexecutors.send_request(
|
willexecutors = Willexecutors.send_request(
|
||||||
"get",
|
"get",
|
||||||
@@ -280,7 +280,7 @@ class Willexecutors:
|
|||||||
_logger.error(f"Failed to download willexecutors list: {e}")
|
_logger.error(f"Failed to download willexecutors list: {e}")
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
def get_willexecutors_list_from_json(bal_plugin):
|
def get_willexecutors_list_from_json():
|
||||||
try:
|
try:
|
||||||
with open("willexecutors.json") as f:
|
with open("willexecutors.json") as f:
|
||||||
willexecutors = json.load(f)
|
willexecutors = json.load(f)
|
||||||
|
|||||||
Reference in New Issue
Block a user