Ready to migrate identity, wait for signMessage methode in sdk

https://github.com/polkawallet-io/sdk/issues/31
This commit is contained in:
poka 2022-08-18 18:22:36 +02:00
parent 1b896960ea
commit 237e581d0f
7 changed files with 71 additions and 9 deletions

View File

@ -184,5 +184,6 @@
"youCannotMigrateIdentityToExistingIdentity": "You cannot migrate an identity\nto an account that already has an identity",
"importOldAccount": "Import your old account",
"enterCesiumId": "Enter your Cesium ID",
"enterCesiumPassword": "Enter your Cesium password"
"enterCesiumPassword": "Enter your Cesium password",
"migrateAccount": "Migrate account"
}

View File

@ -184,5 +184,6 @@
"youCannotMigrateIdentityToExistingIdentity": "You cannot migrate an identity\nto an account that already has an identity",
"importOldAccount": "Import your old account",
"enterCesiumId": "Enter your Cesium ID",
"enterCesiumPassword": "Enter your Cesium password"
"enterCesiumPassword": "Enter your Cesium password",
"migrateAccount": "Migrate account"
}

View File

@ -185,5 +185,6 @@
"youCannotMigrateIdentityToExistingIdentity": "Vous ne pouvez pas migrer une identité\nvers un compte disposant déjà d'une identité",
"importOldAccount": "Importer son ancien compte",
"enterCesiumId": "Entrez votre identifiant Cesium",
"enterCesiumPassword": "Entrez votre mot de passe Cesium"
"enterCesiumPassword": "Entrez votre mot de passe Cesium",
"migrateAccount": "Migrer le compte"
}

View File

@ -270,9 +270,19 @@ class SubstrateSdk with ChangeNotifier {
}
}
// Future addressToPubkey(String address) async {
// await sdk.api.account.decodeAddress([address]);
// }
Future<String> getGenesisHash() async {
final String genesisHash = await sdk.webView!.evalJavascript(
'api.genesisHash.toHex()',
wrapPromise: false,
) ??
'';
// log.d('genesisHash: $genesisHash');
return genesisHash;
}
Future addressToPubkey(String address) async {
await sdk.api.account.decodeAddress([address]);
}
// Future pubkeyToAddress(String pubkey) async {
// await sdk.api.account.encodeAddress([pubkey]);
@ -784,6 +794,45 @@ class SubstrateSdk with ChangeNotifier {
return await executeCall(txInfo, txOptions, password);
}
Future<String> migrateIdentity(
{required String fromAddress,
required String destAddress,
required String password}) async {
transactionStatus = '';
final fromPubkey = await sdk.api.account.decodeAddress([fromAddress]);
final sender = TxSenderData(
fromAddress,
fromPubkey!.keys.first,
);
// final globalBalance = await getBalance(fromAddress);
TxInfoData txInfo;
List txOptions = [];
String? rawParams;
// final destKeyring = getKeypair(destAddress);
final genesisHash = await getGenesisHash();
final idtyIndex = await getIdentityIndexOf(destAddress);
// final oldPubkey = await addressToPubkey(fromAddress);
final messageToSign = 'icok$genesisHash$idtyIndex$fromAddress';
final newKeySig = messageToSign;
txInfo = TxInfoData(
'utility',
'batchAll',
sender,
);
const tx1 = 'api.tx.universalDividend.claimUds()';
final tx2 = 'api.tx.identity.changeOwnerKey("$destAddress", "$newKeySig")';
const tx3 = 'api.tx.balances.transferAll(false)';
rawParams = '[[$tx1, $tx2, $tx3]]';
log.d(
'g1migration args: ${txInfo.module}, ${txInfo.call}, $txOptions, $rawParams');
return await executeCall(txInfo, txOptions, password, rawParams);
}
Future revokeIdentity(String address, String password) async {
final idtyIndex = await getIdentityIndexOf(address);
@ -837,7 +886,13 @@ class SubstrateSdk with ChangeNotifier {
password: password,
);
if (balance != 0) {
log.d('g1migration idtyStatus: $idtyStatus');
if (idtyStatus != 'noid') {
await migrateIdentity(
fromAddress: keypair.address!,
destAddress: destAddress,
password: 'password');
} else if (balance != 0) {
await pay(
fromAddress: keypair.address!,
destAddress: destAddress,

View File

@ -62,6 +62,8 @@ class ImportG1v1 extends StatelessWidget {
final myIdtyStatus = status.data?[2];
final hasConsumer = status.data?[3] ?? false;
// log.d('hasconsumer: $hasConsumer');
if (balance != 0 && !hasConsumer) {
canValidate = true;
validationStatus = '';
@ -216,7 +218,6 @@ class ImportG1v1 extends StatelessWidget {
selectedWallet.address!,
balance: balance,
idtyStatus: idtyStatus);
Navigator.push(
context,
MaterialPageRoute(builder: (context) {
@ -227,7 +228,7 @@ class ImportG1v1 extends StatelessWidget {
}
: null,
child: Text(
'validate'.tr(),
'migrateAccount'.tr(),
style: TextStyle(
fontSize: 23 * ratio,
fontWeight: FontWeight.w600),

View File

@ -88,6 +88,7 @@ class TransactionInProgress extends StatelessWidget {
if (result.contains('blockHash: ')) {
isValid = true;
resultText = 'extrinsicValidated'.tr(args: [actionName]);
log.i('Bloc of last transaction: ${sub.blocNumber} --- $result');
} else {
isValid = false;
resultText = "${"anErrorOccured".tr()}:\n";

View File

@ -62,6 +62,8 @@ dependencies:
package_info_plus: ^1.4.2
polkawallet_sdk: #^0.4.9
git:
# url: https://github.com/polkawallet-io/sdk.git
# ref: develop
url: https://github.com/poka-IT/sdk.git
ref: gecko-old
dots_indicator: ^2.1.0