feat: allow idty with index 0; certsData is nullable
This commit is contained in:
parent
dbdfd0c4fb
commit
08ea8445ad
|
@ -137,12 +137,15 @@ class SubstrateSdk with ChangeNotifier {
|
||||||
////////// 2: GET ONCHAIN STORAGE //////////
|
////////// 2: GET ONCHAIN STORAGE //////////
|
||||||
////////////////////////////////////////////
|
////////////////////////////////////////////
|
||||||
|
|
||||||
Future<int> _getIdentityIndexOf(String address) async {
|
Future<int?> _getIdentityIndexOf(String address) async {
|
||||||
return await _getStorage('identity.identityIndexOf("$address")') ?? 0;
|
return await _getStorage('identity.identityIndexOf("$address")');
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<int>> getCertsCounter(String address) async {
|
Future<List<int>?> getCertsCounter(String address) async {
|
||||||
final idtyIndex = await _getIdentityIndexOf(address);
|
final idtyIndex = await _getIdentityIndexOf(address);
|
||||||
|
if (idtyIndex == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
final certsReceiver =
|
final certsReceiver =
|
||||||
await _getStorage('cert.storageIdtyCertMeta($idtyIndex)') ?? [];
|
await _getStorage('cert.storageIdtyCertMeta($idtyIndex)') ?? [];
|
||||||
|
|
||||||
|
@ -400,7 +403,7 @@ class SubstrateSdk with ChangeNotifier {
|
||||||
|
|
||||||
var idtyIndex = await _getIdentityIndexOf(address);
|
var idtyIndex = await _getIdentityIndexOf(address);
|
||||||
|
|
||||||
if (idtyIndex == 0) {
|
if (idtyIndex == null) {
|
||||||
return 'noid';
|
return 'noid';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -983,7 +986,7 @@ class SubstrateSdk with ChangeNotifier {
|
||||||
// log.d('debug: ${currencyParameters['minCertForMembership']}');
|
// log.d('debug: ${currencyParameters['minCertForMembership']}');
|
||||||
|
|
||||||
log.d(
|
log.d(
|
||||||
"debug toCert: ${toCerts[0]} --- ${currencyParameters['minCertForMembership']!} --- $toIdtyStatus");
|
"debug toCert: ${toCerts?[0]} --- ${currencyParameters['minCertForMembership']!} --- $toIdtyStatus");
|
||||||
|
|
||||||
if (toIdtyStatus == 'noid') {
|
if (toIdtyStatus == 'noid') {
|
||||||
txInfo = TxInfoData(
|
txInfo = TxInfoData(
|
||||||
|
@ -994,7 +997,7 @@ class SubstrateSdk with ChangeNotifier {
|
||||||
txOptions = [destAddress];
|
txOptions = [destAddress];
|
||||||
} else if (toIdtyStatus == 'Validated' ||
|
} else if (toIdtyStatus == 'Validated' ||
|
||||||
toIdtyStatus == 'ConfirmedByOwner') {
|
toIdtyStatus == 'ConfirmedByOwner') {
|
||||||
if (toCerts[0] >= currencyParameters['minCertForMembership']! - 1 &&
|
if (toCerts![0] >= currencyParameters['minCertForMembership']! - 1 &&
|
||||||
toIdtyStatus != 'Validated') {
|
toIdtyStatus != 'Validated') {
|
||||||
log.i('Batch cert and membership validation');
|
log.i('Batch cert and membership validation');
|
||||||
txInfo = TxInfoData(
|
txInfo = TxInfoData(
|
||||||
|
@ -1055,7 +1058,7 @@ class SubstrateSdk with ChangeNotifier {
|
||||||
final prefix = 'icok'.codeUnits;
|
final prefix = 'icok'.codeUnits;
|
||||||
final genesisHashString = await getGenesisHash();
|
final genesisHashString = await getGenesisHash();
|
||||||
final genesisHash = HEX.decode(genesisHashString.substring(2)) as Uint8List;
|
final genesisHash = HEX.decode(genesisHashString.substring(2)) as Uint8List;
|
||||||
final idtyIndex = _int32bytes(await _getIdentityIndexOf(fromAddress));
|
final idtyIndex = _int32bytes((await _getIdentityIndexOf(fromAddress))!);
|
||||||
final oldPubkey = await addressToPubkey(fromAddress);
|
final oldPubkey = await addressToPubkey(fromAddress);
|
||||||
final messageToSign =
|
final messageToSign =
|
||||||
Uint8List.fromList(prefix + genesisHash + idtyIndex + oldPubkey);
|
Uint8List.fromList(prefix + genesisHash + idtyIndex + oldPubkey);
|
||||||
|
@ -1114,7 +1117,7 @@ newKeySig: $newKeySig""");
|
||||||
final prefix = 'revo'.codeUnits;
|
final prefix = 'revo'.codeUnits;
|
||||||
final genesisHashString = await getGenesisHash();
|
final genesisHashString = await getGenesisHash();
|
||||||
final genesisHash = HEX.decode(genesisHashString.substring(2)) as Uint8List;
|
final genesisHash = HEX.decode(genesisHashString.substring(2)) as Uint8List;
|
||||||
final idtyIndexBytes = _int32bytes(idtyIndex);
|
final idtyIndexBytes = _int32bytes(idtyIndex!);
|
||||||
final messageToSign =
|
final messageToSign =
|
||||||
Uint8List.fromList(prefix + genesisHash + idtyIndexBytes);
|
Uint8List.fromList(prefix + genesisHash + idtyIndexBytes);
|
||||||
final revocationSig =
|
final revocationSig =
|
||||||
|
|
|
@ -42,8 +42,6 @@ class WalletOptions extends StatelessWidget {
|
||||||
final duniterIndexer = Provider.of<DuniterIndexer>(context, listen: false);
|
final duniterIndexer = Provider.of<DuniterIndexer>(context, listen: false);
|
||||||
|
|
||||||
final sub = Provider.of<SubstrateSdk>(context, listen: false);
|
final sub = Provider.of<SubstrateSdk>(context, listen: false);
|
||||||
// sub.spawnBlock();
|
|
||||||
// sub.spawnBlock(0, 20);
|
|
||||||
|
|
||||||
log.d(walletOptions.address.text);
|
log.d(walletOptions.address.text);
|
||||||
|
|
||||||
|
|
|
@ -19,10 +19,8 @@ class Certifications extends StatelessWidget {
|
||||||
Consumer<SubstrateSdk>(builder: (context, sdk, _) {
|
Consumer<SubstrateSdk>(builder: (context, sdk, _) {
|
||||||
return FutureBuilder(
|
return FutureBuilder(
|
||||||
future: sdk.getCertsCounter(address),
|
future: sdk.getCertsCounter(address),
|
||||||
builder: (BuildContext context, AsyncSnapshot<List<int>> certs) {
|
builder: (BuildContext context, AsyncSnapshot<List<int>?> certs) {
|
||||||
// log.d(_certs.data);
|
return certs.data != null
|
||||||
|
|
||||||
return certs.data?[0] != 0 && certs.data != null
|
|
||||||
? Row(
|
? Row(
|
||||||
children: [
|
children: [
|
||||||
Image.asset('assets/medal.png', height: 20),
|
Image.asset('assets/medal.png', height: 20),
|
||||||
|
|
Loading…
Reference in New Issue