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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mSIGNA-ltc.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 13 additions & 3 deletions src/accountmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -63,6 +71,8 @@ void AccountModel::setVault(CoinDB::Vault* vault)
*/
void AccountModel::update()
{
setBase58Versions();

QString newCurrencySymbol = getCurrencySymbol();
if (newCurrencySymbol != currencySymbol)
{
Expand Down
3 changes: 3 additions & 0 deletions src/accountmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 14 additions & 0 deletions src/coinparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions src/coinparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions src/createtxdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
42 changes: 41 additions & 1 deletion src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,12 @@ MainWindow::MainWindow() :
refreshAccounts();
});

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

setAcceptDrops(true);

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)
{
if (fileName.isEmpty()) {
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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());
}
Expand All @@ -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());
}
}
Expand Down
17 changes: 17 additions & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ class MainWindow : public QMainWindow

void signal_currencyUnitChanged();

#ifdef SUPPORT_OLD_ADDRESS_VERSIONS
void signal_addressVersionsChanged();
#endif


void unsignedTx();

public slots:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -268,6 +276,9 @@ private slots:
QMenu* networkMenu;
QMenu* fontsMenu;
QMenu* currencyUnitMenu;
#ifdef SUPPORT_OLD_ADDRESS_VERSIONS
QMenu* addressVersionsMenu;
#endif
QMenu* helpMenu;

// toolbars
Expand Down Expand Up @@ -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;

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

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

#include <CoinQ/CoinQ_script.h>

Expand All @@ -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;
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);
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) {
Expand Down
4 changes: 4 additions & 0 deletions src/scriptmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -38,5 +40,7 @@ class ScriptModel : public QStandardItemModel

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

unsigned char base58_versions[2];
};

20 changes: 14 additions & 6 deletions src/txmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand Down Expand Up @@ -116,6 +122,8 @@ class SortableRow

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

QString newCurrencySymbol = getCurrencySymbol();
if (newCurrencySymbol != currencySymbol)
{
Expand Down
2 changes: 2 additions & 0 deletions src/txmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c320d43

Please sign in to comment.