Skip to content

mwc integration #1016

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

Open
wants to merge 17 commits into
base: mwc
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
[submodule "crypto_plugins/frostdart"]
path = crypto_plugins/frostdart
url = https://github.com/cypherstack/frostdart
[submodule "crypto_plugins/flutter_libmwc"]
path = crypto_plugins/flutter_libmwc
url = https://github.com/vekamo/flutter_libmwc
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Highlights include:
- [Bitcoin Cash](https://bch.info/en/)
- [Dogecoin](https://dogecoin.com/)
- [Epic Cash](https://linktr.ee/epiccash)
- [MimbleWimbleCoin](https://mwc.mw)
- [Ethereum](https://ethereum.org/en/)
- [Firo](https://firo.org/)
- [Litecoin](https://litecoin.org/)
Expand Down
1 change: 1 addition & 0 deletions crypto_plugins/flutter_libmwc
Submodule flutter_libmwc added at 2eb30b
75 changes: 72 additions & 3 deletions lib/db/db_version_migration.dart
Copy link
Collaborator

Choose a reason for hiding this comment

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

This file should be reverted as this file is only for migrations of old data of which there is none for a newly added coin

Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,71 @@ class DbVersionMigrator with WalletDB {
await MainDB.instance.addNewTransactionData(transactionsData, walletId);
}

// we need to manually migrate mimblewimblecoin transactions as they are not
// stored on the mimblewimblecoin blockchain
final mimblewimblecoin = Mimblewimblecoin(CryptoCurrencyNetwork.main);
if (info.coinIdentifier == mimblewimblecoin.identifier) {
final txnData = walletBox.get("latest_tx_model") as TransactionData?;

// we ever only used index 0 in the past
const rcvIndex = 0;

final List<Tuple2<isar_models.Transaction, isar_models.Address?>>
transactionsData = [];
if (txnData != null) {
final txns = txnData.getAllTransactions();

for (final tx in txns.values) {
final bool isIncoming = tx.txType == "Received";

final iTx = isar_models.Transaction(
walletId: walletId,
txid: tx.txid,
timestamp: tx.timestamp,
type: isIncoming
? isar_models.TransactionType.incoming
: isar_models.TransactionType.outgoing,
subType: isar_models.TransactionSubType.none,
amount: tx.amount,
amountString: Amount(
rawValue: BigInt.from(tx.amount),
fractionDigits: mimblewimblecoin.fractionDigits,
).toJsonString(),
fee: tx.fees,
height: tx.height,
isCancelled: tx.isCancelled,
isLelantus: false,
slateId: tx.slateId,
otherData: tx.otherData,
nonce: null,
inputs: [],
outputs: [],
numberOfMessages: tx.numberOfMessages,
);

if (tx.address.isEmpty) {
transactionsData.add(Tuple2(iTx, null));
} else {
final address = isar_models.Address(
walletId: walletId,
value: tx.address,
publicKey: [],
derivationIndex: isIncoming ? rcvIndex : -1,
derivationPath: null,
type: isIncoming
? isar_models.AddressType.mimbleWimble
: isar_models.AddressType.unknown,
subType: isIncoming
? isar_models.AddressSubType.receiving
: isar_models.AddressSubType.unknown,
);
transactionsData.add(Tuple2(iTx, address));
}
}
}
await MainDB.instance.addNewTransactionData(transactionsData, walletId);
}

// delete data from hive
await walletBox.delete(receiveAddressesPrefix);
await walletBox.delete("${receiveAddressesPrefix}P2PKH");
Expand All @@ -553,9 +618,13 @@ class DbVersionMigrator with WalletDB {
);
}

// doing this for epic cash will delete transaction history as it is not
// stored on the epic cash blockchain
if (info.coinIdentifier != epic.identifier) {
// doing this for epiccash/mimblewimblecoin will delete transaction history as it is not
// stored on the epiccash/mimblewimblecoin blockchain
final excludedIdentifiers = [
epic.identifier,
mimblewimblecoin.identifier
];
if ((!excludedIdentifiers.contains(info.coinIdentifier))) {
// set flag to initiate full rescan on opening wallet
await DB.instance.put<dynamic>(
boxName: DB.boxNameDBInfo,
Expand Down
16 changes: 16 additions & 0 deletions lib/db/migrate_wallets_to_isar.dart
Copy link
Collaborator

Choose a reason for hiding this comment

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

This file should be reverted as this file is only for migrations of old data of which there is none for a newly added coin

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import '../wallets/isar/models/token_wallet_info.dart';
import '../wallets/isar/models/wallet_info.dart';
import '../wallets/isar/models/wallet_info_meta.dart';
import '../wallets/wallet/supporting/epiccash_wallet_info_extension.dart';
import '../wallets/wallet/supporting/mimblewimblecoin_wallet_info_extension.dart';
import 'hive/db.dart';
import 'isar/main_db.dart';

Expand Down Expand Up @@ -146,6 +147,21 @@ Future<void> migrateWalletsToIsar({
otherData[WalletInfoKeys.epiccashData] = jsonEncode(
epicWalletInfo.toMap(),
);
} else if (old.coinIdentifier ==
Mimblewimblecoin(CryptoCurrencyNetwork.main)) {
final mimblewimblecoinWalletInfo =
ExtraMimblewimblecoinWalletInfo.fromMap({
"receivingIndex": walletBox.get("receivingIndex") as int? ?? 0,
"changeIndex": walletBox.get("changeIndex") as int? ?? 0,
"slatesToAddresses": walletBox.get("slate_to_address") as Map? ?? {},
"slatesToCommits": walletBox.get("slatesToCommits") as Map? ?? {},
"lastScannedBlock": walletBox.get("lastScannedBlock") as int? ?? 0,
"restoreHeight": walletBox.get("restoreHeight") as int? ?? 0,
"creationHeight": walletBox.get("creationHeight") as int? ?? 0,
});
otherData[WalletInfoKeys.mimblewimblecoinData] = jsonEncode(
mimblewimblecoinWalletInfo.toMap(),
);
} else if (old.coinIdentifier ==
Firo(CryptoCurrencyNetwork.main).identifier ||
old.coinIdentifier == Firo(CryptoCurrencyNetwork.test).identifier) {
Expand Down
71 changes: 71 additions & 0 deletions lib/models/isar/models/blockchain_data/v2/transaction_v2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ class TransactionV2 {

bool get isEpiccashTransaction =>
_getFromOtherData(key: TxV2OdKeys.isEpiccashTransaction) == true;
bool get isMimblewimblecoinTransaction =>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Insert the @ignore annotation above bool get isMimblewimblecoinTransaction => so build runner will ignore generating and updating the isar schema for this value. It is not needed and Isar isn't that great for automatically updating ORM stuff.

_getFromOtherData(key: TxV2OdKeys.isMimblewimblecoinTransaction) == true;
int? get numberOfMessages =>
_getFromOtherData(key: TxV2OdKeys.numberOfMessages) as int?;
String? get slateId => _getFromOtherData(key: TxV2OdKeys.slateId) as String?;
Expand Down Expand Up @@ -287,6 +289,74 @@ class TransactionV2 {
}
}

if (isMimblewimblecoinTransaction) {
if (slateId == null) {
return "Restored Funds";
}

if (isCancelled) {
return "Cancelled";
} else if (type == TransactionType.incoming) {
if (isConfirmed(currentChainHeight, minConfirms, minCoinbaseConfirms)) {
return "Received";
} else {
if (numberOfMessages == 1) {
return "Receiving (waiting for sender)";
} else if ((numberOfMessages ?? 0) > 1) {
return "Receiving (waiting for confirmations)"; // TODO test if the sender still has to open again after the receiver has 2 messages present, ie. sender->receiver->sender->node (yes) vs. sender->receiver->node (no)
} else {
return "Receiving ${prettyConfirms()}";
}
}
} else if (type == TransactionType.outgoing) {
if (isConfirmed(currentChainHeight, minConfirms, minCoinbaseConfirms)) {
return "Sent (confirmed)";
} else {
if (numberOfMessages == 1) {
return "Sending (waiting for receiver)";
} else if ((numberOfMessages ?? 0) > 1) {
return "Sending (waiting for confirmations)";
} else {
return "Sending ${prettyConfirms()}";
}
}
}
}

if (isMimblewimblecoinTransaction) {
if (slateId == null) {
return "Restored Funds";
}

if (isCancelled) {
return "Cancelled";
} else if (type == TransactionType.incoming) {
if (isConfirmed(currentChainHeight, minConfirms, minCoinbaseConfirms)) {
return "Received";
} else {
if (numberOfMessages == 1) {
return "Receiving (waiting for sender)";
} else if ((numberOfMessages ?? 0) > 1) {
return "Receiving (waiting for confirmations)"; // TODO test if the sender still has to open again after the receiver has 2 messages present, ie. sender->receiver->sender->node (yes) vs. sender->receiver->node (no)
} else {
return "Receiving ${prettyConfirms()}";
}
}
} else if (type == TransactionType.outgoing) {
if (isConfirmed(currentChainHeight, minConfirms, minCoinbaseConfirms)) {
return "Sent (confirmed)";
} else {
if (numberOfMessages == 1) {
return "Sending (waiting for receiver)";
} else if ((numberOfMessages ?? 0) > 1) {
return "Sending (waiting for confirmations)";
} else {
return "Sending ${prettyConfirms()}";
}
}
}
}

if (type == TransactionType.incoming) {
// if (_transaction.isMinting) {
// return "Minting";
Expand Down Expand Up @@ -347,6 +417,7 @@ abstract final class TxV2OdKeys {
static const size = "size";
static const vSize = "vSize";
static const isEpiccashTransaction = "isEpiccashTransaction";
static const isMimblewimblecoinTransaction = "isMimblewimblecoinTransaction";
static const numberOfMessages = "numberOfMessages";
static const slateId = "slateId";
static const onChainNote = "onChainNote";
Expand Down
Loading