summaryrefslogtreecommitdiffhomepage
path: root/solidity.html.markdown
diff options
context:
space:
mode:
authorNemil Dalal <nemild@gmail.com>2015-11-23 16:39:05 -0500
committerNemil Dalal <nemild@gmail.com>2015-11-23 16:39:05 -0500
commit08f3ee3687fc18286fdb3825f0fc1fd74c086798 (patch)
tree32628d69be80ec131be4692c38db7001e10b299f /solidity.html.markdown
parentd5bcbceb21954d0f8739fb841fc511aa32c2bcc6 (diff)
Added remove function
Diffstat (limited to 'solidity.html.markdown')
-rw-r--r--solidity.html.markdown13
1 files changed, 9 insertions, 4 deletions
diff --git a/solidity.html.markdown b/solidity.html.markdown
index 79debed6..bcbdec5f 100644
--- a/solidity.html.markdown
+++ b/solidity.html.markdown
@@ -35,15 +35,13 @@ contract AcmeBank {
function AcmeBank() {
// msg is a default variable that provides both the
// contract messager's address and amount
- owner = msg.address;
- // the owner has no additional rights, we're setting it for
- // illustrative purposes
+ owner = msg.address; // msg.address refers to the address of the contract creator
}
function deposit(uint balance) {
balances[msg.sender] += msg.value; // no need for "this." or "self." in front of the state variable
- return balances[msg.sender];
+ return balances[msg.sender]; // msg.sender refers to the contract caller
}
function withdraw(uint withdrawAmount) returns (uint remainingBalance) {
@@ -58,6 +56,13 @@ contract AcmeBank {
}
}
+ // It's good practice to have a remove function, which disables this contract
+ function remove () {
+ if(msg.sender == owner) { // Only let the contract creator do this
+ suicide(owner); // suicide makes this contract inactive, and returns funds to the owner
+ }
+ }
+
// The 'constant' prevents the function from editing state variables
function balance() constant {
return balances[msg.sender];