arkpar
10 years ago
18 changed files with 425 additions and 139 deletions
@ -0,0 +1,31 @@ |
|||
import QtQuick 2.2 |
|||
|
|||
Item { |
|||
id: contractLibrary |
|||
property alias model: contractListModel; |
|||
|
|||
Connections { |
|||
target: appContext |
|||
Component.onCompleted: { |
|||
|
|||
//TODO: load a list, dependencies, ets, from external files |
|||
var configSource = fileIo.readFile("qrc:///stdc/config.sol"); |
|||
var nameRegSource = fileIo.readFile("qrc:///stdc/namereg.sol"); |
|||
contractListModel.append({ |
|||
name: "Config", |
|||
url: "qrc:///stdc/config.sol", |
|||
source: configSource |
|||
}); |
|||
contractListModel.append({ |
|||
name: "NameReg", |
|||
url: "qrc:///stdc/namereg.sol", |
|||
source: nameRegSource |
|||
}); |
|||
} |
|||
} |
|||
|
|||
ListModel { |
|||
id: contractListModel |
|||
} |
|||
} |
|||
|
@ -0,0 +1,172 @@ |
|||
import QtQuick 2.2 |
|||
import QtQuick.Controls.Styles 1.1 |
|||
import QtQuick.Controls 1.1 |
|||
import QtQuick.Dialogs 1.1 |
|||
import QtQuick.Layouts 1.1 |
|||
import org.ethereum.qml.QEther 1.0 |
|||
import "js/QEtherHelper.js" as QEtherHelper |
|||
|
|||
Item { |
|||
|
|||
property int defaultStateIndex: -1 |
|||
property alias model: stateListModel |
|||
property var stateList: [] |
|||
|
|||
function fromPlainStateItem(s) { |
|||
return { |
|||
title: s.title, |
|||
balance: QEtherHelper.createEther(s.balance.value, s.balance.unit), |
|||
transactions: s.transactions.map(fromPlainTransactionItem) |
|||
}; |
|||
} |
|||
|
|||
function fromPlainTransactionItem(t) { |
|||
return { |
|||
functionId: t.functionId, |
|||
value: QEtherHelper.createEther(t.value.value, t.value.unit), |
|||
gas: QEtherHelper.createEther(t.gas.value, t.gas.unit), |
|||
gasPrice: QEtherHelper.createEther(t.gasPrice.value, t.gasPrice.unit), |
|||
executeConstructor: t.executeConstructor, |
|||
stdContract: t.stdContract |
|||
}; |
|||
} |
|||
|
|||
function toPlainStateItem(s) { |
|||
return { |
|||
title: s.title, |
|||
balance: { balance: s.balance.value, unit: s.balance.unit }, |
|||
transactions: s.transactions.map(toPlainTransactionItem) |
|||
}; |
|||
} |
|||
|
|||
function toPlainTransactionItem(t) { |
|||
return { |
|||
functionId: t.functionId, |
|||
value: { value: t.value.value, unit: t.value.unit }, |
|||
gas: { value: t.gas.value, unit: t.gas.unit }, |
|||
gasPrice: { value: t.gasPrice.value, unit: t.gasPrice.unit }, |
|||
executeConstructor: t.executeConstructor, |
|||
stdContract: t.stdContract |
|||
}; |
|||
} |
|||
|
|||
Connections { |
|||
target: projectModel |
|||
onProjectClosed: { |
|||
stateListModel.clear(); |
|||
stateList = []; |
|||
} |
|||
onProjectLoaded: { |
|||
if (!projectData.states) |
|||
projectData.states = []; |
|||
if (projectData.defaultStateIndex) |
|||
defaultStateIndex = projectData.defaultStateIndex; |
|||
var items = projectData.states; |
|||
for(var i = 0; i < items.length; i++) { |
|||
var item = fromPlainStateItem(items[i]); |
|||
stateListModel.append(item); |
|||
stateList.push(item); |
|||
} |
|||
} |
|||
onProjectSaving: { |
|||
projectData.states = [] |
|||
for(var i = 0; i < stateListModel.count; i++) { |
|||
projectData.states.push(toPlainStateItem(stateList[i])); |
|||
} |
|||
projectData.defaultStateIndex = defaultStateIndex; |
|||
} |
|||
onNewProject: { |
|||
var state = toPlainTransactionItem(stateListModel.createDefaultState()); |
|||
state.title = qsTr("Default"); |
|||
projectData.states = [ state ]; |
|||
projectData.defaultStateIndex = 0; |
|||
} |
|||
} |
|||
|
|||
StateDialog { |
|||
id: stateDialog |
|||
onAccepted: { |
|||
var item = stateDialog.getItem(); |
|||
if (stateDialog.stateIndex < stateListModel.count) { |
|||
defaultStateIndex = stateDialog.isDefault; |
|||
stateList[stateDialog.stateIndex] = item; |
|||
stateListModel.set(stateDialog.stateIndex, item); |
|||
} else { |
|||
stateList.push(item); |
|||
stateListModel.append(item); |
|||
} |
|||
|
|||
stateListModel.save(); |
|||
} |
|||
} |
|||
|
|||
ContractLibrary { |
|||
id: contractLibrary; |
|||
} |
|||
|
|||
ListModel { |
|||
id: stateListModel |
|||
|
|||
function defaultTransactionItem() { |
|||
return { |
|||
value: QEtherHelper.createEther("100", QEther.Wei), |
|||
gas: QEtherHelper.createEther("125000", QEther.Wei), |
|||
gasPrice: QEtherHelper.createEther("10000000000000", QEther.Wei), |
|||
executeConstructor: false, |
|||
stdContract: false |
|||
}; |
|||
} |
|||
|
|||
function createDefaultState() { |
|||
var ether = QEtherHelper.createEther("100000000000000000000000000", QEther.Wei); |
|||
var item = { |
|||
title: "", |
|||
balance: ether, |
|||
transactions: [] |
|||
}; |
|||
|
|||
//add all stdc contracts |
|||
for (var i = 0; i < contractLibrary.model.count; i++) { |
|||
var contractTransaction = defaultTransactionItem(); |
|||
var contractItem = contractLibrary.model.get(i); |
|||
contractTransaction.url = contractItem.url; |
|||
contractTransaction.functionId = contractItem.name; |
|||
contractTransaction.stdContract = true; |
|||
item.transactions.push(contractTransaction); |
|||
}; |
|||
|
|||
//add constructor |
|||
var ctorTr = defaultTransactionItem(); |
|||
ctorTr.executeConstructor = true; |
|||
ctorTr.functionId = qsTr("Constructor"); |
|||
item.transactions.push(ctorTr); |
|||
return item; |
|||
} |
|||
|
|||
function addState() { |
|||
var item = createDefaultState(); |
|||
stateDialog.open(stateListModel.count, item, defaultStateIndex === -1); |
|||
} |
|||
|
|||
function editState(index) { |
|||
stateDialog.open(index, stateList[index], defaultStateIndex === index); |
|||
} |
|||
|
|||
function runState(index) { |
|||
var item = stateList[index]; |
|||
clientModel.debugState(item); |
|||
} |
|||
|
|||
function deleteState(index) { |
|||
stateListModel.remove(index); |
|||
stateList.splice(index, 1); |
|||
if (index === defaultStateIndex) |
|||
defaultStateIndex = -1; |
|||
save(); |
|||
} |
|||
|
|||
function save() { |
|||
projectModel.saveProject(); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,45 @@ |
|||
//sol Config |
|||
// Simple global configuration registrar. |
|||
// @authors: |
|||
// Gav Wood <g@ethdev.com> |
|||
#require owned, mortal |
|||
contract Config is mortal, owned { |
|||
function register(uint id, address service) { |
|||
if (tx.origin != owner) |
|||
return; |
|||
services[id] = service; |
|||
log1(0, id); |
|||
} |
|||
|
|||
function unregister(uint id) { |
|||
if (msg.sender != owner && services[id] != msg.sender) |
|||
return; |
|||
services[id] = address(0); |
|||
log1(0, id); |
|||
} |
|||
|
|||
function lookup(uint service) constant returns(address a) { |
|||
return services[service]; |
|||
} |
|||
|
|||
mapping (uint => address) services; |
|||
} |
|||
|
|||
/* |
|||
|
|||
// Solidity Interface: |
|||
contract Config{function lookup(uint256 service)constant returns(address a){}function kill(){}function unregister(uint256 id){}function register(uint256 id,address service){}} |
|||
|
|||
// Example Solidity use: |
|||
address addrConfig = 0x661005d2720d855f1d9976f88bb10c1a3398c77f; |
|||
address addrNameReg = Config(addrConfig).lookup(1); |
|||
|
|||
// JS Interface: |
|||
var abiConfig = [{"constant":false,"inputs":[],"name":"kill","outputs":[]},{"constant":true,"inputs":[{"name":"service","type":"uint256"}],"name":"lookup","outputs":[{"name":"a","type":"address"}]},{"constant":false,"inputs":[{"name":"id","type":"uint256"},{"name":"service","type":"address"}],"name":"register","outputs":[]},{"constant":false,"inputs":[{"name":"id","type":"uint256"}],"name":"unregister","outputs":[]}]; |
|||
|
|||
// Example JS use: |
|||
var addrConfig = "0x661005d2720d855f1d9976f88bb10c1a3398c77f"; |
|||
var addrNameReg; |
|||
web3.eth.contract(addrConfig, abiConfig).lookup(1).call().then(function(r){ addrNameReg = r; }) |
|||
|
|||
*/ |
@ -0,0 +1,73 @@ |
|||
//sol NameReg |
|||
// Simple global name registrar. |
|||
// @authors: |
|||
// kobigurk (from #ethereum-dev) |
|||
// Gav Wood <g@ethdev.com> |
|||
|
|||
contract NameRegister { |
|||
function getAddress(string32 _name) constant returns (address o_owner) {} |
|||
function getName(address _owner) constant returns (string32 o_name) {} |
|||
} |
|||
|
|||
#require Config, owned |
|||
contract NameReg is owned, NameRegister { |
|||
function NameReg() { |
|||
toName[Config()] = "Config"; |
|||
toAddress["Config"] = Config(); |
|||
toName[this] = "NameReg"; |
|||
toAddress["NameReg"] = this; |
|||
Config().register(1, this); |
|||
log1(0, hash256(Config())); |
|||
log1(0, hash256(this)); |
|||
} |
|||
|
|||
function register(string32 name) { |
|||
// Don't allow the same name to be overwritten. |
|||
if (toAddress[name] != address(0)) |
|||
return; |
|||
// Unregister previous name if there was one. |
|||
if (toName[msg.sender] != "") |
|||
toAddress[toName[msg.sender]] = 0; |
|||
|
|||
toName[msg.sender] = name; |
|||
toAddress[name] = msg.sender; |
|||
log1(0, hash256(msg.sender)); |
|||
} |
|||
|
|||
function unregister() { |
|||
string32 n = toName[msg.sender]; |
|||
if (n == "") |
|||
return; |
|||
log1(0, hash256(toAddress[n])); |
|||
toName[msg.sender] = ""; |
|||
toAddress[n] = address(0); |
|||
} |
|||
|
|||
function addressOf(string32 name) constant returns (address addr) { |
|||
return toAddress[name]; |
|||
} |
|||
|
|||
function nameOf(address addr) constant returns (string32 name) { |
|||
return toName[addr]; |
|||
} |
|||
|
|||
mapping (address => string32) toName; |
|||
mapping (string32 => address) toAddress; |
|||
} |
|||
|
|||
|
|||
/* |
|||
|
|||
// Solidity Interface: |
|||
contract NameReg{function kill(){}function register(string32 name){}function addressOf(string32 name)constant returns(address addr){}function unregister(){}function nameOf(address addr)constant returns(string32 name){}} |
|||
|
|||
// Example Solidity use: |
|||
NameReg(addrNameReg).register("Some Contract"); |
|||
|
|||
// JS Interface: |
|||
var abiNameReg = [{"constant":true,"inputs":[{"name":"name","type":"string32"}],"name":"addressOf","outputs":[{"name":"addr","type":"address"}]},{"constant":false,"inputs":[],"name":"kill","outputs":[]},{"constant":true,"inputs":[{"name":"addr","type":"address"}],"name":"nameOf","outputs":[{"name":"name","type":"string32"}]},{"constant":false,"inputs":[{"name":"name","type":"string32"}],"name":"register","outputs":[]},{"constant":false,"inputs":[],"name":"unregister","outputs":[]}]; |
|||
|
|||
// Example JS use: |
|||
web3.eth.contract(addrNameReg, abiNameReg).register("My Name").transact(); |
|||
|
|||
*/ |
Loading…
Reference in new issue