-
Notifications
You must be signed in to change notification settings - Fork 161
fix account sending from new accounts #517
Conversation
Codecov Report
@@ Coverage Diff @@
## development #517 +/- ##
===============================================
- Coverage 72.08% 70.49% -1.60%
===============================================
Files 41 41
Lines 2723 2325 -398
===============================================
- Hits 1963 1639 -324
+ Misses 615 543 -72
+ Partials 145 143 -2
Continue to review full report at Codecov.
|
| e.keybaseLock.Lock() | ||
| defer e.keybaseLock.Unlock() | ||
|
|
||
| if e.cliCtx.Keybase == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, this condition could be inverted for better readability
| } | ||
| } | ||
|
|
||
| func (asd AccountSetupDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a couple of questions that I believe should be documented with comments:
- why is this ante handler decorator only for
MsgEthermintand notMsgEthereumTxtoo? - any reason why is the decorator on the second position of the chain of ante decorators?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MsgEthereumTx sets up the account in the NewAccountVerificationDecorator so it didn't need to be added separately, MsgEthermint uses the auth ante handlers which can't be modified, so I added this one to set up the account before the other handlers
I put it as the second one since I figured it would be good to set up the account before the rest of the decorators run, but it could be put right before whichever one validates the account
| acc := avd.ak.GetAccount(ctx, address) | ||
| if acc == nil { | ||
| return ctx, fmt.Errorf("account %s (%s) is nil", common.BytesToAddress(address.Bytes()), address) | ||
| acc = avd.ak.NewAccountWithAddress(ctx, address) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason why the account is set to store instead of creating an error should be documented on the comments for future reference 👍
| for _, key := range e.keys { | ||
| e.logger.Debug("eth_sendTransaction", "key", fmt.Sprintf("0x%x", key.PubKey().Address().Bytes())) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this was a leftover debug log?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will remove!
| for i, key := range e.ethAPI.keys { | ||
| if !bytes.Equal(key.PubKey().Address().Bytes(), address.Bytes()) { | ||
| continue | ||
| } | ||
|
|
||
| tmp := make([]emintcrypto.PrivKeySecp256k1, len(e.ethAPI.keys)-1) | ||
| copy(tmp[:i], e.ethAPI.keys[:i]) | ||
| copy(tmp[i:], e.ethAPI.keys[i+1:]) | ||
| e.ethAPI.keys = tmp | ||
| return true | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure what's the context of this change in relation to the PR title
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I needed to update the ethAPI keys to allow for it to know about the new account that we are trying to send from
I think this could be improved by having one set of keys for both APIs, I can open an issue for that
| return common.Address{}, fmt.Errorf("invalid private key type: %T", privKey) | ||
| } | ||
| e.ethAPI.keys = append(e.ethAPI.keys, emintKey) | ||
| e.logger.Debug("personal_newAccount", "address", fmt.Sprintf("0x%x", emintKey.PubKey().Address().Bytes())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leftover log?
|
|
||
| e.keys = append(e.keys, emintKey) | ||
| e.ethAPI.keys = append(e.ethAPI.keys, emintKey) | ||
| e.logger.Debug("personal_unlockAccount", "address", fmt.Sprintf("0x%x", emintKey.PubKey().Address().Bytes())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto?
| require.NoError(t, err, string(rpcRes.Result)) | ||
|
|
||
| require.Equal(t, "0xef7e", gas) | ||
| require.Equal(t, "0xf552", gas) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why do we have to change this all the time? shouldn't the minimum always be 21,000?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah that's a good question, I'm not totally sure why it changes
| // | ||
| // https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_sign | ||
| func (e *PersonalEthAPI) Sign(ctx context.Context, data hexutil.Bytes, addr common.Address, passwd string) (hexutil.Bytes, error) { | ||
| e.logger.Debug("personal_sign", "data", data, "address", addr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added these ones on purpose so it's easier to tell what RPC method is being called, is there another way to see that?
| // | ||
| // https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_ecRecove | ||
| func (e *PersonalEthAPI) EcRecover(ctx context.Context, data, sig hexutil.Bytes) (common.Address, error) { | ||
| e.logger.Debug("personal_ecRecover", "data", data, "sig", sig) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
Closes: #XXX
Description
personal_newAccountto send transactionsto test:
start rpc server as usual
can use
eth.accounts[0],eth.accounts[1]etc so you don't need to copy paste addrsFor contributor use:
docs/) or specification (x/<module>/spec/)godoccomments.Unreleasedsection inCHANGELOG.mdFiles changedin the Github PR explorerFor admin use:
WIP,R4R,docs, etc)