pragma solidity ^0.4.22;/** * @title safemath
* @dev math operations with safety checks that throw on error
*/library safemath
function div(uint256 a, uint256 b) internal constant returns (uint256)
function sub(uint256 a, uint256 b) internal constant returns (uint256)
function add(uint256 a, uint256 b) internal constant returns (uint256)
}
//管理者
contract owned
// onlyowner 函式修改器是乙個合約屬性,可以被繼承,還能被重寫。它用於在函式執行前檢查某種前置條件
modifier onlyowner
//實現所有權轉移
function transferownership(address newowner) onlyowner public
}//必須是合約建立者才能新增積分 銷毀積分
contract jifen is owned
//事件機制測試
event instructor(bytes32 txid,bytes32 memberoid);
struct txdetail
//檢視對應賬號的積分餘額。 任何人都可以查到任何位址的餘額,正如所有資料在區塊鏈上都是公開的。
//使用者交易明細
//交易細節
//分配積分流程函式1、增加積分 2、增加交易明細 3、維護使用者交易明細
function distributejifen_flow(uint256 value,bytes32 txid,bytes32 memberoid,string companyoid,string siteoid,string createtime,string updatetime,string integral,string types_deductibleamount_consumeamount_goods_goodsqty) onlyowner public returns (bool, string)
//分配積分流程函式1、減少積分 2、增加交易明細 3、維護使用者交易明細
function deductjifen_flow(uint256 value,bytes32 txid,bytes32 memberoid,string companyoid,string siteoid,string createtime,string updatetime,string integral,string types_deductibleamount_consumeamount_goods_goodsqty) onlyowner public returns (bool, string)
function getuser_txslength(bytes32 memberoid) public constant returns (uint256)
}
積分智慧型合約
pragma solidity 0.4.22 title safemath dev math operations with safety checks that throw on error library safemath function div uint256 a,uint256 b int...
編寫智慧型合約
1.安裝node.js 2.安裝truffle npm install g truffle 3.啟動testrpc以太坊環境 testrpc 4.另開終端視窗新建專案 mkdir demo cd demo 5.初始化專案目錄 truffle init 6.建立合約檔案 truffle create ...
部署智慧型合約
合約部署需要挖礦才能成功,我們新開乙個視窗用與挖礦,新開乙個控制台,輸入命令 geth attach 連線到控制台,執行miner.start 1 開始挖礦。合約demo如下 pragma solidity 0.4.0 contract infocontract function getinfo p...