I am trying to create asset based transfer Smart contract by solidity language. i'm using ethereum.
functions are
Create assets (land_id, land_size, land_price) with a ownership of contract owner.
Transfer assets to other person.
- getCurrentOwnership
- Previous Owners list
- getAsset details.
My Contract:
pragma solidity >=0.4.22 <0.6.0;
contract Asset {
uint256 public owners_count;
address public contract_owner; // Manufacturer/owner
bytes32 public land_id; // land_id
bytes32 public land_sqrfeet; // land_sqrfeet
bytes32 public land_created_date; // Created date
mapping(uint => address) public owners; // list of owners
function createland(bytes32 _land_id, bytes32 _land_sqrfeet, bytes32 _land_created_date) public returns (bool){
setOwner(msg.sender);
land_id = _land_id;
land_sqrfeet = _land_sqrfeet;
land_created_date = _land_created_date;
return true;
}
//Modifier that only allows owner of the bag to Smart Contract AKA Good to use the function
modifier onlyOwner(){
require(msg.sender == contract_owner);
_;
}
//This function transfer ownership of contract from one entity to another
function transferOwnership(address _newOwner) public onlyOwner(){
require(_newOwner != address(0));
contract_owner = _newOwner;
}
//Get the previous owner in the mappings
function previousOwner() view public returns(address){
if(owners_count != 0){
uint256 previous_owner = owners_count - 1;
return owners[previous_owner];
}
}
function setOwner(address owner)public{
owners_count += 1 ;
owners[owners_count] = owner;
}
function getCurrentOwner() view public returns(address){
return owners[owners_count] ;
}
function getOwnerCount() view public returns(uint256){
return owners_count;
}}
but with this contract, i can able to get last created asset details. I can not get previous creation assets details.
Questions are:
- Each Assets should be different contract address or one contract address?
- If take one contract address for all assets, how can i get old transaction by contract function?