Skip to content
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

Get addresses from transparent outputs in zcash_script #3148

Closed
Tracked by #3134
mpguerra opened this issue Dec 3, 2021 · 4 comments
Closed
Tracked by #3134

Get addresses from transparent outputs in zcash_script #3148

mpguerra opened this issue Dec 3, 2021 · 4 comments
Assignees
Labels
lightwalletd any work associated with lightwalletd

Comments

@mpguerra
Copy link
Contributor

mpguerra commented Dec 3, 2021

Motivation

lightwalletd uses the getaddresstxids, getaddressbalance, and getaddressutxos RPCs.

These RPCs return the transparent address that receives funds from a transparent output:

zcashd Implementation

Here is how zcashd gets the output addresses using out.scriptPubKey.AddressHash(), and builds its address indexes:

zcash_script needs to return the same addresses for:

  • the provided cached parsed transaction, and
  • the provided transaction data.

Example Code

The new functions are similar to the SigOps functions in:
zcash/zcash@31bd2ba

Something like:

uint160 zcash_script_transparent_output_address(tx, nOut, ...) {
    // parse tx if needed

    if nOut >= tx.number_of_transparent_outputs {
        // set the error to "invalid output index"
        return INVALID_ADDRESS;
    }

    const CTxOut &out = tx.vout[nOut];
    CScript::ScriptType scriptType = out.scriptPubKey.GetType();
    if (scriptType == CScript::UNKNOWN) {
        // set the error to "invalid script"
        return INVALID_ADDRESS;
    }

    // set the error to "no error"
    return out.scriptPubKey.AddressHash();
}
@ftm1000 ftm1000 added the S-needs-triage Status: A bug report needs triage label Feb 10, 2022
@ftm1000
Copy link

ftm1000 commented Feb 10, 2022

@conradoplg
Copy link
Collaborator

@teor2345 could you please add more details to what is required here? What I deduced is that we need to add a new function to zcash_script that receives an output and returns the address from it. Is that correct?

@teor2345
Copy link
Contributor

@teor2345 could you please add more details to what is required here? What I deduced is that we need to add a new function to zcash_script that receives an output and returns the address from it. Is that correct?

zcash_script operates on transactions, so we want to pass the transaction and the transparent output index. Then we want to do the same thing zcashd does to build its address index.

I expanded the explanation and filled in some example code.

I'm hoping we can return a uint160 as a Rust [u8; 20] without having to allocate memory. But I guess we'll see.

@conradoplg
Copy link
Collaborator

Those two PRs mentioned above close this issue. (The zcashd one won't be merged into main and we will keep pointing to that branch, until we create a PR upstream and it's accepted)

@ftm1000 ftm1000 added the lightwalletd any work associated with lightwalletd label Mar 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lightwalletd any work associated with lightwalletd
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants