New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
grpc: Return more info for ValidateAddress. #2091
Conversation
JoeGruffins
commented
Oct 1, 2021
91b11e6
to
6723e4c
Compare
It would be possible to write unit tests if the server accepted a wallet interface. But in the mean time here are the comparisons of script types for addresses that are not owned before and after: P2PK ECDSA secp256k1 P2PK Ed25519 P2PKH ECDSA secp256k1 P2PKH Schnorr secp256k1 P2SH |
6723e4c
to
a465ed6
Compare
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.
Tested fine
rpc/api.proto
Outdated
@@ -1100,6 +1100,8 @@ message ValidateAddressResponse { | |||
StakeSubChangeTy = 9; | |||
PubkeyAltTy = 10; | |||
PubkeyHashAltTy = 11; | |||
TreasuryAddTy = 12; | |||
TreasuryGenTy = 13; |
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.
These were added but not used. Is this correct?
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 believe that if you verified a script hash of a treasury add or gen that your wallet has the script to, this would be returned. On master, testing for treasury is off, but this pr also turns it on. I will try it out and see if I get the return.
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, this looks right. these constants correlate to those of txscript.ScriptClass and must be kept in sync. There's a type conversion between the txscirpt.ScriptClass to this protobuf enum so the values must be the same.
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 believe I used the reverse order of these two in the stdscript PR @JoeGruffins, sorry. Note that there's now a scProto
helper to translate from the more-fine-grained stdscript.ScriptType
to the values in both this enum and the decode enum in the same file. (the txscript.ScriptClass
es are gone and that order is now irrelevant afaict, but we can switch both enums around to be compatiblish with consumers that might be looking for the old txscript order)
Owned scripts (simnet): ScixyRDPYRjX8R9hoCfQD8ouZjEVZvdhD5Z this diff multisig this diff |
It's seems odd that the script itself is not returned although it is over rpc. |
These are the scripts I imported to get these returns: |
22: txscript.OP_EQUALVERIFY, | ||
22: txscript.OP_EQUAL, |
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.
afaict this is correct. It was producing non-standard scripts according to decodescript, and the value was different than what stdaddr will return.
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.
Agree, it is not OP_EQUALVERIFY
9e8f552
to
ba65332
Compare
ba65332
to
2973e01
Compare
Will rebase this soon. |
internal/rpc/rpcserver/server.go
Outdated
semverString = "7.13.0" | ||
semverMajor = 7 | ||
semverMinor = 12 | ||
semverMinor = 13 |
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.
When you rebase, you'll find it's already at 7.13, so you may wish to bump (or just leave it since it is recently bumped on master)
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 leave as it is then.
internal/rpc/rpcserver/server.go
Outdated
result.IsScript = true | ||
_, script := ka.PaymentScript() | ||
result.PayToAddrScript = script | ||
_, redeem := ka.RedeemScript() |
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'm glad you're fixing this. You'll see my comments when you rebase:
dbdf7aa#diff-a23056f9a8432e77f80e98bb56a4207adbd2412877c66818836b2256602beb39R2031
This was one of a few things wrong with this method.
internal/rpc/rpcserver/server.go
Outdated
result.ScriptType = pb.ValidateAddressResponse_ScriptHashTy | ||
result.IsScript = true | ||
} | ||
_, result.PayToAddrScript = addr.PaymentScript() |
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.
Another thing you'll see when rebasing is the stdscript changes in this method. dbdf7aa#diff-a23056f9a8432e77f80e98bb56a4207adbd2412877c66818836b2256602beb39R1993-R1997
I noted how I believed this would be handled, but without consideration to PubKey
and PubKeyAddr
, so possibly your type switch is fine, except perhaps for limiting to v0 scripts.
ver, scr := addr.PaymentScript()
class, _ := stdscript.ExtractAddrs(ver, scr, s.wallet.ChainParams())
result.ScriptType = pb.ValidateAddressResponse_ScriptType(scProto(class))
result.PayToAddrScript = scr
And for the PubKey
field, you could assert addr.(stdaddr.SerializedPubKeyer)
to catch any relevant address type.
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.
Did this.
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.
You got result.PayToAddrScript
assigned in here twice with that last commit.
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.
Thank you. weird. Just combined it all into one commit.
rpc/api.proto
Outdated
@@ -1100,6 +1100,8 @@ message ValidateAddressResponse { | |||
StakeSubChangeTy = 9; | |||
PubkeyAltTy = 10; | |||
PubkeyHashAltTy = 11; | |||
TreasuryAddTy = 12; | |||
TreasuryGenTy = 13; |
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 believe I used the reverse order of these two in the stdscript PR @JoeGruffins, sorry. Note that there's now a scProto
helper to translate from the more-fine-grained stdscript.ScriptType
to the values in both this enum and the decode enum in the same file. (the txscript.ScriptClass
es are gone and that order is now irrelevant afaict, but we can switch both enums around to be compatiblish with consumers that might be looking for the old txscript order)
22: txscript.OP_EQUALVERIFY, | ||
22: txscript.OP_EQUAL, |
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.
Agree, it is not OP_EQUALVERIFY
wallet/udb/addressmanager.go
Outdated
@@ -106,6 +106,10 @@ func normalizeAddress(addr stdaddr.Address) stdaddr.Address { | |||
switch addr := addr.(type) { |
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.
Might consider addr.(stdaddr.AddressPubKeyHasher)
here, both for robustness with >v0 scripts, and other address types.
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.
Done.
Please see the rpc/grpc_example cli app I added. dcrwallet/rpc/grpc_example/main.go Lines 89 to 96 in e2bce3d
This is no unit test, but it's better than nothing. |
2973e01
to
0ee400d
Compare
If it gets my pr merged I'll do it... I see I don't need the first commit any more, popping it off. |
cf3c986
to
69c9106
Compare
bd6c477
to
65ce480
Compare
65ce480
to
b529f68
Compare
Extract all possible data from unknown as well as known addresses. In particular, always return the correct address type. Also allow creating an address id for PubKeyEd25519V0 and PubKeySchnorrSecp256k1V0 types. Extract addrs from redeem script when found in the db.
b529f68
to
60ce70a
Compare
@@ -2050,7 +2050,7 @@ func (s *walletServer) ValidateAddress(ctx context.Context, req *pb.ValidateAddr | |||
switch ka := ka.(type) { | |||
case wallet.BIP0044Address: | |||
_, branch, child := ka.Path() | |||
result.IsInternal = branch == 1 | |||
result.IsInternal = branch == udb.InternalBranch |
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.
For future reference, udb should not be used anywhere outside of the wallet package. This is a layering violation and it's making it more difficult to convert the package to being internal (but this particular case is not as bad as say, depending on a type defined by that package).