qourier-module-v0-ticker-symbol
v0.0.2
Published
The price at which tokens are traded on the CEX (Binance).
Downloads
6
Maintainers
Readme
Ticker Symbol
The price at which tokens are traded on the CEX (Binance).
Use by Developers
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import "@qourier/contracts/Hub.sol";
contract TickerSymbol {
address public hub;
uint256 public price;
uint256 private id;
uint256 private result;
constructor(address hub_, uint256 price_) {
hub = hub_;
price = price_;
}
function createTask(string memory symbol_) public payable {
Hub(hub).createTask1{ value: price }(
bytes32("ticker-symbol"),
[bytes(symbol_)]
);
}
function completeTask(uint256 id_, bytes memory result_) external {
require(msg.sender == hub, "Only Qourier can change the state.");
id = id_;
result = bytesToUint(result_);
}
function getTask() public view returns(uint256, uint256) {
return (id, result);
}
function bytesToUint(bytes memory b) public pure returns (uint256) {
uint256 res = 0;
for (uint256 i = 0; i < b.length; i++) {
uint256 c = uint256(uint8(b[i]));
if (c >= 48 && c <= 57) {
res = res * 10 + (c - 48);
}
}
return res;
}
}