bitcoin-sv / sol2scrypt

Solidity to sCrypt Transplier
BSD 3-Clause "New" or "Revised" License
1 stars 0 forks source link

Known Issues #3

Open freedomhero opened 2 years ago

freedomhero commented 2 years ago
freedomhero commented 2 years ago
xhliu commented 2 years ago

public view function

Visibility https://bitsofco.de/solidity-function-visibility-explained/

xhliu commented 2 years ago

struct inside contract

xhliu commented 2 years ago

qualified import

xhliu commented 2 years ago

dynamic array: static?

freedomhero commented 2 years ago
freedomhero commented 2 years ago

x >> y is equivalent to the mathematical expression x / 2**y, rounded towards negative infinity.

freedomhero commented 2 years ago

Address related:

freedomhero commented 2 years ago
freedomhero commented 2 years ago
freedomhero commented 2 years ago

https://hackernoon.com/getting-deep-into-evm-how-ethereum-works-backstage-ac7efa1f0015

freedomhero commented 2 years ago
    struct Campaign {
        address beneficiary;
        uint fundingGoal;
        uint numFunders;
        uint amount;
        mapping (uint => Funder) funders;
    }
freedomhero commented 2 years ago

https://docs.soliditylang.org/en/v0.8.10/types.html#mapping-types

freedomhero commented 2 years ago
freedomhero commented 2 years ago

https://solidity-cn.readthedocs.io/zh/stable/units-and-global-variables.html

freedomhero commented 2 years ago

https://docs.soliditylang.org/en/v0.8.10/control-structures.html#destructuring-assignments-and-returning-multiple-values

function arithmetics(uint _a, uint _b)
        public
        pure
        returns (uint o_sum, uint o_product)
    {
        o_sum = _a + _b;
        o_product = _a * _b;
    }
freedomhero commented 2 years ago

while / do / for / break / continue / try / catch https://solidity-by-example.org/try-catch

zhfnjust commented 2 years ago

address => Ripemd160 ?

zhfnjust commented 2 years ago
function population_count(uint n) pure public returns (uint count) {
        for (count = 0; n != 0; count++) {
                n &= (n - 1);
        }
}
xhliu commented 2 years ago

address => Ripemd160 ?

address => PubKeyHash

zhfnjust commented 2 years ago
enum State {
                Running,
                Sleeping,
                Waiting,
                Stopped,
                Zombie,
                StateCount
        }
freedomhero commented 2 years ago

https://docs.soliditylang.org/en/v0.8.10/contracts.html#creating-contracts

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.4.22 <0.9.0;

contract OwnedToken {
    // `TokenCreator` is a contract type that is defined below.
    // It is fine to reference it as long as it is not used
    // to create a new contract.
    TokenCreator creator;
    address owner;
    bytes32 name;

    // This is the constructor which registers the
    // creator and the assigned name.
    constructor(bytes32 _name) {
        // State variables are accessed via their name
        // and not via e.g. `this.owner`. Functions can
        // be accessed directly or through `this.f`,
        // but the latter provides an external view
        // to the function. Especially in the constructor,
        // you should not access functions externally,
        // because the function does not exist yet.
        // See the next section for details.
        owner = msg.sender;

        // We perform an explicit type conversion from `address`
        // to `TokenCreator` and assume that the type of
        // the calling contract is `TokenCreator`, there is
        // no real way to verify that.
        // This does not create a new contract.
        creator = TokenCreator(msg.sender);
        name = _name;
    }

    function changeName(bytes32 newName) public {
        // Only the creator can alter the name.
        // We compare the contract based on its
        // address which can be retrieved by
        // explicit conversion to address.
        if (msg.sender == address(creator))
            name = newName;
    }

    function transfer(address newOwner) public {
        // Only the current owner can transfer the token.
        if (msg.sender != owner) return;

        // We ask the creator contract if the transfer
        // should proceed by using a function of the
        // `TokenCreator` contract defined below. If
        // the call fails (e.g. due to out-of-gas),
        // the execution also fails here.
        if (creator.isTokenTransferOK(owner, newOwner))
            owner = newOwner;
    }
}

contract TokenCreator {
    function createToken(bytes32 name)
        public
        returns (OwnedToken tokenAddress)
    {
        // Create a new `Token` contract and return its address.
        // From the JavaScript side, the return type
        // of this function is `address`, as this is
        // the closest type available in the ABI.
        return new OwnedToken(name);
    }

    function changeName(OwnedToken tokenAddress, bytes32 name) public {
        // Again, the external type of `tokenAddress` is
        // simply `address`.
        tokenAddress.changeName(name);
    }

    // Perform checks to determine if transferring a token to the
    // `OwnedToken` contract should proceed
    function isTokenTransferOK(address currentOwner, address newOwner)
        public
        pure
        returns (bool ok)
    {
        // Check an arbitrary condition to see if transfer should proceed
        return keccak256(abi.encodePacked(currentOwner, newOwner))[0] == 0x7f;
    }
}
freedomhero commented 2 years ago

https://docs.soliditylang.org/en/v0.8.10/contracts.html#constant-and-immutable-state-variables

