Skip to content

Commit 4dc4577

Browse files
authored
Merge pull request ethereum#2912 from Arachnid/ens
swarm: Add code to generate genesis JSON for swarm testnet
2 parents 8d94d68 + 218cc1c commit 4dc4577

File tree

6 files changed

+195
-3
lines changed

6 files changed

+195
-3
lines changed

swarm/api/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const (
2121

2222
// by default ens root is north internal
2323
var (
24-
toyNetEnsRoot = common.HexToAddress("0x606aabab27f8aa98b772bf593b18e550ede87176")
24+
toyNetEnsRoot = common.HexToAddress("0xd344889e0be3e9ef6c26b0f60ef66a32e83c1b69")
2525
)
2626

2727
// separate bzz directories

swarm/cmd/makegenesis/genesis.json

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"nonce": "0x42",
3+
"gasLimit": "0x47e7c4",
4+
"difficulty": "0x20000",
5+
"alloc": {
6+
"866b5394fe446751e932b7ef77280f4ab7ea3afe": {
7+
"code": "",
8+
"storage": {},
9+
"balance": "01c51307a94a7800"
10+
},
11+
"0000000000000000000000000000000000000000": {
12+
"code": "",
13+
"storage": {},
14+
"balance": "3aecf856b58800"
15+
},
16+
"0000000000000000000000000000000000000001": {
17+
"code": "",
18+
"storage": {},
19+
"balance": "01"
20+
},
21+
"0000000000000000000000000000000000000002": {
22+
"code": "",
23+
"storage": {},
24+
"balance": "01"
25+
},
26+
"0000000000000000000000000000000000000003": {
27+
"code": "",
28+
"storage": {},
29+
"balance": "01"
30+
},
31+
"0000000000000000000000000000000000000004": {
32+
"code": "",
33+
"storage": {},
34+
"balance": "01"
35+
},
36+
"cb7152b03774fd01a8480001b2bcdfebc4f04363": {
37+
"code": "6060604052361561004b5760e060020a60003504632dff694181146100535780633b3b57de1461007557806341b9dc2b146100a0578063c3d014d614610139578063d5fa2b00146101b2575b61022b610002565b61022d6004356000818152600260205260408120549081141561027057610002565b61023f600435600081815260016020526040812054600160a060020a03169081141561027057610002565b61025c60043560243560007f6164647200000000000000000000000000000000000000000000000000000000821480156100f05750600083815260016020526040812054600160a060020a031614155b8061013257507f636f6e74656e740000000000000000000000000000000000000000000000000082148015610132575060008381526002602052604081205414155b9392505050565b61022b600435602435600080546040805160e060020a6302571be30281526004810186905290518593600160a060020a033381169416926302571be392602482810193602093839003909101908290876161da5a03f11561000257505060405151600160a060020a031691909114905061027557610002565b61022b600435602435600080546040805160e060020a6302571be30281526004810186905290518593600160a060020a033381169416926302571be392602482810193602093839003909101908290876161da5a03f11561000257505060405151600160a060020a03169190911490506102c157610002565b005b60408051918252519081900360200190f35b60408051600160a060020a03929092168252519081900360200190f35b604080519115158252519081900360200190f35b919050565b6000838152600260209081526040918290208490558151848152915185927f0424b6fe0d9c3bdbece0e7879dc241bb0c22e900be8b6c168b4ee08bd9bf83bc92908290030190a2505050565b600083815260016020908152604091829020805473ffffffffffffffffffffffffffffffffffffffff1916851790558151600160a060020a0385168152915185927f52d7d861f09ab3d26239d492e8968629f95e9e318cf0b73bfddc441522a15fd292908290030190a250505056",
38+
"storage": {
39+
"0000000000000000000000000000000000000000000000000000000000000000": "d344889e0be3e9ef6c26b0f60ef66a32e83c1b69"
40+
},
41+
"balance": ""
42+
},
43+
"d344889e0be3e9ef6c26b0f60ef66a32e83c1b69": {
44+
"code": "606060405260e060020a60003504630178b8bf811461004757806302571be31461006e5780631896f70a14610091578063569cd595146100c55780635b0fc9c3146100fc575b005b610130600435600081815260208190526040902060010154600160a060020a03165b919050565b610130600435600081815260208190526040902054600160a060020a0316610069565b6100456004356024356000828152602081905260409020548290600160a060020a0390811633919091161461014d57610002565b6100456004356024356044356000838152602081905260408120548490600160a060020a039081163391909116146101bf57610002565b6100456004356024356000828152602081905260409020548290600160a060020a0390811633919091161461025957610002565b60408051600160a060020a03929092168252519081900360200190f35b60408051600160a060020a0384168152905184917f335721b01866dc23fbee8b6b2c7b1e14d6f05c28cd35a2c934239f94095602a0919081900360200190a2506000828152602081905260409020600101805473ffffffffffffffffffffffffffffffffffffffff1916821790555050565b60408051868152602081810187905282519182900383018220600160a060020a03871683529251929450869288927fce0457fe73731f824cc272376169235128c118b49d344817417c6d108d155e8292908290030190a382600060005060008460001916815260200190815260200160002060005060000160006101000a815481600160a060020a03021916908302179055505050505050565b60408051600160a060020a0384168152905184917fd4735d920b0f87494915f556dd9b54c8f309026070caea5c737245152564d266919081900360200190a2506000828152602081905260409020805473ffffffffffffffffffffffffffffffffffffffff191682179055505056",
45+
"storage": {
46+
"859ecef2e168dc10231b000bd53493b42bc9d944cac29d94582c1e1d43592131": "582c767cca9d78699b04ba8dd7c33071f2d74003"
47+
},
48+
"balance": ""
49+
},
50+
"582c767cca9d78699b04ba8dd7c33071f2d74003": {
51+
"code": "606060405260e060020a6000350463d22057a9811461001b575b005b61001960043560243560025460408051918252602082810185905260008054835194859003840185207f02571be300000000000000000000000000000000000000000000000000000000865260048601819052935193949193600160a060020a03909116926302571be39260248181019391829003018187876161da5a03f11561000257505060405151915050600160a060020a0381166000148015906100d4575033600160a060020a031681600160a060020a031614155b156100de57610002565b60408051600080546002547f569cd59500000000000000000000000000000000000000000000000000000000845260048401526024830188905230600160a060020a039081166044850152935193169263569cd595926064818101939291829003018183876161da5a03f11561000257505060008054600154604080517f1896f70a00000000000000000000000000000000000000000000000000000000815260048101889052600160a060020a0392831660248201529051929091169350631896f70a926044828101939192829003018183876161da5a03f11561000257505060008054604080517f5b0fc9c300000000000000000000000000000000000000000000000000000000815260048101879052600160a060020a0388811660248301529151929091169350635b0fc9c3926044828101939192829003018183876161da5a03f115610002575050505050505056",
52+
"storage": {
53+
"0000000000000000000000000000000000000000000000000000000000000000": "d344889e0be3e9ef6c26b0f60ef66a32e83c1b69",
54+
"0000000000000000000000000000000000000000000000000000000000000001": "cb7152b03774fd01a8480001b2bcdfebc4f04363",
55+
"0000000000000000000000000000000000000000000000000000000000000002": "93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae"
56+
},
57+
"balance": ""
58+
}
59+
}
60+
}

