Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
plugin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
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
link33
plugin
Commits
59265022
Commit
59265022
authored
Mar 25, 2019
by
Hugo
Committed by
vipwzw
Mar 27, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
deal with issue #376
parent
c9abccee
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
102 additions
and
129 deletions
+102
-129
pvfile.go
plugin/consensus/tendermint/types/pvfile.go
+0
-129
valnode.go
plugin/dapp/valnode/commands/valnode.go
+102
-0
No files found.
plugin/consensus/tendermint/types/pvfile.go
deleted
100644 → 0
View file @
c9abccee
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
types
import
(
"math/rand"
"strconv"
"time"
"github.com/33cn/chain33/common/crypto"
"github.com/33cn/chain33/common/log/log15"
"github.com/33cn/chain33/types"
"github.com/spf13/cobra"
)
var
(
tendermintlog
=
log15
.
New
(
"module"
,
"tendermint"
)
strChars
=
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
// 62 characters
genFile
=
"genesis_file.json"
pvFile
=
"priv_validator_"
)
// KeyFileCmd ...
func
KeyFileCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"keyfile"
,
Short
:
"Initialize Tendermint Keyfile"
,
Args
:
cobra
.
MinimumNArgs
(
1
),
}
cmd
.
AddCommand
(
CreateCmd
(),
)
return
cmd
}
// CreateCmd ...
func
CreateCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"create"
,
Short
:
"Begin to create keyfile"
,
Run
:
createFiles
,
}
addCreateCmdFlags
(
cmd
)
return
cmd
}
func
addCreateCmdFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"num"
,
"n"
,
""
,
"Num of the keyfile to create"
)
cmd
.
MarkFlagRequired
(
"num"
)
}
// RandStr ...
func
RandStr
(
length
int
)
string
{
chars
:=
[]
byte
{}
MAIN_LOOP
:
for
{
val
:=
rand
.
Int63
()
for
i
:=
0
;
i
<
10
;
i
++
{
v
:=
int
(
val
&
0x3f
)
// rightmost 6 bits
if
v
>=
62
{
// only 62 characters in strChars
val
>>=
6
continue
}
else
{
chars
=
append
(
chars
,
strChars
[
v
])
if
len
(
chars
)
==
length
{
break
MAIN_LOOP
}
val
>>=
6
}
}
}
return
string
(
chars
)
}
func
initCryptoImpl
()
error
{
cr
,
err
:=
crypto
.
New
(
types
.
GetSignName
(
""
,
types
.
ED25519
))
if
err
!=
nil
{
tendermintlog
.
Error
(
"New crypto impl failed"
,
"err"
,
err
)
return
err
}
ConsensusCrypto
=
cr
return
nil
}
func
createFiles
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
// init crypto instance
err
:=
initCryptoImpl
()
if
err
!=
nil
{
return
}
// genesis file
genDoc
:=
GenesisDoc
{
ChainID
:
Fmt
(
"chain33-%v"
,
RandStr
(
6
)),
GenesisTime
:
time
.
Now
(),
}
num
,
_
:=
cmd
.
Flags
()
.
GetString
(
"num"
)
n
,
err
:=
strconv
.
Atoi
(
num
)
if
err
!=
nil
{
tendermintlog
.
Error
(
"num parameter is not valid digit"
)
return
}
for
i
:=
0
;
i
<
n
;
i
++
{
// create private validator file
pvFileName
:=
pvFile
+
strconv
.
Itoa
(
i
)
+
".json"
privValidator
:=
LoadOrGenPrivValidatorFS
(
pvFileName
)
if
privValidator
==
nil
{
tendermintlog
.
Error
(
"Create priv_validator file failed."
)
break
}
// create genesis validator by the pubkey of private validator
gv
:=
GenesisValidator
{
PubKey
:
KeyText
{
"ed25519"
,
privValidator
.
GetPubKey
()
.
KeyString
()},
Power
:
10
,
}
genDoc
.
Validators
=
append
(
genDoc
.
Validators
,
gv
)
}
if
err
:=
genDoc
.
SaveAs
(
genFile
);
err
!=
nil
{
tendermintlog
.
Error
(
"Generated genesis file failed."
)
return
}
tendermintlog
.
Info
(
"Generated genesis file"
,
"path"
,
genFile
)
}
plugin/dapp/valnode/commands/valnode.go
View file @
59265022
...
...
@@ -9,6 +9,7 @@ import (
"fmt"
"math/rand"
"os"
"strconv"
"time"
"github.com/33cn/chain33/common"
...
...
@@ -17,10 +18,17 @@ import (
"github.com/33cn/chain33/rpc/jsonclient"
rpctypes
"github.com/33cn/chain33/rpc/types"
"github.com/33cn/chain33/types"
ttypes
"github.com/33cn/plugin/plugin/consensus/tendermint/types"
vt
"github.com/33cn/plugin/plugin/dapp/valnode/types"
"github.com/spf13/cobra"
)
var
(
strChars
=
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
// 62 characters
genFile
=
"genesis_file.json"
pvFile
=
"priv_validator_"
)
// ValCmd valnode cmd register
func
ValCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
...
...
@@ -33,6 +41,7 @@ func ValCmd() *cobra.Command {
GetBlockInfoCmd
(),
GetNodeInfoCmd
(),
AddNodeCmd
(),
CreateCmd
(),
)
return
cmd
}
...
...
@@ -190,3 +199,96 @@ func getprivkey() (crypto.PrivKey, error) {
}
return
priv
,
nil
}
//CreateCmd to create keyfiles
func
CreateCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"init_keyfile"
,
Short
:
"Initialize Tendermint Keyfile"
,
Run
:
createFiles
,
}
addCreateCmdFlags
(
cmd
)
return
cmd
}
func
addCreateCmdFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"num"
,
"n"
,
""
,
"Num of the keyfile to create"
)
cmd
.
MarkFlagRequired
(
"num"
)
}
// RandStr ...
func
RandStr
(
length
int
)
string
{
chars
:=
[]
byte
{}
MAIN_LOOP
:
for
{
val
:=
rand
.
Int63
()
for
i
:=
0
;
i
<
10
;
i
++
{
v
:=
int
(
val
&
0x3f
)
// rightmost 6 bits
if
v
>=
62
{
// only 62 characters in strChars
val
>>=
6
continue
}
else
{
chars
=
append
(
chars
,
strChars
[
v
])
if
len
(
chars
)
==
length
{
break
MAIN_LOOP
}
val
>>=
6
}
}
}
return
string
(
chars
)
}
func
initCryptoImpl
()
error
{
cr
,
err
:=
crypto
.
New
(
types
.
GetSignName
(
""
,
types
.
ED25519
))
if
err
!=
nil
{
fmt
.
Printf
(
"New crypto impl failed err: %v"
,
err
)
return
err
}
ttypes
.
ConsensusCrypto
=
cr
return
nil
}
func
createFiles
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
// init crypto instance
err
:=
initCryptoImpl
()
if
err
!=
nil
{
return
}
// genesis file
genDoc
:=
ttypes
.
GenesisDoc
{
ChainID
:
fmt
.
Sprintf
(
"chain33-%v"
,
RandStr
(
6
)),
GenesisTime
:
time
.
Now
(),
}
num
,
_
:=
cmd
.
Flags
()
.
GetString
(
"num"
)
n
,
err
:=
strconv
.
Atoi
(
num
)
if
err
!=
nil
{
fmt
.
Println
(
"num parameter is not valid digit"
)
return
}
for
i
:=
0
;
i
<
n
;
i
++
{
// create private validator file
pvFileName
:=
pvFile
+
strconv
.
Itoa
(
i
)
+
".json"
privValidator
:=
ttypes
.
LoadOrGenPrivValidatorFS
(
pvFileName
)
if
privValidator
==
nil
{
fmt
.
Println
(
"Create priv_validator file failed."
)
break
}
// create genesis validator by the pubkey of private validator
gv
:=
ttypes
.
GenesisValidator
{
PubKey
:
ttypes
.
KeyText
{
Kind
:
"ed25519"
,
Data
:
privValidator
.
GetPubKey
()
.
KeyString
()},
Power
:
10
,
}
genDoc
.
Validators
=
append
(
genDoc
.
Validators
,
gv
)
}
if
err
:=
genDoc
.
SaveAs
(
genFile
);
err
!=
nil
{
fmt
.
Println
(
"Generated genesis file failed."
)
return
}
fmt
.
Printf
(
"Generated genesis file path %v
\n
"
,
genFile
)
}
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