Browse Source

adopted new ethereum.js and solidity types

cl-refactor
arkpar 10 years ago
parent
commit
2da3c83f2e
  1. 3
      mix/qml/html/WebContainer.html
  2. 32
      mix/stdc/std.sol

3
mix/qml/html/WebContainer.html

@ -20,7 +20,8 @@ updateContracts = function(contracts) {
window.web3.reset(); window.web3.reset();
window.contracts = {}; window.contracts = {};
for (var c in contracts) { for (var c in contracts) {
var contract = window.web3.eth.contract(contracts[c].address, contracts[c].interface); var contractProto = window.web3.eth.contract(contracts[c].interface);
var contract = new contractProto(contracts[c].address);
window.contracts[c] = { window.contracts[c] = {
address: c.address, address: c.address,
interface: c.interface, interface: c.interface,

32
mix/stdc/std.sol

@ -13,14 +13,14 @@ contract Config is mortal {
if (tx.origin != owner) if (tx.origin != owner)
return; return;
services[id] = service; services[id] = service;
log1(0, id); log1(0, bytes32(id));
} }
function unregister(uint id) { function unregister(uint id) {
if (msg.sender != owner && services[id] != msg.sender) if (msg.sender != owner && services[id] != msg.sender)
return; return;
services[id] = address(0); services[id] = address(0);
log1(0, id); log1(0, bytes32(id));
} }
function lookup(uint service) constant returns(address a) { function lookup(uint service) constant returns(address a) {
@ -56,8 +56,8 @@ web3.eth.contract(addrConfig, abiConfig).lookup(1).call().then(function(r){ addr
// Gav Wood <g@ethdev.com> // Gav Wood <g@ethdev.com>
contract NameRegister { contract NameRegister {
function getAddress(string32 _name) constant returns (address o_owner) {} function getAddress(bytes32 _name) constant returns (address o_owner) {}
function getName(address _owner) constant returns (string32 o_name) {} function getName(address _owner) constant returns (bytes32 o_name) {}
} }
contract NameReg is owned, NameRegister { contract NameReg is owned, NameRegister {
@ -68,11 +68,11 @@ contract NameReg is owned, NameRegister {
toName[this] = "NameReg"; toName[this] = "NameReg";
toAddress["NameReg"] = this; toAddress["NameReg"] = this;
Config(addrConfig).register(1, this); Config(addrConfig).register(1, this);
log1(0, hash256(addrConfig)); //log1(0, bytes32(addrConfig));
log1(0, hash256(this)); //log1(0, bytes32(this));
} }
function register(string32 name) { function register(bytes32 name) {
// Don't allow the same name to be overwritten. // Don't allow the same name to be overwritten.
if (toAddress[name] != address(0)) if (toAddress[name] != address(0))
return; return;
@ -82,41 +82,41 @@ contract NameReg is owned, NameRegister {
toName[msg.sender] = name; toName[msg.sender] = name;
toAddress[name] = msg.sender; toAddress[name] = msg.sender;
log1(0, hash256(msg.sender)); //log1(0, bytes32(msg.sender));
} }
function unregister() { function unregister() {
string32 n = toName[msg.sender]; bytes32 n = toName[msg.sender];
if (n == "") if (n == "")
return; return;
log1(0, hash256(toAddress[n])); //log1(0, bytes32(toAddress[n]));
toName[msg.sender] = ""; toName[msg.sender] = "";
toAddress[n] = address(0); toAddress[n] = address(0);
} }
function addressOf(string32 name) constant returns (address addr) { function addressOf(bytes32 name) constant returns (address addr) {
return toAddress[name]; return toAddress[name];
} }
function nameOf(address addr) constant returns (string32 name) { function nameOf(address addr) constant returns (bytes32 name) {
return toName[addr]; return toName[addr];
} }
mapping (address => string32) toName; mapping (address => bytes32) toName;
mapping (string32 => address) toAddress; mapping (bytes32 => address) toAddress;
} }
/* /*
// Solidity Interface: // 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){}} contract NameReg{function kill(){}function register(bytes32 name){}function addressOf(bytes32 name)constant returns(address addr){}function unregister(){}function nameOf(address addr)constant returns(bytes32 name){}}
// Example Solidity use: // Example Solidity use:
NameReg(addrNameReg).register("Some Contract"); NameReg(addrNameReg).register("Some Contract");
// JS Interface: // 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":[]}]; var abiNameReg = [{"constant":true,"inputs":[{"name":"name","type":"bytes32"}],"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":"bytes32"}]},{"constant":false,"inputs":[{"name":"name","type":"bytes32"}],"name":"register","outputs":[]},{"constant":false,"inputs":[],"name":"unregister","outputs":[]}];
// Example JS use: // Example JS use:
web3.eth.contract(addrNameReg, abiNameReg).register("My Name").transact(); web3.eth.contract(addrNameReg, abiNameReg).register("My Name").transact();

Loading…
Cancel
Save