Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
burrow
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hang Yu
burrow
Commits
14ddd4d4
Unverified
Commit
14ddd4d4
authored
8 years ago
by
Benjamin Bollen
Browse files
Options
Downloads
Patches
Plain Diff
genesis: add GenesisPrivateValidator and constructors for GenesisAccount and GenesisValidator
parent
8ccff1ff
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
genesis/maker.go
+73
-0
73 additions, 0 deletions
genesis/maker.go
genesis/types.go
+13
-0
13 additions, 0 deletions
genesis/types.go
with
86 additions
and
0 deletions
genesis/maker.go
0 → 100644
+
73
−
0
View file @
14ddd4d4
// Copyright 2015-2017 Monax Industries Limited.
// This file is part of the Monax platform (Monax)
// Monax is free software: you can use, redistribute it and/or modify
// it only under the terms of the GNU General Public License, version
// 3, as published by the Free Software Foundation.
// Monax is distributed WITHOUT ANY WARRANTY pursuant to
// the terms of the Gnu General Public Licence, version 3, including
// (but not limited to) Clause 15 thereof. See the text of the
// GNU General Public License, version 3 for full terms.
// You should have received a copy of the GNU General Public License,
// version 3, with Monax. If not, see <http://www.gnu.org/licenses/>.
package
genesis
import
(
"fmt"
ptypes
"github.com/eris-ltd/eris-db/permission/types"
"github.com/tendermint/go-crypto"
)
// NewGenesisAccount returns a new GenesisAccount
func
NewGenesisAccount
(
address
[]
byte
,
amount
int64
,
name
string
,
permissions
*
ptypes
.
AccountPermissions
)
*
GenesisAccount
{
return
&
GenesisAccount
{
Address
:
address
,
Amount
:
amount
,
Name
:
name
,
Permissions
:
permissions
,
}
}
func
NewGenesisValidator
(
amount
int64
,
name
string
,
unbondToAddress
[]
byte
,
unbondAmount
int64
,
keyType
string
,
publicKeyBytes
[]
byte
)
(
*
GenesisValidator
,
error
)
{
var
publicKey
crypto
.
PubKey
// convert the key bytes into a typed fixed size byte array
switch
keyType
{
case
"ed25519"
:
// TODO: [ben] functionality and checks need to be inherit in the type
if
len
(
publicKeyBytes
)
!=
32
{
return
nil
,
fmt
.
Errorf
(
"Invalid length provided for ed25519 public key (len %v)"
,
len
(
publicKeyBytes
))
}
publicKey
:=
crypto
.
PubKeyEd25519
{}
copy
(
publicKey
[
:
],
publicKeyBytes
[
:
32
])
case
"secp256k1"
:
if
len
(
publicKeyBytes
)
!=
64
{
return
nil
,
fmt
.
Errorf
(
"Invalid length provided for secp256k1 public key (len %v)"
,
len
(
publicKeyBytes
))
}
publicKey
:=
crypto
.
PubKeySecp256k1
{}
copy
(
publicKey
[
:
],
publicKeyBytes
[
:
64
])
default
:
return
nil
,
fmt
.
Errorf
(
"Unsupported key type (%s)"
,
keyType
)
}
// ability to unbond to multiple accounts currently unused
var
unbondTo
[]
BasicAccount
return
&
GenesisValidator
{
PubKey
:
publicKey
,
Amount
:
amount
,
Name
:
name
,
UnbondTo
:
append
(
unbondTo
,
BasicAccount
{
Address
:
unbondToAddress
,
Amount
:
unbondAmount
,
}),
},
nil
}
This diff is collapsed.
Click to expand it.
genesis/types.go
+
13
−
0
View file @
14ddd4d4
...
...
@@ -37,6 +37,19 @@ type GenesisValidator struct {
UnbondTo
[]
BasicAccount
`json:"unbond_to"`
}
// GenesisPrivateValidator marshals the state of the private
// validator for the purpose of Genesis creation; and hence
// is defined in genesis and not under consensus, where
// PrivateValidator (currently inherited from Tendermint) is.
type
GenesisPrivateValidator
struct
{
Address
[]
byte
`json:"address"`
PubKey
crypto
.
PubKey
`json:"pub_key"`
PrivKey
crypto
.
PrivKey
`json:"priv_key"`
LastHeight
int64
`json:"last_height"`
LastRound
int64
`json:"last_round"`
LastStep
int64
`json:"last_step"`
}
type
GenesisParams
struct
{
GlobalPermissions
*
ptypes
.
AccountPermissions
`json:"global_permissions"`
}
...
...
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