Skip to content
This repository has been archived by the owner on Dec 9, 2023. It is now read-only.

Fix TransferCommand::Combine CLI command (index out of bounds error) #201

Open
zoedberg opened this issue Sep 12, 2022 · 0 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@zoedberg
Copy link
Contributor

reporting an issue mentioned in #196:

The TransferCommand::Combine CLI command seems to have a bug: in

let blank_bundle = TransitionBundle::blank(&outpoint_map, &bmap! {})?;
for (transition, indexes) in blank_bundle.revealed_iter() {
    psbt.push_rgb_transition(transition.clone())?;
    for no in indexes {
        psbt.inputs[*no as usize]
            .set_rgb_consumer(cid, transition.node_id())?;
    }
}

psbt.inputs[*no as usize] can sometimes fail depending on the input outpoint vout value and the number of psbt inputs. This happens because no is the vout of an outpoint, which is not the position of the outpoint in the psbt.inputs vector:

fn blank(
    prev_state: &BTreeMap<OutPoint, BTreeSet<OutpointState>>,
    new_outpoints: &BTreeMap<OwnedRightType, (OutPoint, CloseMethod)>,
) -> Result<TransitionBundle, Error> {
    let mut transitions: BTreeMap<Transition, BTreeSet<u16>> = bmap! {};

    for (tx_outpoint, inputs) in prev_state {
        // [...]
        transitions.insert(transition, bset! { tx_outpoint.vout as u16 });
    }

    TransitionBundle::try_from(transitions).map_err(Error::from)
}

I think a fix could be to insert the outpoint in transitions in its entirety instead of just its vout, but I also see other ways to fix this so I would appreciate a suggestion from @dr-orlovsky here

@dr-orlovsky dr-orlovsky self-assigned this Nov 16, 2022
@dr-orlovsky dr-orlovsky added the bug Something isn't working label Nov 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants