good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
d1b52efd
Commit
d1b52efd
authored
Mar 24, 2015
by
Viktor Trón
Browse files
Options
Downloads
Patches
Plain Diff
cli: implement ethereum presale wallet import via cli
parent
34d5a6c1
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
accounts/account_manager.go
+12
-0
12 additions, 0 deletions
accounts/account_manager.go
cmd/ethereum/main.go
+47
-27
47 additions, 27 deletions
cmd/ethereum/main.go
with
59 additions
and
27 deletions
accounts/account_manager.go
+
12
−
0
View file @
d1b52efd
...
@@ -239,3 +239,15 @@ func (am *Manager) Import(path string, keyAuth string) (Account, error) {
...
@@ -239,3 +239,15 @@ func (am *Manager) Import(path string, keyAuth string) (Account, error) {
}
}
return
Account
{
Address
:
key
.
Address
},
nil
return
Account
{
Address
:
key
.
Address
},
nil
}
}
func
(
am
*
Manager
)
ImportPreSaleKey
(
keyJSON
[]
byte
,
password
string
)
(
acc
Account
,
err
error
)
{
var
key
*
crypto
.
Key
key
,
err
=
crypto
.
ImportPreSaleKey
(
am
.
keyStore
,
keyJSON
,
password
)
if
err
!=
nil
{
return
}
if
err
=
am
.
keyStore
.
StoreKey
(
key
,
password
);
err
!=
nil
{
return
}
return
Account
{
Address
:
key
.
Address
},
nil
}
This diff is collapsed.
Click to expand it.
cmd/ethereum/main.go
+
47
−
27
View file @
d1b52efd
...
@@ -23,6 +23,7 @@ package main
...
@@ -23,6 +23,7 @@ package main
import
(
import
(
"bufio"
"bufio"
"fmt"
"fmt"
"io/ioutil"
"os"
"os"
"runtime"
"runtime"
"strconv"
"strconv"
...
@@ -74,6 +75,19 @@ Regular users do not need to execute it.
...
@@ -74,6 +75,19 @@ Regular users do not need to execute it.
The output of this command is supposed to be machine-readable.
The output of this command is supposed to be machine-readable.
`
,
`
,
},
},
{
Action
:
accountList
,
Name
:
"wallet"
,
Usage
:
"ethereum presale wallet"
,
Subcommands
:
[]
cli
.
Command
{
{
Action
:
importWallet
,
Name
:
"import"
,
Usage
:
"import ethereum presale wallet"
,
},
},
},
{
{
Action
:
accountList
,
Action
:
accountList
,
Name
:
"account"
,
Name
:
"account"
,
...
@@ -280,22 +294,7 @@ func unlockAccount(ctx *cli.Context, am *accounts.Manager, account string) (pass
...
@@ -280,22 +294,7 @@ func unlockAccount(ctx *cli.Context, am *accounts.Manager, account string) (pass
var
err
error
var
err
error
// Load startup keys. XXX we are going to need a different format
// Load startup keys. XXX we are going to need a different format
// Attempt to unlock the account
// Attempt to unlock the account
passfile
:=
ctx
.
GlobalString
(
utils
.
PasswordFileFlag
.
Name
)
passphrase
:=
getPassPhrase
(
ctx
,
""
,
false
)
if
len
(
passfile
)
==
0
{
fmt
.
Println
(
"Please enter a passphrase now."
)
auth
,
err
:=
readPassword
(
"Passphrase: "
,
true
)
if
err
!=
nil
{
utils
.
Fatalf
(
"%v"
,
err
)
}
passphrase
=
auth
}
else
{
if
passphrase
,
err
=
common
.
ReadAllFile
(
passfile
);
err
!=
nil
{
utils
.
Fatalf
(
"Unable to read password file '%s': %v"
,
passfile
,
err
)
}
}
err
=
am
.
Unlock
(
common
.
FromHex
(
account
),
passphrase
)
err
=
am
.
Unlock
(
common
.
FromHex
(
account
),
passphrase
)
if
err
!=
nil
{
if
err
!=
nil
{
utils
.
Fatalf
(
"Unlock account failed '%v'"
,
err
)
utils
.
Fatalf
(
"Unlock account failed '%v'"
,
err
)
...
@@ -335,16 +334,16 @@ func accountList(ctx *cli.Context) {
...
@@ -335,16 +334,16 @@ func accountList(ctx *cli.Context) {
}
}
}
}
func
getPassPhrase
(
ctx
*
cli
.
Context
)
(
passphrase
string
)
{
func
getPassPhrase
(
ctx
*
cli
.
Context
,
desc
string
,
confirmation
bool
)
(
passphrase
string
)
{
if
!
ctx
.
GlobalBool
(
utils
.
UnencryptedKeysFlag
.
Name
)
{
if
!
ctx
.
GlobalBool
(
utils
.
UnencryptedKeysFlag
.
Name
)
{
passfile
:=
ctx
.
GlobalString
(
utils
.
PasswordFileFlag
.
Name
)
passfile
:=
ctx
.
GlobalString
(
utils
.
PasswordFileFlag
.
Name
)
if
len
(
passfile
)
==
0
{
if
len
(
passfile
)
==
0
{
fmt
.
Println
(
"The new account will be encrypted with a passphrase."
)
fmt
.
Println
(
desc
)
fmt
.
Println
(
"Please enter a passphrase now."
)
auth
,
err
:=
readPassword
(
"Passphrase: "
,
true
)
auth
,
err
:=
readPassword
(
"Passphrase: "
,
true
)
if
err
!=
nil
{
if
err
!=
nil
{
utils
.
Fatalf
(
"%v"
,
err
)
utils
.
Fatalf
(
"%v"
,
err
)
}
}
if
confirmation
{
confirm
,
err
:=
readPassword
(
"Repeat Passphrase: "
,
false
)
confirm
,
err
:=
readPassword
(
"Repeat Passphrase: "
,
false
)
if
err
!=
nil
{
if
err
!=
nil
{
utils
.
Fatalf
(
"%v"
,
err
)
utils
.
Fatalf
(
"%v"
,
err
)
...
@@ -352,6 +351,7 @@ func getPassPhrase(ctx *cli.Context) (passphrase string) {
...
@@ -352,6 +351,7 @@ func getPassPhrase(ctx *cli.Context) (passphrase string) {
if
auth
!=
confirm
{
if
auth
!=
confirm
{
utils
.
Fatalf
(
"Passphrases did not match."
)
utils
.
Fatalf
(
"Passphrases did not match."
)
}
}
}
passphrase
=
auth
passphrase
=
auth
}
else
{
}
else
{
...
@@ -366,7 +366,7 @@ func getPassPhrase(ctx *cli.Context) (passphrase string) {
...
@@ -366,7 +366,7 @@ func getPassPhrase(ctx *cli.Context) (passphrase string) {
func
accountCreate
(
ctx
*
cli
.
Context
)
{
func
accountCreate
(
ctx
*
cli
.
Context
)
{
am
:=
utils
.
GetAccountManager
(
ctx
)
am
:=
utils
.
GetAccountManager
(
ctx
)
passphrase
:=
getPassPhrase
(
ctx
)
passphrase
:=
getPassPhrase
(
ctx
,
"Your new account is locked with a password. Please give a password. Do not forget this password."
,
true
)
acct
,
err
:=
am
.
NewAccount
(
passphrase
)
acct
,
err
:=
am
.
NewAccount
(
passphrase
)
if
err
!=
nil
{
if
err
!=
nil
{
utils
.
Fatalf
(
"Could not create the account: %v"
,
err
)
utils
.
Fatalf
(
"Could not create the account: %v"
,
err
)
...
@@ -374,13 +374,33 @@ func accountCreate(ctx *cli.Context) {
...
@@ -374,13 +374,33 @@ func accountCreate(ctx *cli.Context) {
fmt
.
Printf
(
"Address: %x
\n
"
,
acct
)
fmt
.
Printf
(
"Address: %x
\n
"
,
acct
)
}
}
func
importWallet
(
ctx
*
cli
.
Context
)
{
keyfile
:=
ctx
.
Args
()
.
First
()
if
len
(
keyfile
)
==
0
{
utils
.
Fatalf
(
"keyfile must be given as argument"
)
}
keyJson
,
err
:=
ioutil
.
ReadFile
(
keyfile
)
if
err
!=
nil
{
utils
.
Fatalf
(
"Could not read wallet file: %v"
,
err
)
}
am
:=
utils
.
GetAccountManager
(
ctx
)
passphrase
:=
getPassPhrase
(
ctx
,
""
,
false
)
acct
,
err
:=
am
.
ImportPreSaleKey
(
keyJson
,
passphrase
)
if
err
!=
nil
{
utils
.
Fatalf
(
"Could not create the account: %v"
,
err
)
}
fmt
.
Printf
(
"Address: %x
\n
"
,
acct
)
}
func
accountImport
(
ctx
*
cli
.
Context
)
{
func
accountImport
(
ctx
*
cli
.
Context
)
{
keyfile
:=
ctx
.
Args
()
.
First
()
keyfile
:=
ctx
.
Args
()
.
First
()
if
len
(
keyfile
)
==
0
{
if
len
(
keyfile
)
==
0
{
utils
.
Fatalf
(
"keyfile must be given as argument"
)
utils
.
Fatalf
(
"keyfile must be given as argument"
)
}
}
am
:=
utils
.
GetAccountManager
(
ctx
)
am
:=
utils
.
GetAccountManager
(
ctx
)
passphrase
:=
getPassPhrase
(
ctx
)
passphrase
:=
getPassPhrase
(
ctx
,
"Your new account is locked with a password. Please give a password. Do not forget this password."
,
true
)
acct
,
err
:=
am
.
Import
(
keyfile
,
passphrase
)
acct
,
err
:=
am
.
Import
(
keyfile
,
passphrase
)
if
err
!=
nil
{
if
err
!=
nil
{
utils
.
Fatalf
(
"Could not create the account: %v"
,
err
)
utils
.
Fatalf
(
"Could not create the account: %v"
,
err
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment