مشکل در قرارداد

contract Decentradit {

    event Donated (bytes32 indexed postId, address indexed postOwner, address indexed donator, uint80 postDonations);
    struct post {
        address postOwner;
        bytes32 parentPost;
        bytes32 contentId;
        int40 votes;
        bytes32 categoryId;
        uint80 donates;
    }
    function donate (bytes32 _postId, uint80  _donationAdded) external 
    {
        address _donator = msg.sender;
        bytes32 _category = postRegistry[_postId].categoryId; 
        address _contributor = postRegistry[_postId].postOwner;
        require (postRegistry[_postId].postOwner != _donator, "you cannot donate your posts");       
        postRegistry[_postId].donates += _donationAdded;
        emit Donated(_postId, _contributor, _donator, postRegistry[_postId].donates);      
    }
    function getPost(bytes32 _postId) public view returns(address, bytes32, bytes32, int72, bytes32, uint80) {   
        return (
            postRegistry[_postId].postOwner,
            postRegistry[_postId].parentPost,
            postRegistry[_postId].contentId,
            postRegistry[_postId].votes,
            postRegistry[_postId].categoryId,
            postRegistry[_postId].donates);
    }

دوستان مشکل فانکشن چیه … اصلا عمل نمیکنه تابع مشابهی برای vote وجود داره که دقیقا با همین ساختار کار میکنه مثلا جای _donationAdded مقدار 1 رو جمع میزنه… input چجوری میشه تو فانکشن استفاده کرد؟

در اول contract خط زیر را اضافه کنید. همچنین یک { بسته در آخر contract کم هست.

    mapping(bytes32=>post) private postRegistry;

یعنی بدین صورت:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.11;

contract Decentradit {

    mapping(bytes32=>post) private postRegistry;
    event Donated (bytes32 indexed postId, address indexed postOwner, address indexed donator, uint80 postDonations);
    struct post {
        address postOwner;
        bytes32 parentPost;
        bytes32 contentId;
        int40 votes;
        bytes32 categoryId;
        uint80 donates;
    }

    function donate (bytes32 _postId, uint80  _donationAdded) external 
    {
        address _donator = msg.sender;
        bytes32 _category = postRegistry[_postId].categoryId; 
        address _contributor = postRegistry[_postId].postOwner;
        require (postRegistry[_postId].postOwner != _donator, "you cannot donate your posts");       
        postRegistry[_postId].donates += _donationAdded;
        emit Donated(_postId, _contributor, _donator, postRegistry[_postId].donates);      
    }
    function getPost(bytes32 _postId) public view returns(address, bytes32, bytes32, int72, bytes32, uint80) {   
        return (
            postRegistry[_postId].postOwner,
            postRegistry[_postId].parentPost,
            postRegistry[_postId].contentId,
            postRegistry[_postId].votes,
            postRegistry[_postId].categoryId,
            postRegistry[_postId].donates);
    }
}
1 پسندیده

ممنون برای پاسخ دو موردی که اشاره کردید رو در قرارداد کامل دارم چون طولانی بود اینجا فقط بخش مرتبط رو گذاشتم… خواستم ببینم ایا ایراد از فانکشن هست… میخوام به این صورت کار کنه که input بگیره بعد که به مقدار دونیت هایی که پست شده اضافه کنه… همین تو کد زیر برای vote دادن به درستی کار میکنه

    function voteUp(bytes32 _postId, uint8 _reputationAdded) external {
        address _voter = msg.sender;
        bytes32 _category = postRegistry[_postId].categoryId;
        address _contributor = postRegistry[_postId].postOwner;
        require (postRegistry[_postId].postOwner != _voter, "you cannot vote your own posts");
        require (voteRegistry[_voter][_postId] == false, "Sender already voted in this post");
        require (validateReputationChange(_voter,_category,_reputationAdded)==true, "This address cannot add this amount of reputation points");
        postRegistry[_postId].votes += 1;
        reputationRegistry[_contributor][_category] += _reputationAdded;
        voteRegistry[_voter][_postId] = true;
        emit Voted(_postId, _contributor, _voter, reputationRegistry[_contributor][_category], reputationRegistry[_voter][_category], postRegistry[_postId].votes, true, _reputationAdded);
    }

الان شما در تابع خودتون با چه ایرادی مواجه شدید؟