eth trueblocks fetch token abi call

This commit is contained in:
julian 2023-03-23 18:04:47 -06:00
parent 1cca6e8e70
commit 85c416fb50

View file

@ -427,34 +427,27 @@ abstract class EthereumAPI {
} }
} }
static Future<EthereumResponse<String>> getTokenAbi( static Future<EthereumResponse<String>> getTokenAbi({
String contractAddress) async { required String name,
required String contractAddress,
}) async {
try { try {
final response = await get( final response = await get(
Uri.parse( Uri.parse(
"$stackBaseServer/abis?addrs=$contractAddress", "$stackBaseServer/abis?addrs=$contractAddress&verbose=true",
), ),
); );
if (response.statusCode == 200) { if (response.statusCode == 200) {
final json = jsonDecode(response.body)["data"] as List; final json = jsonDecode(response.body)["data"] as List;
// trueblocks api does not contain the `anonymous` value
// web3dart expects it so hack it in
// TODO: fix this if we ever actually need to use contract ABI events
for (final map in json) {
if (map["type"] == "event") {
map["anonymous"] = false;
}
}
return EthereumResponse( return EthereumResponse(
jsonEncode(json), jsonEncode(json),
null, null,
); );
} else { } else {
throw EthApiException( throw EthApiException(
"getTokenAbi($contractAddress) failed with status code: " "getTokenAbi($name, $contractAddress) failed with status code: "
"${response.statusCode}", "${response.statusCode}",
); );
} }
@ -465,7 +458,7 @@ abstract class EthereumAPI {
); );
} catch (e, s) { } catch (e, s) {
Logging.instance.log( Logging.instance.log(
"getTokenAbi(): $e\n$s", "getTokenAbi($name, $contractAddress): $e\n$s",
level: LogLevel.Error, level: LogLevel.Error,
); );
return EthereumResponse( return EthereumResponse(