From 99e177a7b7cf313c659af40a67b33cb0264b060b Mon Sep 17 00:00:00 2001 From: mantre Date: Sun, 29 Dec 2024 03:36:02 +0800 Subject: [PATCH] ci: refacor deployment --- config/config.go | 20 ++--- config/config.sample.yml | 54 +++++++----- config/global.go | 1 + config/wallet.sample.neutered | 37 ++++++++ deployment/Dockerfile | 9 +- deployment/deploy.sh | 3 +- deployment/docker-compose.yml | 87 ++++++++++--------- .../engine/command/calculator/calculator.go | 6 +- internal/engine/command/command.go | 6 +- internal/engine/command/market/market.go | 4 +- internal/engine/command/phoenix/phoenix.go | 6 +- internal/engine/command/voucher/voucher.go | 4 +- internal/engine/command/zealy/zealy.go | 4 +- internal/engine/engine.go | 26 +++--- internal/platforms/discord/discord.go | 11 +-- internal/platforms/telegram/telegram.go | 8 +- pkg/wallet/wallet.go | 31 ++----- 17 files changed, 172 insertions(+), 145 deletions(-) create mode 100644 config/wallet.sample.neutered diff --git a/config/config.go b/config/config.go index fcda84b4..2812caad 100644 --- a/config/config.go +++ b/config/config.go @@ -31,11 +31,9 @@ type Database struct { } type Wallet struct { - Enable bool `yaml:"enable"` Address string `yaml:"address"` Path string `yaml:"path"` Password string `yaml:"password"` - RPCUrl string `yaml:"rpc"` } type DiscordBot struct { @@ -105,19 +103,17 @@ func Load(path string) (*Config, error) { // BasicCheck validate presence of required config variables. func (cfg *Config) BasicCheck() error { - if cfg.Wallet.Enable { - if cfg.Wallet.Address == "" { - return fmt.Errorf("config: basic check error: WALLET_ADDRESS dose not set") - } - - // Check if the WalletPath exists. - if !util.PathExists(cfg.Wallet.Path) { - return fmt.Errorf("config: basic check error: WALLET_PATH does not exist: %s", cfg.Wallet.Path) - } + if cfg.Wallet.Address == "" { + return fmt.Errorf("config: Wallet address dose not set") + } + + // Check if the WalletPath exists. + if !util.PathExists(cfg.Wallet.Path) { + return fmt.Errorf("config: Wallet does not exist: %s", cfg.Wallet.Path) } if len(cfg.NetworkNodes) == 0 { - return fmt.Errorf("config: basic check error: NETWORK_NODES is not set or incorrect") + return fmt.Errorf("config: network nodes is empty") } return nil diff --git a/config/config.sample.yml b/config/config.sample.yml index ba9aea60..3fbc6d61 100644 --- a/config/config.sample.yml +++ b/config/config.sample.yml @@ -1,5 +1,7 @@ bot_name: "Pagu-Development" -network: "Mainnet" # Specify the network the bot will use: Mainnet, Testnet, or Localnet. + +# Specify the network the bot will use: Mainnet, Testnet, or Localnet. +network: "Mainnet" # Pactus clients local_node: "localhost:50051" # Address of the local Pactus node for direct communication. @@ -15,36 +17,48 @@ network_nodes: ] # Wallet configuration +# +# Use the Pactus Wallet command-line tool to create a wallet. +# For detailed instructions, visit: +# https://docs.pactus.org/tutorials/pactus-wallet/ +# +# The sample wallet here is neutered, which means it is read-only and can't be used to sign any transactions. +# You can create a full wallet and replace it. wallet: - # Set to true to enable wallet functionality. - enable: false - # Use the `./pactus-wallet` command-line tool to create a wallet. - # For detailed instructions, visit: - # https://docs.pactus.org/tutorials/pactus-wallet/ - # Uncomment and set the following fields if the wallet is enabled: - # address: # Wallet address for transactions. - # rpc: # RPC endpoint of the wallet. - # path: # Path to the wallet file. - # password: # Password for the wallet file. - -# Phoenix TestNet faucet configuration + # This is the Pagu wallet address to send transactions + address: pc1re5uxrtdve6gama8veqt0ttz5vgfne73w9e03w6 + + # Path to the wallet file. + path: ./config/wallet.sample.neutered + + # Password for the wallet file. + password: + +# Phoenix (TestNet) configuration phoenix: - faucet_amount: 5 # Number of coins to send when the faucet is used. + # Number of coins to send when the faucet is used. + faucet_amount: 5 # Database configuration database: - url: "sqlite:db.sqlite" # Database type or connection string. + # The database URL specifies the database type and connection string. + # Pagu supports MySQL and SQLite. + url: "sqlite:db.sqlite" # Discord integration configuration -# Uncomment and set appropriate values to integrate Pagu with your Discord server. +# Set appropriate values to integrate Pagu with your Discord server. discord: -# token: # Discord bot application token. -# guild_id: # Discord server ID where the bot will operate. + # Discord bot application token. + token: + + # Discord server ID where the bot will operate. + guild_id: # Telegram integration configuration -# Uncomment and set appropriate values to integrate Pagu with your Telegram account. +# Set appropriate values to integrate Pagu with your Telegram account. telegram: -# bot_token: # Telegram bot token for authentication. + # Telegram bot token for authentication. + bot_token: # Logger configuration logger: diff --git a/config/global.go b/config/global.go index be85c409..1de6aff2 100644 --- a/config/global.go +++ b/config/global.go @@ -6,6 +6,7 @@ const ( const ( BotNamePaguMainnet = "Pagu-Mainnet" + BotNamePaguStaging = "Pagu-Staging" BotNamePaguTestnet = "Pagu-Testnet" BotNamePaguModerator = "Pagu-Moderator" ) diff --git a/config/wallet.sample.neutered b/config/wallet.sample.neutered new file mode 100644 index 00000000..134e3a2f --- /dev/null +++ b/config/wallet.sample.neutered @@ -0,0 +1,37 @@ +{ + "version": 2, + "uuid": "dc445698-cd6f-46d6-adcb-bb90254ae506", + "created_at": "2024-12-28T12:18:37Z", + "network": 0, + "crc": 2550816060, + "vault": { + "type": 2, + "coin_type": 21888, + "addresses": { + "pc1re5uxrtdve6gama8veqt0ttz5vgfne73w9e03w6": { + "address": "pc1re5uxrtdve6gama8veqt0ttz5vgfne73w9e03w6", + "public_key": "public1ryxkxpppc4ef8pcnjxn8sph4u3lahemzdeeuvsc0hsdg2eewv7pmstyzp87", + "label": "Pagu Address", + "path": "m/44'/21888'/3'/0'" + } + }, + "encrypter": {}, + "key_store": "{}", + "purposes": { + "purpose_bls": { + "xpub_account": "xpublic1pqdwnqqyqsp2spqqpqqqgqgx8avwvym2mlmhk5tatlmp8smml62rtclyj732wrr7xfpzngkjkluqxpy082d9dst4r5lhw4f4p9a4yycdtlgm5qve4pgw79kdu029e44ke7csjdlpwuy0dcys7m77zfflt7yvakwc8qt9dutjukk2xxzmkrexg2mg6c9p3ysdgvja26m7rl8pcdhxfmnyq3x27gmgpzvf79ru3xxqjsfl9g", + "xpub_validator": "xpublic1pqdwnqqyqsp2spqqzqqqgqgzkpldp7s5y29mxpngx49qznj4wttkkan7tpphcmp0f702ef50cmsqxppzjt8tayuns0rcp5js90rg6dct9krtdg29yfspxm0zpnl5uyqypecqgpp3azx884tzer5wrk9rjnufqk3hejjusr4wy8wtf2gum8a4ls58v255kllg25kz4lxlmulkfaxcklqh6dxsdxk4zrd3kevgcc0sd9ww4k", + "next_account_index": 0, + "next_validator_index": 0 + }, + "purpose_bip44": { + "next_ed25519_index": 1 + } + } + }, + "history": { + "transactions": null, + "activities": null, + "pendings": null + } + } diff --git a/deployment/Dockerfile b/deployment/Dockerfile index c010ace4..2476c747 100644 --- a/deployment/Dockerfile +++ b/deployment/Dockerfile @@ -5,14 +5,7 @@ WORKDIR /pagu COPY .. . RUN make build-discord build-telegram -# Discord bot -FROM alpine:3.14 AS discord +FROM alpine:3.14 AS pagu WORKDIR /bin COPY --from=builder /pagu/build/pagu-discord . -CMD ["./pagu-discord", "-c", "/pagu/config.yml", "run"] - -# Telegram bot -FROM alpine:3.14 AS telegram -WORKDIR /bin COPY --from=builder /pagu/build/pagu-telegram . -CMD ["./pagu-telegram", "-c", "/pagu/config.yml", "run"] diff --git a/deployment/deploy.sh b/deployment/deploy.sh index b4196e22..7954c0d2 100644 --- a/deployment/deploy.sh +++ b/deployment/deploy.sh @@ -12,8 +12,7 @@ fi echo "Building ${DOCKER_TAG} version" -docker build -t pagu-discord:${DOCKER_TAG} -f ./deployment/Dockerfile . --target discord -docker build -t pagu-telegram:${DOCKER_TAG} -f ./deployment/Dockerfile . --target telegram +docker build -t pagu:${DOCKER_TAG} -f ./deployment/Dockerfile . docker compose -f ./deployment/docker-compose.yml down docker compose -f ./deployment/docker-compose.yml up -d diff --git a/deployment/docker-compose.yml b/deployment/docker-compose.yml index ca5b25c7..7eced444 100644 --- a/deployment/docker-compose.yml +++ b/deployment/docker-compose.yml @@ -1,89 +1,94 @@ services: - pagu-db: + pagu_mysql: image: mysql:8.0.40-debian - hostname: pagu-db + hostname: pagu_mysql environment: MYSQL_DATABASE: pagu MYSQL_ROOT_PASSWORD: ${PAGU_DB_ROOT_PASSWORD} MYSQL_USER: ${PAGU_DB_USER} MYSQL_PASSWORD: ${PAGU_DB_USER_PASSWORD} - container_name: pagu-db + container_name: pagu_mysql volumes: - ${HOME}/mysql_data:/var/lib/mysql networks: - - pagu-network + - pagu_network env_file: "secrets.env" healthcheck: - test: ["CMD", "mysqladmin" ,"ping", "-h", pagu-db] + test: ["CMD", "mysqladmin" ,"ping", "-h", pagu_mysql] timeout: 5s retries: 10 - pagu-phpmyadmin: + pagu_phpmyadmin: image: phpmyadmin/phpmyadmin environment: - PMA_HOST: pagu-db - container_name: pagu-phpmyadmin + PMA_HOST: pagu_mysql + container_name: pagu_phpmyadmin ports: - "${PHPMYADMIN_PORT}:80" depends_on: - pagu-db: + pagu_mysql: condition: service_healthy networks: - - pagu-network + - pagu_network env_file: "secrets.env" - pagu-discord-mainnet: - image: pagu-discord:stable - container_name: pagu-discord-mainnet + pagu_discord_mainnet: + image: pagu:stable + container_name: pagu_discord_mainnet + command: "./pagu-discord -c /pagu/config_discord_mainnet.yml run" networks: - pagu-network: + pagu_network: depends_on: - - pagu-phpmyadmin + - pagu_phpmyadmin volumes: - - ${HOME}/pagu-discord-mainnet:/pagu + - ${HOME}/pagu:/pagu - pagu-discord-staging: - image: pagu-discord:latest - container_name: pagu-discord-staging + pagu_discord_staging: + image: pagu:latest + container_name: pagu_discord_staging + command: "./pagu-discord -c /pagu/config_discord_staging.yml run" networks: - pagu-network: + pagu_network: depends_on: - - pagu-phpmyadmin + - pagu_phpmyadmin volumes: - - ${HOME}/pagu-discord-staging:/pagu + - ${HOME}/pagu:/pagu - pagu-discord-testnet: - image: pagu-discord:latest - container_name: pagu-discord-testnet + pagu_discord_testnet: + image: pagu:stable + container_name: pagu_discord_testnet + command: "./pagu-discord -c /pagu/config_discord_testnet.yml run" networks: - pagu-network: + pagu_network: depends_on: - - pagu-phpmyadmin + - pagu_phpmyadmin volumes: - - ${HOME}/pagu-discord-testnet:/pagu + - ${HOME}/pagu:/pagu - pagu-discord-moderator: - image: pagu-discord:stable - container_name: pagu-discord-moderator + pagu_discord_moderator: + image: pagu:stable + container_name: pagu_discord_moderator + command: "./pagu-discord -c /pagu/config_discord_moderator.yml run" networks: - pagu-network: + pagu_network: depends_on: - - pagu-phpmyadmin + - pagu_phpmyadmin volumes: - - ${HOME}/pagu-discord-moderator:/pagu + - ${HOME}/pagu:/pagu - pagu-telegram-mainnet: - image: pagu-telegram:stable - container_name: pagu-telegram-mainnet + pagu_telegram_mainnet: + image: pagu:stable + container_name: pagu_telegram_mainnet + command: "./pagu-telegram -c /pagu/config_telegram_mainnet.yml run" networks: - pagu-network: + pagu_network: depends_on: - - pagu-phpmyadmin + - pagu_phpmyadmin volumes: - - ${HOME}/pagu-telegram-mainnet:/pagu + - ${HOME}/pagu:/pagu volumes: pagu-volume: networks: - pagu-network: + pagu_network: diff --git a/internal/engine/command/calculator/calculator.go b/internal/engine/command/calculator/calculator.go index 9c5d42b7..ee95b6a9 100644 --- a/internal/engine/command/calculator/calculator.go +++ b/internal/engine/command/calculator/calculator.go @@ -44,7 +44,7 @@ func (bc *Calculator) GetCommand() *command.Command { SubCommands: nil, AppIDs: entity.AllAppIDs(), Handler: bc.calcRewardHandler, - TargetFlag: command.TargetMaskMain, + TargetFlag: command.TargetMaskMainnet, } subCmdCalcFee := &command.Command{ @@ -61,7 +61,7 @@ func (bc *Calculator) GetCommand() *command.Command { SubCommands: nil, AppIDs: entity.AllAppIDs(), Handler: bc.calcFeeHandler, - TargetFlag: command.TargetMaskMain, + TargetFlag: command.TargetMaskMainnet, } cmdBlockchain := &command.Command{ @@ -71,7 +71,7 @@ func (bc *Calculator) GetCommand() *command.Command { AppIDs: entity.AllAppIDs(), SubCommands: make([]*command.Command, 0), Handler: nil, - TargetFlag: command.TargetMaskMain, + TargetFlag: command.TargetMaskMainnet, } cmdBlockchain.AddSubCommand(subCmdCalcReward) diff --git a/internal/engine/command/command.go b/internal/engine/command/command.go index adbf3563..96144e25 100644 --- a/internal/engine/command/command.go +++ b/internal/engine/command/command.go @@ -8,11 +8,11 @@ import ( ) var ( - TargetMaskMain = 1 - TargetMaskTest = 2 + TargetMaskMainnet = 1 + TargetMaskTestnet = 2 TargetMaskModerator = 4 - TargetMaskAll = TargetMaskMain | TargetMaskTest | TargetMaskModerator + TargetMaskAll = TargetMaskMainnet | TargetMaskTestnet | TargetMaskModerator ) type InputBox int diff --git a/internal/engine/command/market/market.go b/internal/engine/command/market/market.go index f7c7cfe9..92770133 100644 --- a/internal/engine/command/market/market.go +++ b/internal/engine/command/market/market.go @@ -33,7 +33,7 @@ func (m *Market) GetCommand() *command.Command { SubCommands: nil, AppIDs: entity.AllAppIDs(), Handler: m.getPrice, - TargetFlag: command.TargetMaskMain, + TargetFlag: command.TargetMaskMainnet, } cmdMarket := &command.Command{ @@ -43,7 +43,7 @@ func (m *Market) GetCommand() *command.Command { AppIDs: entity.AllAppIDs(), SubCommands: make([]*command.Command, 0), Handler: nil, - TargetFlag: command.TargetMaskMain, + TargetFlag: command.TargetMaskMainnet, } cmdMarket.AddSubCommand(subCmdPrice) diff --git a/internal/engine/command/phoenix/phoenix.go b/internal/engine/command/phoenix/phoenix.go index 7c71707a..435405ea 100644 --- a/internal/engine/command/phoenix/phoenix.go +++ b/internal/engine/command/phoenix/phoenix.go @@ -53,7 +53,7 @@ func (pt *Phoenix) GetCommand() *command.Command { AppIDs: entity.AllAppIDs(), Middlewares: nil, Handler: pt.networkStatusHandler, - TargetFlag: command.TargetMaskTest, + TargetFlag: command.TargetMaskTestnet, } subCmdFaucet := &command.Command{ @@ -71,7 +71,7 @@ func (pt *Phoenix) GetCommand() *command.Command { AppIDs: entity.AllAppIDs(), Middlewares: []command.MiddlewareFunc{middlewareHandler.WalletBalance}, Handler: pt.faucetHandler, - TargetFlag: command.TargetMaskTest, + TargetFlag: command.TargetMaskTestnet, } cmdPhoenix := &command.Command{ @@ -81,7 +81,7 @@ func (pt *Phoenix) GetCommand() *command.Command { AppIDs: entity.AllAppIDs(), SubCommands: make([]*command.Command, 0), Handler: nil, - TargetFlag: command.TargetMaskTest, + TargetFlag: command.TargetMaskTestnet, } cmdPhoenix.AddSubCommand(subCmdFaucet) diff --git a/internal/engine/command/voucher/voucher.go b/internal/engine/command/voucher/voucher.go index b0796022..de65aea5 100644 --- a/internal/engine/command/voucher/voucher.go +++ b/internal/engine/command/voucher/voucher.go @@ -55,7 +55,7 @@ func (v *Voucher) GetCommand() *command.Command { AppIDs: []entity.AppID{entity.AppIDDiscord}, Middlewares: []command.MiddlewareFunc{middlewareHandler.WalletBalance}, Handler: v.claimHandler, - TargetFlag: command.TargetMaskMain, + TargetFlag: command.TargetMaskMainnet, } subCmdCreateOne := &command.Command{ @@ -143,7 +143,7 @@ func (v *Voucher) GetCommand() *command.Command { AppIDs: []entity.AppID{entity.AppIDDiscord}, SubCommands: make([]*command.Command, 0), Handler: nil, - TargetFlag: command.TargetMaskMain | command.TargetMaskModerator, + TargetFlag: command.TargetMaskMainnet | command.TargetMaskModerator, } cmdVoucher.AddSubCommand(subCmdClaim) diff --git a/internal/engine/command/zealy/zealy.go b/internal/engine/command/zealy/zealy.go index 18682fde..9d0d1104 100644 --- a/internal/engine/command/zealy/zealy.go +++ b/internal/engine/command/zealy/zealy.go @@ -41,7 +41,7 @@ func (z *Zealy) GetCommand() *command.Command { SubCommands: nil, AppIDs: []entity.AppID{entity.AppIDDiscord}, Handler: z.claimHandler, - TargetFlag: command.TargetMaskMain, + TargetFlag: command.TargetMaskMainnet, } subCmdStatus := &command.Command{ @@ -61,7 +61,7 @@ func (z *Zealy) GetCommand() *command.Command { AppIDs: []entity.AppID{entity.AppIDDiscord}, SubCommands: make([]*command.Command, 0), Handler: nil, - TargetFlag: command.TargetMaskMain | command.TargetMaskModerator, + TargetFlag: command.TargetMaskMainnet | command.TargetMaskModerator, } cmdZealy.AddSubCommand(subCmdClaim) diff --git a/internal/engine/engine.go b/internal/engine/engine.go index 63360a3d..b111e8cd 100644 --- a/internal/engine/engine.go +++ b/internal/engine/engine.go @@ -56,7 +56,6 @@ func NewBotEngine(cfg *config.Config) (*BotEngine, error) { log.Info("database loaded successfully") mgr := client.NewClientMgr(ctx) - if cfg.LocalNode != "" { localClient, err := client.NewClient(cfg.LocalNode) if err != nil { @@ -69,27 +68,24 @@ func NewBotEngine(cfg *config.Config) (*BotEngine, error) { } for _, nn := range cfg.NetworkNodes { - c, err := client.NewClient(nn) + client, err := client.NewClient(nn) if err != nil { - log.Error("can't add new network node client", "err", err, "addr", nn) + cancel() + + log.Warn("error on adding new network client", "err", err, "addr", nn) } - mgr.AddClient(c) + mgr.AddClient(client) } - var wlt wallet.IWallet - if cfg.Wallet.Enable { - // load or create wallet. - wlt, err = wallet.Open(cfg.Wallet) - if err != nil { - cancel() + wlt, err := wallet.Open(cfg.Wallet) + if err != nil { + cancel() - return nil, WalletError{ - Reason: err.Error(), - } + return nil, WalletError{ + Reason: err.Error(), } - - log.Info("wallet opened successfully", "address", wlt.Address()) } + log.Info("wallet opened successfully", "address", wlt.Address()) if cfg.BotName == config.BotNamePaguModerator { zapToMailConfig := zoho.ZapToMailerConfig{ diff --git a/internal/platforms/discord/discord.go b/internal/platforms/discord/discord.go index 3f72d0aa..eaf54db4 100644 --- a/internal/platforms/discord/discord.go +++ b/internal/platforms/discord/discord.go @@ -87,13 +87,14 @@ func (bot *Bot) registerCommands() error { } switch bot.target { - case config.BotNamePaguMainnet: - if !util.IsFlagSet(beCmd.TargetFlag, command.TargetMaskMain) { + case config.BotNamePaguMainnet, + config.BotNamePaguStaging: + if !util.IsFlagSet(beCmd.TargetFlag, command.TargetMaskMainnet) { continue } case config.BotNamePaguTestnet: - if !util.IsFlagSet(beCmd.TargetFlag, command.TargetMaskTest) { + if !util.IsFlagSet(beCmd.TargetFlag, command.TargetMaskTestnet) { continue } @@ -115,12 +116,12 @@ func (bot *Bot) registerCommands() error { for _, sCmd := range beCmd.SubCommands { switch bot.target { case config.BotNamePaguMainnet: - if !util.IsFlagSet(sCmd.TargetFlag, command.TargetMaskMain) { + if !util.IsFlagSet(sCmd.TargetFlag, command.TargetMaskMainnet) { continue } case config.BotNamePaguTestnet: - if !util.IsFlagSet(sCmd.TargetFlag, command.TargetMaskTest) { + if !util.IsFlagSet(sCmd.TargetFlag, command.TargetMaskTestnet) { continue } diff --git a/internal/platforms/telegram/telegram.go b/internal/platforms/telegram/telegram.go index d1ed7aa6..b4ef98ef 100644 --- a/internal/platforms/telegram/telegram.go +++ b/internal/platforms/telegram/telegram.go @@ -101,12 +101,12 @@ func (bot *Bot) registerCommands() error { switch bot.target { case config.BotNamePaguMainnet: - if !util.IsFlagSet(beCmd.TargetFlag, command.TargetMaskMain) { + if !util.IsFlagSet(beCmd.TargetFlag, command.TargetMaskMainnet) { continue } case config.BotNamePaguTestnet: - if !util.IsFlagSet(beCmd.TargetFlag, command.TargetMaskTest) { + if !util.IsFlagSet(beCmd.TargetFlag, command.TargetMaskTestnet) { continue } } @@ -122,12 +122,12 @@ func (bot *Bot) registerCommands() error { for _, sCmd := range beCmd.SubCommands { switch bot.target { case config.BotNamePaguMainnet: - if !util.IsFlagSet(sCmd.TargetFlag, command.TargetMaskMain) { + if !util.IsFlagSet(sCmd.TargetFlag, command.TargetMaskMainnet) { continue } case config.BotNamePaguTestnet: - if !util.IsFlagSet(sCmd.TargetFlag, command.TargetMaskTest) { + if !util.IsFlagSet(sCmd.TargetFlag, command.TargetMaskTestnet) { continue } diff --git a/pkg/wallet/wallet.go b/pkg/wallet/wallet.go index 720865e7..ad969503 100644 --- a/pkg/wallet/wallet.go +++ b/pkg/wallet/wallet.go @@ -1,9 +1,6 @@ package wallet import ( - "errors" - "os" - "github.com/pactus-project/pactus/types/tx/payload" "github.com/pactus-project/pactus/wallet" "github.com/pagu-project/Pagu/config" @@ -19,21 +16,16 @@ type Wallet struct { } func Open(cfg *config.Wallet) (*Wallet, error) { - if doesWalletExist(cfg.Path) { - wlt, err := wallet.Open(cfg.Path, false) - if err != nil { - return &Wallet{}, err - } - - return &Wallet{ - Wallet: wlt, - address: cfg.Address, - password: cfg.Password, - }, nil + wlt, err := wallet.Open(cfg.Path, false) + if err != nil { + return nil, err } - // if the wallet does not exist, create one - return &Wallet{}, errors.New("can't open the wallet") + return &Wallet{ + Wallet: wlt, + address: cfg.Address, + password: cfg.Password, + }, nil } func (w *Wallet) BondTransaction(pubKey, toAddress, memo string, amt amount.Amount) (string, error) { @@ -133,10 +125,3 @@ func (w *Wallet) Balance() int64 { return int64(balance) } - -// function to check if file exists. -func doesWalletExist(fileName string) bool { - _, err := os.Stat(fileName) - - return !os.IsNotExist(err) -}