Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
didi
github_repo_test
Commits
4c02c304
Commit
4c02c304
authored
Aug 14, 2017
by
didi
Browse files
Streaming Ether - the actual contract. refs #2
parent
df5fe086
Changes
2
Hide whitespace changes
Inline
Side-by-side
backend/contracts/Streem.sol
View file @
4c02c304
// TODO: use the SafeMath lib of openzeppelin (implicit overflow checks etc)?
// TODO: check if this complies with the recommended style: http://solidity.readthedocs.io/en/develop/style-guide.html
pragma
solidity
^
0.4
.
1
1
;
pragma
solidity
^
0.4
.
1
3
;
// Status of this contract: PoC of a basic ERC-20 token with streaming functionality (1 outgoing/incoming stream per account)
// TODO: decide on vocabularity for start/open, stop/close, dry/run out of funds/underwater (distinguish between low and no current funding)
contract
Streem
{
uint256
public
totalSupply
;
string
public
constant
name
=
"Streem"
;
string
public
constant
symbol
=
"STR"
;
uint8
public
constant
decimals
=
0
;
string
public
name
;
string
public
symbol
;
uint8
public
decimals
;
address
owner
;
/*
...
...
@@ -41,17 +41,20 @@ contract Streem {
event
StreamClosed
(
address
indexed
_from
,
address
indexed
_to
,
uint256
_perSecond
,
uint256
_settledBalance
,
uint256
_outstandingBalance
);
// constructor
function
Streem
(
uint
initialSupply
)
{
assert
(
totalSupply
>
0
);
function
Streem
(
uint
initialSupply
,
string
_name
,
string
_symbol
,
uint8
_decimals
)
{
owner
=
msg
.
sender
;
settledBalances
[
msg
.
sender
]
=
int
(
initialSupply
);
totalSupply
=
initialSupply
;
name
=
_name
;
symbol
=
_symbol
;
decimals
=
_decimals
;
streams
.
push
(
Stream
(
0
,
0
,
0
,
0
));
// empty first element for implicit null-like semantics
}
// ################## Public functions ###################
// ERC-20 compliant function for discrete transfers
// TODO: the standard seems to require bool return value
function
transfer
(
address
_to
,
uint256
_value
)
{
assert
(
_value
>
0
&&
balanceOf
(
msg
.
sender
)
>=
_value
);
...
...
@@ -78,6 +81,8 @@ contract Streem {
*/
function
openStream
(
address
receiver
,
uint256
perSecond
)
{
assert
(
!
exists
(
getOutStreamOf
(
msg
.
sender
)));
// TODO: signal this with an event, otherwise it's difficult for clients to understand what's going wrong
assert
(
!
exists
(
getInStreamOf
(
receiver
)));
//assert(balanceOf(msg.sender) > perSecond);
assert
(
balanceOf
(
msg
.
sender
)
>=
0
);
//TODO: what initial requirement makes most sense?
// now is an alias to block.timestamp. See http://solidity.readthedocs.io/en/develop/units-and-global-variables.html?highlight=blocknumber
...
...
backend/contracts/StreemETH.sol
0 → 100644
View file @
4c02c304
pragma
solidity
^
0.4
.
13
;
import
"./Streem.sol"
;
// inspired by https://github.com/mattdf/payment-channel/blob/master/channel.sol
// one instance represents one ERC20 token, the rest is very similar to the normal Streem contract.
// a model where a contract exists per user would offer more implicit security, but be less efficient (?)
contract
StreemETH
is
Streem
{
event
Deposit
(
address
sender
,
uint
amount
);
event
Withdrawal
(
address
sender
,
uint
amount
);
function
StreemETH
()
Streem
(
0
,
"Streaming Ether"
,
"SETH"
,
18
)
{}
// function charge is to be handled outside of this contract (direct call of token.transfer(trusteeAddr, amount))
// conversion from StreemETH to ETH
function
withdraw
(
uint256
amount
)
{
// following the Checks-Effects-Interaction Pattern
assert
(
balanceOf
(
msg
.
sender
)
>=
amount
);
settledBalances
[
msg
.
sender
]
-=
int
(
amount
);
totalSupply
-=
amount
;
msg
.
sender
.
transfer
(
amount
);
Withdrawal
(
msg
.
sender
,
amount
);
}
// converstion from ETH to StreemETH
function
()
payable
{
settledBalances
[
msg
.
sender
]
+=
int
(
msg
.
value
);
totalSupply
+=
msg
.
value
;
Deposit
(
msg
.
sender
,
msg
.
value
);
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment