0
0
0
1. 云栖社区>
2. 博客>
3. 正文

## 艺术品区块链溯源防伪平台（连载二）数字资产的投资与数字资产的份额化

netkiller 2018-11-22 12:37:34 浏览1895

《Netkiller Blockchain 手札》

Mr. Neo Chan, 陈景峯(BG7NYT)

### 2.10.5. 资产投资与份额持有

```
pragma solidity ^0.4.25;

/**
* @title SafeMath
* @dev Math operations with safety checks that revert on error
*/
library SafeMath {

/**
* @dev Multiplies two numbers, reverts on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (a == 0) {
return 0;
}

uint256 c = a * b;
require(c / a == b);

return c;
}

/**
* @dev Integer division of two numbers truncating the quotient, reverts on division by zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0); // Solidity only automatically asserts when dividing by 0
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold

return c;
}

/**
* @dev Subtracts two numbers, reverts on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a);
uint256 c = a - b;

return c;
}

/**
* @dev Adds two numbers, reverts on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a);

return c;
}

/**
* @dev Divides two numbers and returns the remainder (unsigned integer modulo),
* reverts when dividing by zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0);
return a % b;
}
}

contract Ownable {

constructor() public {
owner = msg.sender;
}

modifier onlyOwner() {
require(msg.sender == owner);
_;
}

function transferOwnership(address newOwner) public onlyOwner {
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}

}

contract NetkillerAssetsToken is Ownable {
using SafeMath for uint256;

string public name;
string public symbol;
uint public decimals;
uint256 public totalSupply;

mapping(address => mapping(string => uint256)) internal balances;

event Burn(address indexed from, string _tokenId);

constructor(
string tokenName,
string tokenSymbol,
uint decimalUnits
) public {
owner = msg.sender;
name = tokenName;
symbol = tokenSymbol;
decimals = decimalUnits;
totalSupply = 0;
}

balances[_owner][_tokenId] = 100 * 10 ** uint256(decimals);
tokens[_tokenId] = _owner;
return true;
}

function balanceOf(address _owner, string _tokenId) constant returns(uint balance){
return balances[_owner][_tokenId];
}

function ownerOf(string _tokenId) constant returns (address owner) {
}

uint256 amount = balances[_from][_tokenId];
transfer(_to, amount, _tokenId);
}
function transfer(address _to, uint256 _value, string _tokenId){
require(msg.sender == ownerOf(_tokenId));
require(msg.sender != _to);

uint256 amount = balances[_from][_tokenId];
require(amount >= _value);

balances[_from][_tokenId] = balances[_from][_tokenId].sub(_value);
tokens[_tokenId] = _to;

emit Transfer(_from, _to, _tokenId);
}

function burn(address _owner, string _tokenId) onlyOwner public returns (bool success) {
require(balances[_owner][_tokenId] > 0 && balances[_owner][_tokenId] == 100 * 10 ** uint256(decimals));

balances[_owner][_tokenId] = 0;

totalSupply = totalSupply.sub(1);
emit Burn(msg.sender, _tokenId);
return true;
}

}

```

```
constructor(
string tokenName,
string tokenSymbol,
uint decimalUnits
) public {
owner = msg.sender;
name = tokenName;
symbol = tokenSymbol;
decimals = decimalUnits;
totalSupply = 0;
}

```

```
balances[_owner][_tokenId] = 100 * 10 ** uint256(decimals);
tokens[_tokenId] = _owner;
return true;
}

```

balances[_owner][_tokenId] = 100 * 10 ** uint256(decimals); 初始化份额是 100 表示 100%

```
function ownerOf(string _tokenId) constant returns (address owner) {
}

```

```

uint256 amount = balances[_from][_tokenId];
transfer(_to, amount, _tokenId);
}
function transfer(address _to, uint256 _value, string _tokenId){
require(msg.sender == ownerOf(_tokenId));
require(msg.sender != _to);

uint256 amount = balances[_from][_tokenId];
require(amount >= _value);

balances[_from][_tokenId] = balances[_from][_tokenId].sub(_value);
tokens[_tokenId] = _to;

emit Transfer(_from, _to, _tokenId);
}

```

netkiller
+ 关注