mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-05-09 00:08:32 +00:00
Added remove function
This commit is contained in:
parent
d5bcbceb21
commit
08f3ee3687
@ -35,15 +35,13 @@ contract AcmeBank {
|
|||||||
function AcmeBank() {
|
function AcmeBank() {
|
||||||
// msg is a default variable that provides both the
|
// msg is a default variable that provides both the
|
||||||
// contract messager's address and amount
|
// contract messager's address and amount
|
||||||
owner = msg.address;
|
owner = msg.address; // msg.address refers to the address of the contract creator
|
||||||
// the owner has no additional rights, we're setting it for
|
|
||||||
// illustrative purposes
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function deposit(uint balance) {
|
function deposit(uint balance) {
|
||||||
balances[msg.sender] += msg.value; // no need for "this." or "self." in front of the state variable
|
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) {
|
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
|
// The 'constant' prevents the function from editing state variables
|
||||||
function balance() constant {
|
function balance() constant {
|
||||||
return balances[msg.sender];
|
return balances[msg.sender];
|
||||||
|
Loading…
Reference in New Issue
Block a user