isOwner[owners_[i]] = true;
}
ownersArr= owners_;
threshold= threshold_;
}
// Notethat address recovered from signatures must be strictly increasing
functionexecute(uint8[] sigV, bytes32[] sigR, bytes32[] sigS, address destination, uintvalue, bytes data) {
if(sigR.length != threshold) {throw;}
if(sigR.length != sigS.length || sigR.length != sigV.length) {throw;}
//Follows ERC191 signature scheme: https://github.com/ethereum/EIPs/issues/191
bytes32txHash = sha3(byte(0x19), byte(0), this, destination, value, data, nonce);
addresslastAdd = address(0); // cannot have address(0) as an owner
for (uinti = 0; i < threshold; i++) {
address recovered = ecrecover(txHash, sigV[i], sigR[i], sigS[i]);
if(recovered <= lastAdd || !isOwner[recovered]) throw;
lastAdd = recovered;
}
// If wemake it here all signatures are accounted for
nonce =nonce + 1;
if(!destination.call.value(value)(data)) {throw;}
}
function ()payable {}
}
此代碼也可以在github中找到。
效益
此合約的有益屬性包括:
l 最小代碼庫:只有40行代碼
l 最少可變狀態:唯一可變的數據是,每一次執行都會增加一個單元(unit)。
l 最小界面:由單一功能構成的界面.
由于缺乏復雜的狀態轉換,在沒有資金的情況下,該合約便無法轉入“凍結”狀態。而因為唯一可能的狀態轉換是簡單的增量計數器,所以該合約永遠處于正確狀態。且由于使用了32字節的整數,計數器便不可能溢出。同時,測試也變得更簡單了,因為事實上(除構造函數外)只有一個函數需要測試。
但由于我們盡可能地簡化了鏈上邏輯,因而增加了鏈下工作流程的復雜性,這便導致了一些缺陷與不足,比如:
l 需要用戶給非交易簽名,而這可能妨礙某些硬件錢包的使用
l 為了發送交易,需要終端用戶進行鏈下協調。