Gav Wood
10 years ago
34 changed files with 6497 additions and 374 deletions
@ -0,0 +1,120 @@ |
|||
web3.admin = {}; |
|||
web3.admin.setSessionKey = function(s) { web3.admin.sessionKey = s; }; |
|||
|
|||
var getSessionKey = function () { return web3.admin.sessionKey; }; |
|||
|
|||
web3._extend({ |
|||
property: 'admin', |
|||
methods: [new web3._extend.Method({ |
|||
name: 'web3.setVerbosity', |
|||
call: 'admin_web3_setVerbosity', |
|||
inputFormatter: [null, getSessionKey], |
|||
params: 2 |
|||
}), new web3._extend.Method({ |
|||
name: 'net.start', |
|||
call: 'admin_net_start', |
|||
inputFormatter: [getSessionKey], |
|||
params: 1 |
|||
}), new web3._extend.Method({ |
|||
name: 'net.stop', |
|||
call: 'admin_net_stop', |
|||
inputFormatter: [getSessionKey], |
|||
params: 1 |
|||
}), new web3._extend.Method({ |
|||
name: 'net.connect', |
|||
call: 'admin_net_connect', |
|||
inputFormatter: [null, getSessionKey], |
|||
params: 2 |
|||
}), new web3._extend.Method({ |
|||
name: 'net.peers', |
|||
call: 'admin_net_peers', |
|||
inputFormatter: [getSessionKey], |
|||
params: 1 |
|||
}), new web3._extend.Method({ |
|||
name: 'eth.blockQueueStatus', |
|||
call: 'admin_eth_blockQueueStatus', |
|||
inputFormatter: [getSessionKey], |
|||
params: 1 |
|||
}), new web3._extend.Method({ |
|||
name: 'eth.setAskPrice', |
|||
call: 'admin_eth_setAskPrice', |
|||
inputFormatter: [null, getSessionKey], |
|||
params: 2 |
|||
}), new web3._extend.Method({ |
|||
name: 'eth.setBidPrice', |
|||
call: 'admin_eth_setBidPrice', |
|||
inputFormatter: [null, getSessionKey], |
|||
params: 2 |
|||
}), new web3._extend.Method({ |
|||
name: 'eth.setReferencePrice', |
|||
call: 'admin_eth_setReferencePrice', |
|||
inputFormatter: [null, getSessionKey], |
|||
params: 2 |
|||
}), new web3._extend.Method({ |
|||
name: 'eth.setPriority', |
|||
call: 'admin_eth_setPriority', |
|||
inputFormatter: [null, getSessionKey], |
|||
params: 2 |
|||
}), new web3._extend.Method({ |
|||
name: 'eth.setMining', |
|||
call: 'admin_eth_setMining', |
|||
inputFormatter: [null, getSessionKey], |
|||
params: 2 |
|||
}), new web3._extend.Method({ |
|||
name: 'eth.findBlock', |
|||
call: 'admin_eth_findBlock', |
|||
inputFormatter: [null, getSessionKey], |
|||
params: 2 |
|||
}), new web3._extend.Method({ |
|||
name: 'eth.blockQueueFirstUnknown', |
|||
call: 'admin_eth_blockQueueFirstUnknown', |
|||
inputFormatter: [getSessionKey], |
|||
params: 1 |
|||
}), new web3._extend.Method({ |
|||
name: 'eth.blockQueueRetryUnknown', |
|||
call: 'admin_eth_blockQueueRetryUnknown', |
|||
inputFormatter: [getSessionKey], |
|||
params: 1 |
|||
}), new web3._extend.Method({ |
|||
name: 'eth.allAccounts', |
|||
call: 'admin_eth_allAccounts', |
|||
inputFormatter: [getSessionKey], |
|||
params: 1 |
|||
}), new web3._extend.Method({ |
|||
name: 'eth.newAccount', |
|||
call: 'admin_eth_newAccount', |
|||
inputFormatter: [null, getSessionKey], |
|||
params: 2 |
|||
}), new web3._extend.Method({ |
|||
name: 'eth.setSigningKey', |
|||
call: 'admin_eth_setSigningKey', |
|||
inputFormatter: [null, getSessionKey], |
|||
params: 2 |
|||
}), new web3._extend.Method({ |
|||
name: 'eth.setMiningBenefactor', |
|||
call: 'admin_eth_setMiningBenefactor', |
|||
inputFormatter: [null, getSessionKey], |
|||
params: 2 |
|||
}), new web3._extend.Method({ |
|||
name: 'eth.inspect', |
|||
call: 'admin_eth_inspect', |
|||
inputFormatter: [null, getSessionKey], |
|||
params: 2 |
|||
}), new web3._extend.Method({ |
|||
name: 'eth.reprocess', |
|||
call: 'admin_eth_reprocess', |
|||
inputFormatter: [null, getSessionKey], |
|||
params: 2 |
|||
}), new web3._extend.Method({ |
|||
name: 'eth.vmTrace', |
|||
call: 'admin_eth_vmTrace', |
|||
inputFormatter: [null, null, getSessionKey], |
|||
params: 3 |
|||
}), new web3._extend.Method({ |
|||
name: 'eth.getReceiptByHashAndIndex', |
|||
call: 'admin_eth_getReceiptByHashAndIndex', |
|||
inputFormatter: [null, null, getSessionKey], |
|||
params: 3 |
|||
})] |
|||
}); |
|||
|
@ -1,14 +1,14 @@ |
|||
This file is part of ethereum.js. |
|||
This file is part of web3.js. |
|||
|
|||
ethereum.js is free software: you can redistribute it and/or modify |
|||
web3.js is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU Lesser General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
ethereum.js is distributed in the hope that it will be useful, |
|||
web3.js is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU Lesser General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU Lesser General Public License |
|||
along with ethereum.js. If not, see <http://www.gnu.org/licenses/>. |
|||
along with web3.js. If not, see <http://www.gnu.org/licenses/>. |
|||
|
File diff suppressed because it is too large
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,153 +0,0 @@ |
|||
<!doctype> |
|||
<html> |
|||
<title>JevCoin</title> |
|||
<head> |
|||
<script type="text/javascript" src="../dist/web3.js"></script> |
|||
</head> |
|||
<body> |
|||
|
|||
<h1>JevCoin <code id="contract_addr"></code></h1> |
|||
<div> |
|||
<strong>Balance</strong> |
|||
<span id="balance"></strong> |
|||
</div> |
|||
|
|||
<div> |
|||
<span>Address:</span> |
|||
<input type="text" id="address" style="width:200px"> |
|||
<span>Amount:</span> |
|||
<input type="text" id="amount" style="width:200px"> |
|||
<button onclick="transact()">Send</button> |
|||
<span id="message"></span> |
|||
</div> |
|||
|
|||
<hr> |
|||
|
|||
<table width="100%" id="table"> |
|||
<tr><td style="width:40%;">Address</td><td>Balance</td></tr> |
|||
<tbody id="table_body"></tbody> |
|||
</table> |
|||
|
|||
</body> |
|||
|
|||
<script type="text/javascript"> |
|||
var web3 = require('web3'); |
|||
var eth = web3.eth; |
|||
|
|||
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8080')); |
|||
var desc = [{ |
|||
"name": "balance(address)", |
|||
"type": "function", |
|||
"inputs": [{ |
|||
"name": "who", |
|||
"type": "address" |
|||
}], |
|||
"constant": true, |
|||
"outputs": [{ |
|||
"name": "value", |
|||
"type": "uint256" |
|||
}] |
|||
}, { |
|||
"name": "send(address,uint256)", |
|||
"type": "function", |
|||
"inputs": [{ |
|||
"name": "to", |
|||
"type": "address" |
|||
}, { |
|||
"name": "value", |
|||
"type": "uint256" |
|||
}], |
|||
"outputs": [] |
|||
}, { |
|||
"name":"Changed", |
|||
"type":"event", |
|||
"inputs": [ |
|||
{"name":"from","type":"address","indexed":true}, |
|||
{"name":"amount","type":"uint256","indexed":true}, |
|||
], |
|||
}]; |
|||
|
|||
var address = localStorage.getItem("address"); |
|||
// deploy if not exist |
|||
if(address === null) { |
|||
var code = "0x60056013565b61014f8061003a6000396000f35b620f42406000600033600160a060020a0316815260200190815260200160002081905550560060e060020a600035048063d0679d3414610020578063e3d670d71461003457005b61002e600435602435610049565b60006000f35b61003f600435610129565b8060005260206000f35b806000600033600160a060020a03168152602001908152602001600020541061007157610076565b610125565b806000600033600160a060020a03168152602001908152602001600020908154039081905550806000600084600160a060020a031681526020019081526020016000209081540190819055508033600160a060020a03167fb52dda022b6c1a1f40905a85f257f689aa5d69d850e49cf939d688fbe5af594660006000a38082600160a060020a03167fb52dda022b6c1a1f40905a85f257f689aa5d69d850e49cf939d688fbe5af594660006000a35b5050565b60006000600083600160a060020a0316815260200190815260200160002054905091905056"; |
|||
address = web3.eth.transact({from: eth.coinbase, data: code, gas: "1000000"}); |
|||
localStorage.setItem("address", address); |
|||
} |
|||
document.querySelector("#contract_addr").innerHTML = address; |
|||
|
|||
var Contract = web3.eth.contract(desc); |
|||
contract = new Contract(address); |
|||
contract.Changed({from: eth.accounts[0]}).changed(function() { |
|||
refresh(); |
|||
}); |
|||
|
|||
function refresh() { |
|||
document.querySelector("#balance").innerHTML = contract.balance(eth.coinbase); |
|||
|
|||
var table = document.querySelector("#table_body"); |
|||
table.innerHTML = ""; // clear |
|||
|
|||
/*var storage = eth.getStorage(address);*/ |
|||
/*table.innerHTML = "";*/ |
|||
/*for( var item in storage ) {*/ |
|||
/*table.innerHTML += "<tr><td>"+item+"</td><td>"+web3.toDecimal(storage[item])+"</td></tr>";*/ |
|||
/*}*/ |
|||
} |
|||
|
|||
function transact() { |
|||
var to = document.querySelector("#address"); |
|||
if( to.value.length == 0 ) { |
|||
to = "0x4205b06c2cfa0e30359edcab94543266cb6fa1d3"; |
|||
} else { |
|||
if (to.value.substr(0,2) != "0x") |
|||
to.value = "0x"+to.value; |
|||
} |
|||
|
|||
var value = document.querySelector("#amount"); |
|||
var amount = parseInt( value.value ); |
|||
console.log("transact: ", to.value, " => ", amount) |
|||
|
|||
contract.sendTransaction({from: eth.accounts[0]}).send( to.value, amount ); |
|||
|
|||
to.value = ""; |
|||
value.value = ""; |
|||
|
|||
var message = document.querySelector("#message") |
|||
message.innerHTML = "Submitted"; |
|||
setTimeout(function() { |
|||
message.innerHTML = ""; |
|||
}, 1000); |
|||
} |
|||
|
|||
refresh(); |
|||
</script> |
|||
</html> |
|||
|
|||
<!-- |
|||
contract JevCoin { |
|||
function JevCoin() |
|||
{ |
|||
balances[msg.sender] = 1000000; |
|||
} |
|||
|
|||
event Changed(address indexed from, uint indexed amount); |
|||
function send(address to, uint value) |
|||
{ |
|||
if( balances[msg.sender] < value ) return; |
|||
|
|||
balances[msg.sender] -= value; |
|||
balances[to] += value; |
|||
|
|||
Changed(msg.sender, value); |
|||
Changed(to, value); |
|||
} |
|||
|
|||
function balance(address who) constant returns(uint t) |
|||
{ |
|||
t = balances[who]; |
|||
} |
|||
|
|||
mapping(address => uint256) balances; |
|||
} |
|||
-!> |
@ -1,3 +1,3 @@ |
|||
{ |
|||
"version": "0.5.0" |
|||
"version": "0.6.0" |
|||
} |
|||
|
@ -0,0 +1,76 @@ |
|||
var chai = require('chai'); |
|||
var assert = chai.assert; |
|||
var FakeHttpProvider = require('./helpers/FakeHttpProvider'); |
|||
var web3 = require('../lib/web3'); |
|||
|
|||
|
|||
var tests = [{ |
|||
properties: [new web3._extend.Property({ |
|||
name: 'gasPrice', |
|||
getter: 'eth_gasPrice', |
|||
outputFormatter: web3._extend.formatters.outputBigNumberFormatter |
|||
})] |
|||
},{ |
|||
methods: [new web3._extend.Method({ |
|||
name: 'getBalance', |
|||
call: 'eth_getBalance', |
|||
params: 2, |
|||
inputFormatter: [web3._extend.utils.toAddress, web3._extend.formatters.inputDefaultBlockNumberFormatter], |
|||
outputFormatter: web3._extend.formatters.outputBigNumberFormatter |
|||
})] |
|||
},{ |
|||
property: 'admin', |
|||
properties: [new web3._extend.Property({ |
|||
name: 'gasPrice', |
|||
getter: 'eth_gasPrice', |
|||
outputFormatter: web3._extend.formatters.outputBigNumberFormatter |
|||
})], |
|||
methods: [new web3._extend.Method({ |
|||
name: 'getBalance', |
|||
call: 'eth_getBalance', |
|||
params: 2, |
|||
inputFormatter: [web3._extend.utils.toAddress, web3._extend.formatters.inputDefaultBlockNumberFormatter], |
|||
outputFormatter: web3._extend.formatters.outputBigNumberFormatter |
|||
})] |
|||
}]; |
|||
|
|||
describe('web3', function () { |
|||
describe('_extend', function () { |
|||
tests.forEach(function (test, index) { |
|||
it('test no: ' + index, function () { |
|||
web3._extend(test); |
|||
|
|||
|
|||
if(test.properties) |
|||
test.properties.forEach(function(property){ |
|||
|
|||
var provider = new FakeHttpProvider(); |
|||
web3.setProvider(provider); |
|||
provider.injectResult(''); |
|||
provider.injectValidation(function (payload) { |
|||
assert.equal(payload.jsonrpc, '2.0'); |
|||
assert.equal(payload.method, property.getter); |
|||
}); |
|||
|
|||
if(test.property) { |
|||
assert.isObject(web3[test.property][property.name]); |
|||
assert.isFunction(web3[test.property]['get'+ property.name.charAt(0).toUpperCase() + property.name.slice(1)]); |
|||
} else { |
|||
assert.isObject(web3[property.name]); |
|||
assert.isFunction(web3['get'+ property.name.charAt(0).toUpperCase() + property.name.slice(1)]); |
|||
} |
|||
}); |
|||
|
|||
if(test.methods) |
|||
test.methods.forEach(function(property){ |
|||
if(test.property) |
|||
assert.isFunction(web3[test.property][property.name]); |
|||
else |
|||
assert.isFunction(web3[property.name]); |
|||
}); |
|||
|
|||
}); |
|||
}); |
|||
}); |
|||
}); |
|||
|
Loading…
Reference in new issue