From fd6d794c3571cbe32adc0d9dc947f493df1d9f09 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 12 Jun 2014 18:35:39 +0100 Subject: [PATCH] Standard service JS script. Bug fix for load & LLL macros. Move to new services. --- alethzero/MainWin.cpp | 2 +- include.lll | 2 +- liblll/CodeFragment.cpp | 2 +- liblll/CompilerState.cpp | 2 +- stdserv.js | 73 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 stdserv.js diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index 28f0bba41..043988c57 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -98,7 +98,7 @@ static void initUnits(QComboBox* _b) _b->addItem(QString::fromStdString(units()[n].second), n); } -Address c_config = Address("ccdeac59d35627b7de09332e819d5159e7bb7250"); +Address c_config = Address("9ef0f0d81e040012600b0c1abdef7c48f720f88a"); using namespace boost::process; diff --git a/include.lll b/include.lll index 4d7bb7f72..a25b4e4b7 100644 --- a/include.lll +++ b/include.lll @@ -1,5 +1,5 @@ { -(def 'gav 0x8a40bfaa73256b60764c1bf40675a99083efb075) +(def 'gav 0x51ba59315b3a95761d0863b05ccc7a7f54703d99) (def 'alloc (len) (asm msize 0 1 len msize add sub mstore8)) diff --git a/liblll/CodeFragment.cpp b/liblll/CodeFragment.cpp index 804504f07..9284c1f31 100644 --- a/liblll/CodeFragment.cpp +++ b/liblll/CodeFragment.cpp @@ -343,7 +343,7 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s) cs.defs.clear(); for (unsigned i = 0; i < m.args.size(); ++i) { - requireDeposit(i, 1); + //requireDeposit(i, 1); cs.args[m.args[i]] = code[i]; } m_asm.append(CodeFragment(m.code, cs).m_asm); diff --git a/liblll/CompilerState.cpp b/liblll/CompilerState.cpp index 490e92672..7e990413f 100644 --- a/liblll/CompilerState.cpp +++ b/liblll/CompilerState.cpp @@ -44,7 +44,7 @@ CodeFragment const& CompilerState::getDef(std::string const& _s) void CompilerState::populateStandard() { static const string s = "{" - "(def 'gav 0x8a40bfaa73256b60764c1bf40675a99083efb075)" + "(def 'gav 0x51ba59315b3a95761d0863b05ccc7a7f54703d99)" "(def 'namereg 0x2d0aceee7e5ab874e22ccf8d1a649f59106d74e8)" "(def 'config 0xccdeac59d35627b7de09332e819d5159e7bb7250)" "(def 'gavcoin 0x5620133321fcac7f15a5c570016f6cb6dc263f9d)" diff --git a/stdserv.js b/stdserv.js new file mode 100644 index 000000000..5529c90cc --- /dev/null +++ b/stdserv.js @@ -0,0 +1,73 @@ +env.note('Creating Config...') +var configCode = eth.lll("{ + [[69]] (caller) + (returnlll + (when (= (caller) @@69) + (for {} (< @i (calldatasize)) [i](+ @i 64) + [[ (calldataload @i) ]] (calldataload (+ @i 32)) + ) + ) + ) +}") +env.note('Config code: ' + configCode.unbin()) +var config; +eth.create(eth.key, '0', configCode, 10000, eth.gasPrice, function(a) { config = a; }) + +env.note('Config at address ' + config) + +var nameRegCode = eth.lll("{ + [[(address)]] 'NameReg + [['NameReg]] (address) + [[" + config + "]] 'Config + [['Config]] " + config + " + [[69]] (caller) + (returnlll + (if (calldatasize) + { + (when @@(calldataload 0) (stop)) + (when @@(caller) [[@@(caller)]] 0) + [[(calldataload 0)]] (caller) + [[(caller)]] (calldataload 0) + } + { + (when (= (caller) @@69) (suicide (caller))) + (when @@(caller) { + [[@@(caller)]] 0 + [[(caller)]] 0 + }) + } + ) + ) +}"); +env.note('NameReg code: ' + nameRegCode.unbin()) + +var nameReg; +env.note('Create NameReg...') +eth.create(eth.key, '0', nameRegCode, 10000, eth.gasPrice, function(a) { nameReg = a; }) + +env.note('NameReg at address ' + nameReg) + +env.note('Register NameReg...') +eth.transact(eth.key, '0', config, "0".pad(32) + nameReg.pad(32), 10000, eth.gasPrice); + +var gavCoinCode = eth.lll("{ + [[ (caller) ]]: 0x1000000 + [0] 'GavCoin + (call (- (gas) 100) " + nameReg + " 0 0 7 0 0) + (returnlll { + (when (!= (calldatasize) 64) (stop)) + [fromBal] @@(caller) + [toBal]: @@(calldataload 0) + [value]: (calldataload 32) + (when (< @fromBal @value) (stop)) + [[ (caller) ]]: (- @fromBal @value) + [[ (calldataload 0) ]]: (+ @toBal @value) + }) +}"); + +env.note('Create GavCoin...') +eth.create(eth.key, '0', gavCoinCode, 10000, eth.gasPrice); + +env.note('All done.') + +// env.load('/home/gav/Eth/cpp-ethereum/stdserv.js')