Skip to content

Commit

Permalink
Added support for old p2sh address types if the coin is transitioning.
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeShark committed May 10, 2017
1 parent 122dfbe commit c320d43
Show file tree
Hide file tree
Showing 13 changed files with 140 additions and 12 deletions.
8 changes: 8 additions & 0 deletions build-all.sh
Expand Up @@ -161,6 +161,7 @@ fi


cd $CURRENT_DIR cd $CURRENT_DIR


#TODO: Automatically detect whether the following units need recompilation
# Always recompile coinparams # Always recompile coinparams
if [[ -e build/$BUILD_TYPE/obj/coinparams.o ]] if [[ -e build/$BUILD_TYPE/obj/coinparams.o ]]
then then
Expand All @@ -179,6 +180,13 @@ then
rm build/$BUILD_TYPE/obj/main.o rm build/$BUILD_TYPE/obj/main.o
fi 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 # For OS X, remove any existing instance of the app bundle
if [[ "$OS" == "osx" ]] if [[ "$OS" == "osx" ]]
then then
Expand Down
2 changes: 1 addition & 1 deletion mSIGNA-ltc.pro
Expand Up @@ -12,7 +12,7 @@ RC_FILE = res/mSIGNA_ltc.rc
ICON = res/icons/app_icons/osx-ltc.icns ICON = res/icons/app_icons/osx-ltc.icns


DEFINES += QT_GUI BOOST_THREAD_USE_LIB BOOST_SPIRIT_THREADSAFE DATABASE_SQLITE 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 CONFIG += c++11 rtti thread


QT += widgets network QT += widgets network
Expand Down
16 changes: 13 additions & 3 deletions src/accountmodel.cpp
Expand Up @@ -37,14 +37,22 @@ using namespace std;


AccountModel::AccountModel(CoinDB::SynchedVault& synchedVault) AccountModel::AccountModel(CoinDB::SynchedVault& synchedVault)
: m_synchedVault(synchedVault), numAccounts(0) : m_synchedVault(synchedVault), numAccounts(0)
{
setBase58Versions();
currencySymbol = getCurrencySymbol();
setColumns();
}

void AccountModel::setBase58Versions()
{ {
base58_versions[0] = getCoinParams().pay_to_pubkey_hash_version(); 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(); base58_versions[1] = getCoinParams().pay_to_script_hash_version();
#endif
base58_versions[2] = getCoinParams().pay_to_witness_pubkey_hash_version(); base58_versions[2] = getCoinParams().pay_to_witness_pubkey_hash_version();
base58_versions[3] = getCoinParams().pay_to_witness_script_hash_version(); base58_versions[3] = getCoinParams().pay_to_witness_script_hash_version();

currencySymbol = getCurrencySymbol();
setColumns();
} }


