Skip to content

20Scoops-CNX/solidity-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Solidity Utils

We want to improve solidity basic skill and we also create a basic library for learning and practice. You can see how to use as below:

pragma solidity ^0.4.16;

import "github.com/20Scoops-CNX/solidity-utils/lib/ListInteger.sol";

import "github.com/20Scoops-CNX/solidity-utils/lib/Strings.sol";

import "github.com/20Scoops-CNX/solidity-utils/lib/Integers.sol";

contract ExampleContract {
    using ListInteger for *;
    using Strings for string;
    using Integers for uint;

    uint[] items;
}

ListInteger

add(uint)

Add unsigned integer to array

function example() public view returns (uint[]) {
    items.add(99);
    return items;
}

remove()

Remove item last index like function pop() in array

function example() public view returns (uint[]) {
    items.remove();
    return items;
}

removeByValue(uint)

Remove item by value in array

function example() public view returns (uint[]) {
    items.removeByValue(99);
    return items;
}

removeByIndex(uint)

Remove item by index in array start at 0

function example() public view returns (uint[]) {
    items.removeByIndex(0);
    return items;
}

find(uint) : uint

Find index by value in array

function example() public view returns (uint) {
    uint index = items.find(99);
    return index;
}

sort() : uint[]

Sort ascending unsigned integer in array

function example() public view returns (uint[]) {
    return items.sort();
}

sortDESC() : uint[]

Sort descending unsigned integer in array

function example() public view returns (uint[]) {
    return items.sortDESC();
}

getSize() : uint

Get size array

function example() public view returns (uint) {
    uint size = items.getSize();
    return size;
}

sum() : uint

Sum unsigned integer in array

function example() public view returns (uint) {
    uint result = items.sum();
    return result;
}

Strings

concat(string)

Join two strings

function example() {
    string memory str = "20scoops";
    str = str.concat(" ").concat("CNX");
}

length() : uint

Get the length of a string

function example() returns (uint) {
    string memory str = "20scoops CNX";
    return str.length();
}

replaceAll(bytes1, btyes1) : string

Replace all character in string

function example() public view returns (string) {
    string memory str = "20scoops CNX ";
    return str.replaceAll(" ", "");
}

replace(bytes1, bytes1) : string

Replace character in string

function example() public view returns (string) {
    string memory str = "20scoops CNX ";
    return str.replace(" ", "");
}

compareTo(string) : bool

Compare two string

function example() public view returns (bool) {
    string memory str = "20scoops CNX";
    return str.compareTo("20scoops");
}

Intergers

parseInt(string) : uint

Convert string to unsigned integer

function example() public view returns (uint) {
    return Integers.parseInt("99.00");
}

toString() : uint

Convert unsigned integer to string

function example(uint value) public view returns (string) {
    return value.toString();
}

plus(uint) : uint

Plus unsigned integer

function example() public view returns (uint) {
    uint myInt = 5;
    return myInt.plus(5);
}

minus(uint) : uint

Minus unsigned integer

function example() public view returns (string) {
    uint myInt = 5;
    return myInt.minus(5);
}

divide(uint) : uint

Divide unsigned integer

function example(uint value) public view returns (uint) {
    uint myInt = 5;
    return myInt.divide(5);
}

multiply(uint) : uint

Multiply unsigned integer to string

function example() public view returns (uint) {
    uint myInt = 5;
    return myInt.multiply(5);
}

mod(uint) : uint

Modular unsigned integer

function example() public view returns (string) {
    uint myInt = 500;
    return myInt.mod(6);
}

Releases

No releases published

Packages