Skip to content

Commit

Permalink
feat: unstash changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dtscalac committed May 29, 2024
1 parent 1d131bf commit c9913ce
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 2 deletions.
5 changes: 3 additions & 2 deletions catalyst_voices/lib/app/view/app_page.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// ignore_for_file: discarded_futures

import 'package:catalyst_cardano/catalyst_cardano.dart';
import 'package:catalyst_voices/app/view/app_content.dart';
import 'package:catalyst_voices/dependency/dependencies.dart';
import 'package:catalyst_voices_blocs/catalyst_voices_blocs.dart';
Expand Down Expand Up @@ -38,10 +39,10 @@ final class _AppState extends State<App> {
Future<void> _init() async {
try {
await Dependencies.instance.init();
await CatalystCardano.instance.getCardanoWallets();
} catch (error, stackTrace) {
// TODO(dtscalac): FutureBuilder that uses this future silences all
// errors, replace it here with proper logging solution. This logging here
// is needed to spot early-on any issues with catalyst_cardano plugin.
// errors, replace it here with proper logging solution.
FlutterError.dumpErrorToConsole(
FlutterErrorDetails(exception: error, stack: stackTrace),
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// ignore_for_file: avoid_print

import 'dart:async';
import 'dart:js_interop';

import 'package:catalyst_cardano_platform_interface/catalyst_cardano_platform_interface.dart';
import 'package:catalyst_cardano_serialization/catalyst_cardano_serialization.dart';
import 'package:catalyst_cardano_web/src/interop/catalyst_cardano_interop.dart'
as interop;
import 'package:flutter_web_plugins/flutter_web_plugins.dart' show Registrar;
Expand All @@ -18,6 +21,58 @@ class CatalystCardanoWeb extends CatalystCardanoPlatform {
@override
Future<List<CardanoWallet>> getCardanoWallets() async {
final wallets = interop.getCardanoWallets().toDart;
final wallet = wallets.firstOrNull?.toDart;
if (wallet != null) {
print(wallet.name);
print(wallet.icon);
print(wallet.apiVersion);
print(wallet.supportedExtensions.map((e) => e.cip));
print((await wallet.isEnabled()));

final api = await wallet.enable(
extensions: [
const CipExtension(cip: 30),
const CipExtension(cip: 95),
],
);

print(await api.getBalance());
print(await api.getExtensions());
print(await api.getNetworkId());

final changeAddress = await api.getChangeAddress();
print(changeAddress);

final rewardAddress = await api.getRewardAddresses();
print(rewardAddress);

print(await api.getUnusedAddresses());
print(await api.getUsedAddresses());

final utxos = await api.getUtxos(
amount: const Coin(9900999),
paginate: const Paginate(page: 1, limit: 2),
);
print(utxos);

print(
await api.signData(address: rewardAddress.first, payload: [1, 2, 3]),
);

final unsignedTx = _buildUnsignedTx(utxos);
final witnessSet = await api.signTx(transaction: unsignedTx);

print(witnessSet);

final signedTx = Transaction(
body: unsignedTx.body,
isValid: true,
witnessSet: witnessSet,
);

print(await api.submitTx(transaction: signedTx));
}

return wallets.map((e) => e.toDart).toList();
}

Expand All @@ -27,3 +82,43 @@ class CatalystCardanoWeb extends CatalystCardanoPlatform {
CatalystCardanoPlatform.instance = CatalystCardanoWeb();
}
}

Transaction _buildUnsignedTx(List<TransactionUnspentOutput> utxos) {
const txBuilderConfig = TransactionBuilderConfig(
feeAlgo: LinearFee(
constant: Coin(155381),
coefficient: Coin(44),
),
maxTxSize: 8000,
coinsPerUtxoByte: Coin(4310),
);

final txOutput = TransactionOutput(
address: ShelleyAddress.fromBech32(
'addr_test1vzpwq95z3xyum8vqndgdd9mdnmafh3djcxnc6jemlgdmswcve6tkw',
),
amount: const Coin(900000),
);

final txBuilder = TransactionBuilder(
config: txBuilderConfig,
inputs: utxos,
networkId: NetworkId.testnet,
);

final changeAddress = ShelleyAddress.fromBech32(
'addr_test1qrqr2ved9h96x46yazq89yvcgk0r93gwk0shnv06yfrnfryqhpr26'
'st0zgxmjnq6gqve99gtzxumclt9mwe5ynq03hjqgkjmhd',
);

final txBody = txBuilder
.withOutput(txOutput)
.withChangeAddressIfNeeded(changeAddress)
.buildBody();

return Transaction(
body: txBody,
isValid: true,
witnessSet: const TransactionWitnessSet(vkeyWitnesses: {}),
);
}

0 comments on commit c9913ce

Please sign in to comment.