void AccountModel::setColumns() void AccountModel::setColumns()
Expand All @@ -63,6 +71,8 @@ void AccountModel::setVault(CoinDB::Vault* vault)
*/ */
void AccountModel::update() void AccountModel::update()
{ {
setBase58Versions();

QString newCurrencySymbol = getCurrencySymbol(); QString newCurrencySymbol = getCurrencySymbol();
if (newCurrencySymbol != currencySymbol) if (newCurrencySymbol != currencySymbol)
{ {
Expand Down
3 changes: 3 additions & 0 deletions src/accountmodel.h
Expand Up @@ -52,6 +52,9 @@ class AccountModel : public QStandardItemModel


static const unsigned int DEFAULT_LOOKAHEAD = 25; static const unsigned int DEFAULT_LOOKAHEAD = 25;


// UI operations
void setBase58Versions();

// Account operations // 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(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); 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);
Expand Down
14 changes: 14 additions & 0 deletions src/coinparams.cpp
Expand Up @@ -129,3 +129,17 @@ uint64_t getDefaultFee()
{ {
return getCoinParams().default_fee(); return getCoinParams().default_fee();
} }

#ifdef SUPPORT_OLD_ADDRESS_VERSIONS
static bool useOldAddressVersions = false;

void setAddressVersions(bool useOld)
{
useOldAddressVersions = useOld;
}

bool getUseOldAddressVersions()
{
return useOldAddressVersions;
}
#endif
5 changes: 5 additions & 0 deletions src/coinparams.h
Expand Up @@ -36,3 +36,8 @@ const QString& getCurrencySymbol();
int getCurrencyDecimals(); int getCurrencyDecimals();
uint64_t getCurrencyMax(); uint64_t getCurrencyMax();
uint64_t getDefaultFee(); uint64_t getDefaultFee();

#ifdef SUPPORT_OLD_ADDRESS_VERSIONS
void setAddressVersions(bool useOld = false);
bool getUseOldAddressVersions();
#endif
4 changes: 4 additions & 0 deletions src/createtxdialog.cpp
Expand Up @@ -44,7 +44,11 @@ TxOutLayout::TxOutLayout(uint64_t currencyDivisor, const QString& currencySymbol
{ {
// Base58 version bytes // Base58 version bytes
base58_versions[0] = getCoinParams().pay_to_pubkey_hash_version(); 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(); base58_versions[1] = getCoinParams().pay_to_script_hash_version();
#endif


// Coin parameters // Coin parameters
this->currencyDivisor = currencyDivisor; this->currencyDivisor = currencyDivisor;
Expand Down
42 changes: 41 additions & 1 deletion src/mainwindow.cpp
Expand Up @@ -266,6 +266,12 @@ MainWindow::MainWindow() :
refreshAccounts(); refreshAccounts();
}); });


#ifdef SUPPORT_OLD_ADDRESS_VERSIONS
connect(this, &MainWindow::signal_addressVersionsChanged, [this]() {
refreshAccounts();
});
#endif

setAcceptDrops(true); setAcceptDrops(true);


updateFonts(fontSize); updateFonts(fontSize);
Expand Down Expand Up @@ -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) void MainWindow::newVault(QString fileName)
{ {
if (fileName.isEmpty()) { if (fileName.isEmpty()) {
Expand Down Expand Up @@ -2432,6 +2451,15 @@ void MainWindow::createActions()
connect(showTrailingDecimalsAction, &QAction::toggled, [this]() { selectTrailingDecimals(showTrailingDecimalsAction->isChecked()); }); connect(showTrailingDecimalsAction, &QAction::toggled, [this]() { selectTrailingDecimals(showTrailingDecimalsAction->isChecked()); });
showTrailingDecimalsAction->setChecked(showTrailingDecimals); 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 // about/help actions
aboutAction = new QAction(tr("About..."), this); aboutAction = new QAction(tr("About..."), this);
aboutAction->setStatusTip(tr("About ") + getDefaultSettings().getAppName()); aboutAction->setStatusTip(tr("About ") + getDefaultSettings().getAppName());
Expand Down Expand Up @@ -2543,9 +2571,14 @@ void MainWindow::createMenus()
currencyUnitMenu->addSeparator(); currencyUnitMenu->addSeparator();
currencyUnitMenu->addAction(showTrailingDecimalsAction); 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(); menuBar()->addSeparator();



helpMenu = menuBar()->addMenu(tr("&Help")); helpMenu = menuBar()->addMenu(tr("&Help"));
helpMenu->addAction(aboutAction); helpMenu->addAction(aboutAction);
} }
Expand Down Expand Up @@ -2618,6 +2651,10 @@ void MainWindow::loadSettings()
host = settings.value("host", "localhost").toString(); host = settings.value("host", "localhost").toString();
port = settings.value("port", getCoinParams().default_port()).toInt(); port = settings.value("port", getCoinParams().default_port()).toInt();
autoConnect = settings.value("autoconnect", false).toBool(); 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()); setDocDir(settings.value("lastvaultdir", getDefaultSettings().getDocumentDir()).toString());
} }
Expand All @@ -2640,6 +2677,9 @@ void MainWindow::saveSettings()
settings.setValue("host", host); settings.setValue("host", host);
settings.setValue("port", port); settings.setValue("port", port);
settings.setValue("autoconnect", autoConnect); settings.setValue("autoconnect", autoConnect);
#ifdef SUPPORT_OLD_ADDRESS_VERSIONS
settings.setValue("useoldaddressversions", useOldAddressVersions);
#endif
settings.setValue("lastvaultdir", getDocDir()); settings.setValue("lastvaultdir", getDocDir());
} }
} }
Expand Down
17 changes: 17 additions & 0 deletions src/mainwindow.h
Expand Up @@ -101,6 +101,11 @@ class MainWindow : public QMainWindow