contract C {
    string constant TEXT = "abc";
    bytes32 constant MY_HASH = keccak256("abc");
    uint immutable decimals;
    uint immutable maxBalance;
    address immutable owner = msg.sender;

    constructor(uint _decimals, address _reference) {
        decimals = _decimals;
        // Assignments to immutables can even access the environment.
        maxBalance = _reference.balance;
    }

    function isBalanceTooHigh(address _other) public view returns (bool) {
        return _other.balance > maxBalance;
    }
}

fixed

freedomhero commented 2 years ago

https://docs.soliditylang.org/en/v0.8.10/contracts.html#receive-ether-function

https://solidity-by-example.org/sending-ether/

zhfnjust commented 2 years ago

Can initialize properties

image

freedomhero commented 2 years ago

https://docs.soliditylang.org/en/v0.8.10/contracts.html#fallback-function https://solidity-by-example.org/fallback

freedomhero commented 2 years ago

https://docs.soliditylang.org/en/v0.8.10/contracts.html#function-overloading

freedomhero commented 2 years ago

https://docs.soliditylang.org/en/v0.8.10/contracts.html#events

ignore now

zhfnjust commented 2 years ago

& or &= between integer

      function is_power_of_2(int n) : bool {
                return n != 0 && (n & (n - 1)) == 0;
        }
freedomhero commented 2 years ago

https://docs.soliditylang.org/en/v0.8.10/contracts.html#inheritance

freedomhero commented 2 years ago
freedomhero commented 2 years ago

https://docs.soliditylang.org/en/v0.8.10/contracts.html#interfaces https://solidity-by-example.org/interface https://cryptomarketpool.com/interface-in-solidity-smart-contracts/

freedomhero commented 2 years ago

https://docs.soliditylang.org/en/v0.8.10/contracts.html#using-for

xhliu commented 2 years ago
  • Create contracts

https://docs.soliditylang.org/en/v0.8.10/contracts.html#creating-contracts

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.4.22 <0.9.0;

contract OwnedToken {
    // `TokenCreator` is a contract type that is defined below.
    // It is fine to reference it as long as it is not used
    // to create a new contract.
    TokenCreator creator;
    address owner;
    bytes32 name;

    // This is the constructor which registers the
    // creator and the assigned name.
    constructor(bytes32 _name) {
        // State variables are accessed via their name
        // and not via e.g. `this.owner`. Functions can
        // be accessed directly or through `this.f`,
        // but the latter provides an external view
        // to the function. Especially in the constructor,
        // you should not access functions externally,
        // because the function does not exist yet.
        // See the next section for details.
        owner = msg.sender;

        // We perform an explicit type conversion from `address`
        // to `TokenCreator` and assume that the type of
        // the calling contract is `TokenCreator`, there is
        // no real way to verify that.
        // This does not create a new contract.
        creator = TokenCreator(msg.sender);
        name = _name;
    }

    function changeName(bytes32 newName) public {
        // Only the creator can alter the name.
        // We compare the contract based on its
        // address which can be retrieved by
        // explicit conversion to address.
        if (msg.sender == address(creator))
            name = newName;
    }

    function transfer(address newOwner) public {
        // Only the current owner can transfer the token.
        if (msg.sender != owner) return;

        // We ask the creator contract if the transfer
        // should proceed by using a function of the
        // `TokenCreator` contract defined below. If
        // the call fails (e.g. due to out-of-gas),
        // the execution also fails here.
        if (creator.isTokenTransferOK(owner, newOwner))
            owner = newOwner;
    }
}

contract TokenCreator {
    function createToken(bytes32 name)
        public
        returns (OwnedToken tokenAddress)
    {
        // Create a new `Token` contract and return its address.
        // From the JavaScript side, the return type
        // of this function is `address`, as this is
        // the closest type available in the ABI.
        return new OwnedToken(name);
    }

    function changeName(OwnedToken tokenAddress, bytes32 name) public {
        // Again, the external type of `tokenAddress` is
        // simply `address`.
        tokenAddress.changeName(name);
    }

    // Perform checks to determine if transferring a token to the
    // `OwnedToken` contract should proceed
    function isTokenTransferOK(address currentOwner, address newOwner)
        public
        pure
        returns (bool ok)
    {
        // Check an arbitrary condition to see if transfer should proceed
        return keccak256(abi.encodePacked(currentOwner, newOwner))[0] == 0x7f;
    }
}
contract metaCoin { 
    ...
    }
}

contract coinCaller{
    struct transfer{
        metaCoin coinContract;
        uint amount;
        address recipient;
        bool successful;
        uint balance;
    }
}

https://dappsforbeginners.wordpress.com/tutorials/interactions-between-contracts/

xhliu commented 2 years ago

Delegatecall

https://solidity-by-example.org/delegatecall

xhliu commented 2 years ago

// string literal contract Employee is Person { function gender() public returns (bytes32) { return "female"; } }

xhliu commented 2 years ago

Literal 1e18

freedomhero commented 2 years ago

return in the middle of a function.

function retrieve() external view returns (uint256){
    uint256 x = number * 10;
    if (number > 10) return x;
    return x +  10;
}
zhfnjust commented 2 years ago

.push and .indexOf

contract C {
    using Search for uint[];
    uint[] data;

    function append(uint value) public {
        data.push(value);
    }

    function replace(uint _old, uint _new) public {
        // This performs the library function call
        uint index = data.indexOf(_old);
        if (index == type(uint).max)
            data.push(_new);
        else
            data[index] = _new;
    }
}