Created
August 15, 2018 10:27
-
-
Save phuctu1901/91c6a18cbe3dac710b71f8d90fd28f71 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.24+commit.e67f0147.js&optimize=false&gist=
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.21; | |
contract BotManagement{ | |
function verifyVehicle(address , string ) public returns (bool) {} | |
} | |
contract Bot{ | |
BotManagement botManagementContract; | |
constructor(address _t) public { | |
botManagementContract = BotManagement(_t); | |
} | |
function verifyVehicleatBot(string _plate_id) public returns (bool){ | |
return botManagementContract.verifyVehicle(msg.sender, _plate_id); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.21; | |
contract Vehicles{ | |
function getStatus(string) public view returns(int){} | |
function getOwnerInfo(string) public view returns (address){} | |
} | |
contract BotManagement{ | |
address botAddress; | |
int completeSetup=0; | |
function setBotAddr(address _address) public returns (bool){ | |
if (completeSetup ==0){ | |
botAddress = _address; | |
// completeSetup =1; | |
return true; | |
} | |
return false; | |
} | |
Vehicles vehiclesContract; | |
constructor(address _vaddress, address _address) public{ | |
vehiclesContract = Vehicles(_vaddress); | |
permissionList[_address].owner = _address; | |
permissionList[_address].typePermis = 1; | |
} | |
struct Account{ | |
address owner; | |
uint256 balance; | |
} | |
address[] public accountList; | |
mapping (address => Account) accounts; | |
struct Bot{ | |
address owner; | |
int status; //0: deactive, 1: active; | |
} | |
address[] public botList; | |
mapping( address => Bot) Bots; | |
struct Permission{ | |
address owner; | |
int256 typePermis; | |
//0. Bị thu hồi các quyền. | |
//1. Cấp quyền cho các account khác và các quyền còn lại. | |
//2. Chỉ có quyền đăng ký phương tiện, ko có quyền cấp quyền cho account khác. | |
} | |
mapping (address => Permission) permissionList; | |
function checkPermission() public view returns(int256){ | |
return permissionList[msg.sender].typePermis; | |
} | |
function addPermission(address _address, int256 _type) public returns(bool){ | |
if (checkPermission() == 1) { | |
permissionList[_address].owner = _address; | |
permissionList[_address].typePermis = _type; | |
return true; | |
} | |
return false; | |
} | |
function addBot(address _address) public returns(bool){ | |
if (checkPermission()==1){ | |
Bot storage tmp_bot = Bots[_address]; | |
tmp_bot.owner=_address; | |
tmp_bot.status= 1; | |
botList.push(_address) -1; | |
return true; | |
} | |
return false; | |
} | |
function addAccount(address _address) public returns(bool){ | |
if (checkPermission()==1){ | |
Account storage tmp_account = accounts[_address]; | |
tmp_account.owner = _address; | |
accountList.push(_address) -1; | |
return true; | |
} | |
return false; | |
} | |
function checkAccount(address _address) public view returns(bool){ | |
if (accounts[_address].owner!=_address){ | |
return false; | |
} | |
return true; | |
} | |
function addCoin(address _address) public payable returns (bool){ | |
if (checkAccount(_address)){ | |
accounts[_address].balance+=msg.value; | |
} | |
} | |
function addCoin() public payable returns(bool){ | |
if (accounts[msg.sender].owner==msg.sender){ | |
accounts[msg.sender].balance+=msg.value; | |
return true; | |
} | |
return false; | |
} | |
function getBalance(address _address) public view returns(uint256){ | |
return accounts[_address].balance; | |
} | |
function verifyVehicle(address _address, string _plate_id) public returns (bool){ | |
if (msg.sender==botAddress){ | |
if (Bots[_address].status ==1){ | |
if (vehiclesContract.getStatus(_plate_id) == 1) | |
{ | |
address owner = vehiclesContract.getOwnerInfo(_plate_id); | |
accounts[owner].balance -=100; | |
return true; | |
} | |
} | |
} | |
return false; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.21; | |
contract Vehicles{ | |
function getStatus(string) public view returns(int){} | |
function getOwnerInfo(string) public view returns (address){} | |
} | |
contract BotManagement{ | |
function checkAccount(address) public view returns(bool){} | |
function addCoin(address) public payable returns (bool){ } | |
function getBalance(address) public view returns(uint256){} | |
} | |
contract Customer{ | |
BotManagement botMgmtContract; | |
constructor(address BotManagementContractAddress) public{ | |
botMgmtContract = BotManagement(BotManagementContractAddress); | |
} | |
function getBalance() public view returns(uint256){ | |
return botMgmtContract.getBalance(msg.sender); | |
} | |
function checkAccount() public view returns (bool){ | |
return botMgmtContract.checkAccount(msg.sender); | |
} | |
function addCoin() public payable returns(bool){ | |
botMgmtContract.addCoin.value(msg.value)(msg.sender); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.0; | |
contract PayMain { | |
Main main; | |
function PayMain(address _m) { | |
main = Main(_m); | |
} | |
function () payable { | |
// Call the handlePayment function in the main contract | |
// and forward all funds (msg.value) sent to this contract | |
// and passing in the following data: msg.sender | |
main.handlePayment.value(msg.value)(msg.sender); | |
} | |
} | |
contract Main { | |
function handlePayment(address senderAddress) payable public { | |
// senderAddress in this example could be removed since msg.sender can be used directly | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.21; | |
// contract BotManagement{ | |
// function addAccount(address) public pure returns(bool){} | |
// function checkAccount(address) public pure returns(bool){} | |
// } | |
contract Vehicles{ | |
//Khởi tạo address có quyền truy cập ban đầu. | |
constructor(address _address) public{ | |
permissionList[_address].owner = _address; | |
permissionList[_address].typePermis = 1; | |
} | |
// struct VehicleInfo{ | |
// string plate_id; | |
// uint256 indexOfperson; | |
// } | |
// //Lưu danh sách các xe mà chủ sở hữu | |
// struct ownerVehicle{ | |
// mapping (address => VehicleInfo) VehiclesOfOwner; | |
// uint256 lenghtOfVehicle; | |
// } | |
// mapping(address => ownerVehicle) ownerVehicles; | |
// function addOwnerVehicel(address _owner, string _plate_id, uint256 index) public { | |
// } | |
//Liên kết với smart contract quản lý BOT | |
// int complete_setup = 0; | |
// // BotManagement botMgmtContract; | |
// function setBotMgmt(address _address) public { | |
// if ((checkPermission()==1) && (complete_setup==0)) | |
// { | |
// botMgmtContract = BotManagement(_address); | |
// } | |
// } | |
//Các address có quyền truy cập tới smart contract này. | |
struct Permission{ | |
address owner; | |
int256 typePermis; | |
//0. Bị thu hồi các quyền. | |
//1. Cấp quyền cho các account khác và các quyền còn lại. | |
//2. Chỉ có quyền đăng ký phương tiện, ko có quyền cấp quyền cho account khác. | |
} | |
//Danh sách các address có quyền truy cập | |
mapping (address => Permission) permissionList; | |
//Thông tin cá nhân của người đăng ký phương tiện giao thông | |
struct Person { | |
address owner; | |
string dateRegis; | |
} | |
//Lưu thông tin phương tiện | |
struct Vehicle{ | |
string plate_id; | |
mapping (uint256 => Person) persons;//Danh sách các chủ từng sở hữu phương tiện | |
uint256 lenghtPerson;//Số lần xe đổi chủ | |
string name; | |
string typeOfVehicle; | |
string color; | |
string datePro; | |
string charactic; | |
string manufac; | |
string serial; | |
int status; //1. active, 0. deactive, -1. stolen. | |
} | |
//Danh sách các phương tiện | |
mapping (string => Vehicle) vehicles; | |
string[] public vehiclesList; | |
//Kiểm tra trạng thái của phương tiện, đang hoạt động, ko hoạt động hay đã bị trộm | |
function getStatus(string _plate_id) public view returns(int){ | |
return (vehicles[_plate_id].status); | |
} | |
//Kiểm tra xem chủ nhân address có phải chủ phương tiện. Dùng để | |
//kiểm tra khi có người yêu cầu thay đổi thông tin về phương tiện. | |
function checkOwner(address _owner, string _plate_id) public view returns(bool){ | |
if (vehicles[_plate_id].persons[vehicles[_plate_id].lenghtPerson -1 ].owner != _owner){ | |
return (false); | |
} | |
else{ | |
return (true); | |
} | |
} | |
//Kiểm tra xem address request lên smart contract có những quyền gì | |
function checkPermission() public view returns(int256){ | |
return permissionList[msg.sender].typePermis; | |
} | |
//Thêm address có quyền truy cập smart contract | |
function addPermission(address _address, int256 _type) public returns(bool){ | |
if (checkPermission() == 1) { | |
permissionList[_address].owner = _address; | |
permissionList[_address].typePermis = _type; | |
return true; | |
} | |
return false; | |
} | |
//Đăng ký thêm phương tiện | |
function addVehicle(address _owner, string _plate_id, string _name, string _type, string _color, string _datePro, string _dateRegis, string _charac, string _manufac, string _serial) public returns (bool){ | |
if (checkPermission()<1){ | |
return false; | |
} | |
else{ | |
// if (!botMgmtContract.checkAccount(_owner)){ | |
// botMgmtContract.addAccount(_owner); | |
// } | |
Vehicle storage vehicle = vehicles[_plate_id]; | |
vehicle.lenghtPerson = 0; | |
Person storage p = vehicle.persons[vehicle.lenghtPerson] ; | |
p.owner = _owner; | |
p.dateRegis= _dateRegis; | |
vehicle.plate_id = _plate_id; | |
vehicle.name = _name; | |
vehicle.typeOfVehicle = _type; | |
vehicle.color = _color; | |
vehicle.datePro = _datePro; | |
vehicle.charactic = _charac; | |
vehicle.manufac = _manufac; | |
vehicle.serial = _serial; | |
vehicle.status = 1; | |
vehicle.lenghtPerson++; | |
vehiclesList.push(_plate_id) -1; | |
return true; | |
} | |
} | |
//Chuyển đổi chủ sở hữu phương tiện. | |
function changeOwner(string _plate_id, address _owner, address _new_owner, string _dateRegis) public returns (bool){ | |
if (checkPermission()<1){ | |
return false; | |
} | |
if (!checkOwner(_owner, _plate_id)){ | |
return false; | |
} | |
else{ | |
Person storage p = vehicles[_plate_id].persons[vehicles[_plate_id].lenghtPerson] ; | |
p.owner = _new_owner; | |
p.dateRegis = _dateRegis; | |
vehicles[_plate_id].lenghtPerson ++; | |
return true; | |
} | |
} | |
//Thay đổi trạng thái của phương tiện | |
function changeStatus(string _plate_id, address _owner, int _status) public returns(bool){ | |
if (checkPermission()<1){ | |
return false; | |
} | |
if (!checkOwner(_owner, _plate_id)){ | |
return false; | |
} | |
else{ | |
vehicles[_plate_id].status = _status; | |
return (true); | |
} | |
} | |
//Lấy số lượng chủ mà phương tiện đã qua tay | |
function getOwnerLength(string _plate_id) public view returns(uint){ | |
return vehicles[_plate_id].lenghtPerson; | |
} | |
//Lấy thông tin người chủ cuối cùng của phương tiện | |
function getLastOwner(string _plate_id) public view returns (address){ | |
return (vehicles[_plate_id].persons[vehicles[_plate_id].lenghtPerson-1].owner); | |
} | |
//Lấy thông tin về chủ phương tiện | |
function getOwnerInfo(string _plate_id, uint256 index) public view returns (address, string){ | |
return (vehicles[_plate_id].persons[index].owner, vehicles[_plate_id].persons[index].dateRegis); | |
} | |
//Lấy thông tin về phương tiện - những thông tin cố định. | |
function getFixedInfo(string _plate_id) view public returns (string, string, string, string, string) { | |
return(vehicles[_plate_id].name, vehicles[_plate_id].typeOfVehicle, vehicles[_plate_id].datePro, vehicles[_plate_id].manufac, vehicles[_plate_id].serial); | |
} | |
//Lấy thông tin về phương tiện - những thông tin có thể bị thay đổi. | |
function getDynamicInfo(string _plate_id) view public returns (address, string, string, string, int){ | |
address _owner = vehicles[_plate_id].persons[vehicles[_plate_id].lenghtPerson-1].owner; | |
string storage _dateRegis = vehicles[_plate_id].persons[vehicles[_plate_id].lenghtPerson-1].dateRegis; | |
return (_owner, _dateRegis , vehicles[_plate_id].color, vehicles[_plate_id].charactic, vehicles[_plate_id].status); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment