File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed
Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -78,13 +78,28 @@ contract CheckBalance is FunctionsClient, ConfirmedOwner {
7878 revert UnexpectedRequestID (requestId); // Check if request IDs match
7979 }
8080 // Update the contract's state variables with the response and any errors
81- s_lastResponse = abi.decode (response, (uint256 ));
81+ string memory responseString = abi.decode (response, (string ));
82+ s_lastResponse = stringToUint256 (responseString);
8283 s_lastError = err;
8384
8485 // Emit an event to log the response
8586 emit Response (requestId, s_lastResponse, s_lastError);
8687 }
8788
89+ function stringToUint256 (
90+ string memory s
91+ ) public pure returns (uint256 result ) {
92+ bytes memory b = bytes (s);
93+ uint256 i;
94+ result = 0 ;
95+ for (i = 0 ; i < b.length ; i++ ) {
96+ uint256 c = uint256 (uint8 (b[i]));
97+ if (c >= 48 && c <= 57 ) {
98+ result = result * 10 + (c - 48 );
99+ }
100+ }
101+ }
102+
88103 function getResponse () external view returns (uint256 ) {
89104 return s_lastResponse;
90105 }
You can’t perform that action at this time.
0 commit comments