swarm/cmd/makegenesis/makegenesis.js

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
var Account = require('ethereumjs-account');
2+
var async = require('async');
3+
var fs = require('fs');
4+
var rlp = require('rlp');
5+
var solc = require('solc');
6+
var Transaction = require('ethereumjs-tx');
7+
var Trie = require('merkle-patricia-tree');
8+
var utils = require('ethereumjs-util');
9+
var VM = require('ethereumjs-vm');
10+
11+
var stateTrie = new Trie();
12+
var vm = new VM(stateTrie);
13+
14+
var privatekey = utils.sha3("swarm");
15+
var accountAddress = utils.privateToAddress(privatekey);
16+
17+
var accounts = {
18+
"0000000000000000000000000000000000000001": "0x1",
19+
"0000000000000000000000000000000000000002": "0x1",
20+
"0000000000000000000000000000000000000003": "0x1",
21+
"0000000000000000000000000000000000000004": "0x1",
22+
};
23+
accounts[accountAddress.toString('hex')] = "0x200000000000000";
24+
25+
var source = fs.readFileSync('../../services/ens/contract/ens.sol').toString();
26+
var compiled = solc.compile(source, 1)
27+
var deployer = "0x" + compiled.contracts['DeployENS'].bytecode;
28+
29+
var transactions = [
30+
{
31+
nonce: '0x00',
32+
gasPrice: '0x4a817c800',
33+
gasLimit: '0x3d0900',
34+
value: '0x00',
35+
data: deployer
36+
}
37+
];
38+
39+
function createAccounts(cb) {
40+
async.each(Object.keys(accounts), function(addr, next) {
41+
var account = new Account();
42+
account.balance = accounts[addr];
43+
stateTrie.put(new Buffer(addr, 'hex'), account.serialize(), next);
44+
}, cb);
45+
}
46+
47+
function runTx(cb) {
48+
async.each(transactions, function(txdata, next) {
49+
var tx = new Transaction(txdata);
50+
tx.sign(privatekey);
51+
vm.runTx({tx: tx}, next);
52+
}, cb);
53+
}
54+
55+
function dumpState(cb) {
56+
var stream = stateTrie.createReadStream();
57+
58+
var accountList = [];
59+
stream.on('data', function(data) {
60+
accountList.push(data);
61+
});
62+
stream.on('end', function(err) {
63+
var accountData = {};
64+
async.each(accountList, function(data, next) {
65+
var storage = {};
66+
67+
var account = new Account(data.value);
68+
var storageTrie = stateTrie.copy();
69+
storageTrie.root = account.stateRoot;
70+
71+
var storageStream = storageTrie.createReadStream();
72+
storageStream.on('data', function(data) {
73+
storage[data.key.toString('hex')] = rlp.decode(data.value).toString('hex')
74+
});
75+
storageStream.on('end', function(err) {
76+
account.getCode(stateTrie, function(err, code) {
77+
var address = data.key.toString('hex');
78+
accountData[address] = {
79+
code: code.toString('hex'),
80+
storage: storage,
81+
balance: account.balance.toString('hex')
82+
};
83+
next(err);
84+
});
85+
})
86+
}, function(err) {
87+
console.log(JSON.stringify({
88+
nonce: '0x42',
89+
gasLimit: '0x47e7c4',
90+
difficulty: '0x20000',
91+
alloc: accountData
92+
}, null, 4));
93+
});
94+
});
95+
}
96+
97+
async.series([
98+
createAccounts,
99+
runTx,
100+
dumpState
101+
], function(err) {
102+
console.log("Error: " + err);
103+
});

