Skip to content

Commit

Permalink
fix: fetch from nodes instead of tzkt
Browse files Browse the repository at this point in the history
  • Loading branch information
detherminal committed Jul 27, 2023
1 parent 022ce7e commit 2ee65b5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 7 additions & 6 deletions lib/services/coins/tezos/tezos_wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ class TezosWallet extends CoinServiceAPI with WalletCache, WalletDB {
}

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 theBalance = await get(Uri.parse(api)).then((value) => value.body);
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)).substring(1, (await get(Uri.parse(api)).then((value) => value.body)).length - 2);
Logging.instance.log("Balance for ${await currentReceivingAddress}: $theBalance", level: LogLevel.Info);
var balanceInAmount = Amount(rawValue: BigInt.parse(theBalance.toString()), fractionDigits: 6);
_balance = Balance(
Expand Down Expand Up @@ -355,9 +355,10 @@ class TezosWallet extends CoinServiceAPI with WalletCache, WalletDB {
}

Future<void> updateChainHeight() async {
var api = "https://api.tzkt.io/v1/blocks/count"; // TODO: Can we use current node instead of this?
var returnedHeight = await get(Uri.parse(api)).then((value) => value.body);
final int intHeight = int.parse(returnedHeight.toString());
var api = "${getCurrentNode().host}:${getCurrentNode().port}/chains/main/blocks/head/header/shell";
var jsonParsedResponse = jsonDecode(await get(Uri.parse(api)).then((value) => value.body));
final int intHeight = int.parse(jsonParsedResponse["level"].toString());
Logging.instance.log("Chain height: $intHeight", level: LogLevel.Info);
await updateCachedChainHeight(intHeight);
}

Expand All @@ -375,7 +376,7 @@ class TezosWallet extends CoinServiceAPI with WalletCache, WalletDB {
@override
Future<bool> testNetworkConnection() async{
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;
} catch (e) {
return false;
Expand Down
4 changes: 2 additions & 2 deletions lib/utilities/default_nodes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ abstract class DefaultNodes {
isDown: false
);

static NodeModel get tezos => NodeModel( // TODO: Change this to original one
host: "mainnet.api.tez.ie",
static NodeModel get tezos => NodeModel( // TODO: Change this to stack wallet one
host: "https://mainnet.api.tez.ie",
port: 443,
name: defaultName,
id: _nodeId(Coin.tezos),
Expand Down

0 comments on commit 2ee65b5

Please sign in to comment.