From db011a92f333b8ce53e310a01672131e5c80cfda Mon Sep 17 00:00:00 2001 From: Yilun Date: Fri, 18 Sep 2020 16:43:35 -0700 Subject: [PATCH] Pass get password func to reduce sdk memory usage on mobile Signed-off-by: Yilun --- chain/blockvalidator.go | 6 +++--- cmd/nknd/nknd.go | 4 ++-- dashboard/routes/wallet/open.go | 2 +- vault/wallet.go | 7 +++---- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/chain/blockvalidator.go b/chain/blockvalidator.go index d1db95330..f117346d8 100644 --- a/chain/blockvalidator.go +++ b/chain/blockvalidator.go @@ -33,9 +33,9 @@ const ( ) var ( - ErrIDRegistered = errors.New("ID has be registered") - ErrDuplicateGenerateIDTxn = errors.New("[VerifyTransactionWithBlock], duplicate GenerateID txns") - ErrDuplicateIssueAssetTxn = errors.New("[VerifyTransactionWithBlock], duplicate IssueAsset txns") + ErrIDRegistered = errors.New("id has been registered") + ErrDuplicateGenerateIDTxn = errors.New("duplicate GenerateID txns") + ErrDuplicateIssueAssetTxn = errors.New("duplicate IssueAsset txns") timestampToleranceSalt = util.RandomBytes(32) ) diff --git a/cmd/nknd/nknd.go b/cmd/nknd/nknd.go index 4ffc7f366..0285c2481 100644 --- a/cmd/nknd/nknd.go +++ b/cmd/nknd/nknd.go @@ -181,7 +181,7 @@ func nknMain(c *cli.Context) error { for wallet == nil || account == nil { time.Sleep(time.Second * 3) - wallet, err = vault.GetWallet() + wallet, err = vault.GetWallet(password.GetAccountPassword) if err != nil { fmt.Println(err) continue @@ -194,7 +194,7 @@ func nknMain(c *cli.Context) error { } } else { // Get local account - wallet, err = vault.GetWallet() + wallet, err = vault.GetWallet(password.GetAccountPassword) if err != nil { return err } diff --git a/dashboard/routes/wallet/open.go b/dashboard/routes/wallet/open.go index ffcea18bf..18ff799d3 100644 --- a/dashboard/routes/wallet/open.go +++ b/dashboard/routes/wallet/open.go @@ -36,7 +36,7 @@ func WalletOpenRouter(router *gin.RouterGroup) { } } else { password.Passwd = data.Password - _, err := vault.GetWallet() + _, err := vault.GetWallet(password.GetAccountPassword) if err != nil { log.WebLog.Error("open wallet error: ", err) context.AbortWithError(http.StatusForbidden, err) diff --git a/vault/wallet.go b/vault/wallet.go index 70ee3588c..78dc423bb 100644 --- a/vault/wallet.go +++ b/vault/wallet.go @@ -5,14 +5,13 @@ import ( "fmt" "github.com/nknorg/nkn/v2/common" + "github.com/nknorg/nkn/v2/config" "github.com/nknorg/nkn/v2/crypto" serviceConfig "github.com/nknorg/nkn/v2/dashboard/config" "github.com/nknorg/nkn/v2/pb" "github.com/nknorg/nkn/v2/program" "github.com/nknorg/nkn/v2/signature" "github.com/nknorg/nkn/v2/transaction" - "github.com/nknorg/nkn/v2/config" - "github.com/nknorg/nkn/v2/util/password" ) type Wallet struct { @@ -198,7 +197,7 @@ func (w *Wallet) GetContract() (*program.ProgramContext, error) { return w.contract, nil } -func GetWallet() (*Wallet, error) { +func GetWallet(getPasswordFunc func() ([]byte, error)) (*Wallet, error) { walletFileName := config.Parameters.WalletFile if !common.FileExisted(walletFileName) { serviceConfig.Status = serviceConfig.Status | serviceConfig.SERVICE_STATUS_NO_WALLET_FILE @@ -206,7 +205,7 @@ func GetWallet() (*Wallet, error) { } serviceConfig.Status = serviceConfig.Status &^ serviceConfig.SERVICE_STATUS_NO_WALLET_FILE - passwd, err := password.GetAccountPassword() + passwd, err := getPasswordFunc() defer common.ClearBytes(passwd) if err != nil { serviceConfig.Status = serviceConfig.Status | serviceConfig.SERVICE_STATUS_NO_PASSWORD