mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-08-06 23:06:49 +02:00
Add exposition around example bank
This commit is contained in:
@@ -13,6 +13,10 @@ As Solidity and Ethereum are under active development, experimental or beta feat
|
|||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// Let's start with a simple Bank contract, before diving into to the key components of the language
|
// Let's start with a simple Bank contract, before diving into to the key components of the language
|
||||||
|
// This bank has three main capabilities:
|
||||||
|
// - deposit
|
||||||
|
// - withdrawal
|
||||||
|
// - check balance
|
||||||
|
|
||||||
// ** START EXAMPLE **
|
// ** START EXAMPLE **
|
||||||
// Start with a Natspec comment (the three slashes) that can be used
|
// Start with a Natspec comment (the three slashes) that can be used
|
||||||
@@ -57,14 +61,6 @@ contract AcmeBank {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// It's good practice to have a remove function, which disables this
|
|
||||||
// contract - but does mean that users have to trust the owner
|
|
||||||
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];
|
||||||
@@ -406,6 +402,14 @@ function remove() {
|
|||||||
// - crowdfunding?
|
// - crowdfunding?
|
||||||
// - Peer to peer insurance
|
// - Peer to peer insurance
|
||||||
// ]
|
// ]
|
||||||
|
// It's good practice to have a remove function, which disables this
|
||||||
|
// contract - but does mean that users have to trust the owner
|
||||||
|
// For a decentralized bank without a trusted part
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
// *** END EXAMPLE ***
|
// *** END EXAMPLE ***
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user