Browse Source

pass Secret to the executing transaction.

cl-refactor
yann300 10 years ago
parent
commit
e4c2c654bc
  1. 10
      mix/ClientModel.cpp
  2. 4
      mix/ClientModel.h
  3. 16
      mix/MixClient.cpp
  4. 66
      mix/qml/StateDialog.qml
  5. 18
      mix/qml/StateListModel.qml
  6. 33
      mix/qml/TransactionDialog.qml

10
mix/ClientModel.cpp

@ -38,6 +38,7 @@
#include "QEther.h"
#include "Web3Server.h"
#include "ClientModel.h"
#include "MixClient.h"
using namespace dev;
using namespace dev::eth;
@ -47,6 +48,8 @@ namespace dev
namespace mix
{
const Secret c_defaultUserAccountSecret = Secret("cb73d9408c4720e230387d956eb0f829d8a4dd2c1055f96257167e14e7169074");
class RpcConnector: public jsonrpc::AbstractServerConnector
{
public:
@ -157,10 +160,11 @@ void ClientModel::debugDeployment()
void ClientModel::setupState(QVariantMap _state)
{
QVariantList balances = _state.value("balances").toList();
QVariantList balances = _state.value("accounts").toList();
QVariantList transactions = _state.value("transactions").toList();
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)
{
QVariantMap address = b.toMap();
@ -186,6 +190,7 @@ void ClientModel::setupState(QVariantMap _state)
transactionSettings.gasPrice = 10000000000000;
transactionSettings.gas = 125000;
transactionSettings.value = 0;
transactionSettings.sender = c_defaultUserAccountSecret;
transactionSequence.push_back(transactionSettings);
}
else
@ -193,7 +198,8 @@ void ClientModel::setupState(QVariantMap _state)
if (contractId.isEmpty() && m_context->codeModel()->hasContract()) //TODO: This is to support old project files, remove later
contractId = m_context->codeModel()->contracts().keys()[0];
QVariantList qParams = transaction.value("qType").toList();
TransactionSettings transactionSettings(contractId, functionId, value, gas, gasPrice);
QString sender = transaction.value("sender").toString();
TransactionSettings transactionSettings(contractId, functionId, value, gas, gasPrice, Secret(sender.toStdString()));
for (QVariant const& variant: qParams)
{

4
mix/ClientModel.h

@ -47,8 +47,8 @@ class QVariableDefinition;
struct TransactionSettings
{
TransactionSettings() {}
TransactionSettings(QString const& _contractId, QString const& _functionId, u256 _value, u256 _gas, u256 _gasPrice):
contractId(_contractId), functionId(_functionId), value(_value), gas(_gas), gasPrice(_gasPrice) {}
TransactionSettings(QString const& _contractId, QString const& _functionId, u256 _value, u256 _gas, u256 _gasPrice, Secret _sender):
contractId(_contractId), functionId(_functionId), value(_value), gas(_gas), gasPrice(_gasPrice), sender(_sender) {}
TransactionSettings(QString const& _stdContractName, QString const& _stdContractUrl):
contractId(_stdContractName), stdContractUrl(_stdContractUrl) {}

16
mix/MixClient.cpp

@ -21,6 +21,7 @@
*/
#include <vector>
#include <QDebug>
#include <libdevcore/Exceptions.h>
#include <libethereum/CanonBlockChain.h>
#include <libethereum/Transaction.h>
@ -40,7 +41,6 @@ namespace dev
namespace mix
{
const Secret c_defaultUserAccountSecret = Secret("cb73d9408c4720e230387d956eb0f829d8a4dd2c1055f96257167e14e7169074");
const u256 c_mixGenesisDifficulty = (u256) 1 << 4;
class MixBlockChain: public dev::eth::BlockChain
@ -83,19 +83,13 @@ void MixClient::resetState(std::map<Secret, u256> _accounts)
accountState.init();
std::map<Address, Account> genesisState;
if (_accounts.size() > 0)
for (auto account: _accounts)
{
KeyPair a = KeyPair(account.first);
m_userAccounts.push_back(a);
genesisState.insert(std::make_pair(a.address(), Account(account.second, Account::NormalCreation)));
}
else
for (auto account: _accounts)
{
KeyPair a = KeyPair(c_defaultUserAccountSecret);
KeyPair a = KeyPair(account.first);
m_userAccounts.push_back(a);
genesisState.insert(std::make_pair(a.address() , Account(u256(10000 * ether), Account::NormalCreation)));
genesisState.insert(std::make_pair(a.address(), Account(account.second, Account::NormalCreation)));
}
dev::eth::commit(genesisState, static_cast<MemoryDB&>(m_stateDB), accountState);
h256 stateRoot = accountState.root();
m_bc.reset();

66
mix/qml/StateDialog.qml

@ -12,7 +12,7 @@ Window {
id: modalStateDialog
modality: Qt.ApplicationModal
width: 520
width: 555
height: 480
title: qsTr("Edit State")
visible: false
@ -41,8 +41,7 @@ Window {
accountsModel.clear();
stateAccounts = [];
for (var k = 0; k < item.accounts.length; k++)
{
accountsModel.append(item.accounts[k]);
{ accountsModel.append(item.accounts[k]);
stateAccounts.push(item.accounts[k]);
}
@ -100,23 +99,35 @@ Window {
RowLayout
{
Layout.fillWidth: true
DefaultLabel {
Layout.preferredWidth: 75
text: qsTr("Accounts")
}
Button
Rectangle
{
iconSource: "qrc:/qml/img/plus.png"
action: newAccountAction
width: 10
height: 10
}
Layout.preferredWidth: 75
DefaultLabel {
id: accountsLabel
Layout.preferredWidth: 75
text: qsTr("Accounts")
}
Action {
id: newAccountAction
tooltip: qsTr("Add new Account")
onTriggered: accountsModel.newAccount("10000", QEther.Ether);
Button
{
anchors.top: accountsLabel.bottom
anchors.topMargin: 10
iconSource: "qrc:/qml/img/plus.png"
action: newAccountAction
}
Action {
id: newAccountAction
tooltip: qsTr("Add new Account")
onTriggered:
{
var account = stateListModel.newAccount("1000000", QEther.Ether);
stateAccounts.push(account);
accountsModel.append(account);
}
}
}
TableView
@ -124,9 +135,9 @@ Window {
Layout.fillWidth: true
model: accountsModel
TableViewColumn {
role: "secret"
title: qsTr("Secret")
width: 100
role: "name"
title: qsTr("Name")
width: 120
delegate: Item {
Rectangle
{
@ -134,7 +145,7 @@ Window {
DefaultLabel {
anchors.verticalCenter: parent.verticalCenter
text: {
return styleData.value.substring(0, 5) + '...';
return styleData.value
}
}
}
@ -156,8 +167,8 @@ Window {
}
rowDelegate:
Rectangle {
color: "transparent"
height: 40;
color: styleData.alternate ? "transparent" : "#f0f0f0"
height: 30;
}
}
}
@ -259,13 +270,6 @@ Window {
ListModel {
id: accountsModel
function newAccount(_balance, _unit)
{
var secret = clientModel.newAddress();
accountsModel.append({ secret: secret, balance: QEtherHelper.createEther(_balance, _unit) });
stateAccounts.push({ secret: secret, balance: QEtherHelper.createEther(_balance, _unit) });
}
function removeAccount(_i)
{
accountsModel.remove(_i);
@ -277,6 +281,7 @@ Window {
id: transactionsModel
function editTransaction(index) {
transactionDialog.stateAccounts = stateAccounts;
transactionDialog.open(index, transactionsModel.get(index));
}
@ -286,6 +291,7 @@ Window {
// https://bugreports.qt-project.org/browse/QTBUG-41327
// Second call to signal handler would just edit the item that was just created, no harm done
var item = TransactionHelper.defaultTransaction();
transactionDialog.stateAccounts = stateAccounts;
transactionDialog.open(transactionsModel.count, item);
}

18
mix/qml/StateListModel.qml

@ -23,6 +23,7 @@ Item {
function fromPlainAccountItem(t)
{
return {
name: t.name,
secret: t.secret,
balance: QEtherHelper.createEther(t.balance.value, t.balance.unit)
};
@ -91,6 +92,7 @@ Item {
function toPlainAccountItem(t)
{
return {
name: t.name,
secret: t.secret,
balance: {
value: t.balance.value,
@ -171,7 +173,6 @@ Item {
ListModel {
id: stateListModel
property string defaultSecret: "cb73d9408c4720e230387d956eb0f829d8a4dd2c1055f96257167e14e7169075"
property int defaultStateIndex: 0
signal defaultStateChanged;
signal stateListModelReady;
@ -186,18 +187,23 @@ Item {
};
}
function newAccount(_balance, _unit)
{
var secret = clientModel.newAddress();
var name = qsTr("Account") + " - " + secret.substring(0, 5);
return { name: name, secret: secret, balance: QEtherHelper.createEther(_balance, _unit) };
}
function createDefaultState() {
var ether = QEtherHelper.createEther("1000000", QEther.Ether);
var item = {
title: "",
transactions: [],
accounts: []
};
item.accounts.push({
secret: defaultSecret,
balance: ether
});
item.accounts.push(newAccount("1000000", QEther.Ether));
console.log(JSON.stringify(item.accounts));
//add all stdc contracts
for (var i = 0; i < contractLibrary.model.count; i++) {

33
mix/qml/TransactionDialog.qml

@ -25,6 +25,7 @@ Window {
property var itemParams;
property bool useTransactionDefaultValue: false
property var qType;
property alias stateAccounts: senderComboBox.model
signal accepted;
@ -44,6 +45,8 @@ Window {
rowFunction.visible = true;
itemParams = item.parameters !== undefined ? item.parameters : {};
if (item.sender)
senderComboBox.select(item.sender);
contractsModel.clear();
var contractIndex = -1;
@ -190,6 +193,7 @@ Window {
item.functionId = transactionDialog.functionId;
}
item.sender = senderComboBox.model[senderComboBox.currentIndex].secret;
var orderedQType = [];
for (var p = 0; p < transactionDialog.transactionParams.count; p++) {
var parameter = transactionDialog.transactionParams.get(p);
@ -210,6 +214,35 @@ Window {
id: dialogContent
anchors.top: parent.top
spacing: 10
RowLayout
{
id: rowSender
Layout.fillWidth: true
height: 150
DefaultLabel {
Layout.preferredWidth: 75
text: qsTr("Sender")
}
ComboBox {
function select(secret)
{
for (var i in model)
if (model[i].secret === secret)
{
currentIndex = i;
break;
}
}
id: senderComboBox
Layout.preferredWidth: 350
currentIndex: 0
textRole: "name"
editable: false
}
}
RowLayout
{
id: rowContract

Loading…
Cancel
Save