SaveIpfsToContract

pragma solidity 0.6.2;

/*
     将图片上传到ipfs上,然后将图片连接存储到合约中
     https://ipfs.io/ipfs/QmSvyKduV1rVSngDtfzBsaL7tpv87gCR1Rzr6PtajeasvA
*/
contract SaveIpfsToContract{

    mapping(uint256 => string) p;
    uint256 n = 0;

    function save(bytes memory data) public{
        (string memory a,string memory b,string memory c,string memory d,string memory e,string memory f) = abi.decode(data,(string,string,string,string,string,string));
        p[n + 1] = a;
        p[n + 2] = b;
        p[n + 3] = c;
        p[n + 4] = d;
        p[n + 5] = e;
        p[n + 6] = f;
        n = n + 6;
    }

    // 将字符串转为bytes
    function getBytes(string memory a,string memory b,string memory c,string memory d,string memory e,string memory f) public returns(bytes memory){
        (bool success, bytes memory data) = address(this).call(abi.encodeWithSignature("strToBytes(string,string,string,string,string,string)",a,b,c,d,e,f));
        require(success,"call is fail");
        return data;
    }

    function strToBytes(string memory a,string memory b,string memory c,string memory d,string memory e,string memory f) private pure returns(string memory,string memory,string memory,string memory,string memory,string memory){
        return (a,b,c,d,e,f);
    }

    function get(uint256 m) public view returns (string memory){
        return p[m];
    }

}

你可能感兴趣的:(SaveIpfsToContract)