11import 'package:flutter/widgets.dart' ;
22import 'package:sembast/sembast.dart' ;
3+ import 'package:sembast/utils/value_utils.dart' ;
34import 'package:sentinelx/models/db/txDB.dart' ;
5+ import 'package:sentinelx/shared_state/appState.dart' ;
46
57import '../db_test.dart' ;
68
@@ -36,7 +38,10 @@ class Tx {
3638 String key;
3739 static const String STORE_NAME = 'txs' ;
3840
39- static Future <Database > get _db async => await TxDB .instance.database;
41+ //associated xpub and address will be updated in this filed
42+ List <String > associatedWallets = [];
43+
44+ static Future <Database > get _db async => await TxDB .instance (AppState ().selectedWallet.getTxDb ()).database;
4045 static final txStore = stringMapStoreFactory.store (STORE_NAME );
4146
4247 Tx (
@@ -68,6 +73,10 @@ class Tx {
6873 out.add (new Out .fromJson (v));
6974 });
7075 }
76+ if (json['associatedWallets' ] != null ) {
77+ List <String > wallets = json['associatedWallets' ].cast <String >();
78+ this .associatedWallets = wallets.toList ();
79+ }
7180 blockHeight = json['block_height' ];
7281 balance = json['balance' ];
7382 }
@@ -87,27 +96,70 @@ class Tx {
8796 }
8897 data['block_height' ] = this .blockHeight;
8998 data['balance' ] = this .balance;
90- data['key' ] = this .hash;
99+ // data['key'] = this.hash;
100+
101+ if (this .associatedWallets != null ) {
102+ data['associatedWallets' ] = this .associatedWallets;
103+ }
91104 return data;
92105 }
93106
94- static Future insert (List <Tx > items) async {
95- var db = await _db;
96- await db.transaction ((txn) async {
97- for (var i = 0 ; i < items.length; i++ ) {
98- await txStore.add (txn, items[i].toJson ());
107+ void update (Map <String , dynamic > jsonTx, bool isXpub) {
108+ jsonTx.keys.forEach ((key) {
109+ switch (key) {
110+ case "hash" :
111+ {
112+ hash = jsonTx['hash' ];
113+ break ;
114+ }
115+ case "time" :
116+ {
117+ time = jsonTx['time' ];
118+ break ;
119+ }
120+ case "version" :
121+ {
122+ version = jsonTx['version' ];
123+ break ;
124+ }
125+ case "locktime" :
126+ {
127+ locktime = jsonTx['locktime' ];
128+ break ;
129+ }
130+ case "result" :
131+ {
132+ result = jsonTx['result' ];
133+ break ;
134+ }
135+ case "inputs" :
136+ {
137+ if (jsonTx['inputs' ] != null ) {
138+ inputs = new List <Inputs >();
139+ jsonTx['inputs' ].forEach ((v) {
140+ inputs.add (new Inputs .fromJson (v));
141+ });
142+ }
143+ break ;
144+ }
145+ case "out" :
146+ {
147+ if (jsonTx['out' ] != null ) {
148+ out = new List <Out >();
149+ jsonTx['out' ].forEach ((v) {
150+ out.add (new Out .fromJson (v));
151+ });
152+ }
153+ break ;
154+ }
155+ case "block_height" :
156+ {
157+ blockHeight = jsonTx['block_height' ];
158+ break ;
159+ }
99160 }
100161 });
101162 }
102-
103- static Future <List <Tx >> getTxes () async {
104- final recordSnapshots = await txStore.find (await _db);
105- return recordSnapshots.map ((snapshot) {
106- final tx = Tx .fromJson (snapshot.value);
107- tx.key = snapshot.key;
108- return tx;
109- }).toList ();
110- }
111163}
112164
113165class PrevOut {
@@ -218,3 +270,10 @@ class Address {
218270 return data;
219271 }
220272}
273+
274+ class ListSection extends Tx {
275+ String section = "" ;
276+ DateTime timeStamp = DateTime .now ();
277+ ListSection ({this .section, this .timeStamp});
278+
279+ }
0 commit comments