-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
340 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package genesis | ||
|
||
import ( | ||
"github.com/vechain/thor/v2/genesis" | ||
) | ||
|
||
// CustomGenesis is user customized genesis | ||
type CustomGenesis struct { | ||
LaunchTime uint64 `json:"launchTime"` | ||
GasLimit uint64 `json:"gaslimit"` | ||
ExtraData string `json:"extraData"` | ||
Accounts []genesis.Account `json:"accounts"` | ||
Authority []genesis.Authority `json:"authority"` | ||
Params genesis.Params `json:"params"` | ||
Executor genesis.Executor `json:"executor"` | ||
ForkConfig *ForkConfig `json:"forkConfig"` | ||
} | ||
|
||
type ForkConfig struct { | ||
VIP191 uint32 | ||
ETH_CONST uint32 | ||
BLOCKLIST uint32 | ||
ETH_IST uint32 | ||
VIP214 uint32 | ||
FINALITY uint32 | ||
VIPGASCOEF uint32 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,23 @@ | ||
package node | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/ethereum/go-ethereum/crypto" | ||
"github.com/ethereum/go-ethereum/p2p/discover" | ||
"github.com/vechain/thor/v2/genesis" | ||
) | ||
|
||
const ( | ||
MasterNode = "masterNode" | ||
RegularNode = "regularNode" | ||
) | ||
|
||
type Node struct { | ||
ID string `json:"id"` //TODO this is a mandatory field | ||
Genesis *genesis.CustomGenesis `json:"genesis,omitempty"` //TODO would be nice to have validation in this format | ||
DataDir string `json:"dataDir,omitempty"` | ||
ConfigDir string `json:"configDir,omitempty"` | ||
P2PListenPort int `json:"p2pListenPort"` | ||
APIAddr string `json:"apiAddr"` | ||
APICORS string `json:"apiCORS"` | ||
Type string `json:"type"` | ||
Key string `json:"key"` | ||
EnodeData string `json:"enode"` // todo: this should be a generated method | ||
ExecArtifact string `json:"execArtifact"` // used to determine the executing version of the node ( path, dockerImage, etc) | ||
Verbosity int `json:"verbosity"` | ||
} | ||
|
||
func (n *Node) Enode(ipAddr string) (string, error) { | ||
privKey, err := crypto.HexToECDSA(n.Key) | ||
if err != nil { | ||
return "", fmt.Errorf("unable to process key for node %s : %w", n.ID, err) | ||
} | ||
|
||
return fmt.Sprintf("enode://%x@%s:%v", discover.PubkeyID(&privKey.PublicKey).Bytes(), ipAddr, n.P2PListenPort), nil | ||
type Node interface { | ||
Enode(ipAddr string) (string, error) | ||
SetExecArtifact(artifact string) | ||
GetConfigDir() string | ||
SetConfigDir(join string) | ||
GetDataDir() string | ||
SetDataDir(join string) | ||
GetID() string | ||
GetExecArtifact() string | ||
GetKey() string | ||
GetGenesis() any | ||
GetAPIAddr() string | ||
GetAPICORS() string | ||
GetP2PListenPort() int | ||
GetVerbosity() int | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package node | ||
|
||
import ( | ||
"fmt" | ||
"github.com/ethereum/go-ethereum/crypto" | ||
"github.com/ethereum/go-ethereum/p2p/discover" | ||
) | ||
|
||
type BaseNode struct { | ||
ID string `json:"id"` //TODO this is a mandatory field | ||
Key string `json:"key"` | ||
APIAddr string `json:"apiAddr"` | ||
APICORS string `json:"apiCORS"` | ||
ConfigDir string `json:"configDir,omitempty"` | ||
DataDir string `json:"dataDir,omitempty"` | ||
ExecArtifact string `json:"execArtifact"` // used to determine the executing version of the node ( path, dockerImage, etc) | ||
P2PListenPort int `json:"p2pListenPort"` | ||
Verbosity int `json:"verbosity"` | ||
EnodeData string `json:"enode"` // todo: this should be a generated method | ||
Type string `json:"type"` | ||
} | ||
|
||
func (b *BaseNode) GetVerbosity() int { | ||
return b.Verbosity | ||
} | ||
|
||
func (b *BaseNode) GetP2PListenPort() int { | ||
return b.P2PListenPort | ||
} | ||
|
||
func (b *BaseNode) GetAPIAddr() string { | ||
return b.APIAddr | ||
} | ||
|
||
func (b *BaseNode) GetAPICORS() string { | ||
return b.APICORS | ||
} | ||
|
||
func (b *BaseNode) GetGenesis() any { | ||
return b.GetExecArtifact() | ||
} | ||
|
||
func (b *BaseNode) GetKey() string { | ||
return b.Key | ||
} | ||
|
||
func New() Node { | ||
return &BaseNode{} | ||
} | ||
|
||
func (b *BaseNode) GetConfigDir() string { | ||
return b.ConfigDir | ||
} | ||
|
||
func (b *BaseNode) SetConfigDir(s string) { | ||
b.ConfigDir = s | ||
} | ||
|
||
func (b *BaseNode) GetDataDir() string { | ||
return b.DataDir | ||
} | ||
|
||
func (b *BaseNode) SetDataDir(s string) { | ||
b.DataDir = s | ||
} | ||
|
||
func (b *BaseNode) GetID() string { | ||
return b.ID | ||
} | ||
|
||
func (b *BaseNode) GetExecArtifact() string { | ||
return b.ExecArtifact | ||
} | ||
|
||
func (b *BaseNode) SetExecArtifact(artifact string) { | ||
b.ExecArtifact = artifact | ||
} | ||
|
||
func (b *BaseNode) Enode(ipAddr string) (string, error) { | ||
privKey, err := crypto.HexToECDSA(b.Key) | ||
if err != nil { | ||
return "", fmt.Errorf("unable to process key for node %s : %w", b.ID, err) | ||
} | ||
|
||
return fmt.Sprintf("enode://%x@%s:%v", discover.PubkeyID(&privKey.PublicKey).Bytes(), ipAddr, b.P2PListenPort), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package node | ||
|
||
import ( | ||
"github.com/vechain/networkhub/network/node/genesis" | ||
) | ||
|
||
type NodePostCoefFork struct { | ||
BaseNode | ||
Genesis *genesis.CustomGenesis `json:"genesis,omitempty"` //TODO would be nice to have validation in this format | ||
} | ||
|
||
func (n *NodePostCoefFork) GetGenesis() any { | ||
return n.Genesis | ||
} |
Oops, something went wrong.