Skip to content

Commit

Permalink
fix: set provider to predicate
Browse files Browse the repository at this point in the history
  • Loading branch information
mpoplavkov committed Feb 14, 2024
1 parent dca7b37 commit c8295d8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use fuel_crypto::fuel_types::ContractId;
use fuel_crypto::SecretKey;
use fuel_tx::Salt;
use fuels::accounts::predicate::Predicate;
use fuels::prelude::{Contract, WalletUnlocked};
use fuels::prelude::{Contract, Provider, WalletUnlocked};
use fuels::types::Bits256;
use sha2::{Digest, Sha256};

Expand Down Expand Up @@ -41,20 +41,21 @@ pub fn get_script_hash(script: &model::WithdrawalScript<WalletUnlocked>) -> [u8;
b256.0
}

pub fn get_predicate_from_script_hash(r1_public_key: String, script_hash: [u8; 32]) -> Predicate {
pub fn get_predicate_from_script_hash(r1_public_key: String, script_hash: [u8; 32], provider: &Provider) -> Predicate {
let pub_key = Bits256::from_hex_str(r1_public_key.as_str()).unwrap();
let configurables = model::SecureEnclavePredicateConfigurables::new()
.with_SECURE_ENCLAVE_PUBLIC_KEY(pub_key)
.with_EXPECTED_SCRIPT_BYTECODE_HASH(Bits256(script_hash));
let predicate_code = hex::decode(gen_consts::SECURE_ENCLAVE_PREDICATE_CODE).unwrap();
let predicate = Predicate::from_code(predicate_code)
.with_configurables(configurables);
.with_configurables(configurables)
.with_provider(provider.clone());
predicate
}

pub fn get_predicate(r1_public_key: &String, recovery_secret_key: &SecretKey, recovery_wallet: &WalletUnlocked) -> Predicate {
let recovery_contract = get_recovery_checker_contract(recovery_secret_key);
let withdrawal_script = get_script(recovery_wallet, recovery_contract.contract_id());
let script_hash = get_script_hash(&withdrawal_script);
get_predicate_from_script_hash(r1_public_key.clone(), script_hash)
get_predicate_from_script_hash(r1_public_key.clone(), script_hash, recovery_wallet.provider().unwrap())
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ void main() {
"fuel1nnh77tj74f0sp6e39q7mmkpjwhnsqedmwq2ld2afmn4atf676wmq8wl7qy");
});

test('tx request creation', () async {
final smartContractWallet =
await getSmartContractWallet(stubR1PublicKey, testWalletPrivateKey);
final (tx, txId) = await smartContractWallet.genTransferTxRequest(
toB256: testDestinationB256, amount: 1, asset: ethAsset);
expect(txId.isEmpty, false);
expect(tx.isEmpty, false);
});

test('deploy contract', () async {
final smartContractWallet =
await getSmartContractWallet(stubR1PublicKey, testWalletPrivateKey);
Expand Down
1 change: 1 addition & 0 deletions packages/fuelet_smart_contract_wallet/test/test_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter_rust_bridge/flutter_rust_bridge.dart';
import 'package:fuelet_smart_contract_wallet/src/bridge_generated.dart';

const betaApiUrl = 'https://beta-5.fuel.network';
const testDestinationB256 = '0xfe1177573a47310756f27ef25c7229b5da8d5109a7258b297f23a6768c78cb40';
const testWalletPrivateKey =
'e5e05a4ab2919dc01b97c90a48853fd4dfbd204e92e44327375702ab09bb184e';
const stubR1PublicKey =
Expand Down

0 comments on commit c8295d8

Please sign in to comment.