Commit 944ab64d authored by didi's avatar didi
Browse files

renamed staticBalances to settledBalances

parent b659db45
......@@ -56,4 +56,10 @@ Guess: Allowing 2 incoming and 2 outgoing streams would allow to construct all c
Logically identical to the *limited number of streams* option.
But probably a considerably bigger implementation challenge in terms of complexity and gas cost. E.g. fixed size array nomore an option.
A possibility could be to have *openStream()* measure the complexity of the dependencies based on the involved addresses and not execute if it exceeds some safety threshold.
\ No newline at end of file
A possibility could be to have *openStream()* measure the complexity of the dependencies based on the involved addresses and not execute if it exceeds some safety threshold.
## Basic strategy
Whenever a transaction takes place, it can be used for some bookkeeping.
Most importantly, a kind of intermediate settlement can be done for open streams. This can be seen as persisting the results of calculations.
Since dynamically calculated status snapshots depending on the current time are guaranteed / final, such states can as well be persisted.
\ No newline at end of file
......@@ -11,7 +11,12 @@ contract Streem {
uint8 public constant decimals = 0;
address owner;
mapping (address => uint256) staticBalances;
/*
* this map stores the fractions of account balances which are already "settled" by a transaction.
* It's just an implementation detail - the "settled" fraction of balance is in no way different or superior to
* the "unsettled" one.
*/
mapping (address => uint256) settledBalances;
struct Stream {
address sender;
......@@ -31,14 +36,14 @@ contract Streem {
function Streem(uint initialSupply) {
owner = msg.sender;
staticBalances[msg.sender] = initialSupply;
settledBalances[msg.sender] = initialSupply;
totalSupply = initialSupply;
}
// TODO: this is just for the test token. Issuance mechanism for mainnet token to be decided.
function issueTo(address receiver, uint256 amount) {
require(msg.sender == owner);
staticBalances[receiver] += amount;
settledBalances[receiver] += amount;
totalSupply += amount;
}
......@@ -61,15 +66,15 @@ contract Streem {
uint256 streamBal = (now - stream.startTimestamp) * stream.perSecond;
uint256 settleBal = 0;
uint256 outstandingBal = 0;
if(streamBal <= staticBalances[msg.sender]) {
if(streamBal <= settledBalances[msg.sender]) {
settleBal = streamBal;
} else {
// special case: the receiver (partially) defaults on the stream
settleBal = staticBalances[msg.sender];
settleBal = settledBalances[msg.sender];
outstandingBal = streamBal - settleBal;
}
staticBalances[msg.sender] -= settleBal;
staticBalances[stream.receiver] += settleBal;
settledBalances[msg.sender] -= settleBal;
settledBalances[stream.receiver] += settleBal;
delete inStreams[stream.receiver];
delete outStreams[msg.sender];
......@@ -79,13 +84,13 @@ contract Streem {
// TODO: needs to consider the dynamic balance (streams included). How to deal with _value > staticBalance? Allow negative staticBalance?
function transfer(address _to, uint256 _value) {
//Default assumes totalSupply can't be over max (2^256 - 1).
//If your token leaves out totalSupply and can issue more tokens as time goes on, you need to check if it doesn't wrap.
//Replace the if with this one instead.
//if (balances[msg.sender] >= _value && balances[_to] + _value > balances[_to]) {
assert(staticBalances[msg.sender] >= _value && _value > 0);
staticBalances[msg.sender] -= _value;
staticBalances[_to] += _value;
assert(_value > 0 && balanceOf(msg.sender) >= _value);
// As a temporary solution, allow only transfers for which we have enough funds already "settled". TODO: fix
assert(settledBalances[msg.sender] >= _value);
settledBalances[msg.sender] -= _value;
settledBalances[_to] += _value;
Transfer(msg.sender, _to, _value);
}
......@@ -117,7 +122,7 @@ contract Streem {
var inS = inStreams[s.sender];
uint256 isb = exists(inS) ? streamBalance(inS) : 0;
uint sb = staticBalances[s.sender];
uint sb = settledBalances[s.sender];
return min(osb, sb + isb);
}
......@@ -141,7 +146,7 @@ contract Streem {
}
// TODO: check overflow before casting
balance = int256(staticBalances[_owner] + inStreamBal - outStreamBal);
balance = int256(settledBalances[_owner] + inStreamBal - outStreamBal);
return balance;
}
......@@ -156,6 +161,6 @@ contract Streem {
uint256 outStreamBal = exists(outS) ? streamBalance(outS) : 0;
// TODO: check overflow before casting
return staticBalances[_owner] + inStreamBal - outStreamBal;
return settledBalances[_owner] + inStreamBal - outStreamBal;
}
}
......@@ -259,7 +259,7 @@ const contract = {
"type": "event"
}
],
"unlinked_binary": "0x6060604052341561000c57fe5b604051602080610ab483398101604052515b60018054600160a060020a03191633600160a060020a031690811790915560009081526002602052604081208290558190555b505b610a52806100626000396000f300606060405236156100935763ffffffff60e060020a60003504166306fdde0381146100955780631207f0c11461012557806318160ddd1461014657806326a90b7d14610168578063313ce5671461019657806364a80c0c146101bc57806370a08231146101dd5780637ae2b5c71461020b57806395d89b41146102335780639dad9382146102c3578063a9059cbb146102d5575bfe5b341561009d57fe5b6100a56102f6565b6040805160208082528351818301528351919283929083019185019080838382156100eb575b8051825260208311156100eb57601f1990920191602091820191016100cb565b505050905090810190601f1680156101175780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561012d57fe5b610144600160a060020a0360043516602435610319565b005b341561014e57fe5b61015661035e565b60408051918252519081900360200190f35b341561017057fe5b610156600160a060020a0360043516610364565b60408051918252519081900360200190f35b341561019e57fe5b6101a66103fc565b6040805160ff9092168252519081900360200190f35b34156101c457fe5b610144600160a060020a0360043516602435610401565b005b34156101e557fe5b610156600160a060020a0360043516610512565b60408051918252519081900360200190f35b341561021357fe5b610156600435602435610696565b60408051918252519081900360200190f35b341561023b57fe5b6100a56106b0565b6040805160208082528351818301528351919283929083019185019080838382156100eb575b8051825260208311156100eb57601f1990920191602091820191016100cb565b505050905090810190601f1680156101175780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34156102cb57fe5b6101446106d0565b005b34156102dd57fe5b610144600160a060020a0360043516602435610848565b005b604080518082019091526006815260d060020a6553747265656d02602082015281565b60015433600160a060020a039081169116146103355760006000fd5b600160a060020a03821660009081526002602052604081208054830190558054820190555b5050565b60005481565b600160a060020a03811660009081526004602052604081206003810154829190829081901561039d578260020154836003015442030293505b5050600160a060020a0384166000908152600360208190526040822090810154156103d2578060020154816003015442030291505b600160a060020a038616600090815260026020526040902054840182900394505b50505050919050565b600081565b6104096109ff565b600061041433610512565b1161041b57fe5b5060408051608081018252600160a060020a0333811680835285821660208085018281528587018881524260608801908152600086815260038086528a82208a518154908b16600160a060020a0319918216178255865160018084018054928e1692841692909217909155865160028085019190915586519385019390935589855260048952938d90208c518154908d169083161781559651938701805494909b1693169290921790985591519183019190915551940193909355845186815294519394909391927f4baaa557c21346b70bdc9482890b5d7e315f6a2123611e74004857ebecde068692918290030190a35b505050565b600160a060020a038082166000908152600460209081526040808320815160808101835281548616815260018201549095169285019290925260028201549084015260038101546060840152909182908190819061056f906108e5565b61057a5760006105bd565b604080516080810182528554600160a060020a0390811682526001870154166020820152600286015491810191909152600385015460608201526105bd906108f2565b5b600160a060020a0380881660009081526003602081815260409283902083516080810185528a548616815260018b015490951691850191909152600289015492840192909252870154606083015291945090925061061b906108e5565b610626576000610669565b604080516080810182528354600160a060020a039081168252600185015416602082015260028401549181019190915260038301546060820152610669906108f2565b5b600160a060020a0387166000908152600260205260409020548401819003955090505b50505050919050565b60008183106106a557816106a7565b825b90505b92915050565b604080518082019091526003815260e960020a6229aa2902602082015281565b600160a060020a03331660009081526003602081905260408220908101549091908190819015156106fd57fe5b83600201548460030154420302925060009150600090506002600033600160a060020a0316600160a060020a03168152602001908152602001600020548311151561074a57829150610769565b5050600160a060020a0333166000908152600260205260409020548082035b600160a060020a0333811660008181526002602081815260408084208054899003905560018a810180548816865282862080548b019055805488168652600484528286208054600160a060020a031990811682558184018054821690558187018890556003918201889055888852818652848820805482168155938401805490911690558286018790559190910194909455925491890154835190815290810187905280830186905291519316927f96c5271ec05cb2683bdc50cf109341f5a4e45b02907df1c23a8855bddbe030a19181900360600190a35b50505050565b600160a060020a0333166000908152600260205260409020548190108015906108715750600081115b151561087957fe5b600160a060020a03338116600081815260026020908152604080832080548790039055938616808352918490208054860190558351858152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35b5050565b606081015115155b919050565b60006000600060006000610905866109ec565b8651600160a060020a03908116600090815260046020908152604091829020825160808101845281548516815260018201549094169184019190915260028101549183019190915260038101546060830152919550909350610966906108e5565b6109715760006109b4565b604080516080810182528454600160a060020a0390811682526001860154166020820152600285015491810191909152600384015460608201526109b4906108f2565b5b8651600160a060020a031660009081526002602052604090205490925090506109e084828401610696565b94505b50505050919050565b604081015160608201514203025b919050565b604080516080810182526000808252602082018190529181018290526060810191909152905600a165627a7a723058209925509c083502443d85e404030df8da00a0a32cdcfce52f3939f2dc3da262720029",
"unlinked_binary": "0x6060604052341561000c57fe5b604051602080610ac683398101604052515b60018054600160a060020a03191633600160a060020a031690811790915560009081526002602052604081208290558190555b505b610a64806100626000396000f300606060405236156100935763ffffffff60e060020a60003504166306fdde0381146100955780631207f0c11461012557806318160ddd1461014657806326a90b7d14610168578063313ce5671461019657806364a80c0c146101bc57806370a08231146101dd5780637ae2b5c71461020b57806395d89b41146102335780639dad9382146102c3578063a9059cbb146102d5575bfe5b341561009d57fe5b6100a56102f6565b6040805160208082528351818301528351919283929083019185019080838382156100eb575b8051825260208311156100eb57601f1990920191602091820191016100cb565b505050905090810190601f1680156101175780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561012d57fe5b610144600160a060020a0360043516602435610319565b005b341561014e57fe5b61015661035e565b60408051918252519081900360200190f35b341561017057fe5b610156600160a060020a0360043516610364565b60408051918252519081900360200190f35b341561019e57fe5b6101a66103fc565b6040805160ff9092168252519081900360200190f35b34156101c457fe5b610144600160a060020a0360043516602435610401565b005b34156101e557fe5b610156600160a060020a0360043516610512565b60408051918252519081900360200190f35b341561021357fe5b610156600435602435610696565b60408051918252519081900360200190f35b341561023b57fe5b6100a56106b0565b6040805160208082528351818301528351919283929083019185019080838382156100eb575b8051825260208311156100eb57601f1990920191602091820191016100cb565b505050905090810190601f1680156101175780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34156102cb57fe5b6101446106d0565b005b34156102dd57fe5b610144600160a060020a0360043516602435610848565b005b604080518082019091526006815260d060020a6553747265656d02602082015281565b60015433600160a060020a039081169116146103355760006000fd5b600160a060020a03821660009081526002602052604081208054830190558054820190555b5050565b60005481565b600160a060020a03811660009081526004602052604081206003810154829190829081901561039d578260020154836003015442030293505b5050600160a060020a0384166000908152600360208190526040822090810154156103d2578060020154816003015442030291505b600160a060020a038616600090815260026020526040902054840182900394505b50505050919050565b600081565b610409610a11565b600061041433610512565b1161041b57fe5b5060408051608081018252600160a060020a0333811680835285821660208085018281528587018881524260608801908152600086815260038086528a82208a518154908b16600160a060020a0319918216178255865160018084018054928e1692841692909217909155865160028085019190915586519385019390935589855260048952938d90208c518154908d169083161781559651938701805494909b1693169290921790985591519183019190915551940193909355845186815294519394909391927f4baaa557c21346b70bdc9482890b5d7e315f6a2123611e74004857ebecde068692918290030190a35b505050565b600160a060020a038082166000908152600460209081526040808320815160808101835281548616815260018201549095169285019290925260028201549084015260038101546060840152909182908190819061056f906108f7565b61057a5760006105bd565b604080516080810182528554600160a060020a0390811682526001870154166020820152600286015491810191909152600385015460608201526105bd90610904565b5b600160a060020a038088166000908152600360208181526040928390208351608081018552815486168152600182015490951691850191909152600281015492840192909252810154606083015291945090925061061b906108f7565b610626576000610669565b604080516080810182528354600160a060020a03908116825260018501541660208201526002840154918101919091526003830154606082015261066990610904565b5b600160a060020a0387166000908152600260205260409020548401819003955090505b50505050919050565b60008183106106a557816106a7565b825b90505b92915050565b604080518082019091526003815260e960020a6229aa2902602082015281565b600160a060020a03331660009081526003602081905260408220908101549091908190819015156106fd57fe5b83600201548460030154420302925060009150600090506002600033600160a060020a0316600160a060020a03168152602001908152602001600020548311151561074a57829150610769565b5050600160a060020a0333166000908152600260205260409020548082035b600160a060020a0333811660008181526002602081815260408084208054899003905560018a810180548816865282862080548b019055805488168652600484528286208054600160a060020a031990811682558184018054821690558187018890556003918201889055888852818652848820805482168155938401805490911690558286018790559190910194909455925491890154835190815290810187905280830186905291519316927f96c5271ec05cb2683bdc50cf109341f5a4e45b02907df1c23a8855bddbe030a19181900360600190a35b50505050565b60008111801561086057508061085d33610512565b10155b151561086857fe5b600160a060020a0333166000908152600260205260409020548190101561088b57fe5b600160a060020a03338116600081815260026020908152604080832080548790039055938616808352918490208054860190558351858152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35b5050565b606081015115155b919050565b60006000600060006000610917866109fe565b8651600160a060020a03908116600090815260046020908152604091829020825160808101845281548516815260018201549094169184019190915260028101549183019190915260038101546060830152919550909350610978906108f7565b6109835760006109c6565b604080516080810182528454600160a060020a0390811682526001860154166020820152600285015491810191909152600384015460608201526109c690610904565b5b8651600160a060020a031660009081526002602052604090205490925090506109f284828401610696565b94505b50505050919050565b604081015160608201514203025b919050565b604080516080810182526000808252602082018190529181018290526060810191909152905600a165627a7a72305820895b2b4a5129e2edc484c0d1034d3d1402a6c5e9fbb0f6b26e8c0d5412e19d210029",
"networks": {
"1500075197859": {
"events": {
......@@ -763,5 +763,5 @@ const contract = {
}
},
"schema_version": "0.0.5",
"updated_at": 1501285455112
"updated_at": 1501346911351
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment