Skip to content

Commit

Permalink
send tx through recovered account
Browse files Browse the repository at this point in the history
  • Loading branch information
shawn committed Jun 10, 2020
1 parent d6623dd commit 9d5bfff
Show file tree
Hide file tree
Showing 22 changed files with 451 additions and 245 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,4 @@ We got grants from Web3 Foundation, at the same time, we are helping Acala Netwo

### Tipping address

Kusama address: `E8Yd2tgy9BQi2dGPAMc9GgiGJy3wsibhL1EU4kCLf1g1A3V`
Kusama address: `EyWJe5kRSpDXLSaUxE3WcoDSgSos2TpRL2rSSd45R61YRqH`
2 changes: 1 addition & 1 deletion lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class _WalletAppState extends State<WalletApp> {
// profile
AccountManagePage.route: (_) => AccountManagePage(_appStore),
ContactsPage.route: (_) => ContactsPage(_appStore.settings),
ContactListPage.route: (_) => ContactListPage(_appStore.settings),
ContactListPage.route: (_) => ContactListPage(_appStore),
ContactPage.route: (_) => ContactPage(_appStore),
ChangeNamePage.route: (_) => ChangeNamePage(_appStore.account),
ChangePasswordPage.route: (_) => ChangePasswordPage(_appStore.account),
Expand Down
10 changes: 8 additions & 2 deletions lib/common/components/accountSelectList.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,27 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:polka_wallet/common/components/addressIcon.dart';
import 'package:polka_wallet/store/account/types/accountData.dart';
import 'package:polka_wallet/store/app.dart';
import 'package:polka_wallet/utils/format.dart';

class AccountSelectList extends StatelessWidget {
AccountSelectList(this.list);
AccountSelectList(this.store, this.list);

final AppStore store;
final List<AccountData> list;

@override
Widget build(BuildContext context) {
Map<String, String> pubKeyAddressMap =
store.account.pubKeyAddressMap[store.settings.endpoint.ss58];
return ListView(
children: list.map((i) {
return ListTile(
leading: AddressIcon(i.address, pubKey: i.pubKey),
title: Text(Fmt.accountName(context, i)),
subtitle: Text(Fmt.address(i.address) ?? ''),
subtitle: Text(Fmt.address(
i.encoded != null ? pubKeyAddressMap[i.pubKey] : i.address) ??
''),
trailing: Icon(Icons.arrow_forward_ios, size: 16),
onTap: () => Navigator.of(context).pop(i),
);
Expand Down
4 changes: 3 additions & 1 deletion lib/common/components/addressFormItem.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ class AddressFormItem extends StatelessWidget {
Widget build(BuildContext context) {
Color grey = Theme.of(context).unselectedWidgetColor;

String address = globalAppStore.account.currentAddress;
String address = globalAppStore
.account.pubKeyAddressMap[globalAppStore.settings.endpoint.ss58]
[account.pubKey];

Column content = Column(
crossAxisAlignment: CrossAxisAlignment.start,
Expand Down
19 changes: 8 additions & 11 deletions lib/common/components/passwordInputDialog.dart
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
import 'package:flutter/cupertino.dart';
import 'package:polka_wallet/service/substrateApi/api.dart';
import 'package:polka_wallet/store/account/types/accountData.dart';
import 'package:polka_wallet/utils/format.dart';
import 'package:polka_wallet/utils/i18n/index.dart';

class PasswordInputDialog extends StatefulWidget {
PasswordInputDialog({this.title, this.onOk});
PasswordInputDialog({this.account, this.title, this.onOk});

final AccountData account;
final Widget title;
final Function onOk;

@override
_PasswordInputDialog createState() =>
_PasswordInputDialog(title: title, onOk: onOk);
_PasswordInputDialog createState() => _PasswordInputDialog();
}

class _PasswordInputDialog extends State<PasswordInputDialog> {
_PasswordInputDialog({this.title, this.onOk});

final Widget title;
final Function(String) onOk;

final TextEditingController _passCtrl = new TextEditingController();

Future<void> _onOk(String password) async {
var res = await webApi.account.checkAccountPassword(password);
var res =
await webApi.account.checkAccountPassword(widget.account, password);
if (res == null) {
final Map<String, String> dic = I18n.of(context).profile;
showCupertinoDialog(
Expand All @@ -42,7 +39,7 @@ class _PasswordInputDialog extends State<PasswordInputDialog> {
},
);
} else {
onOk(password);
widget.onOk(password);
Navigator.of(context).pop();
}
}
Expand All @@ -58,7 +55,7 @@ class _PasswordInputDialog extends State<PasswordInputDialog> {
final Map<String, String> dic = I18n.of(context).home;

return CupertinoAlertDialog(
title: title ?? Container(),
title: widget.title ?? Container(),
content: Padding(
padding: EdgeInsets.only(top: 16),
child: CupertinoTextField(
Expand Down
53 changes: 50 additions & 3 deletions lib/js_service_kusama/src/service/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import {
keyExtractSuri,
mnemonicGenerate,
cryptoWaitReady,
blake2AsU8a,
decodeAddress as decAddress,
} from "@polkadot/util-crypto";
import { hexToU8a, u8aToHex, hexToString } from "@polkadot/util";
import { hexToU8a, u8aToHex, hexToString, u8aConcat } from "@polkadot/util";
import generateIcon from "@polkadot/ui-shared/polkadotIcon";
import registry from "../utils/registry";

import { Keyring } from "@polkadot/keyring";
let keyring = new Keyring({ ss58Format: 0, type: "sr25519" });
Expand Down Expand Up @@ -224,9 +227,45 @@ async function txFeeEstimate(txInfo, paramList) {
return dispatchInfo;
}

function sendTx(txInfo, paramList) {
function createSignPayload(address, cmd, payload) {
return u8aConcat(
new Uint8Array([0x53]),
new Uint8Array([0x01]),
new Uint8Array([cmd]),
decAddress(address),
u8aToU8a(payload)
);
}

function makeTx(txInfo, paramList) {
return new Promise((resolve, reject) => {
const tx = api.tx[txInfo.module][txInfo.call](...paramList);
tx.signAsync(txInfo.address, {
signer: {
signPayload: (payload) => {
// limit size of the transaction
const qrIsHashed = payload.method.length > 5000;
const wrapper = registry.createType("ExtrinsicPayload", payload, {
version: payload.version,
});
const qrPayload = qrIsHashed
? blake2AsU8a(wrapper.toU8a(true))
: wrapper.toU8a();
resolve({
isQrVisible: true,
qrAddress: payload.address,
qrIsHashed,
qrPayload,
});
},
},
}).catch((err) => {});
});
}

function sendTx(txInfo, paramList) {
return new Promise((resolve, reject) => {
let tx = api.tx[txInfo.module][txInfo.call](...paramList);
let unsub = () => {};
const onStatusChange = (result) => {
if (result.status.isInBlock || result.status.isFinalized) {
Expand All @@ -248,7 +287,14 @@ function sendTx(txInfo, paramList) {
return;
}

const keyPair = keyring.getPair(hexToU8a(txInfo.pubKey));
let keyPair;
if (!txInfo.proxy) {
keyPair = keyring.getPair(hexToU8a(txInfo.pubKey));
} else {
tx = api.tx.recovery.asRecovered(txInfo.address, tx);
keyPair = keyring.getPair(hexToU8a(txInfo.proxy));
}

try {
keyPair.decodePkcs8(txInfo.password);
} catch (err) {
Expand Down Expand Up @@ -330,6 +376,7 @@ export default {
getAccountIndex,
getBlockTime,
txFeeEstimate,
makeTx,
sendTx,
checkPassword,
changePassword,
Expand Down
2 changes: 2 additions & 0 deletions lib/page/account/scanPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class ScanPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
Future onScan(String data) async {
print('on scan');
print(data);
String address = '';
if (data != null) {
for (String item in data.split(':')) {
Expand Down
Loading

0 comments on commit 9d5bfff

Please sign in to comment.