mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-24 19:25:52 +00:00
fetch correct proxy token ABI
This commit is contained in:
parent
2181e10163
commit
b7eaf9a8c2
2 changed files with 91 additions and 138 deletions
|
@ -465,89 +465,42 @@ abstract class EthereumAPI {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// static Future<EthereumResponse<String>> getTokenAbi22(
|
/// Fetch the underlying contract address that a proxy contract points to
|
||||||
// String contractAddress) async {
|
static Future<EthereumResponse<String>> getProxyTokenImplementationAddress(
|
||||||
// try {
|
String contractAddress,
|
||||||
// final response = await get(
|
) async {
|
||||||
// Uri.parse(
|
try {
|
||||||
// "https://api.etherscan.io/api?module=contract&action=getabi&address=$contractAddress&apikey=EG6J7RJIQVSTP2BS59D3TY2G55YHS5F2HP",
|
final response = await get(Uri.parse(
|
||||||
// ),
|
"$stackBaseServer/state?addrs=$contractAddress&parts=proxy"));
|
||||||
// );
|
if (response.statusCode == 200) {
|
||||||
//
|
final json = jsonDecode(response.body);
|
||||||
// if (response.statusCode == 200) {
|
final list = json["data"] as List;
|
||||||
// final json = jsonDecode(response.body) as Map;
|
final map = Map<String, dynamic>.from(list.first as Map);
|
||||||
// print("========================== 222222222222222 ================");
|
|
||||||
// dev.log((jsonDecode(json["result"] as String)).toString());
|
|
||||||
// print(
|
|
||||||
// "============================ 2222222222222222222 ==============");
|
|
||||||
//
|
|
||||||
// return EthereumResponse(
|
|
||||||
// json["result"] as String,
|
|
||||||
// null,
|
|
||||||
// );
|
|
||||||
// } else {
|
|
||||||
// throw EthApiException(
|
|
||||||
// "getTokenAbi($contractAddress) failed with status code: "
|
|
||||||
// "${response.statusCode}",
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// } on EthApiException catch (e) {
|
|
||||||
// return EthereumResponse(
|
|
||||||
// null,
|
|
||||||
// e,
|
|
||||||
// );
|
|
||||||
// } catch (e, s) {
|
|
||||||
// Logging.instance.log(
|
|
||||||
// "getTokenAbi(): $e\n$s",
|
|
||||||
// level: LogLevel.Error,
|
|
||||||
// );
|
|
||||||
// return EthereumResponse(
|
|
||||||
// null,
|
|
||||||
// EthApiException(e.toString()),
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// /// Fetch the underlying contract address that a proxy contract points to
|
return EthereumResponse(
|
||||||
// static Future<EthereumResponse<String>> getProxyTokenImplementation(
|
map["proxy"] as String,
|
||||||
// String contractAddress) async {
|
null,
|
||||||
// try {
|
);
|
||||||
// final response = await get(Uri.parse(
|
} else {
|
||||||
// "$stackURI?module=contract&action=getsourcecode&address=$contractAddress"));
|
throw EthApiException(
|
||||||
// // "$etherscanApi?module=contract&action=getsourcecode&address=$contractAddress&apikey=EG6J7RJIQVSTP2BS59D3TY2G55YHS5F2HP"));
|
"getProxyTokenImplementationAddress($contractAddress) failed with"
|
||||||
// if (response.statusCode == 200) {
|
" status code: ${response.statusCode}",
|
||||||
// final json = jsonDecode(response.body);
|
);
|
||||||
// if (json["message"] == "OK") {
|
}
|
||||||
// final list = json["result"] as List;
|
} on EthApiException catch (e) {
|
||||||
// final map = Map<String, dynamic>.from(list.first as Map);
|
return EthereumResponse(
|
||||||
//
|
null,
|
||||||
// return EthereumResponse(
|
e,
|
||||||
// map["Implementation"] as String,
|
);
|
||||||
// null,
|
} catch (e, s) {
|
||||||
// );
|
Logging.instance.log(
|
||||||
// } else {
|
"getProxyTokenImplementationAddress($contractAddress) : $e\n$s",
|
||||||
// throw EthApiException(json["message"] as String);
|
level: LogLevel.Error,
|
||||||
// }
|
);
|
||||||
// } else {
|
return EthereumResponse(
|
||||||
// throw EthApiException(
|
null,
|
||||||
// "fetchProxyTokenImplementation($contractAddress) failed with status code: "
|
EthApiException(e.toString()),
|
||||||
// "${response.statusCode}",
|
);
|
||||||
// );
|
}
|
||||||
// }
|
}
|
||||||
// } on EthApiException catch (e) {
|
|
||||||
// return EthereumResponse(
|
|
||||||
// null,
|
|
||||||
// e,
|
|
||||||
// );
|
|
||||||
// } catch (e, s) {
|
|
||||||
// Logging.instance.log(
|
|
||||||
// "fetchProxyTokenImplementation(): $e\n$s",
|
|
||||||
// level: LogLevel.Error,
|
|
||||||
// );
|
|
||||||
// return EthereumResponse(
|
|
||||||
// null,
|
|
||||||
// EthApiException(e.toString()),
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:convert';
|
|
||||||
|
|
||||||
import 'package:decimal/decimal.dart';
|
import 'package:decimal/decimal.dart';
|
||||||
import 'package:ethereum_addresses/ethereum_addresses.dart';
|
import 'package:ethereum_addresses/ethereum_addresses.dart';
|
||||||
|
@ -163,65 +162,66 @@ class EthTokenWallet extends ChangeNotifier with EthTokenCache {
|
||||||
_sendFunction = _deployedContract.function('transfer');
|
_sendFunction = _deployedContract.function('transfer');
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
//====================================================================
|
//====================================================================
|
||||||
final list = List<Map<String, dynamic>>.from(
|
// final list = List<Map<String, dynamic>>.from(
|
||||||
jsonDecode(tokenContract.abi!) as List);
|
// jsonDecode(tokenContract.abi!) as List);
|
||||||
final functionNames = list.map((e) => e["name"] as String);
|
// final functionNames = list.map((e) => e["name"] as String);
|
||||||
|
//
|
||||||
if (!functionNames.contains("balanceOf")) {
|
// if (!functionNames.contains("balanceOf")) {
|
||||||
list.add(
|
// list.add(
|
||||||
{
|
// {
|
||||||
"encoding": "0x70a08231",
|
// "encoding": "0x70a08231",
|
||||||
"inputs": [
|
// "inputs": [
|
||||||
{"name": "account", "type": "address"}
|
// {"name": "account", "type": "address"}
|
||||||
],
|
// ],
|
||||||
"name": "balanceOf",
|
// "name": "balanceOf",
|
||||||
"outputs": [
|
// "outputs": [
|
||||||
{"name": "val_0", "type": "uint256"}
|
// {"name": "val_0", "type": "uint256"}
|
||||||
],
|
// ],
|
||||||
"signature": "balanceOf(address)",
|
// "signature": "balanceOf(address)",
|
||||||
"type": "function"
|
// "type": "function"
|
||||||
},
|
// },
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if (!functionNames.contains("transfer")) {
|
// if (!functionNames.contains("transfer")) {
|
||||||
list.add(
|
// list.add(
|
||||||
{
|
// {
|
||||||
"encoding": "0xa9059cbb",
|
// "encoding": "0xa9059cbb",
|
||||||
"inputs": [
|
// "inputs": [
|
||||||
{"name": "dst", "type": "address"},
|
// {"name": "dst", "type": "address"},
|
||||||
{"name": "rawAmount", "type": "uint256"}
|
// {"name": "rawAmount", "type": "uint256"}
|
||||||
],
|
// ],
|
||||||
"name": "transfer",
|
// "name": "transfer",
|
||||||
"outputs": [
|
// "outputs": [
|
||||||
{"name": "val_0", "type": "bool"}
|
// {"name": "val_0", "type": "bool"}
|
||||||
],
|
// ],
|
||||||
"signature": "transfer(address,uint256)",
|
// "signature": "transfer(address,uint256)",
|
||||||
"type": "function"
|
// "type": "function"
|
||||||
},
|
// },
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
//====================================================================
|
//====================================================================
|
||||||
|
|
||||||
// function not found so likely a proxy so we need to fetch the impl
|
// function not found so likely a proxy so we need to fetch the impl
|
||||||
//====================================================================
|
//====================================================================
|
||||||
final updatedToken = tokenContract.copyWith(abi: jsonEncode(list));
|
// final updatedToken = tokenContract.copyWith(abi: jsonEncode(list));
|
||||||
// Store updated contract
|
// // Store updated contract
|
||||||
final id = await MainDB.instance.putEthContract(updatedToken);
|
// final id = await MainDB.instance.putEthContract(updatedToken);
|
||||||
_tokenContract = updatedToken..id = id;
|
// _tokenContract = updatedToken..id = id;
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
// final contractAddressResponse =
|
final contractAddressResponse =
|
||||||
// await EthereumAPI.getProxyTokenImplementation(contractAddress.hex);
|
await EthereumAPI.getProxyTokenImplementationAddress(
|
||||||
//
|
contractAddress.hex);
|
||||||
// if (contractAddressResponse.value != null) {
|
|
||||||
// _tokenContract = await _updateTokenABI(
|
if (contractAddressResponse.value != null) {
|
||||||
// forContract: tokenContract,
|
_tokenContract = await _updateTokenABI(
|
||||||
// usingContractAddress: contractAddressResponse.value!,
|
forContract: tokenContract,
|
||||||
// );
|
usingContractAddress: contractAddressResponse.value!,
|
||||||
// } else {
|
);
|
||||||
// throw contractAddressResponse.exception!;
|
} else {
|
||||||
// }
|
throw contractAddressResponse.exception!;
|
||||||
|
}
|
||||||
//====================================================================
|
//====================================================================
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue