Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
770808ce
Commit
770808ce
authored
May 17, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Readline repl for linux & osx
parent
2ac292dc
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
122 additions
and
39 deletions
+122
-39
gui.go
ethereal/ui/gui.go
+1
-1
ethereum.go
ethereum/ethereum.go
+2
-2
javascript_console.go
ethereum/javascript_console.go
+38
-33
repl_darwin.go
ethereum/repl_darwin.go
+55
-0
repl_linux.go
ethereum/repl_linux.go
+1
-0
repl_windows.go
ethereum/repl_windows.go
+20
-0
cmd.go
utils/cmd.go
+5
-3
No files found.
ethereal/ui/gui.go
View file @
770808ce
...
...
@@ -197,7 +197,7 @@ func (gui *Gui) update() {
case
b
:=
<-
blockChan
:
block
:=
b
.
Resource
.
(
*
ethchain
.
Block
)
if
bytes
.
Compare
(
block
.
Coinbase
,
gui
.
addr
)
==
0
{
gui
.
setWalletValue
(
gui
.
eth
.
StateManager
()
.
Proc
State
()
.
GetAccount
(
gui
.
addr
)
.
Amount
,
nil
)
gui
.
setWalletValue
(
gui
.
eth
.
StateManager
()
.
Current
State
()
.
GetAccount
(
gui
.
addr
)
.
Amount
,
nil
)
}
case
txMsg
:=
<-
txChan
:
...
...
ethereum/ethereum.go
View file @
770808ce
...
...
@@ -151,9 +151,9 @@ save these words so you can restore your account later: %s
console
:=
NewConsole
(
ethereum
)
go
console
.
Start
()
}
else
if
StartJsConsole
{
c
:=
NewJSConsole
(
ethereum
)
repl
:=
NewJSRepl
(
ethereum
)
go
c
.
Start
()
go
repl
.
Start
()
}
if
StartRpc
{
...
...
ethereum/javascript_console.go
View file @
770808ce
package
main
import
(
"bufio"
"fmt"
"github.com/ethereum/eth-go"
"github.com/ethereum/eth-go/ethpub"
"github.com/robertkrimen/otto"
"os"
)
type
JSConsole
struct
{
type
Repl
interface
{
Start
()
}
type
JSRE
struct
{
vm
*
otto
.
Otto
lib
*
ethpub
.
PEthereum
}
func
NewJSConsole
(
ethereum
*
eth
.
Ethereum
)
*
JSConsole
{
return
&
JSConsole
{
vm
:
otto
.
New
(),
lib
:
ethpub
.
NewPEthereum
(
ethereum
)}
func
NewJSRE
(
ethereum
*
eth
.
Ethereum
)
*
JSRE
{
re
:=
&
JSRE
{
vm
:
otto
.
New
(),
lib
:
ethpub
.
NewPEthereum
(
ethereum
)}
re
.
Bind
(
"eth"
,
&
JSEthereum
{
re
.
lib
,
re
.
vm
})
return
re
}
func
(
self
*
JSRE
)
Bind
(
name
string
,
v
interface
{})
{
self
.
vm
.
Set
(
name
,
v
)
}
func
(
self
*
JSRE
)
Run
(
code
string
)
(
otto
.
Value
,
error
)
{
return
self
.
vm
.
Run
(
code
)
}
func
(
self
*
JSConsole
)
Start
()
{
self
.
initBindings
()
type
JSRepl
struct
{
re
*
JSRE
}
func
NewJSRepl
(
ethereum
*
eth
.
Ethereum
)
*
JSRepl
{
return
&
JSRepl
{
re
:
NewJSRE
(
ethereum
)}
}
func
(
self
*
JSRepl
)
Start
()
{
fmt
.
Println
(
"Eth JavaScript console"
)
reader
:=
bufio
.
NewReader
(
os
.
Stdin
)
for
{
fmt
.
Printf
(
"eth >>> "
)
str
,
_
,
err
:=
reader
.
ReadLine
()
if
err
!=
nil
{
fmt
.
Println
(
"Error reading input"
,
err
)
}
else
{
self
.
ParseInput
(
string
(
str
))
}
}
self
.
read
()
}
func
(
self
*
JS
Console
)
P
arseInput
(
code
string
)
{
func
(
self
*
JS
Repl
)
p
arseInput
(
code
string
)
{
defer
func
()
{
if
r
:=
recover
();
r
!=
nil
{
fmt
.
Println
(
"[native] error"
,
r
)
}
}()
value
,
err
:=
self
.
vm
.
Run
(
code
)
value
,
err
:=
self
.
re
.
Run
(
code
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
return
...
...
@@ -50,28 +61,22 @@ func (self *JSConsole) ParseInput(code string) {
fmt
.
Println
(
value
)
}
func
(
self
*
JSConsole
)
initBindings
()
{
t
:=
&
JSWrapper
{
self
.
lib
,
self
.
vm
}
self
.
vm
.
Set
(
"eth"
,
t
)
}
// The JS wrapper attempts to wrap the PEthereum object and returns
// proper javascript objects
type
JSWrapper
struct
{
// The JSEthereum object attempts to wrap the PEthereum object and returns
// meaningful javascript objects
type
JSEthereum
struct
{
*
ethpub
.
PEthereum
vm
*
otto
.
Otto
}
func
(
self
*
JS
Wrapper
)
GetKey
()
otto
.
Value
{
func
(
self
*
JS
Ethereum
)
GetKey
()
otto
.
Value
{
return
self
.
toVal
(
self
.
PEthereum
.
GetKey
())
}
func
(
self
*
JS
Wrapper
)
GetStateObject
(
addr
string
)
otto
.
Value
{
func
(
self
*
JS
Ethereum
)
GetStateObject
(
addr
string
)
otto
.
Value
{
return
self
.
toVal
(
self
.
PEthereum
.
GetStateObject
(
addr
))
}
func
(
self
*
JS
Wrapper
)
Transact
(
key
,
recipient
,
valueStr
,
gasStr
,
gasPriceStr
,
dataStr
string
)
otto
.
Value
{
func
(
self
*
JS
Ethereum
)
Transact
(
key
,
recipient
,
valueStr
,
gasStr
,
gasPriceStr
,
dataStr
string
)
otto
.
Value
{
r
,
err
:=
self
.
PEthereum
.
Transact
(
key
,
recipient
,
valueStr
,
gasStr
,
gasPriceStr
,
dataStr
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
...
...
@@ -82,7 +87,7 @@ func (self *JSWrapper) Transact(key, recipient, valueStr, gasStr, gasPriceStr, d
return
self
.
toVal
(
r
)
}
func
(
self
*
JS
Wrapper
)
Create
(
key
,
valueStr
,
gasStr
,
gasPriceStr
,
initStr
,
bodyStr
string
)
otto
.
Value
{
func
(
self
*
JS
Ethereum
)
Create
(
key
,
valueStr
,
gasStr
,
gasPriceStr
,
initStr
,
bodyStr
string
)
otto
.
Value
{
r
,
err
:=
self
.
PEthereum
.
Create
(
key
,
valueStr
,
gasStr
,
gasPriceStr
,
initStr
,
bodyStr
)
if
err
!=
nil
{
...
...
@@ -95,7 +100,7 @@ func (self *JSWrapper) Create(key, valueStr, gasStr, gasPriceStr, initStr, bodyS
}
// Wrapper function
func
(
self
*
JS
Wrapper
)
toVal
(
v
interface
{})
otto
.
Value
{
func
(
self
*
JS
Ethereum
)
toVal
(
v
interface
{})
otto
.
Value
{
result
,
err
:=
self
.
vm
.
ToValue
(
v
)
if
err
!=
nil
{
...
...
ethereum/repl_darwin.go
0 → 100644
View file @
770808ce
package
main
// #cgo LDFLAGS: -lreadline
// #include <stdio.h>
// #include <stdlib.h>
// #include <readline/readline.h>
// #include <readline/history.h>
import
"C"
import
"unsafe"
func
readLine
(
prompt
*
string
)
*
string
{
var
p
*
C
.
char
//readline allows an empty prompt(NULL)
if
prompt
!=
nil
{
p
=
C
.
CString
(
*
prompt
)
}
ret
:=
C
.
readline
(
p
)
if
p
!=
nil
{
C
.
free
(
unsafe
.
Pointer
(
p
))
}
if
ret
==
nil
{
return
nil
}
//EOF
s
:=
C
.
GoString
(
ret
)
C
.
free
(
unsafe
.
Pointer
(
ret
))
return
&
s
}
func
addHistory
(
s
string
)
{
p
:=
C
.
CString
(
s
)
C
.
add_history
(
p
)
C
.
free
(
unsafe
.
Pointer
(
p
))
}
func
(
self
*
JSRepl
)
read
()
{
prompt
:=
"eth >>> "
L
:
for
{
switch
result
:=
readLine
(
&
prompt
);
true
{
case
result
==
nil
:
break
L
//exit loop
case
*
result
!=
""
:
//ignore blank lines
addHistory
(
*
result
)
//allow user to recall this line
self
.
parseInput
(
*
result
)
}
}
}
ethereum/repl_linux.go
0 → 120000
View file @
770808ce
repl_darwin
.
go
\ No newline at end of file
ethereum/repl_windows.go
0 → 100644
View file @
770808ce
package
main
import
(
"bufio"
"fmt"
"os"
)
func
(
self
*
JSRepl
)
read
()
{
reader
:=
bufio
.
NewReader
(
os
.
Stdin
)
for
{
fmt
.
Printf
(
"eth >>> "
)
str
,
_
,
err
:=
reader
.
ReadLine
()
if
err
!=
nil
{
fmt
.
Println
(
"Error reading input"
,
err
)
}
else
{
self
.
parseInput
(
string
(
str
))
}
}
}
utils/cmd.go
View file @
770808ce
...
...
@@ -35,9 +35,11 @@ func DoMining(ethereum *eth.Ethereum) {
// Give it some time to connect with peers
time
.
Sleep
(
3
*
time
.
Second
)
for
ethereum
.
IsUpToDate
()
==
false
{
time
.
Sleep
(
5
*
time
.
Second
)
}
/*
for ethereum.IsUpToDate() == false {
time.Sleep(5 * time.Second)
}
*/
log
.
Println
(
"Miner started"
)
miner
:=
ethminer
.
NewDefaultMiner
(
addr
,
ethereum
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment