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
64a6c2c1
Commit
64a6c2c1
authored
9 years ago
by
Bas van Kervel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
eth: add new RPC method (personal.) SignAndSendTransaction
parent
e798e4fd
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
165 additions
and
71 deletions
+165
-71
account_manager.go
accounts/account_manager.go
+14
-2
accounts_test.go
accounts/accounts_test.go
+28
-0
js.go
cmd/geth/js.go
+1
-1
api.go
eth/api.go
+113
-67
backend.go
eth/backend.go
+3
-1
web3ext.go
internal/web3ext/web3ext.go
+6
-0
No files found.
accounts/account_manager.go
View file @
64a6c2c1
...
...
@@ -147,9 +147,21 @@ func (am *Manager) Sign(addr common.Address, hash []byte) (signature []byte, err
return
crypto
.
Sign
(
hash
,
unlockedKey
.
PrivateKey
)
}
// SignWithPassphrase signs hash if the private key matching the given address can be
// decrypted with the given passphrase.
func
(
am
*
Manager
)
SignWithPassphrase
(
addr
common
.
Address
,
passphrase
string
,
hash
[]
byte
)
(
signature
[]
byte
,
err
error
)
{
_
,
key
,
err
:=
am
.
getDecryptedKey
(
Account
{
Address
:
addr
},
passphrase
)
if
err
!=
nil
{
return
nil
,
err
}
defer
zeroKey
(
key
.
PrivateKey
)
return
crypto
.
Sign
(
hash
,
key
.
PrivateKey
)
}
// Unlock unlocks the given account indefinitely.
func
(
am
*
Manager
)
Unlock
(
a
Account
,
keyAuth
string
)
error
{
return
am
.
TimedUnlock
(
a
,
keyAuth
,
0
)
func
(
am
*
Manager
)
Unlock
(
a
Account
,
passphrase
string
)
error
{
return
am
.
TimedUnlock
(
a
,
passphrase
,
0
)
}
// Lock removes the private key with the given address from memory.
...
...
This diff is collapsed.
Click to expand it.
accounts/accounts_test.go
View file @
64a6c2c1
...
...
@@ -81,6 +81,34 @@ func TestSign(t *testing.T) {
}
}
func
TestSignWithPassphrase
(
t
*
testing
.
T
)
{
dir
,
am
:=
tmpManager
(
t
,
true
)
defer
os
.
RemoveAll
(
dir
)
pass
:=
"passwd"
acc
,
err
:=
am
.
NewAccount
(
pass
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
_
,
unlocked
:=
am
.
unlocked
[
acc
.
Address
];
unlocked
{
t
.
Fatal
(
"expected account to be locked"
)
}
_
,
err
=
am
.
SignWithPassphrase
(
acc
.
Address
,
pass
,
testSigData
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
_
,
unlocked
:=
am
.
unlocked
[
acc
.
Address
];
unlocked
{
t
.
Fatal
(
"expected account to be locked"
)
}
if
_
,
err
=
am
.
SignWithPassphrase
(
acc
.
Address
,
"invalid passwd"
,
testSigData
);
err
==
nil
{
t
.
Fatal
(
"expected SignHash to fail with invalid password"
)
}
}
func
TestTimedUnlock
(
t
*
testing
.
T
)
{
dir
,
am
:=
tmpManager
(
t
,
true
)
defer
os
.
RemoveAll
(
dir
)
...
...
This diff is collapsed.
Click to expand it.
cmd/geth/js.go
View file @
64a6c2c1
...
...
@@ -41,7 +41,7 @@ import (
)
var
(
passwordRegexp
=
regexp
.
MustCompile
(
"personal.[nu]"
)
passwordRegexp
=
regexp
.
MustCompile
(
"personal.[nu
s
]"
)
onlyws
=
regexp
.
MustCompile
(
"^
\\
s*$"
)
exit
=
regexp
.
MustCompile
(
"^
\\
s*exit
\\
s*;*
\\
s*$"
)
)
...
...
This diff is collapsed.
Click to expand it.
eth/api.go
View file @
64a6c2c1
This diff is collapsed.
Click to expand it.
eth/backend.go
View file @
64a6c2c1
...
...
@@ -26,6 +26,7 @@ import (
"path/filepath"
"regexp"
"strings"
"sync"
"time"
"github.com/ethereum/ethash"
...
...
@@ -113,6 +114,7 @@ type Ethereum struct {
// Handlers
txPool
*
core
.
TxPool
txMu
sync
.
Mutex
blockchain
*
core
.
BlockChain
accountManager
*
accounts
.
Manager
pow
*
ethash
.
Ethash
...
...
@@ -293,7 +295,7 @@ func (s *Ethereum) APIs() []rpc.API {
},
{
Namespace
:
"personal"
,
Version
:
"1.0"
,
Service
:
NewPrivateAccountAPI
(
s
.
accountManager
),
Service
:
NewPrivateAccountAPI
(
s
),
Public
:
false
,
},
{
Namespace
:
"eth"
,
...
...
This diff is collapsed.
Click to expand it.
internal/web3ext/web3ext.go
View file @
64a6c2c1
...
...
@@ -431,6 +431,12 @@ web3._extend({
name: 'importRawKey',
call: 'personal_importRawKey',
params: 2
}),
new web3._extend.Method({
name: 'signAndSendTransaction',
call: 'personal_signAndSendTransaction',
params: 2,
inputFormatter: [web3._extend.formatters.inputTransactionFormatter, null]
})
]
});
...
...
This diff is collapsed.
Click to expand it.
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