walletnode

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 18, 2021 License: GPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RPCUser       = "walletUser"         //RPC默认的认证账户名
	RPCPassword   = "walletPassword2017" //RPC默认的认证账户密码
	RPCDockerPort = "9360/tcp"           //Docker中默认的RPC端口

	// DockerAllowed = "127.0.0.1" // ?500 For productive environment
	DockerAllowed = "0.0.0.0"

	MainNetDataPath = "/data" //容器中目录,实则在物理机:"/openwallet/<Symbol>/data"
	TestNetDataPath = "/data" //容器中目录,实则在物理机:"/openwallet/<Symbol>/testdata"

	MountSrcPrefix = "/openwallet/data" // The prefix to mounted source directory
	MountDstDir    = "/data"            // Which directory will be mounted in container
)

Variables

View Source
var (
	Symbol                   string                              // Current fullnode wallet's symbol
	FullnodeContainerConfigs map[string]*FullnodeContainerConfig // All configs of fullnode wallet for Docker
	WNConfig                 *WalletnodeConfig
)

Functions

func CheckAndCreateConfig

func CheckAndCreateConfig(symbol string) error

Check <Symbol>.ini file, create new if not

Workflow:

1> 当前目录没有 ini,是否创建?
	1.1 存在,return nil
2> 询问是否设置为测试链?
3> 获取Master服务器IP地址和端口

Types

type FullnodeContainerConfig

type FullnodeContainerConfig struct {
	NAME string
	//CMD      [2][]string // Commands to run fullnode wallet ex: {{"/bin/sh", "mainnet"}, {"/bin/sh", "testnet"}}
	PORT      [][3]string // Which ports need to be mapped, ex: {{innerPort, mainNetPort, testNetPort}, ...}
	APIPORT   []string    // Port of default fullnode API(within container), from PORT
	IMAGE     string      // Image that container run from
	ENCRYPT   []string    // Encrypt wallet fullnode as an option
	STOPCMD   []string    // Use CMD to stop service
	NOTESTNET bool        // Is to support Testnet?
	LOGFIELS  [2]string   // [2]string{mainnet, testnet}
}

type NodeManager

type NodeManager struct {
}

For WMD Interface:NodeManager ()

func (*NodeManager) CreateNodeFlow

func (w *NodeManager) CreateNodeFlow(symbol string) error

Create a new container for wallet fullnode

Workflow:

// 步骤一: 判定本地 .ini 文件是否存在
if  .ini 不存在,创建一个默认的 {
	1> 询问用户配置参数
	2> 创建初始 .ini 文件
} else {									// .ini 存在
	1> 无操作,进入下一步
}

// 步骤二:判断是否需要创建节点容器
if 容器不存在 or 不正常 {
	1> 删除后,或直接创建一个新的(需:)
	2> 导出 container 数据(IP, status)
} else {									// 正常
	1> 导出 container 数据(IP, status)
}

// 步骤三
1> 根据导出的 container 数据,更新配置文件中关于 container 的项(重复更新,方便用户改错后自动恢复)

func (*NodeManager) GetNodeStatus

func (nm *NodeManager) GetNodeStatus(symbol string) error

func (*NodeManager) LogsNodeFlow

func (nm *NodeManager) LogsNodeFlow(symbol string) error

func (*NodeManager) RemoveNodeFlow

func (nm *NodeManager) RemoveNodeFlow(symbol string) error

func (*NodeManager) RestartNodeFlow

func (nm *NodeManager) RestartNodeFlow(symbol string) error

func (*NodeManager) StartNodeFlow

func (nm *NodeManager) StartNodeFlow(symbol string) error

func (*NodeManager) StopNodeFlow

func (nm *NodeManager) StopNodeFlow(symbol string) error

type WalletnodeConfig

type WalletnodeConfig struct {
	RPCUser     string // RPC认证账户名
	RPCPassword string // RPC认证账户密码
	WalletURL   string // Fullnode API URL
	// contains filtered or unexported fields
}

Node setup 节点配置

type WalletnodeManager

type WalletnodeManager struct{}

func (*WalletnodeManager) CheckAdnCreateContainer

func (wn *WalletnodeManager) CheckAdnCreateContainer(symbol string) error

CheckAdnCreateContainer check wallet container, create if not

Pre-requirement

INI file exists!

Workflow:

if 钱包容器存在:
	return nil
else 钱包容器不存在 or 坏了,创建:
	1> 初始化物理服务器目录
	return {IP, Status}

func (*WalletnodeManager) CopyFromContainer

func (w *WalletnodeManager) CopyFromContainer(symbol, src, dst string) error

CopyFromContainer copy file from container to local filesystem

src := "wallet.dat"  // 备份来源,全节点中的�文件名 (MainDataPath + '/' + src)
dst := "2018.....wallet.dat" // 备份目标,自设
src/dst: filename

func (*WalletnodeManager) CopyToContainer

func (w *WalletnodeManager) CopyToContainer(symbol, src, dst string) error

CopyToContainer copy file to container from local filesystem

Define:

src: filename
dst: path

Example:

src := "/tmp/2018......wallet.dat"  // �恢复来源,�用户提供
dst := "wallet.dat" // 恢复目标的文件名 (MainDataPath + '/' + dst)

func (*WalletnodeManager) GetWalletnodeStatus

func (w *WalletnodeManager) GetWalletnodeStatus(symbol string) (status string, err error)

GetWalletnodeStatus get walletnode status

func (*WalletnodeManager) LogsWalletnode

func (w *WalletnodeManager) LogsWalletnode(symbol string) error

LogsWalletnode watch logs now

func (*WalletnodeManager) RemoveWalletnode

func (w *WalletnodeManager) RemoveWalletnode(symbol string) error

RemoveWalletnode remove walletnode

func (*WalletnodeManager) RestartWalletnode

func (w *WalletnodeManager) RestartWalletnode(symbol string) error

RestartWalletnode restart walletnode

func (*WalletnodeManager) StartWalletnode

func (w *WalletnodeManager) StartWalletnode(symbol string) error

StartWalletnode start walletnode

func (*WalletnodeManager) StopWalletnode

func (w *WalletnodeManager) StopWalletnode(symbol string) error

StopWalletnode stop walletnode

type WalletnodeManagerInterface

type WalletnodeManagerInterface interface {
	GetWalletnodeStatus(symbol string) error
	StartWalletnode(symbol string) error
	StopWalletnode(symbol string) error
	RestartWalletnode(symbol string) error

	// 获取全节点配置
	GetWalletnodeConfig(symbol string) *WalletnodeConfig
	// 更新全节点配置
	// UpdateWalletnodeConfig(nc *WalletnodeConfig, symbol string) error
	// 从钱包节点备份到本地
	CopyFromContainer(symbol, src, dst string) error
	// 从本地恢复钱包到节点
	CopyToContainer(symbol, src, dst string)
}

API for Walletnode Management

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL