Skip to content

Commit

Permalink
fix: mobile wallet bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
mpoplavkov committed Feb 6, 2024
1 parent a8d886b commit 2fd5b04
Showing 1 changed file with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,41 @@ import 'dart:typed_data';

import 'package:convert/convert.dart';
import 'package:flutter_fuelet_smart_contract_wallet/ffi/mobile_wrapper.dart';
import 'package:flutter_fuelet_smart_contract_wallet/wallet/smart_contract_wallet.dart';
import 'package:flutter_fuelet_smart_contract_wallet/wallet/wrapped_smart_contract_wallet.dart';
import 'package:fuelet_smart_contract_wallet/fuelet_smart_contract_wallet.dart';
import 'package:fuelet_smart_contract_wallet/fuelet_smart_contract_wallet.dart'
as fuelet;

import 'base_wallet.dart';

class PlatformSmartContractWalletImpl extends BaseWallet {
static final FueletSmartContractWallet _bridge = createLib();
static final fuelet.FueletSmartContractWallet _bridge = createLib();

@override
Future<WrappedSmartContractWallet> connect(
{required String networkUrl,
required String r1PublicKey,
required String recoveryWalletPrivateKey}) async {
final rustSmartContractWallet = await SmartContractWallet.connect(
final rustSmartContractWallet = await fuelet.SmartContractWallet.connect(
bridge: _bridge,
r1PublicKey: r1PublicKey,
recoveryPrivateKey: recoveryWalletPrivateKey,
nodeUrl: networkUrl);
return MobileSmartContractWallet(
rustSmartContractWallet: rustSmartContractWallet,
predicateBech32Address: rustSmartContractWallet.bech32_address,
r1PublicKey: rustSmartContractWallet.r1_public_key);
predicateBech32Address: rustSmartContractWallet.bech32Address,
r1PublicKey: rustSmartContractWallet.r1PublicKey);
}
}

class MobileSmartContractWallet extends WrappedSmartContractWallet {
final SmartContractWallet _rustSmartContractWallet;
final fuelet.SmartContractWallet _rustSmartContractWallet;
@override
final String predicateBech32Address;
@override
final String r1PublicKey;

MobileSmartContractWallet(
{required SmartContractWallet rustSmartContractWallet,
{required fuelet.SmartContractWallet rustSmartContractWallet,
required this.predicateBech32Address,
required this.r1PublicKey})
: _rustSmartContractWallet = rustSmartContractWallet;
Expand All @@ -52,8 +52,10 @@ class MobileSmartContractWallet extends WrappedSmartContractWallet {
required int fractionalAmount,
required String assetId}) async {
final (txBytes, txIdBytes) =
await _rustSmartContractWallet.gen_transfer_tx_request(
destinationB256Address, fractionalAmount, assetId);
await _rustSmartContractWallet.genTransferTxRequest(
toB256: destinationB256Address,
amount: fractionalAmount,
asset: assetId);
return (hex.encode(txBytes), hex.encode(txIdBytes));
}

Expand All @@ -63,7 +65,8 @@ class MobileSmartContractWallet extends WrappedSmartContractWallet {
required String r1Signature}) {
final txBytes = hex.decode(transactionRequestHexOrJson);
final signatureBytes = hex.decode(r1Signature);
return _rustSmartContractWallet.sendTransaction(
encodedTx: Uint8List.fromList(txBytes), signature: signatureBytes);
return _rustSmartContractWallet.sendTx(
encodedTx: Uint8List.fromList(txBytes),
signature: Uint8List.fromList(signatureBytes));
}
}

0 comments on commit 2fd5b04

Please sign in to comment.