void signal_currencyUnitChanged(); void signal_currencyUnitChanged();


#ifdef SUPPORT_OLD_ADDRESS_VERSIONS
void signal_addressVersionsChanged();
#endif


void unsignedTx(); void unsignedTx();


public slots: public slots:
Expand Down Expand Up @@ -129,6 +134,9 @@ private slots:
void selectCurrencyUnit(); void selectCurrencyUnit();
void selectCurrencyUnit(const QString& newCurrencyUnitPrefix); void selectCurrencyUnit(const QString& newCurrencyUnitPrefix);
void selectTrailingDecimals(bool newShowTrailingDecimals); void selectTrailingDecimals(bool newShowTrailingDecimals);
#ifdef SUPPORT_OLD_ADDRESS_VERSIONS
void selectAddressVersions(bool useOld);
#endif


/////////////////// ///////////////////
// VAULT OPERATIONS // VAULT OPERATIONS
Expand Down Expand Up @@ -268,6 +276,9 @@ private slots:
QMenu* networkMenu; QMenu* networkMenu;
QMenu* fontsMenu; QMenu* fontsMenu;
QMenu* currencyUnitMenu; QMenu* currencyUnitMenu;
#ifdef SUPPORT_OLD_ADDRESS_VERSIONS
QMenu* addressVersionsMenu;
#endif
QMenu* helpMenu; QMenu* helpMenu;


// toolbars // toolbars
Expand Down Expand Up @@ -365,6 +376,12 @@ private slots:
QList<QAction*> currencyUnitActions; QList<QAction*> currencyUnitActions;
QAction* showTrailingDecimalsAction; QAction* showTrailingDecimalsAction;


#ifdef SUPPORT_OLD_ADDRESS_VERSIONS
// address version actions
bool useOldAddressVersions;
QAction* useOldAddressVersionsAction;
#endif

// about/help actions // about/help actions
QAction* aboutAction; QAction* aboutAction;


Expand Down
15 changes: 14 additions & 1 deletion src/scriptmodel.cpp
Expand Up @@ -14,6 +14,7 @@
#include "scriptmodel.h" #include "scriptmodel.h"


#include "settings.h" #include "settings.h"
#include "coinparams.h"


#include <CoinQ/CoinQ_script.h> #include <CoinQ/CoinQ_script.h>


Expand All @@ -27,16 +28,28 @@ ScriptModel::ScriptModel(QObject* parent)
: QStandardItemModel(parent) : QStandardItemModel(parent)
{ {
initColumns(); initColumns();
setBase58Versions();
} }


