fix: fetch from nodes instead of tzkt

This commit is contained in:
detherminal 2023-07-27 23:15:49 +03:00
parent 022ce7ed34
commit 2ee65b584e
2 changed files with 9 additions and 8 deletions

View file

@ -292,8 +292,8 @@ class TezosWallet extends CoinServiceAPI with WalletCache, WalletDB {
} }
Future<void> updateBalance() async { Future<void> updateBalance() async {
var api = "https://api.mainnet.tzkt.io/v1/accounts/${await currentReceivingAddress}/balance"; // TODO: Can we use current node instead of this? var api = "${getCurrentNode().host}:${getCurrentNode().port}/chains/main/blocks/head/context/contracts/${await currentReceivingAddress}/balance";
var theBalance = await get(Uri.parse(api)).then((value) => value.body); var theBalance = (await get(Uri.parse(api)).then((value) => value.body)).substring(1, (await get(Uri.parse(api)).then((value) => value.body)).length - 2);
Logging.instance.log("Balance for ${await currentReceivingAddress}: $theBalance", level: LogLevel.Info); Logging.instance.log("Balance for ${await currentReceivingAddress}: $theBalance", level: LogLevel.Info);
var balanceInAmount = Amount(rawValue: BigInt.parse(theBalance.toString()), fractionDigits: 6); var balanceInAmount = Amount(rawValue: BigInt.parse(theBalance.toString()), fractionDigits: 6);
_balance = Balance( _balance = Balance(
@ -355,9 +355,10 @@ class TezosWallet extends CoinServiceAPI with WalletCache, WalletDB {
} }
Future<void> updateChainHeight() async { Future<void> updateChainHeight() async {
var api = "https://api.tzkt.io/v1/blocks/count"; // TODO: Can we use current node instead of this? var api = "${getCurrentNode().host}:${getCurrentNode().port}/chains/main/blocks/head/header/shell";
var returnedHeight = await get(Uri.parse(api)).then((value) => value.body); var jsonParsedResponse = jsonDecode(await get(Uri.parse(api)).then((value) => value.body));
final int intHeight = int.parse(returnedHeight.toString()); final int intHeight = int.parse(jsonParsedResponse["level"].toString());
Logging.instance.log("Chain height: $intHeight", level: LogLevel.Info);
await updateCachedChainHeight(intHeight); await updateCachedChainHeight(intHeight);
} }
@ -375,7 +376,7 @@ class TezosWallet extends CoinServiceAPI with WalletCache, WalletDB {
@override @override
Future<bool> testNetworkConnection() async{ Future<bool> testNetworkConnection() async{
try { try {
await get(Uri.parse("https://api.mainnet.tzkt.io/v1/accounts/${await currentReceivingAddress}/balance")); await get(Uri.parse("${getCurrentNode().host}:${getCurrentNode().port}/chains/main/blocks/head/header/shell"));
return true; return true;
} catch (e) { } catch (e) {
return false; return false;

View file

@ -182,8 +182,8 @@ abstract class DefaultNodes {
isDown: false isDown: false
); );
static NodeModel get tezos => NodeModel( // TODO: Change this to original one static NodeModel get tezos => NodeModel( // TODO: Change this to stack wallet one
host: "mainnet.api.tez.ie", host: "https://mainnet.api.tez.ie",
port: 443, port: 443,
name: defaultName, name: defaultName,
id: _nodeId(Coin.tezos), id: _nodeId(Coin.tezos),