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

Wallet: Support transactions to multiple recipients #62

Open
JoshOrndorff opened this issue Apr 11, 2023 · 6 comments
Open

Wallet: Support transactions to multiple recipients #62

JoshOrndorff opened this issue Apr 11, 2023 · 6 comments

Comments

@JoshOrndorff
Copy link
Contributor

Currently the wallet allows sending inputs from multiple owners in a single transaction, but only allows a single recipient to all specified outputs.

To support specifying a recipient on a per-output basis we will need to expand the cli somehow.

@NadigerAmit
Copy link
Contributor

NadigerAmit commented Feb 26, 2024

@JoshOrndorff

I am planning to add the multiple recipient support as below, Please let me know if it is ok not ?

Approach1:

/// Default recipient is  SHAWN_KEY and output amount is 0
pub const DEFAULT_RECIPIENT: &str = "d2bf4b844dfefd6772a8843e669f943408966a977e3ae2af1dd78e0f55f4df67 0";

#[derive(Debug, Args)]
pub struct SpendArgs {
    /// An input to be consumed by this transaction. This argument may be specified multiple times.
    /// They must all be coins.
    #[arg(long, short, verbatim_doc_comment, value_parser = output_ref_from_string)]
    pub input: Vec<OutputRef>,

    /// Variable number of recipients and their associated coins.
    /// For example, "--recipients 0x1234 1 2 --recipients 0x5678 3 4 6"
   #[arg(long, short, verbatim_doc_comment, value_parser = parse_recipient_coins, action = Append, 
    default_value = DEFAULT_RECIPIENT)]
   pub recipients: Vec<(H256, Vec<u128>)>,
}

// I need to refine this API , to return the SHAWN_PUB_KEY
fn parse_recipient_coins(s: &str) ->  Result<(H256, Vec<u128>), &'static str> {
    let parts: Vec<&str> = s.split_whitespace().collect();
    if parts.len() >= 2 {
        let recipient = h256_from_string(parts[0]);
        let coins = parts[1..].iter().filter_map(|&c| c.parse().ok()).collect();
        match recipient {
            Ok(r) => {return Ok((r, coins));},
            _ => {},
        };
    }
    Err("Invalid input format")
}

And I need to send the command line args as below
./target/release/tuxedo-template-wallet spend-coins-multi-recipient -i a95362504966abd5ee55223d09e860bb1dd60eba1425b80fb05e1cc3ad66bf7100000000 -r "0xfa96831be67e2abe0378467e1156b401d2ab044b0a66fc7703b8d90e84c45c54 1 2" -r "0xc2f52af267b5a3f46510e39e6dcdbd5904b722396727866f22f272ba687a9953 3 4 6"

Result: I could receive the command line args successfully .

But I think ideal way below:

Approach2:

#[derive(Debug, Args)]
pub struct SpendArgs1 {
    /// An input to be consumed by this transaction. This argument may be specified multiple times.
    /// They must all be coins.
    #[arg(long, short, verbatim_doc_comment, value_parser = output_ref_from_string)]
    pub input: Vec<OutputRef>,

    #[arg(long, short, verbatim_doc_comment, value_parser = h256_from_string, default_value = SHAWN_PUB_KEY)]
    pub recipients:Vec<Recipients>
}

#[derive(Debug, Args,Clone)]
pub struct Recipients {
    #[arg(long, short, verbatim_doc_comment, value_parser = h256_from_string, default_value = SHAWN_PUB_KEY)]
    pub recipient: H256,
    
    #[arg(long, short, verbatim_doc_comment, action = Append)]
    pub output_amount: Vec<u128>,
}

For this approach I am not finding a correct way to send the cmd line arguments.
If possible, Please share your opinion.

@NadigerAmit
Copy link
Contributor

NadigerAmit commented Feb 27, 2024

the transfer to multiple recipient is working good :

image

@JoshOrndorff
Copy link
Contributor Author

Nice job getting something working. Please open a PR with your work-in-progress already so I can play around with it as well. I'm excited about this.

The way you have parsing working is reasonable and good enough. Another alternative would be that for each -r you provide a single address and single value. So if you want multiple coins to go to the same address you provide two different -r with that address. Not sure if it is better than yours, just different.

Your idea for pub struct Recipient is nice. But that type shouldn't be #[derive(Args)] or any other clap stuff. Then your parse function returns that type instead of the (H256, Vec<u128>).

Anyway, you're doing well, please open a PR.

NadigerAmit added a commit to mlabs-haskell/Tuxedo that referenced this issue Mar 4, 2024
…ew comments.

Issue fix for Off-Narrative-Labs#62 and other changes related review comments
@NadigerAmit
Copy link
Contributor

@JoshOrndorff,
Thank you so much.
I will create a PR soon. In the meantime, if you can access the below please check the 'spend_coins' function:
https://github.com/mlabs-haskell/Tuxedo/blob/main/wallet/src/money.rs

Note: The above code is still experimental and may not meet the standard quality. I appreciate your understanding in this regard.

I am successful with Approach 1. In the future will do some more experiments with Approach 2.

@JoshOrndorff
Copy link
Contributor Author

@NadigerAmit I hope you will be able to open a PR for this feature. LMK if I can help.

@NadigerAmit
Copy link
Contributor

@JoshOrndorff, Thanks. I will open a PR this week after one more round of test and the relevant modification in the README file.

NadigerAmit added a commit to mlabs-haskell/Tuxedo that referenced this issue Apr 24, 2024
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

2 participants