Permalink
Browse files

Added support for old p2sh address types if the coin is transitioning.

  • Loading branch information...
CodeShark committed May 10, 2017
1 parent 122dfbe commit c320d4376e7c042a3b8404f865a3875c77cbe650
Showing with 140 additions and 12 deletions.
  1. +8 −0 build-all.sh
  2. +1 −1 mSIGNA-ltc.pro
  3. +13 −3 src/accountmodel.cpp
  4. +3 −0 src/accountmodel.h
  5. +14 −0 src/coinparams.cpp
  6. +5 −0 src/coinparams.h
  7. +4 −0 src/createtxdialog.cpp
  8. +41 −1 src/mainwindow.cpp
  9. +17 −0 src/mainwindow.h
  10. +14 −1 src/scriptmodel.cpp
  11. +4 −0 src/scriptmodel.h
  12. +14 −6 src/txmodel.cpp
  13. +2 −0 src/txmodel.h
@@ -161,6 +161,7 @@ fi
cd $CURRENT_DIR
#TODO: Automatically detect whether the following units need recompilation
# Always recompile coinparams
if [[ -e build/$BUILD_TYPE/obj/coinparams.o ]]
then
@@ -179,6 +180,13 @@ then
rm build/$BUILD_TYPE/obj/main.o
fi
# The following units also need to be recompiled
# accountmodel.o
# createtxdialog.o
# mainwindow.o
# scriptmodel.o
# txmodel.o
# For OS X, remove any existing instance of the app bundle
if [[ "$OS" == "osx" ]]
then
@@ -12,7 +12,7 @@ RC_FILE = res/mSIGNA_ltc.rc
ICON = res/icons/app_icons/osx-ltc.icns
DEFINES += QT_GUI BOOST_THREAD_USE_LIB BOOST_SPIRIT_THREADSAFE DATABASE_SQLITE
DEFINES += DEFAULT_NETWORK_LITECOIN
DEFINES += DEFAULT_NETWORK_LITECOIN SUPPORT_OLD_ADDRESS_VERSIONS
CONFIG += c++11 rtti thread
QT += widgets network
@@ -37,14 +37,22 @@ using namespace std;
AccountModel::AccountModel(CoinDB::SynchedVault& synchedVault)
: m_synchedVault(synchedVault), numAccounts(0)
{
setBase58Versions();
currencySymbol = getCurrencySymbol();
setColumns();
}
void AccountModel::setBase58Versions()
{
base58_versions[0] = getCoinParams().pay_to_pubkey_hash_version();
#ifdef SUPPORT_OLD_ADDRESS_VERSIONS
base58_versions[1] = getUseOldAddressVersions() ? getCoinParams().old_pay_to_script_hash_version() : getCoinParams().pay_to_script_hash_version();
#else
base58_versions[1] = getCoinParams().pay_to_script_hash_version();
#endif
base58_versions[2] = getCoinParams().pay_to_witness_pubkey_hash_version();
base58_versions[3] = getCoinParams().pay_to_witness_script_hash_version();
currencySymbol = getCurrencySymbol();
setColumns();
}
void AccountModel::setColumns()
@@ -63,6 +71,8 @@ void AccountModel::setVault(CoinDB::Vault* vault)
*/
void AccountModel::update()
{
setBase58Versions();
QString newCurrencySymbol = getCurrencySymbol();
if (newCurrencySymbol != currencySymbol)
{
@@ -52,6 +52,9 @@ class AccountModel : public QStandardItemModel
static const unsigned int DEFAULT_LOOKAHEAD = 25;
// UI operations
void setBase58Versions();
// Account operations
void newAccount(const QString& name, unsigned int minsigs, const QList<QString>& keychainNames, qint64 msecsSinceEpoch = QDateTime::currentDateTime().toMSecsSinceEpoch(), unsigned int unusedPoolSize = DEFAULT_LOOKAHEAD);
void newAccount(bool enableSegwit, bool useSegwitP2SH, const QString& name, unsigned int minsigs, const QList<QString>& keychainNames, qint64 msecsSinceEpoch = QDateTime::currentDateTime().toMSecsSinceEpoch(), unsigned int unusedPoolSize = DEFAULT_LOOKAHEAD);
@@ -129,3 +129,17 @@ uint64_t getDefaultFee()
{
return getCoinParams().default_fee();
}
#ifdef SUPPORT_OLD_ADDRESS_VERSIONS
static bool useOldAddressVersions = false;
void setAddressVersions(bool useOld)
{
useOldAddressVersions = useOld;
}
bool getUseOldAddressVersions()
{
return useOldAddressVersions;
}
#endif
@@ -36,3 +36,8 @@ const QString& getCurrencySymbol();
int getCurrencyDecimals();
uint64_t getCurrencyMax();
uint64_t getDefaultFee();
#ifdef SUPPORT_OLD_ADDRESS_VERSIONS
void setAddressVersions(bool useOld = false);
bool getUseOldAddressVersions();
#endif
@@ -44,7 +44,11 @@ TxOutLayout::TxOutLayout(uint64_t currencyDivisor, const QString& currencySymbol
{
// Base58 version bytes
base58_versions[0] = getCoinParams().pay_to_pubkey_hash_version();
#ifdef SUPPORT_OLD_ADDRESS_VERSIONS
base58_versions[1] = getUseOldAddressVersions() ? getCoinParams().old_pay_to_script_hash_version() : getCoinParams().pay_to_script_hash_version();
#else
base58_versions[1] = getCoinParams().pay_to_script_hash_version();
#endif
// Coin parameters
this->currencyDivisor = currencyDivisor;
@@ -266,6 +266,12 @@ MainWindow::MainWindow() :
refreshAccounts();
});
#ifdef SUPPORT_OLD_ADDRESS_VERSIONS
connect(this, &MainWindow::signal_addressVersionsChanged, [this]() {
refreshAccounts();
});
#endif
setAcceptDrops(true);
updateFonts(fontSize);
@@ -488,6 +494,19 @@ void MainWindow::selectTrailingDecimals(bool newShowTrailingDecimals)
}
}
#ifdef SUPPORT_OLD_ADDRESS_VERSIONS
void MainWindow::selectAddressVersions(bool newUseOldAddressVersions)
{
if (newUseOldAddressVersions != useOldAddressVersions)
{
useOldAddressVersions = newUseOldAddressVersions;
saveSettings();
setAddressVersions(useOldAddressVersions);
emit signal_addressVersionsChanged();
}
}
#endif
void MainWindow::newVault(QString fileName)
{
if (fileName.isEmpty()) {
@@ -2432,6 +2451,15 @@ void MainWindow::createActions()
connect(showTrailingDecimalsAction, &QAction::toggled, [this]() { selectTrailingDecimals(showTrailingDecimalsAction->isChecked()); });
showTrailingDecimalsAction->setChecked(showTrailingDecimals);
#ifdef SUPPORT_OLD_ADDRESS_VERSIONS
// address version actions
useOldAddressVersionsAction = new QAction(tr("Use Old Address Versions"), this);
useOldAddressVersionsAction->setCheckable(true);
useOldAddressVersionsAction->setStatusTip(tr("Use old address versions"));
connect(useOldAddressVersionsAction, &QAction::toggled, [this]() { selectAddressVersions(useOldAddressVersionsAction->isChecked()); });
useOldAddressVersionsAction->setChecked(useOldAddressVersions);
#endif
// about/help actions
aboutAction = new QAction(tr("About..."), this);
aboutAction->setStatusTip(tr("About ") + getDefaultSettings().getAppName());
@@ -2543,9 +2571,14 @@ void MainWindow::createMenus()
currencyUnitMenu->addSeparator();
currencyUnitMenu->addAction(showTrailingDecimalsAction);
#ifdef SUPPORT_OLD_ADDRESS_VERSIONS
addressVersionsMenu = menuBar()->addMenu(tr("Address Versions"));
addressVersionsMenu->addSeparator()->setText("Addresses Versions");
addressVersionsMenu->addAction(useOldAddressVersionsAction);
#endif
menuBar()->addSeparator();
helpMenu = menuBar()->addMenu(tr("&Help"));
helpMenu->addAction(aboutAction);
}
@@ -2618,6 +2651,10 @@ void MainWindow::loadSettings()
host = settings.value("host", "localhost").toString();
port = settings.value("port", getCoinParams().default_port()).toInt();
autoConnect = settings.value("autoconnect", false).toBool();
#ifdef SUPPORT_OLD_ADDRESS_VERSIONS
useOldAddressVersions = settings.value("useoldaddressversions", false).toBool();
setAddressVersions(useOldAddressVersions);
#endif
setDocDir(settings.value("lastvaultdir", getDefaultSettings().getDocumentDir()).toString());
}
@@ -2640,6 +2677,9 @@ void MainWindow::saveSettings()
settings.setValue("host", host);
settings.setValue("port", port);
settings.setValue("autoconnect", autoConnect);
#ifdef SUPPORT_OLD_ADDRESS_VERSIONS
settings.setValue("useoldaddressversions", useOldAddressVersions);
#endif
settings.setValue("lastvaultdir", getDocDir());
}
}
@@ -101,6 +101,11 @@ class MainWindow : public QMainWindow
void signal_currencyUnitChanged();
#ifdef SUPPORT_OLD_ADDRESS_VERSIONS
void signal_addressVersionsChanged();
#endif
void unsignedTx();
public slots:
@@ -129,6 +134,9 @@ private slots:
void selectCurrencyUnit();
void selectCurrencyUnit(const QString& newCurrencyUnitPrefix);
void selectTrailingDecimals(bool newShowTrailingDecimals);
#ifdef SUPPORT_OLD_ADDRESS_VERSIONS
void selectAddressVersions(bool useOld);
#endif
///////////////////
// VAULT OPERATIONS
@@ -268,6 +276,9 @@ private slots:
QMenu* networkMenu;
QMenu* fontsMenu;
QMenu* currencyUnitMenu;
#ifdef SUPPORT_OLD_ADDRESS_VERSIONS
QMenu* addressVersionsMenu;
#endif
QMenu* helpMenu;
// toolbars
@@ -365,6 +376,12 @@ private slots:
QList<QAction*> currencyUnitActions;
QAction* showTrailingDecimalsAction;
#ifdef SUPPORT_OLD_ADDRESS_VERSIONS
// address version actions
bool useOldAddressVersions;
QAction* useOldAddressVersionsAction;
#endif
// about/help actions
QAction* aboutAction;
@@ -14,6 +14,7 @@
#include "scriptmodel.h"
#include "settings.h"
#include "coinparams.h"
#include <CoinQ/CoinQ_script.h>
@@ -27,16 +28,28 @@ ScriptModel::ScriptModel(QObject* parent)
: QStandardItemModel(parent)
{
initColumns();
setBase58Versions();
}
ScriptModel::ScriptModel(CoinDB::Vault* vault, const QString& accountName, QObject* parent)
: QStandardItemModel(parent)
{
initColumns();
setBase58Versions();
setVault(vault);
setAccount(accountName);
}
void ScriptModel::setBase58Versions()
{
base58_versions[0] = getCoinParams().pay_to_pubkey_hash_version();
#ifdef SUPPORT_OLD_ADDRESS_VERSIONS
base58_versions[1] = getUseOldAddressVersions() ? getCoinParams().old_pay_to_script_hash_version() : getCoinParams().pay_to_script_hash_version();
#else
base58_versions[1] = getCoinParams().pay_to_script_hash_version();
#endif
}
void ScriptModel::initColumns()
{
QStringList columns;
@@ -72,7 +85,7 @@ void ScriptModel::update()
std::vector<SigningScriptView> scripts = vault->getSigningScriptViews(accountName.toStdString(), "", SigningScript::CHANGE | SigningScript::ISSUED | SigningScript::USED);
for (auto& script: scripts) {
QList<QStandardItem*> row;
QString address = QString::fromStdString(getAddressForTxOutScript(script.txoutscript, getDefaultSettings().getBase58Versions()));
QString address = QString::fromStdString(getAddressForTxOutScript(script.txoutscript, base58_versions));
QString type;
switch (script.status) {
@@ -25,6 +25,8 @@ class ScriptModel : public QStandardItemModel
ScriptModel(QObject* parent = NULL);
ScriptModel(CoinDB::Vault* vault, const QString& accountName, QObject* parent = NULL);
void setBase58Versions();
void setVault(CoinDB::Vault* vault);
void setAccount(const QString& accountName);
void update();
@@ -38,5 +40,7 @@ class ScriptModel : public QStandardItemModel
CoinDB::Vault* vault;
QString accountName; // empty when not loaded
unsigned char base58_versions[2];
};
@@ -35,9 +35,7 @@ using namespace std;
TxModel::TxModel(QObject* parent)
: QStandardItemModel(parent)
{
base58_versions[0] = getCoinParams().pay_to_pubkey_hash_version();
base58_versions[1] = getCoinParams().pay_to_script_hash_version();
setBase58Versions();
currencySymbol = getCurrencySymbol();
setColumns();
@@ -46,16 +44,24 @@ TxModel::TxModel(QObject* parent)
TxModel::TxModel(CoinDB::Vault* vault, const QString& accountName, QObject* parent)
: QStandardItemModel(parent)
{
base58_versions[0] = getCoinParams().pay_to_pubkey_hash_version();
base58_versions[1] = getCoinParams().pay_to_script_hash_version();
setBase58Versions();
currencySymbol = getCurrencySymbol();
setColumns();
setVault(vault);
setAccount(accountName);
}
void TxModel::setBase58Versions()
{
base58_versions[0] = getCoinParams().pay_to_pubkey_hash_version();
#ifdef SUPPORT_OLD_ADDRESS_VERSIONS
base58_versions[1] = getUseOldAddressVersions() ? getCoinParams().old_pay_to_script_hash_version() : getCoinParams().pay_to_script_hash_version();
#else
base58_versions[1] = getCoinParams().pay_to_script_hash_version();
#endif
}
void TxModel::setColumns()
{
QStringList columns;
@@ -116,6 +122,8 @@ class SortableRow
void TxModel::update()
{
setBase58Versions();
QString newCurrencySymbol = getCurrencySymbol();
if (newCurrencySymbol != currencySymbol)
{
@@ -32,6 +32,8 @@ class TxModel : public QStandardItemModel
TxModel(QObject* parent = nullptr);
TxModel(CoinDB::Vault* vault, const QString& accountName, QObject* parent = nullptr);
void setBase58Versions();
void setVault(CoinDB::Vault* vault);
CoinDB::Vault* getVault() const { return vault; }
void setAccount(const QString& accountName);

0 comments on commit c320d43

Please sign in to comment.