text 解决方案介绍Solidity方案示例https://gangachris.com/posts/introduction-to-solidity/

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text 解决方案介绍Solidity方案示例https://gangachris.com/posts/introduction-to-solidity/相关的知识,希望对你有一定的参考价值。

pragma solidity ^0.4.20;

contract Cars {
    // we declare a custom type car
    struct Car {
        bytes32 make;
        uint year;
    }

    // we create a map that takes ethereum address and maps them to a Cars array
    mapping(address => Car[]) public carOwners;

    function registerCar(bytes32 _make, uint yr) public {
        // assign new struct
        // assign the car
        carOwners[msg.sender].push(Car({
            make: _make,
            year: yr
        }));
    }

    // change car ownership by providing owner and index
    function changeOwnership(address toOwner, uint index) public returns (bool) {
        // check if sender has cars
        // can be refactored to a function modifier
        if (carOwners[msg.sender].length == 0) {
            return false;
        }

        if (carOwners[msg.sender].length > index+1) {
            return false;
        }

        carOwners[toOwner].push(carOwners[msg.sender][index]);

        // TODO: remove the car from the current owner, otherwise there's a duplicate.
    }

    // get a car by providing owner and index
    function getCarMake(address owner, uint index) public view returns (bytes32 carMake) {
        if (carOwners[owner].length == 0 ){
            return;
        }

        if (carOwners[owner].length > index+1) {
            return;
        }

        carMake = carOwners[owner][index].make;
    }
}

以上是关于text 解决方案介绍Solidity方案示例https://gangachris.com/posts/introduction-to-solidity/的主要内容,如果未能解决你的问题,请参考以下文章

[Contract] Solidity 生成随机数方案

Solidity状态槽冲突问题

智能合约实战 solidity 语法学习 09 [ 以太坊 ether ERC20标准API介绍及示例 ]name symbol decimals totalSupply balanceOf...

智能合约实战 solidity 语法学习 09 [ 以太坊 ether ERC20标准API介绍及示例 ]name symbol decimals totalSupply balanceOf...

智能合约实战 solidity 语法学习 09 [ 以太坊 ether ERC20标准API介绍及示例 ]name symbol decimals totalSupply balanceOf...(代

Mac geth中不能编译Solidity代码解决方案