Есть ли способ просто разблокировать учетные записи, не открывая консоль с помощью geth
?
Я пишу несколько сценариев для автоматизации создания кластера, и мне хотелось бы просто вызвать geth
разблокировку некоторых учетных записей, не запуская другой экземпляр или не подключаясь к существующему.
Если я запускаю что-то вроде:
geth --genesis "$GENESIS_FILE" --datadir "$DATA_DIR" --networkid "$NETWORK_ID" \
--password <(echo -n $ACCOUNT_PASSWD) --unlock "$UNLOCK_INDEXES" \
--exec '""' attach > /dev/null
после запуска узла учетные записи не разблокируются .
Единственный способ, которым мне удалось разблокировать учетные записи, — это разблокировать их во время работы geth
, чтобы запустить узел.
Просто для уточнения:
Вы можете использовать следующую команду для подключения к узлу geth, чтобы разблокировать учетную запись с помощью API JavaScript personal.unlockAccount(...) ( https://github.com/ethereum/go-ethereum/wiki/JavaScript-Console# personalunlockaccount ), где третий параметр — продолжительность в секундах:
> geth --exec "personal.unlockAccount(eth.accounts[0], 'password', 1000)" attach
true
Или вы можете создать файл, например, unlock.js со следующим содержимым:
personal.unlockAccount(eth.accounts[0], 'password', 1000);
А затем используйте следующую команду, чтобы разблокировать учетную запись:
> geth --exec "loadScript('unlock.js')" attach
true
Отвечая на приведенный ниже вопрос относительно продолжительности по умолчанию, если продолжительность не указана, подразумевается продолжительность 0. И продолжительность 0 разблокирует учетную запись до выхода из программы, например, нет истечения срока действия.
Из https://github.com/ethereum/go-ethereum/blob/master/internal/ethapi/api.go#L239-L254 :
// UnlockAccount will unlock the account associated with the given address with
// the given password for duration seconds. If duration is nil it will use a
// default of 300 seconds. It returns an indication if the account was unlocked.
func (s *PrivateAccountAPI) UnlockAccount(addr common.Address, password string, duration *uint64) (bool, error) {
const max = uint64(time.Duration(math.MaxInt64) / time.Second)
var d time.Duration
if duration == nil {
d = 300 * time.Second
} else if *duration > max {
return false, errors.New("unlock duration too large")
} else {
d = time.Duration(*duration) * time.Second
}
err := s.am.TimedUnlock(accounts.Account{Address: addr}, password, d)
return err == nil, err
}
И с https://github.com/ethereum/go-ethereum/blob/master/accounts/account_manager.go#L181-L216 , где вы можете увидеть комментарий A timeout of 0 unlocks the account until the program exits
:
// TimedUnlock unlocks the given account with the passphrase. The account
// stays unlocked for the duration of timeout. A timeout of 0 unlocks the account
// until the program exits. The account must match a unique key file.
//
// If the account address is already unlocked for a duration, TimedUnlock extends or
// shortens the active unlock timeout. If the address was previously unlocked
// indefinitely the timeout is not altered.
func (am *Manager) TimedUnlock(a Account, passphrase string, timeout time.Duration) error {
a, key, err := am.getDecryptedKey(a, passphrase)
if err != nil {
return err
}
am.mu.Lock()
defer am.mu.Unlock()
u, found := am.unlocked[a.Address]
if found {
if u.abort == nil {
// The address was unlocked indefinitely, so unlocking
// it with a timeout would be confusing.
zeroKey(key.PrivateKey)
return nil
} else {
// Terminate the expire goroutine and replace it below.
close(u.abort)
}
}
if timeout > 0 {
u = &unlocked{Key: key, abort: make(chan struct{})}
go am.expire(a.Address, u, timeout)
} else {
u = &unlocked{Key: key}
}
am.unlocked[a.Address] = u
return nil
}
Энрике Барселуш
duration
, как долго учетная запись будет оставаться разблокированной?конфиденциальностьisahumanright.eth
Химаншу шарма