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

Stake address indexing mismatch #448

Open
gonzalezzfelipe opened this issue Feb 11, 2025 · 0 comments
Open

Stake address indexing mismatch #448

gonzalezzfelipe opened this issue Feb 11, 2025 · 0 comments

Comments

@gonzalezzfelipe
Copy link
Contributor

When accessing the ledger data using the get_utxos_by_stake function I'm getting inconsistent results. When investigation the issue we came to the realization that this has to do with the way that the indexes are created when extracting the stake part of the addresses.

This address (addr_test1xznnmfk43w5cag3m7e9nnfe0wcsg5lx8afv4u9utjk3zxv88r4lf2ucjd6gahe9xvre2pd6rq9jt38yve8fcjpz7g7gsxhngng) has the following stake address: stake_test17rn36l54wvfxaywmujnxpu4qkapsze9cnjxvn5ufq30y0yggrutfp.

The code used to extract the stake part of the address is the following:

    fn split_address(utxo: &MultiEraOutput) -> Result<SplitAddressResult, Error> {  // The third part of the result corresponds to the bytes used for the stake address index.
        use pallas::ledger::addresses::Address;

        match utxo.address() {
            Ok(address) => match &address {
                Address::Shelley(x) => {
                    let a = x.to_vec();
                    let b = x.payment().to_vec();
                    let c = x.delegation().to_vec();
                    Ok(SplitAddressResult(Some(a), Some(b), Some(c)))
                }
                Address::Stake(x) => {
                    let a = x.to_vec();
                    let c = x.to_vec();
                    Ok(SplitAddressResult(Some(a), None, Some(c)))
                }
                Address::Byron(x) => {
                    let a = x.to_vec();
                    Ok(SplitAddressResult(Some(a), None, None))
                }
            },
            Err(err) => Err(err.into()),
        }
    }

Extracting the relevant part of this code into a snippet, we can check the following:

use pallas::ledger::addresses::Address;

fn main() {
    let address = "addr_test1xznnmfk43w5cag3m7e9nnfe0wcsg5lx8afv4u9utjk3zxv88r4lf2ucjd6gahe9xvre2pd6rq9jt38yve8fcjpz7g7gsxhngng";
    let stake = "stake_test17rn36l54wvfxaywmujnxpu4qkapsze9cnjxvn5ufq30y0yggrutfp";

    // The first one is a Shelley address, so I extract the delegation part
    let address_bytes = match Address::from_bech32(address).unwrap() {
        Address::Shelley(x) => x.delegation().to_vec(),
        _ => None.expect("Unexpected"),
    };

    // The second one is a stake address, so I just take the bytes.
    let stake_bytes = match Address::from_bech32(stake).unwrap() {
        Address::Stake(x) => x.to_vec(),
        _ => None.expect("Unexpected"),
    };

    println!(
        "Stake part extracted from shelley address: {:?}",
        address_bytes
    );
    println!("Stake part extracted from stake address: {:?}", stake_bytes);
}

Output:

Stake part extracted from shelley address: [231, 29, 126, 149, 115, 18, 110, 145, 219, 228, 166, 96, 242, 160, 183, 67, 1, 100, 184, 156, 140, 201, 211, 137, 4, 94, 71, 145]
Stake part extracted from stake address: [240, 231, 29, 126, 149, 115, 18, 110, 145, 219, 228, 166, 96, 242, 160, 183, 67, 1, 100, 184, 156, 140, 201, 211, 137, 4, 94, 71, 145]

Something to note is that they are the same, except for a leading byte in the case of the stake part as extracted from the stake address.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant