Skip to content
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

Create and sign xts in dart #1626

Merged
merged 35 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
ab58e17
[service/tx] add naive implementation of txbuilder
clangenb Jan 26, 2024
5f92388
add multiaddress extensions for keys
clangenb Jan 26, 2024
3af19a3
[service/tx] rename TxApi to TxBuilder
clangenb Jan 26, 2024
ab13ede
[service/tx] try to send tx with dart generate code, tx-validation fa…
clangenb Jan 26, 2024
775117f
[service/tx] verify that encoded call ist correct.
clangenb Jan 26, 2024
37bfd00
[service/tx] rename our extrinsic type to opaque extrinsic
clangenb Jan 26, 2024
49c6fa5
change branch of our polkadart for
clangenb Jan 26, 2024
c21a088
[tx_builder] minor fix and successfully send a tx with native currency
clangenb Jan 26, 2024
30222a3
bump polkadart
clangenb Jan 26, 2024
b742ba5
[tx_dart_test] fix variable naming warning
clangenb Jan 26, 2024
45b3ac0
bump lock file
clangenb Jan 26, 2024
ac7cd1a
fix redundant community identifier definition
clangenb Jan 26, 2024
dbd1edb
[send_tx_dart_test] try to pay with community currency, currently fai…
clangenb Jan 26, 2024
215c78c
bump polkadart now we can pay with community currency
clangenb Jan 26, 2024
96f9b8f
[service/tx] rename submitToJs to `submitTxInner`
clangenb Jan 29, 2024
80b68bc
wip strongly type whole extrinsic send process
clangenb Jan 29, 2024
0a1efa7
[service/tx] extract all tx notification constructors and remove extr…
clangenb Jan 29, 2024
7094076
[service/tx] fix correct cid type in claim rewards
clangenb Jan 29, 2024
13afc5c
[service/tx] use new way for submitClaimRewards and unregisterPartici…
clangenb Jan 29, 2024
6805036
[service/tx] `submitRegisterParticipant` now uses the new way
clangenb Jan 29, 2024
06c28cc
[service/tx] `submitAttestAttendees` now uses the new way
clangenb Jan 29, 2024
d54a19a
[service/tx] `submitFaucetDrip` now uses the new way
clangenb Jan 29, 2024
1a052d8
[service/tx] `submitEncointerBalance` uses now the dart way
clangenb Jan 29, 2024
6453ee6
[service/tx] fix `submitEndorseNewcomer` type error
clangenb Jan 29, 2024
d6d3412
[service/tx] next phase sudo works
clangenb Jan 29, 2024
f8bb1d5
[service/tx] reap voucher uses now the dart way
clangenb Jan 29, 2024
bdc632f
fmt
clangenb Jan 29, 2024
afd4b32
[service/tx] remove unused showStatusSnackBar param
clangenb Jan 29, 2024
e3d8da9
[service/tx] remove dead `TxApi`
clangenb Jan 29, 2024
b99b628
[service/tx] remove obsolete todo
clangenb Jan 29, 2024
65f8ac5
[service/tx] better error handling
clangenb Jan 29, 2024
79782ac
[service/tx] extract `getExtrinsicReport` from the extrinsic callback
clangenb Jan 29, 2024
12f74f7
[service/tx] added issue number for catching exception in extrinsic c…
clangenb Jan 29, 2024
401051d
[service/tx] fix punctuation in doc
clangenb Jan 29, 2024
f37976d
[service/tx] fix conflicting tuple implementation
clangenb Jan 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/lib/models/communities/community_identifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ class CommunityIdentifier {
return utf8.decode(geohash) + codec.encode(digest);
}

et.CommunityIdentifier toPolkadart() {
return et.CommunityIdentifier(geohash: geohash, digest: digest);
}

// By default, the dart `==` operator returns only true iff both variables point to the same instance. We want to
// override this behaviour, such that it is also true if the instances contain the same values.
@override
Expand Down
18 changes: 16 additions & 2 deletions app/lib/page-encointer/ceremony_box/ceremony_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,14 @@ class CeremonyBox extends StatelessWidget {
if (store.dataUpdate.expired) {
await awaitDataUpdateWithDialog(context, store);
}
await submitRegisterParticipant(context, store, api);
await submitRegisterParticipant(
context,
store,
api,
store.account.getKeyringAccount(store.account.currentAccountPubKey!),
store.encointer.chosenCid!,
txPaymentAsset: store.encointer.getTxPaymentAsset(store.encointer.chosenCid),
);
}),
),
if (store.encointer.showRestartCeremonyButton)
Expand Down Expand Up @@ -117,7 +124,14 @@ class CeremonyBox extends StatelessWidget {
Text(context.l10n.claimsSubmitN(store.encointer.communityAccount!.scannedAttendeesCount)),
],
),
onPressed: () => submitAttestClaims(context, store, api),
onPressed: () => submitAttestAttendees(
context,
store,
api,
store.account.getKeyringAccount(store.account.currentAccountPubKey!),
store.encointer.chosenCid!,
txPaymentAsset: store.encointer.getTxPaymentAsset(store.encointer.chosenCid),
),
),
)
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:encointer_wallet/service/substrate_api/api.dart';
import 'package:encointer_wallet/l10n/l10.dart';
import 'package:encointer_wallet/service/tx/lib/tx.dart';
import 'package:encointer_wallet/store/app.dart';
import 'package:encointer_wallet/models/index.dart';

class UnregisteredLinkButton extends StatefulWidget {
const UnregisteredLinkButton({super.key});
Expand All @@ -24,7 +25,24 @@ class _UnregisteredLinkButtonState extends State<UnregisteredLinkButton> {
setState(() {
_submitting = true;
});
await submitUnRegisterParticipant(context, context.read<AppStore>(), webApi);

final store = context.read<AppStore>();

final lastProofOfAttendance = store.encointer.communityAccount?.participantType?.isReputable ?? false
? store.encointer.account
?.lastProofOfAttendance // can still be null if the participant did not register on the same phone.
: null;

await submitUnRegisterParticipant(
context,
store,
webApi,
store.account.getKeyringAccount(store.account.currentAccountPubKey!),
store.encointer.chosenCid!,
lastProofOfAttendance: lastProofOfAttendance,
txPaymentAsset: store.encointer.getTxPaymentAsset(store.encointer.chosenCid),
);

setState(() {
_submitting = false;
});
Expand Down
9 changes: 8 additions & 1 deletion app/lib/page-encointer/meetup/ceremony_step3_finish.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,14 @@ class CeremonyStep3Finish extends StatelessWidget {
Text(l10n.claimsSubmitN(store.encointer.communityAccount!.scannedAttendeesCount)),
],
),
onPressed: (context) => submitAttestClaims(context, store, api),
onPressed: (context) => submitAttestAttendees(
context,
store,
api,
store.account.getKeyringAccount(store.account.currentAccountPubKey!),
store.encointer.chosenCid!,
txPaymentAsset: store.encointer.getTxPaymentAsset(store.encointer.chosenCid),
),
);
} else {
return Column(
Expand Down
6 changes: 5 additions & 1 deletion app/lib/page/assets/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,19 @@ class _AssetsViewState extends State<AssetsView> {
if (snapshot.hasData) {
final hasPendingIssuance = snapshot.data!;

final store = widget.store;

if (hasPendingIssuance) {
return SubmitButton(
key: const Key(EWTestKeys.claimPendingDev),
child: Text(l10n.issuancePending, textAlign: TextAlign.center),
onPressed: (context) => submitClaimRewards(
context,
widget.store,
store,
webApi,
store.account.getKeyringAccount(store.account.currentAccountPubKey!),
widget.store.encointer.chosenCid!,
txPaymentAsset: store.encointer.getTxPaymentAsset(store.encointer.chosenCid),
),
);
} else {
Expand Down
38 changes: 22 additions & 16 deletions app/lib/page/assets/transfer/payment_confirmation_page/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ class _PaymentConfirmationPageState extends State<PaymentConfirmationPage> {
final cid = params.cid;
final recipientAccount = params.recipientAccount;
final amount = params.amount;
final recipientAddress =
AddressUtils.pubKeyHexToAddress(recipientAccount.pubKey, prefix: store.settings.endpoint.ss58!);
final recipientAddress = Address(
pubkey: AddressUtils.pubKeyHexToPubKey(recipientAccount.pubKey),
prefix: store.settings.endpoint.ss58!,
);

return Scaffold(
appBar: AppBar(title: Text(l10n.payment)),
Expand Down Expand Up @@ -133,31 +135,35 @@ class _PaymentConfirmationPageState extends State<PaymentConfirmationPage> {
);
}

Future<void> _submit(BuildContext context, CommunityIdentifier cid, String recipientAddress, double? amount) async {
final params = encointerBalanceTransferParams(cid, recipientAddress, amount, context.l10n);

setState(() {
_transferState = TransferState.submitting;
});

Future<void> _submit(
BuildContext context,
CommunityIdentifier cid,
Address recipientAddress,
double amount,
) async {
final pin = await context.read<LoginStore>().getPin(context);
if (pin != null) {
await submitTx(
setState(() {
_transferState = TransferState.submitting;
});

final store = context.read<AppStore>();
await submitEncointerTransfer(
context,
context.read<AppStore>(),
store,
widget.api,
params,
store.account.getKeyringAccount(store.account.currentAccountPubKey!),
cid,
recipientAddress,
amount,
txPaymentAsset: store.encointer.getTxPaymentAsset(store.encointer.chosenCid),
onFinish: onFinish,
onError: onError,
);

Log.d('TransferState after callback: $_transferState', 'PaymentConfirmationPage');
// trigger rebuild after state update in callback
setState(() {});
} else {
setState(() {
_transferState = TransferState.notStarted;
});
Comment on lines -157 to -160
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was unnecessary, we now change the state to submitting after checking the pin, this makes it easier.

}
}

Expand Down
6 changes: 3 additions & 3 deletions app/lib/page/profile/account/account_manage_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,12 @@ class _AccountManagePageState extends State<AccountManagePage> {
shrinkWrap: true,
itemCount: faucets!.length,
itemBuilder: (BuildContext context, int index) {
final faucetAccount = faucets!.keys.elementAt(index);
final faucetPubKeyHex = faucets!.keys.elementAt(index);
return FaucetListTile(
store,
userAddress: addressSS58,
faucet: faucets![faucetAccount]!,
faucetAccount: faucetAccount,
faucet: faucets![faucetPubKeyHex]!,
faucetPubKey: faucetPubKeyHex,
);
},
)
Expand Down
22 changes: 18 additions & 4 deletions app/lib/page/profile/account/faucet_list_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ class FaucetListTile extends StatefulWidget {
this.store, {
super.key,
required this.userAddress,
required this.faucetAccount,
required this.faucetPubKey,
required this.faucet,
});

final AppStore store;

final String userAddress;
final String faucetAccount;
final String faucetPubKey;
final Faucet faucet;

@override
Expand Down Expand Up @@ -79,7 +79,11 @@ class _FaucetListTileState extends State<FaucetListTile> {
if (snapshot.data!.isNotEmpty) {
return SubmitButtonSmall(
onPressed: (context) async {
await _submitFaucetDripTxs(context, snapshot.data!, widget.faucetAccount);
await _submitFaucetDripTxs(
context,
snapshot.data!,
widget.faucetPubKey,
);
future = _getUncommittedReputationIds(widget.userAddress);
nativeBalance = getNativeFreeBalance(widget.userAddress);
setState(() {});
Expand Down Expand Up @@ -130,8 +134,18 @@ class _FaucetListTileState extends State<FaucetListTile> {
Map<int, CommunityIdentifier> ids,
String faucetAccount,
) async {
final store = widget.store;
final e = ids.entries.first;
return submitFaucetDrip(context, widget.store, webApi, faucetAccount, e.value, e.key);
return submitFaucetDrip(
context,
store,
webApi,
store.account.getKeyringAccount(store.account.currentAccountPubKey!),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now submit the signer, this will make it easier to implement #1469.

faucetAccount,
e.value,
e.key,
txPaymentAsset: store.encointer.getTxPaymentAsset(store.encointer.chosenCid),
);
}

Future<BigInt> getNativeFreeBalance(String address) async {
Expand Down
10 changes: 9 additions & 1 deletion app/lib/page/profile/contacts/contact_detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,15 @@ class EndorseButton extends StatelessWidget {
} else if (store.encointer.currentPhase != CeremonyPhase.Registering) {
await _popupDialog(context, l10n.canEndorseInRegisteringPhaseOnly);
} else {
await submitEndorseNewcomer(context, store, api, store.encointer.chosenCid, address);
await submitEndorseNewcomer(
context,
store,
api,
store.account.getKeyringAccount(store.account.currentAccountPubKey!),
store.encointer.chosenCid!,
Address.decode(address),
txPaymentAsset: store.encointer.getTxPaymentAsset(store.encointer.chosenCid),
);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/lib/page/profile/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ class _ProfileState extends State<Profile> {
Text('Next-Phase (only works for local dev-network)'),
],
),
onPressed: (_) async {
final res = await submitNextPhase(webApi);
onPressed: (BuildContext context) async {
final res = await submitNextPhaseWithAlice(context, store, webApi);
RootSnackBar.showMsg(res.toString());
},
),
Expand Down
41 changes: 23 additions & 18 deletions app/lib/page/reap_voucher/reap_voucher_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class ReapVoucherPage extends StatefulWidget {
}

class _ReapVoucherPageState extends State<ReapVoucherPage> {
late KeyringAccount _voucherKeyringAccount;
String? _voucherAddress;
double? _voucherBalance;

Expand All @@ -56,8 +57,8 @@ class _ReapVoucherPageState extends State<ReapVoucherPage> {
Log.d('Fetching voucher data...', 'ReapVoucherPage');
final store = context.read<AppStore>();

final voucherPair = await KeyringAccount.fromUri('Voucher', voucherUri);
_voucherAddress = voucherPair.address(prefix: store.settings.endpoint.ss58 ?? 42).encode();
_voucherKeyringAccount = await KeyringAccount.fromUri('Voucher', voucherUri);
_voucherAddress = _voucherKeyringAccount.address(prefix: store.settings.endpoint.ss58 ?? 42).encode();

setState(() {});

Expand Down Expand Up @@ -96,12 +97,12 @@ class _ReapVoucherPageState extends State<ReapVoucherPage> {
@override
Widget build(BuildContext context) {
final l10n = context.l10n;
final store = context.watch<AppStore>();
final store = context.read<AppStore>();
final h2Grey = context.titleLarge.copyWith(color: AppColors.encointerGrey);
final h4Grey = context.bodyLarge.copyWith(color: AppColors.encointerGrey);

final voucher = widget.voucher;
final recipient = store.account.currentAddress;
final recipient = Address.decode(store.account.currentAddress);

return Scaffold(
appBar: AppBar(title: Text(l10n.voucher)),
Expand Down Expand Up @@ -156,7 +157,7 @@ class _ReapVoucherPageState extends State<ReapVoucherPage> {
SubmitButton(
key: const Key(EWTestKeys.submitVoucher),
onPressed: _isReady
? (context) => _submitReapVoucher(context, voucher.voucherUri, voucher.cid, recipient)
? (context) => _submitReapVoucher(context, _voucherKeyringAccount, voucher.cid, recipient)
: null,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
Expand All @@ -175,24 +176,28 @@ class _ReapVoucherPageState extends State<ReapVoucherPage> {

Future<void> _submitReapVoucher(
BuildContext context,
String voucherUri,
KeyringAccount voucherKeyringAccount,
CommunityIdentifier cid,
String recipientAddress,
Address recipientAddress,
) async {
// Fixme, use proper threshold here: #589
if (_voucherBalance! < 0.04) return showRedeemFailedDialog(context, context.l10n.voucherBalanceTooLow);

final res = await submitReapVoucher(widget.api, voucherUri, recipientAddress, cid);

if (res['hash'] == null) {
Log.d('Error redeeming voucher: ${res['error']}', 'ReapVoucherPage');
await showRedeemFailedDialog(context, res['error'] as String?);
} else {
await VoucherDialogs.showRedeemSuccessDialog(
context: context,
onOK: () => Navigator.of(context).popUntil((route) => route.isFirst),
);
}
await submitEncointerTransferAll(
context, context.read<AppStore>(), widget.api, voucherKeyringAccount, recipientAddress, cid,
// the voucher obviously has tokens in cid.
txPaymentAsset: cid,
onError: (report) async {
Log.d('Error redeeming voucher: ${report.toJson()}', 'ReapVoucherPage');
await showRedeemFailedDialog(context, report.toJson().toString());
},
onFinish: (context, report) async {
await VoucherDialogs.showRedeemSuccessDialog(
context: context,
onOK: () => Navigator.of(context).popUntil((route) => route.isFirst),
);
},
);
}

Future<ChangeResult?> _changeNetworkAndCommunityIfNeeded(
Expand Down
17 changes: 7 additions & 10 deletions app/lib/service/substrate_api/account_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:encointer_wallet/service/log/log_service.dart';
import 'package:encointer_wallet/service/notification/lib/notification.dart';
import 'package:encointer_wallet/service/substrate_api/api.dart';
import 'package:encointer_wallet/service/substrate_api/core/js_api.dart';
import 'package:encointer_wallet/service/tx/lib/src/tx_notification.dart';
import 'package:encointer_wallet/service/tx/lib/src/send_tx_dart.dart';
import 'package:encointer_wallet/store/account/account.dart';
import 'package:encointer_wallet/store/app.dart';
Expand Down Expand Up @@ -52,22 +53,18 @@ class AccountApi {
}

Future<ExtrinsicReport> sendTxAndShowNotification(
Map<String, dynamic> txInfo,
List<dynamic>? params, {
String? rawParam,
OpaqueExtrinsic xt,
TxNotification? notification, {
String? cid,
}) async {
final res = await getSignedTx(txInfo, params, rawParam: rawParam);
final report = await EWAuthorApi(provider).submitAndWatchExtrinsicWithReport(xt);

final report =
await EWAuthorApi(provider).submitAndWatchExtrinsicWithReport(Extrinsic.fromHex(res['xt'] as String));

if (report.isExtrinsicSuccess) {
if (report.isExtrinsicSuccess && notification != null) {
final hash = report.blockHash;
unawaited(NotificationPlugin.showNotification(
int.parse(hash.substring(0, 6)),
'${txInfo['notificationTitle']}',
'${txInfo['notificationBody']}',
notification.title,
notification.body,
cid: cid,
));
}
Expand Down
Loading
Loading