mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 20:56:42 +00:00
merged from develop
This commit is contained in:
commit
d62c9b8314
11 changed files with 164 additions and 46 deletions
|
|
@ -7,7 +7,7 @@
|
|||
</head>
|
||||
<body>
|
||||
|
||||
<h1>JevCoin</h1>
|
||||
<h1>JevCoin <code id="address"></code></h1>
|
||||
<div>
|
||||
<strong>Balance</strong>
|
||||
<span id="balance"></strong>
|
||||
|
|
@ -20,7 +20,11 @@
|
|||
<button onclick="transact()">Send</button>
|
||||
</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>
|
||||
|
|
@ -29,21 +33,22 @@
|
|||
var web3 = require('web3');
|
||||
var eth = web3.eth;
|
||||
|
||||
web3.setProvider(new
|
||||
web3.providers.HttpSyncProvider('http://localhost:8545'));
|
||||
var desc = [{
|
||||
web3.setProvider(new web3.providers.HttpSyncProvider('http://localhost:8545'));
|
||||
var desc = [{
|
||||
"name": "balance(address)",
|
||||
"type": "function",
|
||||
"inputs": [{
|
||||
"name": "who",
|
||||
"type": "address"
|
||||
}],
|
||||
"const": true,
|
||||
"constant": true,
|
||||
"outputs": [{
|
||||
"name": "value",
|
||||
"type": "uint256"
|
||||
}]
|
||||
}, {
|
||||
"name": "send(address,uint256)",
|
||||
"type": "function",
|
||||
"inputs": [{
|
||||
"name": "to",
|
||||
"type": "address"
|
||||
|
|
@ -52,48 +57,91 @@
|
|||
"type": "uint256"
|
||||
}],
|
||||
"outputs": []
|
||||
}, {
|
||||
"name":"changed",
|
||||
"type":"event",
|
||||
"inputs": [
|
||||
{"name":"to","type":"address","indexed":true},
|
||||
{"name":"from","type":"address","indexed":true},
|
||||
],
|
||||
}];
|
||||
|
||||
var address = web3.db.get("jevcoin", "address");
|
||||
if( address.length == 0 ) {
|
||||
var code = "0x60056011565b60ae8060356000396000f35b64174876e800600033600160a060020a031660005260205260406000208190555056006001600060e060020a600035048063d0679d34146022578063e3d670d714603457005b602e6004356024356047565b60006000f35b603d600435608d565b8060005260206000f35b80600083600160a060020a0316600052602052604060002090815401908190555080600033600160a060020a031660005260205260406000209081540390819055505050565b6000600082600160a060020a0316600052602052604060002054905091905056";
|
||||
address = web3.eth.transact({
|
||||
data: code,
|
||||
gasprice: "1000000000000000",
|
||||
gas: "10000",
|
||||
});
|
||||
web3.db.put("jevcoin", "address", address);
|
||||
}
|
||||
var address = localStorage.getItem("address");
|
||||
// deploy if not exist
|
||||
if (address == null) {
|
||||
var code = "0x60056013565b610132806100356000396000f35b620f4240600033600160a060020a0316600052602052604060002081905550560060e060020a6000350480637bb98a681461002b578063d0679d3414610039578063e3d670d71461004d57005b61003361012d565b60006000f35b610047600435602435610062565b60006000f35b61005860043561010b565b8060005260206000f35b80600033600160a060020a0316600052602052604060002054106100855761008a565b610107565b80600033600160a060020a0316600052602052604060002090815403908190555080600083600160a060020a0316600052602052604060002090815401908190555081600160a060020a031633600160a060020a03167f1863989b4bb7c5c3941722099764574df7a459f9f9c6b6cdca35ddc9731792b860006000a35b5050565b6000600082600160a060020a03166000526020526040600020549050919050565b5b60008156";
|
||||
address = web3.eth.transact({
|
||||
data: code,
|
||||
gasPrice: "1000000000000000",
|
||||
gas: "10000",
|
||||
});
|
||||
localStorage.setItem("address", address);
|
||||
}
|
||||
document.querySelector("#address").innerHTML = address.toUpperCase();
|
||||
|
||||
var contract = web3.eth.contract(address, desc);
|
||||
contract.changed({from: eth.accounts[0]}).changed(function() {
|
||||
refresh();
|
||||
});
|
||||
eth.watch('chain').changed(function() {
|
||||
refresh();
|
||||
});
|
||||
|
||||
function reflesh() {
|
||||
document.querySelector("#balance").innerHTML = contract.call().balance(eth.coinbase);
|
||||
function refresh() {
|
||||
document.querySelector("#balance").innerHTML = contract.balance(eth.coinbase);
|
||||
|
||||
var table = document.querySelector("#table");
|
||||
var table = document.querySelector("#table_body");
|
||||
table.innerHTML = ""; // clear
|
||||
|
||||
var storage = eth.storageAt(address);
|
||||
table.innerHTML = "";
|
||||
for( var item in storage ) {
|
||||
table.innerHTML += "<tr><td>"+item+"</td><td>"+web3.toDecimal(storage[item])+"</td></tr>";
|
||||
table.innerHTML += "<tr><td>"+item.toUpperCase()+"</td><td>"+web3.toDecimal(storage[item])+"</td></tr>";
|
||||
}
|
||||
}
|
||||
|
||||
function transact() {
|
||||
var to = document.querySelector("#address").value;
|
||||
if( to.length == 0 ) {
|
||||
to = "0x4205b06c2cfa0e30359edcab94543266cb6fa1d3";
|
||||
} else {
|
||||
to = "0x"+to;
|
||||
}
|
||||
|
||||
if( to.length == 0 ) {
|
||||
to = "0x4205b06c2cfa0e30359edcab94543266cb6fa1d3";
|
||||
} else {
|
||||
to = "0x"+to;
|
||||
}
|
||||
|
||||
var value = parseInt( document.querySelector("#amount").value );
|
||||
|
||||
contract.transact({gas: "10000", gasprice: eth.gasPrice}).send( to, value );
|
||||
contract.send( to, value );
|
||||
}
|
||||
|
||||
reflesh();
|
||||
refresh();
|
||||
</script>
|
||||
|
||||
</html>
|
||||
|
||||
<!--
|
||||
contract JevCoin {
|
||||
function JevCoin()
|
||||
{
|
||||
balances[msg.sender] = 1000000;
|
||||
}
|
||||
|
||||
event changed(address indexed from, address indexed to);
|
||||
function send(address to, uint value)
|
||||
{
|
||||
if( balances[msg.sender] < value ) return;
|
||||
|
||||
balances[msg.sender] -= value;
|
||||
balances[to] += value;
|
||||
|
||||
changed(msg.sender, to);
|
||||
}
|
||||
|
||||
function balance(address who) constant returns(uint t)
|
||||
{
|
||||
t = balances[who];
|
||||
}
|
||||
|
||||
mapping(address => uint256) balances;
|
||||
}
|
||||
-!>
|
||||
|
|
|
|||
|
|
@ -8,11 +8,9 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/ethutil"
|
||||
"github.com/ethereum/go-ethereum/event"
|
||||
"github.com/ethereum/go-ethereum/logger"
|
||||
"github.com/ethereum/go-ethereum/p2p"
|
||||
"github.com/ethereum/go-ethereum/pow"
|
||||
"github.com/ethereum/go-ethereum/pow/ezp"
|
||||
"github.com/ethereum/go-ethereum/state"
|
||||
|
|
@ -21,20 +19,6 @@ import (
|
|||
|
||||
var statelogger = logger.NewLogger("BLOCK")
|
||||
|
||||
type EthManager interface {
|
||||
BlockProcessor() *BlockProcessor
|
||||
ChainManager() *ChainManager
|
||||
TxPool() *TxPool
|
||||
PeerCount() int
|
||||
IsMining() bool
|
||||
IsListening() bool
|
||||
Peers() []*p2p.Peer
|
||||
KeyManager() *crypto.KeyManager
|
||||
ClientIdentity() p2p.ClientIdentity
|
||||
Db() ethutil.Database
|
||||
EventMux() *event.TypeMux
|
||||
}
|
||||
|
||||
type BlockProcessor struct {
|
||||
db ethutil.Database
|
||||
// Mutex for locking the block processor. Blocks can only be handled one at a time
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ func (self *Filter) FilterLogs(logs state.Logs) state.Logs {
|
|||
|
||||
// Filter the logs for interesting stuff
|
||||
for _, log := range logs {
|
||||
if len(self.address) > 0 && !bytes.Equal(self.address, log.Address()) {
|
||||
if !bytes.Equal(self.address, log.Address()) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
|||
22
core/manager.go
Normal file
22
core/manager.go
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
package core
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/ethutil"
|
||||
"github.com/ethereum/go-ethereum/event"
|
||||
"github.com/ethereum/go-ethereum/p2p"
|
||||
)
|
||||
|
||||
type EthManager interface {
|
||||
BlockProcessor() *BlockProcessor
|
||||
ChainManager() *ChainManager
|
||||
TxPool() *TxPool
|
||||
PeerCount() int
|
||||
IsMining() bool
|
||||
IsListening() bool
|
||||
Peers() []*p2p.Peer
|
||||
KeyManager() *crypto.KeyManager
|
||||
ClientIdentity() p2p.ClientIdentity
|
||||
Db() ethutil.Database
|
||||
EventMux() *event.TypeMux
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
// XXX This is the old filter system specifically for messages. This is till in used and could use some refactoring
|
||||
package filter
|
||||
|
||||
// TODO make use of the generic filtering system
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
|
|
@ -103,8 +103,13 @@ func (s *RpcHttpServer) apiHandler(api *rpc.EthereumApi) http.Handler {
|
|||
return
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
rpchttplogger.Debugf("Generated response: %T %s", response, response)
|
||||
JSON.Send(w, &rpc.RpcSuccessResponse{JsonRpc: reqParsed.JsonRpc, ID: reqParsed.ID, Error: false, Result: response})
|
||||
=======
|
||||
rpchttplogger.DebugDetailf("Generated response: %T %s", response, response)
|
||||
JSON.Send(w, &rpc.RpcSuccessResponse{JsonRpc: jsonrpcver, ID: reqParsed.ID, Result: response})
|
||||
>>>>>>> develop
|
||||
}
|
||||
|
||||
return http.HandlerFunc(fn)
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ func (self *Iterator) Next() bool {
|
|||
self.Key = []byte(DecodeCompact(k))
|
||||
|
||||
return len(k) > 0
|
||||
|
||||
}
|
||||
|
||||
func (self *Iterator) next(node Node, key []byte) []byte {
|
||||
|
|
@ -67,7 +66,7 @@ func (self *Iterator) next(node Node, key []byte) []byte {
|
|||
if BeginsWith(key, k) {
|
||||
ret = self.next(cnode, skey)
|
||||
} else if bytes.Compare(k, key[:len(k)]) > 0 {
|
||||
ret = self.key(node)
|
||||
return self.key(node)
|
||||
}
|
||||
|
||||
if ret != nil {
|
||||
|
|
|
|||
|
|
@ -257,3 +257,42 @@ func BenchmarkUpdate(b *testing.B) {
|
|||
}
|
||||
trie.Hash()
|
||||
}
|
||||
|
||||
type kv struct {
|
||||
k, v []byte
|
||||
t bool
|
||||
}
|
||||
|
||||
func TestLargeData(t *testing.T) {
|
||||
trie := NewEmpty()
|
||||
vals := make(map[string]*kv)
|
||||
|
||||
for i := byte(1); i < 255; i++ {
|
||||
value := &kv{ethutil.LeftPadBytes([]byte{i}, 32), []byte{i}, false}
|
||||
value2 := &kv{ethutil.LeftPadBytes([]byte{10, i}, 32), []byte{i}, false}
|
||||
trie.Update(value.k, value.v)
|
||||
trie.Update(value2.k, value2.v)
|
||||
vals[string(value.k)] = value
|
||||
vals[string(value2.k)] = value2
|
||||
fmt.Println(value, "\n", value2)
|
||||
}
|
||||
|
||||
it := trie.Iterator()
|
||||
for it.Next() {
|
||||
vals[string(it.Key)].t = true
|
||||
}
|
||||
|
||||
var untouched []*kv
|
||||
for _, value := range vals {
|
||||
if !value.t {
|
||||
untouched = append(untouched, value)
|
||||
}
|
||||
}
|
||||
|
||||
if len(untouched) > 0 {
|
||||
t.Errorf("Missed %d nodes", len(untouched))
|
||||
for _, value := range untouched {
|
||||
t.Error(value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,12 @@ type Message struct {
|
|||
Flags byte
|
||||
Signature []byte
|
||||
Payload []byte
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
Sent int64
|
||||
|
||||
To *ecdsa.PublicKey
|
||||
>>>>>>> develop
|
||||
}
|
||||
|
||||
func NewMessage(payload []byte) *Message {
|
||||
|
|
|
|||
|
|
@ -256,6 +256,8 @@ func (self *Whisper) postEvent(envelope *Envelope) {
|
|||
func (self *Whisper) open(envelope *Envelope) (*Message, *ecdsa.PrivateKey) {
|
||||
for _, key := range self.keys {
|
||||
if message, err := envelope.Open(key); err == nil || (err != nil && err == ecies.ErrInvalidPublicKey) {
|
||||
message.To = &key.PublicKey
|
||||
|
||||
return message, key
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -101,14 +101,26 @@ type WhisperMessage struct {
|
|||
ref *whisper.Message
|
||||
Flags int32 `json:"flags"`
|
||||
Payload string `json:"payload"`
|
||||
To string `json:"to"`
|
||||
From string `json:"from"`
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
Sent int64 `json:"sent"`
|
||||
>>>>>>> develop
|
||||
}
|
||||
|
||||
func NewWhisperMessage(msg *whisper.Message) WhisperMessage {
|
||||
return WhisperMessage{
|
||||
ref: msg,
|
||||
<<<<<<< HEAD
|
||||
Flags: int32(msg.Flags),
|
||||
Payload: "0x" + ethutil.Bytes2Hex(msg.Payload),
|
||||
From: "0x" + ethutil.Bytes2Hex(crypto.FromECDSAPub(msg.Recover())),
|
||||
=======
|
||||
Payload: toHex(msg.Payload),
|
||||
From: toHex(crypto.FromECDSAPub(msg.Recover())),
|
||||
To: toHex(crypto.FromECDSAPub(msg.To)),
|
||||
Sent: msg.Sent,
|
||||
>>>>>>> develop
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue