fuel
May 12, 2023, 10:11am
1
@furnic on the topic How to pass not hard coded addrresses in predicate? sent a link to answer the question of how to provide data to predicate with configurable block Predicates - The Fuel Rust SDK
But if we go to check the latest version of Rust book Predicates - The Fuel Rust SDK then there is no information about configurable. When I try to set configurable I have an error:
So is there a final doc with updates that has full functionality?
The fuels.rs SDK has this feature but it has not made it into a release yet. If you change your version in your cargo.toml from 0.41 to master
fuels = { git = "https://github.com/FuelLabs/fuels-rs", branch = "master"}
You can access the functionality then.
See for more: feat!: add predicate configurables by hal3e · Pull Request #935 · FuelLabs/fuels-rs · GitHub
1 Like
fuel
May 16, 2023, 4:11pm
4
Hello @SwayStar123
I’m just added fuels-rs from master using this
fuels = { git = "https://github.com/FuelLabs/fuels-rs", branch = "master"}
instead of this
fuels = { version = "0.41", features = ["fuel-core-lib"] }
On my rust test, I’m using inputs and outputs with ScriptCall
let script_call = ScriptCallHandler::new(
vec![],
UnresolvedBytes::default(),
wallet.clone(),
provider.clone(),
Default::default(),
)
.with_inputs(vec![input_predicate, input_from_taker])
.with_outputs(vec![
output_to_receiver,
output_to_taker,
partial_fulfill_output,
output_asked_change,
])
.tx_params(TxParameters::default().set_gas_price(1));
Also, rust sdk uses fuel_tx::Output
and fuels::types::input::Input
but on master version we have this fuels_tx export
//! A prelude is provided which imports all the important data types and traits for you. Use this when you want to quickly bootstrap a new project.
//!
//! ```no_run
//! # #[allow(unused)]
//! use fuels::prelude::*;
//! ```
//!
//! Examples on how you can use the types imported by the prelude can be found in
//! the [test suite](https://github.com/FuelLabs/fuels-rs/tree/master/packages/fuels/tests)
pub mod tx {
pub use fuel_tx::{Bytes32, ConsensusParameters, Receipt, Salt, StorageSlot};
}
#[cfg(feature = "std")]
pub mod client {
pub use fuel_core_client::client::{FuelClient, PageDirection, PaginationRequest};
}
pub mod macros {
pub use fuels_macros::*;
Instead of this
And I was forced to install fuel_tx and have some versions issues
Please add Output
type export on release version
P.S
Is there any func on fuels-rs that can generate inputs and outputs like that?
}
fn transaction_output_variable() -> Output {
Output::Variable {
amount: 0,
to: Address::zeroed(),
asset_id: AssetId::default(),
}
}
pub async fn transaction_inputs_outputs(
wallet: &WalletUnlocked,
provider: &Provider,
assets: &Vec<AssetId>,
amounts: Option<&Vec<u64>>,
) -> TransactionParameters {
let mut input_coins: Vec<Input> = vec![]; // capacity depends on wallet resources
let mut output_variables: Vec<Output> = Vec::with_capacity(assets.len());
for (asset_index, asset) in assets.iter().enumerate() {
input_coins.extend(
fuel
May 16, 2023, 9:57pm
5
looks like you already have something like that
This code
let output_offered_change = predicate // case 0
.get_asset_outputs_for_amount(wallet.address(), asset0, 0)
.iter()
.find(|out| matches!(out, Output::Change { .. }))
.unwrap()
.to_owned();
println!("output = {:#?}", output_offered_change);
let output_offered_change = Output::Change { // case 1
to: Address::from(wallet.address()),
amount: 0,
asset_id: asset0,
};
println!("output = {:#?}", output_offered_change);
Gives this logs
output = Change {
to: 0xc5b66e2ce7521c159739026f3682e7abac4cec06d689c2ca261f3d2541585bc2,
amount: 0,
asset_id: 0x4e68158aa0dd81c438160a6ef38829363cf96eeef1ae5c6cb3cccb1c52a7e685,
}
output = Change {
to: 0x5d99ee966b42cd8fc7bdd1364b389153a9e78b42b7d4a691470674e817888d4e,
amount: 0,
asset_id: 0x4e68158aa0dd81c438160a6ef38829363cf96eeef1ae5c6cb3cccb1c52a7e685,
}
It looks the same, but if I put case0 to with_outputs
it does not work with error (that means output don’t work)
With case 1 it works well
thread 'local_tests::cancel_order_test::cancel_order_test' panicked at 'assertion failed: `(left == right)`
left: `1000000000`,
right: `0`', tests/local_tests/cancel_order_test.rs:83:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
test local_tests::cancel_order_test::cancel_order_test ... FAILED
It happens because addresses are different, case0 used predicate address, case1 uses wallet address
fuel
May 16, 2023, 10:57pm
6
I figured out what was going on, I had to call
wallet.get_asset_outputs_for_amount(wallet.address(), asset0, 0);
1 Like