qourier-module-v0-ticker-symbol

0.0.2 • Public • Published

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;
    }
}

Package Sidebar

Install

npm i qourier-module-v0-ticker-symbol

Weekly Downloads

2

Version

0.0.2

License

MIT

Unpacked Size

2.4 kB

Total Files

3

Last publish

Collaborators

  • alexbakers