ScriptModel::ScriptModel(CoinDB::Vault* vault, const QString& accountName, QObject* parent) ScriptModel::ScriptModel(CoinDB::Vault* vault, const QString& accountName, QObject* parent)
: QStandardItemModel(parent) : QStandardItemModel(parent)
{ {
initColumns(); initColumns();
setBase58Versions();
setVault(vault); setVault(vault);
setAccount(accountName); 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() void ScriptModel::initColumns()
{ {
QStringList columns; QStringList columns;
Expand Down Expand Up @@ -72,7 +85,7 @@ void ScriptModel::update()
std::vector<SigningScriptView> scripts = vault->getSigningScriptViews(accountName.toStdString(), "", SigningScript::CHANGE | SigningScript::ISSUED | SigningScript::USED); std::vector<SigningScriptView> scripts = vault->getSigningScriptViews(accountName.toStdString(), "", SigningScript::CHANGE | SigningScript::ISSUED | SigningScript::USED);
for (auto& script: scripts) { for (auto& script: scripts) {
QList<QStandardItem*> row; QList<QStandardItem*> row;
QString address = QString::fromStdString(getAddressForTxOutScript(script.txoutscript, getDefaultSettings().getBase58Versions())); QString address = QString::fromStdString(getAddressForTxOutScript(script.txoutscript, base58_versions));


QString type; QString type;
switch (script.status) { switch (script.status) {
Expand Down
4 changes: 4 additions & 0 deletions src/scriptmodel.h
Expand Up @@ -25,6 +25,8 @@ class ScriptModel : public QStandardItemModel
ScriptModel(QObject* parent = NULL); ScriptModel(QObject* parent = NULL);
ScriptModel(CoinDB::Vault* vault, const QString& accountName, QObject* parent = NULL); ScriptModel(CoinDB::Vault* vault, const QString& accountName, QObject* parent = NULL);


void setBase58Versions();

void setVault(CoinDB::Vault* vault); void setVault(CoinDB::Vault* vault);
void setAccount(const QString& accountName); void setAccount(const QString& accountName);
void update(); void update();
Expand All @@ -38,5 +40,7 @@ class ScriptModel : public QStandardItemModel


CoinDB::Vault* vault; CoinDB::Vault* vault;
QString accountName; // empty when not loaded QString accountName; // empty when not loaded

unsigned char base58_versions[2];
}; };


20 changes: 14 additions & 6 deletions src/txmodel.cpp
Expand Up @@ -35,9 +35,7 @@ using namespace std;
TxModel::TxModel(QObject* parent) TxModel::TxModel(QObject* parent)
: QStandardItemModel(parent) : QStandardItemModel(parent)
{ {
base58_versions[0] = getCoinParams().pay_to_pubkey_hash_version(); setBase58Versions();
base58_versions[1] = getCoinParams().pay_to_script_hash_version();

currencySymbol = getCurrencySymbol(); currencySymbol = getCurrencySymbol();


setColumns(); setColumns();
Expand All @@ -46,16 +44,24 @@ TxModel::TxModel(QObject* parent)
TxModel::TxModel(CoinDB::Vault* vault, const QString& accountName, QObject* parent) TxModel::TxModel(CoinDB::Vault* vault, const QString& accountName, QObject* parent)
: QStandardItemModel(parent) : QStandardItemModel(parent)
{ {
base58_versions[0] = getCoinParams().pay_to_pubkey_hash_version(); setBase58Versions();
base58_versions[1] = getCoinParams().pay_to_script_hash_version();

currencySymbol = getCurrencySymbol(); currencySymbol = getCurrencySymbol();


setColumns(); setColumns();
setVault(vault); setVault(vault);
setAccount(accountName); 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() void TxModel::setColumns()
{ {
QStringList columns; QStringList columns;
Expand Down Expand Up @@ -116,6 +122,8 @@ class SortableRow


void TxModel::update() void TxModel::update()
{ {
setBase58Versions();

QString newCurrencySymbol = getCurrencySymbol(); QString newCurrencySymbol = getCurrencySymbol();
if (newCurrencySymbol != currencySymbol) if (newCurrencySymbol != currencySymbol)
{ {
Expand Down
2 changes: 2 additions & 0 deletions src/txmodel.h
Expand Up @@ -32,6 +32,8 @@ class TxModel : public QStandardItemModel
TxModel(QObject* parent = nullptr); TxModel(QObject* parent = nullptr);
TxModel(CoinDB::Vault* vault, const QString& accountName, QObject* parent = nullptr); TxModel(CoinDB::Vault* vault, const QString& accountName, QObject* parent = nullptr);


void setBase58Versions();

void setVault(CoinDB::Vault* vault); void setVault(CoinDB::Vault* vault);
CoinDB::Vault* getVault() const { return vault; } CoinDB::Vault* getVault() const { return vault; }
void setAccount(const QString& accountName); void setAccount(const QString& accountName);
Expand Down

0 comments on commit c320d43

Please sign in to comment.