Last active
April 15, 2023 11:13
-
-
Save dharniel45/fcabc5da54ed417e3fff83e3342cbf5b to your computer and use it in GitHub Desktop.
feedback.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Future<DeployedContract> getContract() async { | |
String abiFile = await rootBundle.loadString("assets/contract.json"); | |
String contractAddress = "0xc3b3E80d184cA5aec3A49A40350D42623AFf3fab"; | |
final contract = DeployedContract(ContractAbi.fromJson(abiFile, "Feedback"), | |
EthereumAddress.fromHex(contractAddress)); | |
return contract; | |
} | |
Future<List<dynamic>> callFunction(String name) async { | |
final contract = await getContract(); | |
final function = contract.function(name); | |
final result = await ethClient | |
.call(contract: contract, function: function, params: []); | |
return result; | |
} | |
Future<void> getFeedbackCount() async { | |
List<dynamic> resultsA = await callFunction("getFeedbackCountPositive"); | |
List<dynamic> resultsB = await callFunction("getFeedbackCountNegative"); | |
positiveCount = resultsP[0]; | |
negativeCount = resultsN[0]; | |
setState(() {}); | |
} | |
final result = await ethClient | |
.call(contract: contract, function: function, params: []); | |
Future<List<dynamic>> callFunction(String name) async { | |
final contract = await getContract(); | |
final function = contract.function(name); | |
final result = await ethClient | |
.call(contract: contract, function: function, params: []); | |
return result; | |
} | |
Future<void> vote(bool submitPositiveFeedback) async { | |
snackBar(label: "Counting Feedback"); | |
Credentials key = EthPrivateKey.fromHex( | |
"4e6fa9734a4b4a2caad6c253af546f8c7b8795016b5153459e90d21d7f8f5543"); | |
final contract = await getContract(); | |
final function = contract.function( | |
submitPositiveFeedback ? "submitPositiveFeedback" : "submitNegativeFeedback", | |
); | |
await ethClient.sendTransaction( | |
key, | |
Transaction.callContract( | |
contract: contract, function: function, parameters: []), | |
chainId: 4); | |
ScaffoldMessenger.of(context).removeCurrentSnackBar(); | |
snackBar(label: "Counting feedback"); | |
Future.delayed(const Duration(seconds: 20), () { | |
ScaffoldMessenger.of(context).removeCurrentSnackBar(); | |
snackBar(label: "Counted feedback"); | |
getTotalVotes(); | |
ScaffoldMessenger.of(context).clearSnackBars(); | |
}); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment