@@ -332,60 +332,61 @@ class TezosWallet extends CoinServiceAPI with WalletCache, WalletDB {
332332
333333 Future <void > updateTransactions () async {
334334 // TODO: Use node RPC instead of tzstats API
335- var api =
336- "https://api.tzstats.com/tables/op?address=${await currentReceivingAddress }" ;
337- var jsonResponse =
338- jsonDecode (await get (Uri .parse (api)).then ((value) => value.body));
335+ var api = "https://api.tzstats.com/tables/op?address=${await currentReceivingAddress }" ;
336+ var jsonResponse = jsonDecode (await get (Uri .parse (api)).then ((value) => value.body));
339337 List <Tuple2 <Transaction , Address >> txs = [];
340338 for (var tx in jsonResponse as List ) {
341- var txApi = "https://api.tzstats.com/explorer/op/${tx ["hash" ]}" ;
342- var txJsonResponse = jsonDecode (
343- await get (Uri .parse (txApi)).then ((value) => value.body))[0 ];
344- TransactionType txType;
345- if (txJsonResponse["sender" ] == (await currentReceivingAddress)) {
346- txType = TransactionType .outgoing;
347- } else {
348- txType = TransactionType .incoming;
339+ if (tx[1 ] == "transaction" ) {
340+ var txApi = "https://api.tzstats.com/explorer/op/${tx [2 ]}" ;
341+ var txJsonResponse = jsonDecode (await get (Uri .parse (txApi)).then ((value) => value.body));
342+ // Check if list is larger than 1 (if it is, it's a batch transaction)
343+ if (! ((txJsonResponse as List ).length > 1 )) {
344+ for (var (opJson as Map ) in txJsonResponse) {
345+ if (opJson.containsKey ("volume" )) { // This is to check if transaction is a token transfer
346+ TransactionType txType;
347+ if (opJson["sender" ] == (await currentReceivingAddress)) {
348+ txType = TransactionType .outgoing;
349+ } else {
350+ txType = TransactionType .incoming;
351+ }
352+ var theTx = Transaction (
353+ walletId: walletId,
354+ txid: opJson["hash" ].toString (),
355+ timestamp: DateTime .parse (opJson["time" ].toString ()).toUtc ().millisecondsSinceEpoch ~ / 1000 ,
356+ type: txType,
357+ subType: TransactionSubType .none,
358+ amount: (float.parse (opJson["volume" ].toString ()) * 1000000 ).toInt (),
359+ amountString: Amount (
360+ rawValue: BigInt .parse ((float.parse (opJson["volume" ].toString ()) * 1000000 ).toInt ().toString ()),
361+ fractionDigits: 6
362+ ).toJsonString (),
363+ fee: (float.parse (opJson["fee" ].toString ()) * 1000000 ).toInt (),
364+ height: int .parse (opJson["height" ].toString ()),
365+ isCancelled: false ,
366+ isLelantus: false ,
367+ slateId: "" ,
368+ otherData: "" ,
369+ inputs: [],
370+ outputs: [],
371+ nonce: 0 ,
372+ numberOfMessages: null ,
373+ );
374+ var theAddress = Address (
375+ walletId: walletId,
376+ value: opJson["receiver" ].toString (),
377+ publicKey: [], // TODO: Add public key
378+ derivationIndex: 0 ,
379+ derivationPath: null ,
380+ type: AddressType .unknown,
381+ subType: AddressSubType .unknown,
382+ );
383+ txs.add (Tuple2 (theTx, theAddress));
384+ }
385+ }
386+ }
349387 }
350- var theTx = Transaction (
351- walletId: walletId,
352- txid: txJsonResponse["hash" ].toString (),
353- timestamp: DateTime .parse (txJsonResponse["time" ].toString ())
354- .toUtc ()
355- .millisecondsSinceEpoch ~ /
356- 1000 ,
357- type: txType,
358- subType: TransactionSubType .none,
359- amount: (float.parse (txJsonResponse["volume" ].toString ()) * 1000000 )
360- .toInt (),
361- amountString: Amount (
362- rawValue: BigInt .parse (
363- (float.parse (txJsonResponse["volume" ].toString ()) * 1000000 )
364- .toString ()),
365- fractionDigits: 6 )
366- .toJsonString (),
367- fee: (float.parse (txJsonResponse["fee" ].toString ()) * 1000000 ).toInt (),
368- height: int .parse (txJsonResponse["height" ].toString ()),
369- isCancelled: false ,
370- isLelantus: false ,
371- slateId: "" ,
372- otherData: "" ,
373- inputs: [],
374- outputs: [],
375- nonce: 0 ,
376- numberOfMessages: null ,
377- );
378- var theAddress = Address (
379- walletId: walletId,
380- value: txJsonResponse["receiver" ].toString (),
381- publicKey: [], // TODO: Add public key
382- derivationIndex: 0 ,
383- derivationPath: null ,
384- type: AddressType .unknown,
385- subType: AddressSubType .unknown,
386- );
387- txs.add (Tuple2 (theTx, theAddress));
388388 }
389+ Logging .instance.log ("Transactions: $txs " , level: LogLevel .Info );
389390 await db.addNewTransactionData (txs, walletId);
390391 }
391392
0 commit comments