Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(#11) replace import mortal by contract Mortal #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 29 additions & 18 deletions contracts/47_array_passer.sol
Original file line number Diff line number Diff line change
@@ -1,51 +1,62 @@
import "mortal";
pragma solidity ^0.4.22;

contract Mortal {
/* Define variable owner of the type address */
address owner;

/* This constructor is executed at initialization and sets the owner of the contract */
constructor() public { owner = msg.sender; }

/* Function to recover the funds on the contract */
function kill() public { if (msg.sender == owner) selfdestruct(msg.sender); }
}

// contract Descriptor {
// function getDescription() constant returns (uint16[3]){

// function getDescription() constant returns (uint16[3]){
// uint16[3] somevar;
// return somevar;
// }
// }

contract ArrayPasser is mortal {
contract ArrayPasser is Mortal {

address creator;

/***
* 1. Declare a 3x3 map of Tiles
***/
uint8 mapsize = 3;
Tile[3][3] tiles;
Tile[3][3] tiles;

struct Tile
struct Tile
{
/***
* 2. A tile is comprised of the owner, elevation and a pointer to a
* 2. A tile is comprised of the owner, elevation and a pointer to a
* contract that explains what the tile looks like
****/
uint8 elevation;
//Descriptor descriptor;
}

/***
* 3. Upon construction, initialize the internal map elevations.
* The Descriptors start uninitialized.
***/
function ArrayPasser(uint8[9] incmap)
function ArrayPasser(uint8[9] incmap)
{
creator = msg.sender;
uint8 counter = 0;
for(uint8 y = 0; y < mapsize; y++)
{
for(uint8 x = 0; x < mapsize; x++)
{
tiles[x][y].elevation = incmap[counter];
tiles[x][y].elevation = incmap[counter];
counter = counter + 1;
}
}
}
}
}

/***
* 4. After contract mined, check the map elevations
***/
Expand All @@ -56,9 +67,9 @@ contract ArrayPasser is mortal {
{
for(uint8 x = 0; x < mapsize; x++)
{
elevations[x][y] = tiles[x][y].elevation;
}
}
elevations[x][y] = tiles[x][y].elevation;
}
}
return elevations;
}
}
}
84 changes: 46 additions & 38 deletions contracts/48_msg_value_to_bytes20.sol
Original file line number Diff line number Diff line change
@@ -1,48 +1,56 @@
import "mortal";
pragma solidity ^0.4.22;

contract MsgValueToBytes20 is mortal {
contract Mortal {
/* Define variable owner of the type address */
address owner;

/* This constructor is executed at initialization and sets the owner of the contract */
constructor() public { owner = msg.sender; }

/* Function to recover the funds on the contract */
function kill() public { if (msg.sender == owner) selfdestruct(msg.sender); }
}

contract MsgValueToBytes20 is Mortal {

uint initialval;
uint80 uint80val;
uint80 uint80val;
bytes20 finalval;

function convertMsgValueToBytes20()
{
initialval = msg.value;
if(msg.value > 0 || msg.value < 1208925819614629174706176) // 1 wei up to (2^80 - 1) wei is the valid uint80 range
{
uint80val = uint80(msg.value);
finalval = bytes20(uint80val);
}
}

function getInitialval() constant returns (uint)
{
return initialval;
}

function getUint80val() constant returns (uint80)
{
return uint80val;
}

function getFinalval() constant returns (bytes20)
{
return finalval;
}


function convertMsgValueToBytes20() {
initialval = msg.value;

// 1 wei up to (2^80 - 1) wei is the valid uint80 range
if (msg.value > 0 || msg.value < 1208925819614629174706176) {
uint80val = uint80(msg.value);
finalval = bytes20(uint80val);
}
}

function getInitialval() constant returns (uint) {
return initialval;
}

function getUint80val() constant returns (uint80) {
return uint80val;
}

function getFinalval() constant returns (bytes20) {
return finalval;
}

}


/*
DEMO:

msgvaluetobytes20.convertMsgValueToBytes20.sendTransaction({from:eth.coinbase,value:web3.toWei(.001,"ether")});

> msgvaluetobytes20.getInitialval();
10000
> msgvaluetobytes20.getUint80val();
10000
> msgvaluetobytes20.getFinalval();
"0x0000000000000000000000000000000000002710"
> msgvaluetobytes20.convertMsgValueToBytes20.sendTransaction({from:eth.coinbase,value:web3.toWei(.001,"ether")});
> msgvaluetobytes20.getInitialval();
10000
> msgvaluetobytes20.getUint80val();
10000
> msgvaluetobytes20.getFinalval();
"0x0000000000000000000000000000000000002710"

*/
*/