swarm/cmd/makegenesis/package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "makegenesis",
3+
"version": "0.0.0",
4+
"dependencies": {
5+
"async": "^2.0.1",
6+
"ethereumjs-account": "^2.0.3",
7+
"ethereumjs-block": "^1.2.2",
8+
"ethereumjs-tx": "^1.1.2",
9+
"ethereumjs-util": "^4.5.0",
10+
"ethereumjs-vm": "^1.4.0",
11+
"merkle-patricia-tree": "^2.1.2",
12+
"rlp": "^2.0.0",
13+
"solc": "0.3.5"
14+
}
15+
}

swarm/services/ens/contract/ens.sol

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,12 @@ contract PublicResolver is Resolver {
215215
ContentChanged(node, hash);
216216
}
217217
}
218+
219+
contract DeployENS {
220+
function DeployENS() {
221+
var ens = new ENS(this);
222+
var registrar = new FIFSRegistrar(ens, 0);
223+
ens.setOwner(0, registrar);
224+
selfdestruct(msg.sender);
225+
}
226+
}

swarm/services/ens/ens.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package ens
44

55
import (
6+
"math/big"
67
"strings"
78

89
"github.com/ethereum/go-ethereum/accounts/abi/bind"
@@ -141,7 +142,9 @@ func (self *ENS) Register(name string) (*types.Transaction, error) {
141142
return nil, err
142143
}
143144

144-
return registrar.Register(label, self.TransactOpts.From)
145+
opts := self.TransactOpts
146+
opts.GasLimit = big.NewInt(200000)
147+
return registrar.Contract.Register(&opts, label, self.TransactOpts.From)
145148
}
146149

147150
// SetContentHash sets the content hash associated with a name. Only works if the caller
@@ -154,5 +157,7 @@ func (self *ENS) SetContentHash(name string, hash common.Hash) (*types.Transacti
154157
return nil, err
155158
}
156159

157-
return resolver.SetContent(node, hash)
160+
opts := self.TransactOpts
161+
opts.GasLimit = big.NewInt(200000)
162+
return resolver.Contract.SetContent(&opts, node, hash)
158163
}

0 commit comments

Comments
 (0)