0

Please have a look at the contract

pragma solidity ^0.5.1;

/**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
 */
 library SafeMath {
 function mul(uint256 a, uint256 b) internal pure returns (uint256) {
    if (a == 0) {
    return 0;
   }
   uint256 c = a * b;
   assert(c / a == b);
   return c;
  }

  function div(uint256 a, uint256 b) internal pure returns (uint256) {
   // assert(b > 0); // Solidity automatically throws when dividing by 0
   uint256 c = a / b;
   // assert(a == b * c + a % b); // There is no case in which this doesn't hold
   return c;
  }

  function sub(uint256 a, uint256 b) internal pure returns (uint256) {
   assert(b <= a);
   return a - b;
 }

 function add(uint256 a, uint256 b) internal pure returns (uint256) {
   uint256 c = a + b;
   assert(c >= a);
   return c;
  }
 }

contract Token {
 /// @return total amount of tokens
  function totalSupply() public pure returns (uint256 supply);

  /// @param _owner The address from which the balance will be retrieved
 /// @return The balance
 function balanceOf(address _owner) public pure returns (uint256 balance);

 /// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
 /// @param _value The amount of token to be transferred
 /// @return Whether the transfer was successful or not
 function transfer(address _to, uint256 _value) public returns (bool success);

  /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
 /// @param _from The address of the sender
 /// @param _to The address of the recipient
 /// @param _value The amount of token to be transferred
 /// @return Whether the transfer was successful or not
  function transferFrom(address _from, address _to, uint256 _value) public 
  returns (bool success);

 /// @notice `msg.sender` approves `_addr` to spend `_value` tokens
 /// @param _spender The address of the account able to transfer the tokens
 /// @param _value The amount of wei to be approved for transfer
  /// @return Whether the approval was successful or not
  function approve(address _spender, uint256 _value) public returns (bool success);

  /// @param _owner The address of the account owning tokens
 /// @param _spender The address of the account able to transfer the tokens
 /// @return Amount of remaining tokens allowed to spent
 function allowance(address _owner, address _spender) public pure returns (uint256 remaining);

 event Transfer(address indexed _from, address indexed _to, uint256 _value);
  event Approval(address indexed _owner, address indexed _spender, uint256 _value);

  uint public decimals;
 string public name;
  }

 /**
 * @title Ownable
 * @dev The Ownable contract has an owner address, and provides basic 
authorization control
* functions, this simplifies the implementation of "user permissions".
 */
  contract Ownable {

  address public owner;

  /**
   * @dev The Ownable constructor sets the original `owner` of the contract to the sender
  * account.
   */
  constructor() public {
    owner = msg.sender;
  }

  /**
   * @dev Throws if called by any account other than the owner.
   */
  modifier onlyOwner() {
   require(msg.sender == owner);
    _;
   }

   /**
    * @dev Allows the current owner to transfer control of the contract to a newOwner.
   * @param newOwner The address to transfer ownership to.
   */
  function transferOwnership(address newOwner) onlyOwner public {
    require(newOwner != address(0));      
   owner = newOwner;
  }

 }
 contract Gateway is Ownable{
using SafeMath for uint;


struct BuyInfo {
  address buyerAddress; 
  address sellerAddress;
  uint value;
  address currency;
}

mapping(address => mapping(uint => BuyInfo)) public payment;


function getBuyerAddressPayment(address _sellerAddress, uint _orderId) public pure returns(address){
  return  payment[_sellerAddress][_orderId].buyerAddress;
}    
function getSellerAddressPayment(address _sellerAddress, uint _orderId) public pure returns(address){
  return  payment[_sellerAddress][_orderId].sellerAddress;
}    

function getValuePayment(address _sellerAddress, uint _orderId) public pure returns(uint){
  return  payment[_sellerAddress][_orderId].value;
}    

function getCurrencyPayment(address _sellerAddress, uint _orderId) public pure returns(address){
  return  payment[_sellerAddress][_orderId].currency;
}


function payToken(address _tokenAddress, address _sellerAddress, uint _orderId,  uint _value) public returns (bool success){
  require(_tokenAddress != address(0));
  require(_sellerAddress != address(0)); 
  require(_value > 0);
  Token token = Token(_tokenAddress);
  require(token.allowance(msg.sender, this) >= _value);
  payment[_sellerAddress][_orderId] = BuyInfo(msg.sender, _sellerAddress, _value, _tokenAddress);
  success = true;
}
function payEth(address _sellerAddress, uint _orderId, uint _value) internal returns  (bool success){
  require(_sellerAddress != address(0)); 
  require(_value > 0);
  payment[_sellerAddress][_orderId] = BuyInfo(msg.sender, _sellerAddress, _value, 0x0000000000000000000000000000000000000001);    
  success = true;
}

function balanceOfToken(address _tokenAddress, address _Address) public pure returns (uint) {
  Token token = Token(_tokenAddress);
  return token.balanceOf(_Address);
}

function bytesToAddress(bytes source) internal pure returns(address) {
  uint result;
  uint mul = 1;
  for(uint i = 20; i > 0; i--) {
    result += uint8(source[i-1])*mul;
    mul = mul*256;
  }
  return address(result);
}
function() external payable {
  require(msg.data.length == 20); 
  require(msg.value > 99999999999);
  address sellerAddress = bytesToAddress(bytes(msg.data));
  uint value = msg.value.div(10000000000).mul(10000000000);
  uint orderId = msg.value.sub(value);
  payEth(sellerAddress, orderId, value);
  }
}

Actually the main contract is working fine can be found in Etherscan. Main Contract

What am I trying to do? As you can that there is a charge that can be deducted in the main contract. I'm trying to create a new contract without that function.

What is the error in the mentioned code? The error is in line 161. Error - TypeError: Data location must be "storage" or "memory" for parameter in function, but none was given. function bytesToAddress(bytes source) internal pure returns(address) { ^----------^

I'm trying to new and trying to modify the contract. Any help will be appreciated.

0

Just add the keyword memory, so it becomes: function bytesToAddress(bytes memory source) internal pure returns(address) {. Otherwise the compiler doesn't know where to (temporarily?) store the variable contents.

You can read more about these here: https://solidity.readthedocs.io/en/develop/introduction-to-smart-contracts.html#storage-memory-and-the-stack

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.