Created
March 31, 2016 02:36
-
-
Save y12studio/383ead51a3193cba33d7bc15defa48bb to your computer and use it in GitHub Desktop.
Y12 Marriage Contract 3 with GovOracle
This file contains hidden or 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
// ------------------------------------------- | |
// 政府驗證服務智能婚約 2016 | |
// 在法律許可的範圍內,作者(們)已將此軟體的著作權、相關權利與鄰接權釋出到全球的公眾領域。此軟體之散布不含任何擔保責任。 | |
// 您應該已經連同軟體取得一份CC0的公眾領域貢獻宣告複本,若沒有收到,則請見:http://creativecommons.org/publicdomain/zero/1.0/。 | |
// ------------------------------------------- | |
// Ethereum以太坊智能合約環境說明 https://gist.github.com/y12studio/f142cd9789c7d396d8f7 | |
// 有意願測試簽智能婚約可聯絡 https://github.com/y12studio | |
// 測試流程參閱 ymc1.sol | |
// <GOV_ORACLE> | |
contract GovOracleI { | |
// | |
// 我們認為下面這些真理是不言而喻的:造物者創造了平等的個人,並賦予他們若干不可剝奪的權利,其中包括生命權、自由權和追求幸福的權利。 | |
// 為了保障這些權利,人們才在他們之間建立政府,而政府之正當權力,則來自被統治者的同意。 | |
// 美國獨立宣言 - 維基百科 https://zh.wikipedia.org/wiki/%E7%BE%8E%E5%9C%8B%E7%8D%A8%E7%AB%8B%E5%AE%A3%E8%A8%80 | |
// | |
function query(address kycAddr, bytes32 kycHash, string _datasource, string _arg) returns (bytes32 _id); | |
function getTaxFee(bytes32 kycHash, string _datasource) returns (uint _taxfee); | |
} | |
contract usingGovOracle { | |
GovOracleI gov; | |
uint public VERIFY_MaritalStatus_OK = 987; | |
function gov_query(address kycAddr, bytes32 kycHash, string datasource, string arg) internal returns (bytes32 id){ | |
uint taxFee = gov.getTaxFee(kycHash,datasource); | |
return gov.query.value(taxFee)(kycAddr, kycHash , datasource, arg); | |
} | |
function parseResult(string _r) internal returns (uint) { | |
// parseGovQuery(_r) | |
return VERIFY_MaritalStatus_OK; | |
} | |
} | |
// </GOV_ORACLE> | |
contract YMarriageContract is usingGovOracle { | |
// 發起婚約提案方 | |
address public mblue; | |
bytes32 public mblueHash; | |
// 發起金額 | |
uint public mValue; | |
// 婚約提案收受方 | |
address public mred; | |
bytes32 public mredHash; | |
// 婚證或可供證明的婚姻的數位證明 | |
bytes32 public marriageHash; | |
// 天命 | |
address public god; | |
// 第三方:法院,時間,命運,第三者聯盟 | |
address public thirdPartyDao; | |
uint public giftStart; | |
uint public giftTime; | |
uint public giftValue; | |
uint32 public giftCount; | |
mapping (address => uint) giftBalances; | |
mapping (uint => address) giftIndex; | |
uint public thirdStart; | |
uint public thirdTime; | |
State public state; | |
enum State { BlueKyc, Created, Proposal ,Locked, Inactive } | |
modifier onlyGod(){ | |
if (msg.sender != god) throw; | |
_ | |
} | |
modifier onlyThirdPartyDao(){ | |
if (msg.sender != thirdPartyDao) throw; | |
_ | |
} | |
// 發起方為藍方 | |
function YMarriageContract() { | |
if(msg.value < 1 finney ) throw; | |
mblue = msg.sender; | |
mValue = msg.value; | |
state = State.BlueKyc; | |
gov_query(mblue, mblueHash, 'Verify','Marital Status'); | |
} | |
function __govOracleCallback(address addr, bytes32 hash, string result) { | |
if(parseResult(result) != VERIFY_MaritalStatus_OK){ | |
mblue.send(this.balance); | |
state = State.Inactive; | |
}else{ | |
state = State.Created; | |
} | |
} | |
// 將身份證明拍照取得SHA256(照片) | |
function willYouMarryMe(bytes32 id_hash){ | |
if(state != State.Created) throw; | |
if (msg.sender != mblue) throw; | |
mblueHash = id_hash; | |
state = State.Proposal; | |
} | |
// 確認方為紅方,提供SHA256(身份證明)以及SHA256(證書/錄影/合照) | |
function proposalYes(bytes32 id_hash, bytes32 marriage_fact_hash, uint gift_time){ | |
if (state != State.Proposal) throw; | |
if (msg.value != mValue) throw; | |
if (msg.sender == mblue) throw; | |
mred = msg.sender; | |
mredHash = id_hash; | |
marriageHash = marriage_fact_hash; | |
giftStart = now; | |
giftTime = gift_time; | |
state = State.Locked; | |
} | |
// Sorry. | |
function proposalSorry(){ | |
if (state != State.Proposal) throw; | |
if (msg.sender == mblue) throw; | |
mblue.send(this.balance); | |
state = State.Inactive; | |
} | |
// 紅包只收0.999ETH或1.314ETH或大於6ETHH | |
function sendGift(){ | |
if(state != State.Locked) throw; | |
// 過期不收 | |
if (now > giftStart + giftTime) throw; | |
if(msg.value < 1 finney) throw; | |
// if(msg.value < 6 ether || msg.value != 999 finney || msg.value != 1314 finney) throw; | |
giftValue += msg.value; | |
giftIndex[giftCount] = msg.sender; | |
giftBalances[msg.sender] = msg.value; | |
giftCount++; | |
} | |
// 紅包到期每人可領走1/4,總計領走1/2 | |
// [Update]經網友更正有個提光紅包的可能性,這裡不修正留著討論下面幾個議題: | |
// 1. 想像如智約如信用卡合約數千行,假設發起人被告上法院,故意跟過失問題。 | |
// 2. 合約是否內建過失免責條款,或是引入過失保險智約或仲裁智約。 | |
// 3. 包紅包可能不是人,而是發行代幣集資的紅包智約(例如YRT2/YRT3),如何發起求償。 | |
function withdrawGift() { | |
if(state != State.Locked) throw; | |
if (msg.sender != mblue && msg.sender != mred) throw; | |
if (now < giftStart + giftTime) throw; | |
uint rValue = giftValue / 4; | |
mblue.send(rValue); | |
mred.send(rValue); | |
} | |
// 時間以秒計算,一天86400,一百年3153600000 | |
function setupThirdPartyDao(address _address, uint _time) onlyGod { | |
if(state != State.Locked) throw; | |
thirdStart = now; | |
thirdTime = _time; | |
thirdPartyDao = _address; | |
} | |
function iterateReturnGifts(){ | |
for(uint i=0;i<giftCount;i++){ | |
address giftAddr = giftIndex[i]; | |
giftAddr.send(giftBalances[giftAddr]/2); | |
} | |
} | |
// 合意解約取回1/2。 | |
function doUsPartByPeace() { | |
if(state != State.Locked) throw; | |
if (msg.sender != mblue && msg.sender != mred) throw; | |
// 先退紅包 1/2 | |
iterateReturnGifts(); | |
// 剩下再分 | |
uint rValue = this.balance / 2; | |
mblue.send(rValue); | |
mred.send(this.balance); | |
state = State.Inactive; | |
} | |
// 單方解約取回1/5 | |
function doUsPartByOne() { | |
if(state != State.Locked) throw; | |
if (msg.sender != mblue && msg.sender != mred) throw; | |
// 先退紅包 1/2 | |
iterateReturnGifts(); | |
// 剩下再分 | |
uint rValue = this.balance / 5; | |
msg.sender.send(rValue); | |
if(msg.sender == mblue) { | |
mred.send(this.balance); | |
}else{ | |
mblue.send(this.balance); | |
} | |
state = State.Inactive; | |
} | |
// 第三方介入只能取回1/3 | |
function doUsPartByThird() onlyThirdPartyDao { | |
if (state != State.Locked) throw; | |
if (now > thirdStart + thirdTime) throw; | |
// 先退紅包 1/2 | |
iterateReturnGifts(); | |
// 剩下再分 | |
uint rValue = this.balance / 3; | |
mblue.send(rValue); | |
mred.send(rValue); | |
thirdPartyDao.send(this.balance); | |
state = State.Inactive; | |
} | |
function devOnlyClose() { | |
mblue.send(this.balance); | |
} | |
function () { | |
throw; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment