From 1befd233f86811f6d78bd73832857d1e40cee390 Mon Sep 17 00:00:00 2001 From: jkrvivian Date: Tue, 31 Oct 2023 14:50:01 +0800 Subject: [PATCH] Add faucetBindAddress to account wallet --- accountwallet/config.go | 2 ++ accountwallet/options.go | 6 ++++++ accountwallet/wallet.go | 6 +++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/accountwallet/config.go b/accountwallet/config.go index 5792039..fbf0e87 100644 --- a/accountwallet/config.go +++ b/accountwallet/config.go @@ -64,6 +64,7 @@ func AvailableCommands(cmd string) bool { type Configuration struct { BindAddress string `json:"bindAddress,omitempty"` + FaucetBindAddress string `json:"faucetBindAddress,omitempty"` AccountStatesFile string `json:"accountStatesFile,omitempty"` GenesisSeed string `json:"genesisSeed,omitempty"` BlockIssuerPrivateKey string `json:"blockIssuerPrivateKey,omitempty"` @@ -75,6 +76,7 @@ var accountConfigFile = "config.json" var ( dockerAccountConfigJSON = `{ "bindAddress": "http://localhost:8080", + "faucetBindAddress": "http://localhost:8088", "accountStatesFile": "wallet.dat", "genesisSeed": "7R1itJx5hVuo9w9hjg5cwKFmek4HMSoBDgJZN8hKGxih", "blockIssuerPrivateKey": "db39d2fde6301d313b108dc9db1ee724d0f405f6fde966bd776365bc5f4a5fb31e4b21eb51dcddf65c20db1065e1f1514658b23a3ddbf48d30c0efc926a9a648", diff --git a/accountwallet/options.go b/accountwallet/options.go index 51b28fc..207ae46 100644 --- a/accountwallet/options.go +++ b/accountwallet/options.go @@ -11,6 +11,12 @@ func WithClientURL(url string) options.Option[AccountWallet] { } } +func WithFaucetURL(url string) options.Option[AccountWallet] { + return func(w *AccountWallet) { + w.optsFaucetURL = url + } +} + func WithAccountStatesFile(fileName string) options.Option[AccountWallet] { return func(w *AccountWallet) { w.optsAccountStatesFile = fileName diff --git a/accountwallet/wallet.go b/accountwallet/wallet.go index 63824fd..9f0ed98 100644 --- a/accountwallet/wallet.go +++ b/accountwallet/wallet.go @@ -29,6 +29,9 @@ func Run(config *Configuration) (*AccountWallet, error) { if config.BindAddress != "" { opts = append(opts, WithClientURL(config.BindAddress)) } + if config.FaucetBindAddress != "" { + opts = append(opts, WithFaucetURL(config.FaucetBindAddress)) + } if config.AccountStatesFile != "" { opts = append(opts, WithAccountStatesFile(config.AccountStatesFile)) } @@ -69,6 +72,7 @@ type AccountWallet struct { client *models.WebClient optsClientBindAddress string + optsFaucetURL string optsAccountStatesFile string optsFaucetParams *faucetParams optsRequestTimeout time.Duration @@ -83,7 +87,7 @@ func NewAccountWallet(opts ...options.Option[AccountWallet]) (*AccountWallet, er optsRequestTimeout: time.Second * 120, optsRequestTicker: time.Second * 5, }, opts, func(w *AccountWallet) { - w.client, initErr = models.NewWebClient(w.optsClientBindAddress) + w.client, initErr = models.NewWebClient(w.optsClientBindAddress, w.optsFaucetURL) if initErr != nil { log.Errorf("failed to create web client: %s", initErr.Error())