Skip to content

Commit 5d65a3c

Browse files
committed
Merge branch 'develop' into feature/readmeImprovement
2 parents 0b3af3a + aa1336a commit 5d65a3c

19 files changed

+387
-46
lines changed

.travis.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
language: objective-c
2+
osx_image: xcode10
3+
xcode_project: web3swift.xcworkspace # path to your xcodeproj folder
4+
xcode_scheme: web3swift-iOS
5+
xcode_destination: platform=iOS Simulator, OS=12.0, name=iPhone X
6+
before_install:
7+
- gem install cocoapods --pre --no-rdoc --no-ri --no-document --quiet
8+
- pod install
9+
script:
10+
- xcodebuild -scheme web3swift-iOS -workspace web3swift.xcworkspace -sdk iphonesimulator build test
11+
after_success:
12+
- bash <(curl -s https://codecov.io/bash)

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
<img align="left" width="25" height="25" src="https://user-images.githubusercontent.com/28599454/41086111-af4bc3b0-6a41-11e8-9f9f-2d642b12666e.png">[Ask questions](https://stackoverflow.com/questions/tagged/web3swift)
2-
## Important notices
3-
The work for 2.0 release is about to start. Ideas for new more Swift idiomatic API are welcome in issues.
4-
51
# web3swift
62

73
[![Version](https://img.shields.io/cocoapods/v/web3swift.svg?style=flat)](http://cocoapods.org/pods/web3swift)
84
[![License](https://img.shields.io/cocoapods/l/web3swift.svg?style=flat)](http://cocoapods.org/pods/web3swift)
95
[![Platform](https://img.shields.io/cocoapods/p/web3swift.svg?style=flat)](http://cocoapods.org/pods/web3swift)
10-
[![support](https://brianmacdonald.github.io/Ethonate/svg/eth-support-blue.svg)](https://brianmacdonald.github.io/Ethonate/address#0x6394b37Cf80A7358b38068f0CA4760ad49983a1B)
6+
[![support](https://brianmacdonald.github.io/Ethonate/svg/eth-support-blue.svg)](https://brianmacdonald.github.io/Ethonate/address#0xe22b8979739d724343bd002f9f432f5990879901)
7+
[![Build Status](https://travis-ci.com/matterinc/web3swift.svg?branch=develop)](https://travis-ci.com/matterinc/web3swift)
8+
9+
<img align="left" width="25" height="25" src="https://user-images.githubusercontent.com/28599454/41086111-af4bc3b0-6a41-11e8-9f9f-2d642b12666e.png">[Ask questions](https://stackoverflow.com/questions/tagged/web3swift)
1110

1211
**web3swift** is your toolbelt for any kind interactions with Ethereum network.
1312

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
pragma solidity ^0.4.24;
2+
3+
/**
4+
* @title SafeMath
5+
* @dev Math operations with safety checks that revert on error
6+
*/
7+
library SafeMath {
8+
9+
/**
10+
* @dev Multiplies two numbers, reverts on overflow.
11+
*/
12+
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
13+
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
14+
// benefit is lost if 'b' is also tested.
15+
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
16+
if (a == 0) {
17+
return 0;
18+
}
19+
20+
uint256 c = a * b;
21+
require(c / a == b);
22+
23+
return c;
24+
}
25+
26+
/**
27+
* @dev Integer division of two numbers truncating the quotient, reverts on division by zero.
28+
*/
29+
function div(uint256 a, uint256 b) internal pure returns (uint256) {
30+
require(b > 0); // Solidity only automatically asserts when dividing by 0
31+
uint256 c = a / b;
32+
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
33+
34+
return c;
35+
}
36+
37+
/**
38+
* @dev Subtracts two numbers, reverts on overflow (i.e. if subtrahend is greater than minuend).
39+
*/
40+
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
41+
require(b <= a);
42+
uint256 c = a - b;
43+
44+
return c;
45+
}
46+
47+
/**
48+
* @dev Adds two numbers, reverts on overflow.
49+
*/
50+
function add(uint256 a, uint256 b) internal pure returns (uint256) {
51+
uint256 c = a + b;
52+
require(c >= a);
53+
54+
return c;
55+
}
56+
57+
/**
58+
* @dev Divides two numbers and returns the remainder (unsigned integer modulo),
59+
* reverts when dividing by zero.
60+
*/
61+
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
62+
require(b != 0);
63+
return a % b;
64+
}
65+
}
6 KB
Binary file not shown.
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
pragma solidity ^0.4.24;
2+
3+
import "./IERC20.sol";
4+
import "../SafeMath/SafeMath.sol";
5+
6+
/**
7+
* @title Standard ERC20 token
8+
*
9+
* @dev Implementation of the basic standard token.
10+
* https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md
11+
* Originally based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
12+
*/
13+
contract ERC20 is IERC20 {
14+
using SafeMath for uint256;
15+
16+
mapping (address => uint256) private _balances;
17+
18+
mapping (address => mapping (address => uint256)) private _allowed;
19+
20+
uint256 private _totalSupply;
21+
22+
/**
23+
* @dev Total number of tokens in existence
24+
*/
25+
function totalSupply() public view returns (uint256) {
26+
return _totalSupply;
27+
}
28+
29+
/**
30+
* @dev Gets the balance of the specified address.
31+
* @param owner The address to query the balance of.
32+
* @return An uint256 representing the amount owned by the passed address.
33+
*/
34+
function balanceOf(address owner) public view returns (uint256) {
35+
return _balances[owner];
36+
}
37+
38+
/**
39+
* @dev Function to check the amount of tokens that an owner allowed to a spender.
40+
* @param owner address The address which owns the funds.
41+
* @param spender address The address which will spend the funds.
42+
* @return A uint256 specifying the amount of tokens still available for the spender.
43+
*/
44+
function allowance(
45+
address owner,
46+
address spender
47+
)
48+
public
49+
view
50+
returns (uint256)
51+
{
52+
return _allowed[owner][spender];
53+
}
54+
55+
/**
56+
* @dev Transfer token for a specified address
57+
* @param to The address to transfer to.
58+
* @param value The amount to be transferred.
59+
*/
60+
function transfer(address to, uint256 value) public returns (bool) {
61+
require(value <= _balances[msg.sender]);
62+
require(to != address(0));
63+
64+
_balances[msg.sender] = _balances[msg.sender].sub(value);
65+
_balances[to] = _balances[to].add(value);
66+
emit Transfer(msg.sender, to, value);
67+
return true;
68+
}
69+
70+
/**
71+
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
72+
* Beware that changing an allowance with this method brings the risk that someone may use both the old
73+
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
74+
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
75+
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
76+
* @param spender The address which will spend the funds.
77+
* @param value The amount of tokens to be spent.
78+
*/
79+
function approve(address spender, uint256 value) public returns (bool) {
80+
require(spender != address(0));
81+
82+
_allowed[msg.sender][spender] = value;
83+
emit Approval(msg.sender, spender, value);
84+
return true;
85+
}
86+
87+
/**
88+
* @dev Transfer tokens from one address to another
89+
* @param from address The address which you want to send tokens from
90+
* @param to address The address which you want to transfer to
91+
* @param value uint256 the amount of tokens to be transferred
92+
*/
93+
function transferFrom(
94+
address from,
95+
address to,
96+
uint256 value
97+
)
98+
public
99+
returns (bool)
100+
{
101+
require(value <= _balances[from]);
102+
require(value <= _allowed[from][msg.sender]);
103+
require(to != address(0));
104+
105+
_balances[from] = _balances[from].sub(value);
106+
_balances[to] = _balances[to].add(value);
107+
_allowed[from][msg.sender] = _allowed[from][msg.sender].sub(value);
108+
emit Transfer(from, to, value);
109+
return true;
110+
}
111+
112+
/**
113+
* @dev Increase the amount of tokens that an owner allowed to a spender.
114+
* approve should be called when allowed_[_spender] == 0. To increment
115+
* allowed value is better to use this function to avoid 2 calls (and wait until
116+
* the first transaction is mined)
117+
* From MonolithDAO Token.sol
118+
* @param spender The address which will spend the funds.
119+
* @param addedValue The amount of tokens to increase the allowance by.
120+
*/
121+
function increaseAllowance(
122+
address spender,
123+
uint256 addedValue
124+
)
125+
public
126+
returns (bool)
127+
{
128+
require(spender != address(0));
129+
130+
_allowed[msg.sender][spender] = (
131+
_allowed[msg.sender][spender].add(addedValue));
132+
emit Approval(msg.sender, spender, _allowed[msg.sender][spender]);
133+
return true;
134+
}
135+
136+
/**
137+
* @dev Decrease the amount of tokens that an owner allowed to a spender.
138+
* approve should be called when allowed_[_spender] == 0. To decrement
139+
* allowed value is better to use this function to avoid 2 calls (and wait until
140+
* the first transaction is mined)
141+
* From MonolithDAO Token.sol
142+
* @param spender The address which will spend the funds.
143+
* @param subtractedValue The amount of tokens to decrease the allowance by.
144+
*/
145+
function decreaseAllowance(
146+
address spender,
147+
uint256 subtractedValue
148+
)
149+
public
150+
returns (bool)
151+
{
152+
require(spender != address(0));
153+
154+
_allowed[msg.sender][spender] = (
155+
_allowed[msg.sender][spender].sub(subtractedValue));
156+
emit Approval(msg.sender, spender, _allowed[msg.sender][spender]);
157+
return true;
158+
}
159+
160+
/**
161+
* @dev Internal function that mints an amount of the token and assigns it to
162+
* an account. This encapsulates the modification of balances such that the
163+
* proper events are emitted.
164+
* @param account The account that will receive the created tokens.
165+
* @param amount The amount that will be created.
166+
*/
167+
function _mint(address account, uint256 amount) internal {
168+
require(account != 0);
169+
_totalSupply = _totalSupply.add(amount);
170+
_balances[account] = _balances[account].add(amount);
171+
emit Transfer(address(0), account, amount);
172+
}
173+
174+
/**
175+
* @dev Internal function that burns an amount of the token of a given
176+
* account.
177+
* @param account The account whose tokens will be burnt.
178+
* @param amount The amount that will be burnt.
179+
*/
180+
function _burn(address account, uint256 amount) internal {
181+
require(account != 0);
182+
require(amount <= _balances[account]);
183+
184+
_totalSupply = _totalSupply.sub(amount);
185+
_balances[account] = _balances[account].sub(amount);
186+
emit Transfer(account, address(0), amount);
187+
}
188+
189+
/**
190+
* @dev Internal function that burns an amount of the token of a given
191+
* account, deducting from the sender's allowance for said account. Uses the
192+
* internal burn function.
193+
* @param account The account whose tokens will be burnt.
194+
* @param amount The amount that will be burnt.
195+
*/
196+
function _burnFrom(address account, uint256 amount) internal {
197+
require(amount <= _allowed[account][msg.sender]);
198+
199+
// Should https://github.com/OpenZeppelin/zeppelin-solidity/issues/707 be accepted,
200+
// this function needs to emit an event with the updated approval.
201+
_allowed[account][msg.sender] = _allowed[account][msg.sender].sub(
202+
amount);
203+
_burn(account, amount);
204+
}
205+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
pragma solidity ^0.4.24;
2+
3+
/**
4+
* @title ERC20 interface
5+
* @dev see https://github.com/ethereum/EIPs/issues/20
6+
*/
7+
interface IERC20 {
8+
function totalSupply() external view returns (uint256);
9+
10+
function balanceOf(address who) external view returns (uint256);
11+
12+
function allowance(address owner, address spender)
13+
external view returns (uint256);
14+
15+
function transfer(address to, uint256 value) external returns (bool);
16+
17+
function approve(address spender, uint256 value)
18+
external returns (bool);
19+
20+
function transferFrom(address from, address to, uint256 value)
21+
external returns (bool);
22+
23+
event Transfer(
24+
address indexed from,
25+
address indexed to,
26+
uint256 value
27+
);
28+
29+
event Approval(
30+
address indexed owner,
31+
address indexed spender,
32+
uint256 value
33+
);
34+
}

TestToken/Token/Web3SwiftToken.sol

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
pragma solidity ^0.4.24;
2+
3+
import "../Helpers/TokenBasics/ERC20.sol";
4+
5+
contract web3swift is ERC20 {
6+
7+
string public constant name = "web3swift";
8+
string public constant symbol = "w3s";
9+
uint8 public constant decimals = 18;
10+
11+
uint256 public constant INITIAL_SUPPLY = 1024 * (10 ** uint256(decimals));
12+
13+
/**
14+
* @dev Constructor that gives msg.sender all of existing tokens.
15+
*/
16+
constructor() public {
17+
_mint(msg.sender, INITIAL_SUPPLY);
18+
}
19+

0 commit comments

Comments
 (0)