Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

personal API #420

Merged
merged 23 commits into from
Aug 13, 2020
Merged

personal API #420

merged 23 commits into from
Aug 13, 2020

Conversation

noot
Copy link
Contributor

@noot noot commented Aug 3, 2020

related to: #414

Description

implements the personal ethereum JSON-RPC API
TODO:

  • personal_importRawKey (unsure about how this would work)

For contributor use:

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer

For admin use:

  • Added appropriate labels to PR (ex. WIP, R4R, docs, etc)
  • Reviewers assigned
  • Squashed all commits, uses message "Merge pull request #XYZ: [title]" (coding standards)

@noot noot requested a review from fedekunze as a code owner August 3, 2020 22:35
@noot noot marked this pull request as draft August 3, 2020 22:36
@noot noot self-assigned this Aug 3, 2020
}

// LockAccount will lock the account associated with the given address when it's unlocked.
func (e *PersonalEthAPI) LockAccount(addr common.Address) bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alessio do you know if the keyring supports this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it doesn't. Some backends (e.g. file, pass) require password to unlock the keystore every time it is accessed. The OS-backed backend normally unlocks the keyring once and keep it unlocked for the whole user session

@noot noot marked this pull request as ready for review August 11, 2020 02:01
@codecov
Copy link

codecov bot commented Aug 11, 2020

Codecov Report

Merging #420 into development will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff              @@
##           development     #420   +/-   ##
============================================
  Coverage        70.93%   70.93%           
============================================
  Files               38       38           
  Lines             2467     2467           
============================================
  Hits              1750     1750           
  Misses             588      588           
  Partials           129      129           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a2a5799...4653437. Read the comment docs.

rpc/personal_api.go Outdated Show resolved Hide resolved
rpc/personal_api.go Outdated Show resolved Hide resolved
rpc/personal_api.go Outdated Show resolved Hide resolved
}

// TODO: this only works on local keys
privKey, err := e.cliCtx.Keybase.ExportPrivateKeyObject(name, password)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why we are exporting the privkey in order to unlock it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a bit of a workaround but the "unlocked" keys are stored in e.keys, so to unlock the key we need to export it and save it in e.keys, let me know if this isn't a good idea

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm I guess it's ok for now? We should document it on the comments and create an issue to track this work

rpc/personal_api.go Outdated Show resolved Hide resolved
rpc/personal_api.go Outdated Show resolved Hide resolved
@noot noot changed the title [wip] personal API personal API Aug 11, 2020
Copy link
Contributor

@fedekunze fedekunze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor comments. I'd be nice to add some docs too

rpc/personal_api.go Show resolved Hide resolved
rpc/personal_api.go Outdated Show resolved Hide resolved
rpc/personal_api.go Outdated Show resolved Hide resolved
rpc/personal_api.go Show resolved Hide resolved
@noot noot requested a review from fedekunze August 12, 2020 15:08
Copy link
Contributor

@fedekunze fedekunze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor final comments

rpc/personal_api.go Show resolved Hide resolved
rpc/personal_api.go Show resolved Hide resolved
rpc/personal_api.go Show resolved Hide resolved
rpc/personal_api.go Outdated Show resolved Hide resolved
rpc/personal_api.go Show resolved Hide resolved
rpc/personal_api.go Show resolved Hide resolved
rpc/personal_api.go Show resolved Hide resolved
return false, fmt.Errorf("cannot find key with given address")
}

// TODO: this only works on local keys
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we wrap the code below on an if that satisfies this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it'll return an error if it's not a local key, is that okay?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

from, err = getAddress()
if err != nil {
fmt.Printf("failed to get account: %s\n", err)
os.Exit(1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use Fatal or Fatalf?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean t.Fatal? there's no testing.T available in this func since it's the TestMain

Copy link
Contributor

@fedekunze fedekunze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested ACK. Pending error handling on keys ≠ local

@noot noot merged commit 1cb712f into development Aug 13, 2020
@noot noot deleted the noot/personal branch August 13, 2020 17:14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants