Skip to content

Commit 68d958e

Browse files
Jesus NajeraJesus Najera
Jesus Najera
authored and
Jesus Najera
committed
library, importing & transactions practice
1 parent deb7db1 commit 68d958e

File tree

4 files changed

+75
-0
lines changed

4 files changed

+75
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

Transaction.sol

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
pragma solidity ^0.4.9;
2+
3+
contract Transaction {
4+
// each contract has an ethereum address - it can be found with: address(this)
5+
6+
event SenderLogger(address);
7+
event ValueLogger(uint);
8+
9+
address private owner;
10+
11+
modifier isOwner {
12+
require(owner==msg.sender);
13+
_;
14+
}
15+
16+
modifier validValue {
17+
require(msg.value >= 1);
18+
_;
19+
}
20+
21+
function Transaction() {
22+
owner = msg.sender;
23+
}
24+
25+
//payable is a modifier that can be added to any function
26+
//payable is a reserved keyword that allows a contract to receive ether
27+
// a contract can have exactly one unnamed function, it is default executed if contract is called w no parms
28+
function () payable isOwner validValue {
29+
SenderLogger(msg.sender);
30+
ValueLogger(msg.value);
31+
}
32+
}

libraryImportingPractice/library.sol

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
pragma solidity ^0.4.8;
2+
3+
library IntExtended {
4+
5+
function decrement(uint _self) returns (uint) {
6+
return _self-1;
7+
}
8+
9+
function decrementByValue(uint _self, uint _value) returns (uint) {
10+
return _self-_value;
11+
}
12+
13+
function increment(uint _self) returns (uint) {
14+
return _self+1;
15+
}
16+
17+
function incrementByValue(uint _self, uint _value) returns (uint) {
18+
return _self+_value;
19+
}
20+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
pragma solidity ^0.4.8;
2+
3+
import "browser/library.sol";
4+
5+
contract testLibrary {
6+
using IntExtended for uint;
7+
8+
function testDecrement(uint _base) returns (uint) {
9+
return IntExtended.decrement(_base);
10+
}
11+
12+
function testDecrementByValue(uint _base, uint _value) returns (uint) {
13+
return _base.decrementByValue(_value);
14+
}
15+
16+
function testIncrement(uint _base) returns (uint) {
17+
return IntExtended.increment(_base);
18+
}
19+
20+
function testIncrementByValue(uint _base, uint _value) returns (uint) {
21+
return _base.incrementByValue(_value);
22+
}
23+
}

0 commit comments

Comments
 (0)