Skip to content

Commit 2d90943

Browse files
authored
Merge pull request #1157 from cypherstack/mweb
Initial Mweb
2 parents 157dccb + 401af1f commit 2d90943

File tree

134 files changed

+6471
-2848
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+6471
-2848
lines changed

docs/building.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Here you will find instructions on how to install the necessary tools for buildi
77
- The only OS supported for building Android and Linux desktop is Ubuntu 20.04. Windows builds require using Ubuntu 20.04 on WSL2. macOS builds for itself and iOS. Advanced users may also be able to build on other Debian-based distributions like Linux Mint.
88
- Android setup ([Android Studio](https://developer.android.com/studio) and subsequent dependencies)
99
- 100 GB of storage
10+
- Install go: [https://go.dev/doc/install](https://go.dev/doc/install)
1011

1112
## Linux host
1213

@@ -163,6 +164,8 @@ cd scripts/windows
163164
./deps.sh
164165
```
165166

167+
install go in WSL [https://go.dev/doc/install](https://go.dev/doc/install) (follow linux instructions) and ensure you have `x86_64-w64-mingw32-gcc`
168+
166169
and use `scripts/build_app.sh` to build plugins:
167170
```
168171
cd ..

lib/db/drift/database.dart

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111
import 'dart:async';
12+
import 'dart:math' as math;
1213

1314
import 'package:drift/drift.dart';
1415
import 'package:drift_flutter/drift_flutter.dart';
@@ -44,13 +45,56 @@ class SparkNames extends Table {
4445
Set<Column> get primaryKey => {name};
4546
}
4647

47-
@DriftDatabase(tables: [SparkNames])
48+
class MwebUtxos extends Table {
49+
TextColumn get outputId => text()();
50+
TextColumn get address => text()();
51+
IntColumn get value => integer()();
52+
IntColumn get height => integer()();
53+
IntColumn get blockTime => integer()();
54+
BoolColumn get blocked => boolean()();
55+
BoolColumn get used => boolean()();
56+
57+
@override
58+
Set<Column> get primaryKey => {outputId};
59+
}
60+
61+
extension MwebUtxoExt on MwebUtxo {
62+
int getConfirmations(int currentChainHeight) {
63+
if (blockTime <= 0) return 0;
64+
if (height <= 0) return 0;
65+
return math.max(0, currentChainHeight - (height - 1));
66+
}
67+
68+
bool isConfirmed(
69+
int currentChainHeight,
70+
int minimumConfirms, {
71+
int? overrideMinConfirms,
72+
}) {
73+
final confirmations = getConfirmations(currentChainHeight);
74+
75+
if (overrideMinConfirms != null) {
76+
return confirmations >= overrideMinConfirms;
77+
}
78+
return confirmations >= minimumConfirms;
79+
}
80+
}
81+
82+
@DriftDatabase(tables: [SparkNames, MwebUtxos])
4883
final class WalletDatabase extends _$WalletDatabase {
4984
WalletDatabase._(String walletId, [QueryExecutor? executor])
5085
: super(executor ?? _openConnection(walletId));
5186

5287
@override
53-
int get schemaVersion => 1;
88+
int get schemaVersion => 2;
89+
90+
@override
91+
MigrationStrategy get migration => MigrationStrategy(
92+
onUpgrade: (m, from, to) async {
93+
if (from == 1 && to == 2) {
94+
await m.createTable(mwebUtxos);
95+
}
96+
},
97+
);
5498

5599
static QueryExecutor _openConnection(String walletId) {
56100
return driftDatabase(

0 commit comments

Comments
 (0)