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
4ec38e39
Commit
4ec38e39
authored
Mar 25, 2015
by
zelig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
common: remove WriteFile and ReadAllFile (use ioutil instead)
parent
23e41a57
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
22 additions
and
92 deletions
+22
-92
js_test.go
cmd/ethereum/js_test.go
+3
-3
main.go
cmd/ethereum/main.go
+3
-2
bindings.go
cmd/mist/bindings.go
+4
-3
gui.go
cmd/mist/gui.go
+3
-2
path.go
common/path.go
+0
-30
path_test.go
common/path_test.go
+1
-46
crypto.go
crypto/crypto.go
+4
-2
jsre_test.go
jsre/jsre_test.go
+4
-4
No files found.
cmd/ethereum/js_test.go
View file @
4ec38e39
...
@@ -2,6 +2,7 @@ package main
...
@@ -2,6 +2,7 @@ package main
import
(
import
(
"fmt"
"fmt"
"io/ioutil"
"os"
"os"
"path"
"path"
"testing"
"testing"
...
@@ -9,7 +10,6 @@ import (
...
@@ -9,7 +10,6 @@ import (
"github.com/robertkrimen/otto"
"github.com/robertkrimen/otto"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/eth"
)
)
...
@@ -30,8 +30,8 @@ func testJEthRE(t *testing.T) (repl *jsre, ethereum *eth.Ethereum, err error) {
...
@@ -30,8 +30,8 @@ func testJEthRE(t *testing.T) (repl *jsre, ethereum *eth.Ethereum, err error) {
}
}
// FIXME: this does not work ATM
// FIXME: this does not work ATM
ks
:=
crypto
.
NewKeyStorePlain
(
"/tmp/eth/keys"
)
ks
:=
crypto
.
NewKeyStorePlain
(
"/tmp/eth/keys"
)
common
.
WriteFile
(
"/tmp/eth/keys/e273f01c99144c438695e10f24926dc1f9fbf62d/e273f01c99144c438695e10f24926dc1f9fbf62d"
,
ioutil
.
WriteFile
(
"/tmp/eth/keys/e273f01c99144c438695e10f24926dc1f9fbf62d/e273f01c99144c438695e10f24926dc1f9fbf62d"
,
[]
byte
(
`{"Id":"RhRXD+fNRKS4jx+7ZfEsNA==","Address":"4nPwHJkUTEOGleEPJJJtwfn79i0=","PrivateKey":"h4ACVpe74uIvi5Cg/2tX/Yrm2xdr3J7QoMbMtNX2CNc="}`
))
[]
byte
(
`{"Id":"RhRXD+fNRKS4jx+7ZfEsNA==","Address":"4nPwHJkUTEOGleEPJJJtwfn79i0=","PrivateKey":"h4ACVpe74uIvi5Cg/2tX/Yrm2xdr3J7QoMbMtNX2CNc="}`
)
,
os
.
ModePerm
)
port
++
port
++
ethereum
,
err
=
eth
.
New
(
&
eth
.
Config
{
ethereum
,
err
=
eth
.
New
(
&
eth
.
Config
{
...
...
cmd/ethereum/main.go
View file @
4ec38e39
...
@@ -355,10 +355,11 @@ func getPassPhrase(ctx *cli.Context, desc string, confirmation bool) (passphrase
...
@@ -355,10 +355,11 @@ func getPassPhrase(ctx *cli.Context, desc string, confirmation bool) (passphrase
passphrase
=
auth
passphrase
=
auth
}
else
{
}
else
{
var
err
error
passbytes
,
err
:=
ioutil
.
ReadFile
(
passfile
)
if
passphrase
,
err
=
common
.
ReadAllFile
(
passfile
);
err
!=
nil
{
if
err
!=
nil
{
utils
.
Fatalf
(
"Unable to read password file '%s': %v"
,
passfile
,
err
)
utils
.
Fatalf
(
"Unable to read password file '%s': %v"
,
passfile
,
err
)
}
}
passphrase
=
string
(
passbytes
)
}
}
}
}
return
return
...
...
cmd/mist/bindings.go
View file @
4ec38e39
...
@@ -22,13 +22,14 @@ package main
...
@@ -22,13 +22,14 @@ package main
import
(
import
(
"encoding/json"
"encoding/json"
"io/ioutil"
"os"
"os"
"strconv"
"strconv"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
)
)
type
plugin
struct
{
type
plugin
struct
{
...
@@ -46,14 +47,14 @@ func (self *Gui) AddPlugin(pluginPath string) {
...
@@ -46,14 +47,14 @@ func (self *Gui) AddPlugin(pluginPath string) {
self
.
plugins
[
pluginPath
]
=
plugin
{
Name
:
pluginPath
,
Path
:
pluginPath
}
self
.
plugins
[
pluginPath
]
=
plugin
{
Name
:
pluginPath
,
Path
:
pluginPath
}
json
,
_
:=
json
.
MarshalIndent
(
self
.
plugins
,
""
,
" "
)
json
,
_
:=
json
.
MarshalIndent
(
self
.
plugins
,
""
,
" "
)
common
.
WriteFile
(
self
.
eth
.
DataDir
+
"/plugins.json"
,
json
)
ioutil
.
WriteFile
(
self
.
eth
.
DataDir
+
"/plugins.json"
,
json
,
os
.
ModePerm
)
}
}
func
(
self
*
Gui
)
RemovePlugin
(
pluginPath
string
)
{
func
(
self
*
Gui
)
RemovePlugin
(
pluginPath
string
)
{
delete
(
self
.
plugins
,
pluginPath
)
delete
(
self
.
plugins
,
pluginPath
)
json
,
_
:=
json
.
MarshalIndent
(
self
.
plugins
,
""
,
" "
)
json
,
_
:=
json
.
MarshalIndent
(
self
.
plugins
,
""
,
" "
)
common
.
WriteFile
(
self
.
eth
.
DataDir
+
"/plugins.json"
,
json
)
ioutil
.
WriteFile
(
self
.
eth
.
DataDir
+
"/plugins.json"
,
json
,
os
.
ModePerm
)
}
}
func
(
self
*
Gui
)
DumpState
(
hash
,
path
string
)
{
func
(
self
*
Gui
)
DumpState
(
hash
,
path
string
)
{
...
...
cmd/mist/gui.go
View file @
4ec38e39
...
@@ -25,6 +25,7 @@ import "C"
...
@@ -25,6 +25,7 @@ import "C"
import
(
import
(
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"io/ioutil"
"math/big"
"math/big"
"path"
"path"
"runtime"
"runtime"
...
@@ -91,8 +92,8 @@ func NewWindow(ethereum *eth.Ethereum) *Gui {
...
@@ -91,8 +92,8 @@ func NewWindow(ethereum *eth.Ethereum) *Gui {
plugins
:
make
(
map
[
string
]
plugin
),
plugins
:
make
(
map
[
string
]
plugin
),
serviceEvents
:
make
(
chan
ServEv
,
1
),
serviceEvents
:
make
(
chan
ServEv
,
1
),
}
}
data
,
_
:=
common
.
ReadAll
File
(
path
.
Join
(
ethereum
.
DataDir
,
"plugins.json"
))
data
,
_
:=
ioutil
.
Read
File
(
path
.
Join
(
ethereum
.
DataDir
,
"plugins.json"
))
json
.
Unmarshal
(
[]
byte
(
data
)
,
&
gui
.
plugins
)
json
.
Unmarshal
(
data
,
&
gui
.
plugins
)
return
gui
return
gui
}
}
...
...
common/path.go
View file @
4ec38e39
...
@@ -2,7 +2,6 @@ package common
...
@@ -2,7 +2,6 @@ package common
import
(
import
(
"fmt"
"fmt"
"io/ioutil"
"os"
"os"
"os/user"
"os/user"
"path"
"path"
...
@@ -43,35 +42,6 @@ func FileExist(filePath string) bool {
...
@@ -43,35 +42,6 @@ func FileExist(filePath string) bool {
return
true
return
true
}
}
func
ReadAllFile
(
filePath
string
)
(
string
,
error
)
{
file
,
err
:=
os
.
Open
(
filePath
)
if
err
!=
nil
{
return
""
,
err
}
data
,
err
:=
ioutil
.
ReadAll
(
file
)
if
err
!=
nil
{
return
""
,
err
}
return
string
(
data
),
nil
}
func
WriteFile
(
filePath
string
,
content
[]
byte
)
error
{
fh
,
err
:=
os
.
OpenFile
(
filePath
,
os
.
O_TRUNC
|
os
.
O_RDWR
|
os
.
O_CREATE
,
os
.
ModePerm
)
if
err
!=
nil
{
return
err
}
defer
fh
.
Close
()
_
,
err
=
fh
.
Write
(
content
)
if
err
!=
nil
{
return
err
}
return
nil
}
func
AbsolutePath
(
Datadir
string
,
filename
string
)
string
{
func
AbsolutePath
(
Datadir
string
,
filename
string
)
string
{
if
path
.
IsAbs
(
filename
)
{
if
path
.
IsAbs
(
filename
)
{
return
filename
return
filename
...
...
common/path_test.go
View file @
4ec38e39
...
@@ -2,56 +2,11 @@ package common
...
@@ -2,56 +2,11 @@ package common
import
(
import
(
"os"
"os"
"testing"
//
"testing"
checker
"gopkg.in/check.v1"
checker
"gopkg.in/check.v1"
)
)
func
TestGoodFile
(
t
*
testing
.
T
)
{
goodpath
:=
"~/goethereumtest.pass"
path
:=
ExpandHomePath
(
goodpath
)
contentstring
:=
"3.14159265358979323846"
err
:=
WriteFile
(
path
,
[]
byte
(
contentstring
))
if
err
!=
nil
{
t
.
Error
(
"Could not write file"
)
}
if
!
FileExist
(
path
)
{
t
.
Error
(
"File not found at"
,
path
)
}
v
,
err
:=
ReadAllFile
(
path
)
if
err
!=
nil
{
t
.
Error
(
"Could not read file"
,
path
)
}
if
v
!=
contentstring
{
t
.
Error
(
"Expected"
,
contentstring
,
"Got"
,
v
)
}
}
func
TestBadFile
(
t
*
testing
.
T
)
{
badpath
:=
"/this/path/should/not/exist/goethereumtest.fail"
path
:=
ExpandHomePath
(
badpath
)
contentstring
:=
"3.14159265358979323846"
err
:=
WriteFile
(
path
,
[]
byte
(
contentstring
))
if
err
==
nil
{
t
.
Error
(
"Wrote file, but should not be able to"
,
path
)
}
if
FileExist
(
path
)
{
t
.
Error
(
"Found file, but should not be able to"
,
path
)
}
v
,
err
:=
ReadAllFile
(
path
)
if
err
==
nil
{
t
.
Error
(
"Read file, but should not be able to"
,
v
)
}
}
type
CommonSuite
struct
{}
type
CommonSuite
struct
{}
var
_
=
checker
.
Suite
(
&
CommonSuite
{})
var
_
=
checker
.
Suite
(
&
CommonSuite
{})
...
...
crypto/crypto.go
View file @
4ec38e39
...
@@ -9,6 +9,7 @@ import (
...
@@ -9,6 +9,7 @@ import (
"crypto/sha256"
"crypto/sha256"
"fmt"
"fmt"
"io"
"io"
"io/ioutil"
"os"
"os"
"encoding/hex"
"encoding/hex"
...
@@ -139,9 +140,10 @@ func LoadECDSA(file string) (*ecdsa.PrivateKey, error) {
...
@@ -139,9 +140,10 @@ func LoadECDSA(file string) (*ecdsa.PrivateKey, error) {
return
ToECDSA
(
buf
),
nil
return
ToECDSA
(
buf
),
nil
}
}
// SaveECDSA saves a secp256k1 private key from the given file.
// SaveECDSA saves a secp256k1 private key to the given file with restrictive
// permissions
func
SaveECDSA
(
file
string
,
key
*
ecdsa
.
PrivateKey
)
error
{
func
SaveECDSA
(
file
string
,
key
*
ecdsa
.
PrivateKey
)
error
{
return
common
.
WriteFile
(
file
,
FromECDSA
(
key
)
)
return
ioutil
.
WriteFile
(
file
,
FromECDSA
(
key
),
0600
)
}
}
func
GenerateKey
()
(
*
ecdsa
.
PrivateKey
,
error
)
{
func
GenerateKey
()
(
*
ecdsa
.
PrivateKey
,
error
)
{
...
...
jsre/jsre_test.go
View file @
4ec38e39
...
@@ -2,9 +2,9 @@ package jsre
...
@@ -2,9 +2,9 @@ package jsre
import
(
import
(
"github.com/robertkrimen/otto"
"github.com/robertkrimen/otto"
"io/ioutil"
"os"
"testing"
"testing"
"github.com/ethereum/go-ethereum/common"
)
)
type
testNativeObjectBinding
struct
{
type
testNativeObjectBinding
struct
{
...
@@ -26,7 +26,7 @@ func (no *testNativeObjectBinding) TestMethod(call otto.FunctionCall) otto.Value
...
@@ -26,7 +26,7 @@ func (no *testNativeObjectBinding) TestMethod(call otto.FunctionCall) otto.Value
func
TestExec
(
t
*
testing
.
T
)
{
func
TestExec
(
t
*
testing
.
T
)
{
jsre
:=
New
(
"/tmp"
)
jsre
:=
New
(
"/tmp"
)
common
.
WriteFile
(
"/tmp/test.js"
,
[]
byte
(
`msg = "testMsg"`
)
)
ioutil
.
WriteFile
(
"/tmp/test.js"
,
[]
byte
(
`msg = "testMsg"`
),
os
.
ModePerm
)
err
:=
jsre
.
Exec
(
"test.js"
)
err
:=
jsre
.
Exec
(
"test.js"
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"expected no error, got %v"
,
err
)
t
.
Errorf
(
"expected no error, got %v"
,
err
)
...
@@ -64,7 +64,7 @@ func TestBind(t *testing.T) {
...
@@ -64,7 +64,7 @@ func TestBind(t *testing.T) {
func
TestLoadScript
(
t
*
testing
.
T
)
{
func
TestLoadScript
(
t
*
testing
.
T
)
{
jsre
:=
New
(
"/tmp"
)
jsre
:=
New
(
"/tmp"
)
common
.
WriteFile
(
"/tmp/test.js"
,
[]
byte
(
`msg = "testMsg"`
)
)
ioutil
.
WriteFile
(
"/tmp/test.js"
,
[]
byte
(
`msg = "testMsg"`
),
os
.
ModePerm
)
_
,
err
:=
jsre
.
Run
(
`loadScript("test.js")`
)
_
,
err
:=
jsre
.
Run
(
`loadScript("test.js")`
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"expected no error, got %v"
,
err
)
t
.
Errorf
(
"expected no error, got %v"
,
err
)
...
...
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