-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Set custom transaction inputs and outputs for predicates #755
Comments
Team, I need your feedback on this. In the let script = ScriptBuilder::new()
.set_inputs(vec![input_predicate, input_from_taker])
.set_outputs(vec![
output_to_receiver,
output_to_taker,
output_asked_change,
])
.set_gas_limit(10_000_000)
.set_script(vec![Opcode::RET(REG_ONE)]);
In the new releases of the SDK we can not use this code directly as we do not have the So now we have 3 options:
let tx_parameters = TxParameters {
gas_limit: 10_000_000,
..Default::default()
};
let mut tx = Wallet::build_transfer_tx(
&[input_predicate, input_from_taker],
&[output_to_receiver, output_to_taker, output_asked_change],
tx_parameters,
);
taker_wallet.sign_transaction(&mut tx).await.unwrap();
let _receipts = provider.send_transaction(&tx).await.unwrap();
If we go with this option. I would add a new methods to the
What do you think. @FuelLabs/sdk-rust @supiket |
Option 1 or potentially 3 seems the most suitable to me, but if having a function to convert Interacting with a predicate requires knowing exactly what the predicate does and the transaction inputs and outputs. The way to interact with them would vary depending on what the predicate does, so I don't think there is a way to work around setting inputs and outputs in a custom way unless there exists a general pattern that almost always holds, which as far as I know, doesn't exist. I'm for more flexibility and the less abstraction, what do you think @simonr0204? |
Just to add some context to the conversation... IMO setting the right offset and encoding the data is not trivial. That is why I am so conflicted. In this example, you did not have to deal with it directly but if you had to you would have had to manually do something like this: // Iterate through the spendable resources and calculate the appropriate offsets
// for the coin or message predicates
let mut offset = base_predicate_offset(&predicate.consensus_parameters().await?);
let inputs = spendable_predicate_resources
.into_iter()
.map(|resource| match resource {
Resource::Coin(coin) => {
offset += coin_predicate_data_offset(code.len());
let data = predicate_data.clone().resolve(offset as u64);
offset += data.len();
self.create_coin_predicate(coin, asset_id, code.clone(), data)
}
Resource::Message(message) => {
offset += message_predicate_data_offset(message.data.len(), code.len());
let data = predicate_data.clone().resolve(offset as u64);
offset += data.len();
self.create_message_predicate(message, code.clone(), data)
}
})
.collect::<Vec<_>>(); The code above uses |
This is a tough UX problem, so I'm still in the thinking process. My thoughts so far...
This block right here by @supiket is extremely on point. All three paragraphs are on point; the summary is that adding unnecessary abstraction layers is a bad idea. If you're working with predicates, you're operating at the That said, regardless if you're working with Now, the question is, does approach (1) really require the user to compute the offsets themselves? If yes, we must introduce an abstraction layer because we don't want users to think about |
The answer is unfortunately yes and no. If they are not using dynamic data like vectors then they would not have to deal with offsets. As soon as they have dynamic data as input, they need the correct offsets. Debugging in this case is very hard because you only get a revert error which states that the predicate failed to validate. |
After our latest talk on this, have we decided to go with the option that abstracts the offsets from users, i.e. option 3? |
Yes that is correct. I will make a PR with the initial implementation and we can continue the discussion there. |
@Salka1988 and @MujkicA is this issue obsolete now that #815 is merged ? |
Yes, you're right. For exemple: ScriptTransactionBuilder::default().set_inputs(inputs).set_outputs(outputs).build();
CreateTransactionBuilder::default().set_inputs(inputs).set_outputs(outputs).build(); This works for both wallets and predicates. For more details see |
Implement
with_inputs()
andwith_outputs()
functionality for predicates (#726).@hal3e
The text was updated successfully, but these errors were encountered: