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

Doesn't support structs in emitted events #82

Closed
bnolan opened this issue May 9, 2022 · 2 comments
Closed

Doesn't support structs in emitted events #82

bnolan opened this issue May 9, 2022 · 2 comments
Assignees
Labels
bug Something isn't working cannot reproduce Need more information

Comments

@bnolan
Copy link

bnolan commented May 9, 2022

Various errors when trying to decode logs from this contract:

// SDPX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "../openzeppelin/openzeppelin-contracts@4.0.0/contracts/token/ERC20/ERC20.sol";
import "../openzeppelin/openzeppelin-contracts@4.0.0/contracts/security/Pausable.sol";
import "../openzeppelin/openzeppelin-contracts@4.0.0/contracts/access/Ownable.sol";

struct Tip { 
    address sender;
    uint128 post;
    address author;
    uint amount;
}

contract FolkTipping is Pausable, Ownable {
    Tip[] public tips;
    mapping(uint128 => uint) public postValue;
   
    address internal tokenAddress;
    uint public minTip;
    uint public maxTip;

    event NewTip(Tip tip);
    event NewTipForAuthor(address author, Tip tip);
    event NewTipForPost(uint128 post, Tip tip);
   
    constructor (address _tokenAddress) {
        tokenAddress = _tokenAddress;
        minTip = 1;
        maxTip = type(uint).max;
    }
   
    function tip (uint128 post, address author, uint amount) public whenNotPaused {
        ERC20 token = ERC20(tokenAddress);

        require(author != msg.sender, 'Author cannot be sender');
        require(post > 0, 'Post id cannot be null');
        require(amount >= minTip, 'Amount less than minTip');
        require(amount < maxTip, 'Amount more than maxTip');
        require(token.transferFrom(msg.sender, author, amount));

        Tip memory t = Tip(msg.sender, post, author, amount);
        tips.push(t);
        postValue[post] += amount;

        emit NewTip(t);
        emit NewTipForAuthor(author, t);
        emit NewTipForPost(post, t);
    }

   function getTipCount() public view returns(uint result){
        result = tips.length;
   }

   function getTip(uint index) public view returns(Tip memory result){
        result = tips[index];
   }

   function getPostValue(uint128 post) public view returns(uint result){
        result = postValue[post];
   }

    function setMin (uint t) public onlyOwner {
        require(t < maxTip);
        minTip = t;
    }

    function setMax (uint t) public onlyOwner {
        require(t > minTip);
        maxTip = t;
    }

    function pause () public onlyOwner {
        _pause();
    }

    function unpause () public onlyOwner {
        _unpause();
    }
}

I'm working on adding support for structs / tuples, any pointers for me? Otherwise I'll submit a PR when it's ready.

@kurotaky
Copy link
Collaborator

kurotaky commented May 9, 2022

Hi, I would be grateful if you could post the error on the issue, but Pull Request is always welcome!

@q9f
Copy link
Owner

q9f commented May 10, 2022

Hi @bnolan - if you could describe in 2-3 lines of Ruby what you tried and eventually attach an error log, this would be much appreciated and drastically reduce the time for us to identify the issue. 🙏🏼

@q9f q9f added bug Something isn't working cannot reproduce Need more information labels May 13, 2022
@q9f q9f closed this as completed May 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cannot reproduce Need more information
Projects
None yet
Development

No branches or pull requests

3 participants