Skip to content

Commit

Permalink
Pass get password func to reduce sdk memory usage on mobile
Browse files Browse the repository at this point in the history
Signed-off-by: Yilun <[email protected]>
  • Loading branch information
yilunzhang committed Sep 24, 2020
1 parent 3dc82e1 commit db011a9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
6 changes: 3 additions & 3 deletions chain/blockvalidator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)

Expand Down
4 changes: 2 additions & 2 deletions cmd/nknd/nknd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion dashboard/routes/wallet/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions vault/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -198,15 +197,15 @@ 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
return nil, fmt.Errorf("wallet file %s does not exist, please create a wallet using nknc", walletFileName)
}
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
Expand Down

0 comments on commit db011a9

Please sign in to comment.