2014-05-29 13:24:37 +00:00
|
|
|
|
|
|
|
|
2014-06-17 17:40:56 +00:00
|
|
|
// the sample is good example how one can
|
|
|
|
// save program that manage his own currency
|
2014-05-29 13:24:37 +00:00
|
|
|
|
|
|
|
init:
|
|
|
|
|
2014-06-17 17:40:56 +00:00
|
|
|
// this part run only on init stage
|
|
|
|
// we are about to set the maxim
|
|
|
|
// amount of currency
|
2014-06-05 03:49:19 +00:00
|
|
|
contract.storage[0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826] = 10000000
|
2014-05-29 13:24:37 +00:00
|
|
|
code:
|
|
|
|
|
|
|
|
|
2014-06-17 17:40:56 +00:00
|
|
|
// the currency manager
|
|
|
|
// support two functions
|
2014-05-29 13:24:37 +00:00
|
|
|
if msg.datasize == 1:
|
|
|
|
|
2014-06-17 17:40:56 +00:00
|
|
|
// 1. balance check
|
2014-05-29 13:24:37 +00:00
|
|
|
addr = msg.data[0]
|
|
|
|
return(contract.storage[addr])
|
|
|
|
else:
|
|
|
|
|
2014-06-17 17:40:56 +00:00
|
|
|
// 2. balance manipulation
|
2014-05-29 13:24:37 +00:00
|
|
|
from = msg.sender
|
|
|
|
fromvalue = contract.storage[from]
|
|
|
|
to = msg.data[0]
|
|
|
|
value = msg.data[1]
|
|
|
|
if fromvalue >= value:
|
|
|
|
contract.storage[from] = fromvalue - value
|
|
|
|
contract.storage[to] = contract.storage[to] + value
|
|
|
|
return(1)
|
|
|
|
else:
|
2014-05-31 19:17:55 +00:00
|
|
|
return(0)
|