Browse Source

- The first account use to deploy config contracts.

- Other accounts are rdeletable if not used by a transaction.
cl-refactor
yann300 10 years ago
parent
commit
ff644c65c1
  1. 9
      mix/ClientModel.cpp
  2. 5
      mix/MixClient.cpp
  3. 47
      mix/qml/StateDialog.qml
  4. 22
      mix/qml/StateListModel.qml

9
mix/ClientModel.cpp

@ -48,8 +48,6 @@ namespace dev
namespace mix namespace mix
{ {
const Secret c_defaultUserAccountSecret = Secret("cb73d9408c4720e230387d956eb0f829d8a4dd2c1055f96257167e14e7169074");
class RpcConnector: public jsonrpc::AbstractServerConnector class RpcConnector: public jsonrpc::AbstractServerConnector
{ {
public: public:
@ -159,7 +157,6 @@ void ClientModel::setupState(QVariantMap _state)
QVariantList transactions = _state.value("transactions").toList(); QVariantList transactions = _state.value("transactions").toList();
std::map<Secret, u256> accounts; std::map<Secret, u256> accounts;
accounts.insert(std::make_pair(c_defaultUserAccountSecret, 10000 * ether)); //Default account, used to deploy config contracts.
for (auto const& b: balances) for (auto const& b: balances)
{ {
QVariantMap address = b.toMap(); QVariantMap address = b.toMap();
@ -175,7 +172,7 @@ void ClientModel::setupState(QVariantMap _state)
u256 gas = boost::get<u256>(qvariant_cast<QBigInt*>(transaction.value("gas"))->internalValue()); u256 gas = boost::get<u256>(qvariant_cast<QBigInt*>(transaction.value("gas"))->internalValue());
u256 value = (qvariant_cast<QEther*>(transaction.value("value")))->toU256Wei(); u256 value = (qvariant_cast<QEther*>(transaction.value("value")))->toU256Wei();
u256 gasPrice = (qvariant_cast<QEther*>(transaction.value("gasPrice")))->toU256Wei(); u256 gasPrice = (qvariant_cast<QEther*>(transaction.value("gasPrice")))->toU256Wei();
QString sender = transaction.value("sender").toString();
bool isStdContract = (transaction.value("stdContract").toBool()); bool isStdContract = (transaction.value("stdContract").toBool());
if (isStdContract) if (isStdContract)
{ {
@ -185,7 +182,7 @@ void ClientModel::setupState(QVariantMap _state)
transactionSettings.gasPrice = 10000000000000; transactionSettings.gasPrice = 10000000000000;
transactionSettings.gas = 125000; transactionSettings.gas = 125000;
transactionSettings.value = 0; transactionSettings.value = 0;
transactionSettings.sender = c_defaultUserAccountSecret; transactionSettings.sender = Secret(sender.toStdString());
transactionSequence.push_back(transactionSettings); transactionSequence.push_back(transactionSettings);
} }
else else
@ -193,7 +190,7 @@ void ClientModel::setupState(QVariantMap _state)
if (contractId.isEmpty() && m_context->codeModel()->hasContract()) //TODO: This is to support old project files, remove later if (contractId.isEmpty() && m_context->codeModel()->hasContract()) //TODO: This is to support old project files, remove later
contractId = m_context->codeModel()->contracts().keys()[0]; contractId = m_context->codeModel()->contracts().keys()[0];
QVariantList qParams = transaction.value("qType").toList(); QVariantList qParams = transaction.value("qType").toList();
QString sender = transaction.value("sender").toString();
TransactionSettings transactionSettings(contractId, functionId, value, gas, gasPrice, Secret(sender.toStdString())); TransactionSettings transactionSettings(contractId, functionId, value, gas, gasPrice, Secret(sender.toStdString()));
for (QVariant const& variant: qParams) for (QVariant const& variant: qParams)

5
mix/MixClient.cpp

@ -41,6 +41,7 @@ namespace dev
namespace mix namespace mix
{ {
const Secret c_defaultUserAccountSecret = Secret("cb73d9408c4720e230387d956eb0f829d8a4dd2c1055f96257167e14e7169074");
const u256 c_mixGenesisDifficulty = (u256) 1 << 4; const u256 c_mixGenesisDifficulty = (u256) 1 << 4;
class MixBlockChain: public dev::eth::BlockChain class MixBlockChain: public dev::eth::BlockChain
@ -64,7 +65,9 @@ public:
MixClient::MixClient(std::string const& _dbPath): MixClient::MixClient(std::string const& _dbPath):
m_dbPath(_dbPath), m_minigThreads(0) m_dbPath(_dbPath), m_minigThreads(0)
{ {
//resetState(); std::map<Secret, u256> account;
account.insert(std::make_pair(c_defaultUserAccountSecret, 1000000 * ether));
resetState(account);
} }
MixClient::~MixClient() MixClient::~MixClient()

47
mix/qml/StateDialog.qml

@ -1,5 +1,6 @@
import QtQuick 2.2 import QtQuick 2.2
import QtQuick.Controls 1.1 import QtQuick.Controls 1.1
import QtQuick.Dialogs 1.1
import QtQuick.Layouts 1.1 import QtQuick.Layouts 1.1
import QtQuick.Window 2.0 import QtQuick.Window 2.0
import QtQuick.Controls.Styles 1.3 import QtQuick.Controls.Styles 1.3
@ -12,7 +13,7 @@ Window {
id: modalStateDialog id: modalStateDialog
modality: Qt.ApplicationModal modality: Qt.ApplicationModal
width: 570 width: 590
height: 480 height: 480
title: qsTr("Edit State") title: qsTr("Edit State")
visible: false visible: false
@ -129,20 +130,50 @@ Window {
} }
} }
MessageDialog
{
id: alertAlreadyUsed
text: qsTr("This account is in use. You cannot remove it. The first account is used to deploy config contract and cannot be removed.")
icon: StandardIcon.Warning
standardButtons: StandardButton.Ok
}
TableView TableView
{ {
id: accountsView id: accountsView
Layout.fillWidth: true Layout.fillWidth: true
model: accountsModel model: accountsModel
headerVisible: false
TableViewColumn { TableViewColumn {
role: "name" role: "name"
title: qsTr("Name") title: qsTr("Name")
width: 120 width: 150
delegate: Item { delegate: Item {
Rectangle RowLayout
{ {
height: 25 height: 25
width: parent.width width: parent.width
Button
{
iconSource: "qrc:/qml/img/delete_sign.png"
action: deleteAccountAction
}
Action {
id: deleteAccountAction
tooltip: qsTr("delete Account")
onTriggered:
{
if (transactionsModel.isUsed(stateAccounts[styleData.row].secret))
alertAlreadyUsed.open();
else
{
stateAccounts.splice(styleData.row, 1);
accountsModel.remove(styleData.row);
}
}
}
DefaultTextField { DefaultTextField {
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
onTextChanged: { onTextChanged: {
@ -304,6 +335,16 @@ Window {
stateTransactions.splice(index, 1); stateTransactions.splice(index, 1);
transactionsModel.remove(index); transactionsModel.remove(index);
} }
function isUsed(secret)
{
for (var i in stateTransactions)
{
if (stateTransactions[i].sender === secret)
return true;
}
return false;
}
} }
Component { Component {

22
mix/qml/StateListModel.qml

@ -11,10 +11,10 @@ Item {
property alias model: stateListModel property alias model: stateListModel
property var stateList: [] property var stateList: []
property string defaultAccount: "cb73d9408c4720e230387d956eb0f829d8a4dd2c1055f96257167e14e7169074"
function fromPlainStateItem(s) { function fromPlainStateItem(s) {
if (!s.accounts) if (!s.accounts)
s.accounts = [stateListModel.newAccount("1000000", QEther.Ether)]; //support old project s.accounts = [stateListModel.newAccount("1000000", QEther.Ether, defaultAccount)]; //support old project
return { return {
title: s.title, title: s.title,
transactions: s.transactions.map(fromPlainTransactionItem), transactions: s.transactions.map(fromPlainTransactionItem),
@ -32,6 +32,8 @@ Item {
} }
function fromPlainTransactionItem(t) { function fromPlainTransactionItem(t) {
if (!t.sender)
t.sender = defaultAccount; //support old project
var r = { var r = {
contractId: t.contractId, contractId: t.contractId,
functionId: t.functionId, functionId: t.functionId,
@ -40,7 +42,8 @@ Item {
gas: QEtherHelper.createBigInt(t.gas.value), gas: QEtherHelper.createBigInt(t.gas.value),
gasPrice: QEtherHelper.createEther(t.gasPrice.value, t.gasPrice.unit), gasPrice: QEtherHelper.createEther(t.gasPrice.value, t.gasPrice.unit),
stdContract: t.stdContract, stdContract: t.stdContract,
parameters: {} parameters: {},
sender: t.sender
}; };
var qType = []; var qType = [];
for (var key in t.parameters) for (var key in t.parameters)
@ -189,11 +192,12 @@ Item {
}; };
} }
function newAccount(_balance, _unit) function newAccount(_balance, _unit, _secret)
{ {
var secret = clientModel.newAddress(); if (!_secret)
var name = qsTr("Account") + "-" + secret.substring(0, 4); _secret = clientModel.newAddress();
return { name: name, secret: secret, balance: QEtherHelper.createEther(_balance, _unit) }; var name = qsTr("Account") + "-" + _secret.substring(0, 4);
return { name: name, secret: _secret, balance: QEtherHelper.createEther(_balance, _unit) };
} }
function createDefaultState() { function createDefaultState() {
@ -203,7 +207,7 @@ Item {
accounts: [] accounts: []
}; };
item.accounts.push(newAccount("1000000", QEther.Ether)); item.accounts.push(newAccount("1000000", QEther.Ether, defaultAccount));
//add all stdc contracts //add all stdc contracts
for (var i = 0; i < contractLibrary.model.count; i++) { for (var i = 0; i < contractLibrary.model.count; i++) {
@ -213,6 +217,7 @@ Item {
contractTransaction.contractId = contractItem.name; contractTransaction.contractId = contractItem.name;
contractTransaction.functionId = contractItem.name; contractTransaction.functionId = contractItem.name;
contractTransaction.stdContract = true; contractTransaction.stdContract = true;
contractTransaction.sender = item.accounts[0].secret; // default account is used to deploy std contract.
item.transactions.push(contractTransaction); item.transactions.push(contractTransaction);
}; };
@ -221,6 +226,7 @@ Item {
var ctorTr = defaultTransactionItem(); var ctorTr = defaultTransactionItem();
ctorTr.functionId = c; ctorTr.functionId = c;
ctorTr.contractId = c; ctorTr.contractId = c;
ctorTr.sender = item.accounts[0].secret;
item.transactions.push(ctorTr); item.transactions.push(ctorTr);
} }
return item; return item;

Loading…
Cancel
Save