Last active
          April 3, 2019 19:08 
        
      - 
      
- 
        Save loredanacirstea/1b3afb7b4e0e0775f53c9c7a99ae1aca to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | /* | |
| browser/dType_V2.sol:52:29: TypeError: Invalid type for argument in function call. Invalid implicit conversion from bytes24 to function (struct typeALib.TypeA memory) pure external returns (struct typeALib.TypeA memory) requested. | |
| return typeALib.map(signature, typeAarr); | |
| ^-------^ | |
| */ | |
| pragma solidity ^0.5.0; | |
| pragma experimental ABIEncoderV2; | |
| library typeALib { | |
| struct TypeA { | |
| uint256 balance; | |
| address token; | |
| } | |
| function map( | |
| function(TypeA memory) external pure returns (TypeA memory) callback, | |
| TypeA[] memory typeAarr | |
| ) | |
| view | |
| public | |
| returns (TypeA[] memory result) | |
| { | |
| uint length = typeAarr.length; | |
| result = new TypeA[](length); | |
| for (uint i = 0; i < length; i++) { | |
| result[i] = callback(typeAarr[i]); | |
| } | |
| return result; | |
| } | |
| } | |
| contract typeAAFunctions { | |
| using typeALib for typeALib.TypeA; | |
| function double(typeALib.TypeA memory typeA) | |
| pure | |
| public | |
| returns(typeALib.TypeA memory result) | |
| { | |
| typeA.balance *= 2; | |
| return typeA; | |
| } | |
| function doubleBalances(typeALib.TypeA[] memory typeAarr) | |
| view | |
| public | |
| returns(typeALib.TypeA[] memory result) | |
| { | |
| bytes memory sign = abi.encodePacked(address(this), this.double.selector); | |
| bytes24 signature; | |
| assembly { | |
| signature := mload(add(sign, 32)) | |
| } | |
| return typeALib.map(signature, typeAarr); | |
| } | |
| function doubleBalances2(typeALib.TypeA[] memory typeAarr) | |
| view | |
| public | |
| returns(typeALib.TypeA[] memory result) | |
| { | |
| return typeALib.map(this.double, typeAarr); | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment