-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Very quick and dirty proof of concept of navigation, img loading with…
… the evm:// protocol.
- Loading branch information
Showing
3 changed files
with
106 additions
and
3 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
// Uncomment this line to use console.log | ||
import "hardhat/console.sol"; | ||
|
||
library ToString { | ||
|
||
function toString(uint value) internal pure returns (string memory) { | ||
// Inspired by OraclizeAPI's implementation - MIT license | ||
// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol | ||
|
||
if (value == 0) { | ||
return "0"; | ||
} | ||
uint temp = value; | ||
uint digits; | ||
while (temp != 0) { | ||
digits++; | ||
temp /= 10; | ||
} | ||
bytes memory buffer = new bytes(digits); | ||
while (value != 0) { | ||
digits -= 1; | ||
buffer[digits] = bytes1(uint8(48 + uint(value % 10))); | ||
value /= 10; | ||
} | ||
return string(buffer); | ||
} | ||
|
||
function toString(int value) internal pure returns (string memory) { | ||
return string(abi.encodePacked(value < 0 ? "-" : "", toString(uint(value < 0 ? - value : value)))); | ||
} | ||
|
||
function addressToString(address x) internal pure returns (string memory) { | ||
// Fetched from https://ethereum.stackexchange.com/questions/8346/convert-address-to-string/8447#8447 | ||
|
||
bytes memory s = new bytes(40); | ||
for (uint i = 0; i < 20; i++) { | ||
bytes1 b = bytes1(uint8(uint(uint160(x)) / (2**(8*(19 - i))))); | ||
bytes1 hi = bytes1(uint8(b) / 16); | ||
bytes1 lo = bytes1(uint8(b) - 16 * uint8(hi)); | ||
s[2*i] = char(hi); | ||
s[2*i+1] = char(lo); | ||
} | ||
return string(s); | ||
} | ||
|
||
function char(bytes1 b) internal pure returns (bytes1 c) { | ||
// Fetched from https://ethereum.stackexchange.com/questions/8346/convert-address-to-string/8447#8447 | ||
|
||
if (uint8(b) < 10) return bytes1(uint8(b) + 0x30); | ||
else return bytes1(uint8(b) + 0x57); | ||
} | ||
|
||
} |
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