iT邦幫忙

0

求助 Remix-Ethereum IDE撰寫智慧合約

  • 分享至 

  • xImage

由於小妹我專題要寫出一份智慧合約,但在compile的部分有些地方卡住好幾天了,看了幾篇iT邦上的教學文仍然有些不懂,所以上來求助大家的幫助QQ

https://ithelp.ithome.com.tw/upload/images/20191209/20123135L5aPhGyBxb.png
https://ithelp.ithome.com.tw/upload/images/20191209/201231356Sf6RzRDb9.png]
https://ithelp.ithome.com.tw/upload/images/20191209/20123135o8oUDc7hpX.png

以上看起來是變數名稱出問題,但改了也不行...

https://ithelp.ithome.com.tw/upload/images/20191209/20123135D6jgpMHdBr.png

上面這個我就不知道問題在哪了...

麻煩各位大神幫忙了!

補上程式碼,照著二樓的修正後剩兩個地方了!謝謝~

pragma solidity >=0.4.22 <0.8.8;

contract sl{
address own;
address plateform;
address debit; //借款人
uint numcredit=0; //投資人
uint interest; //利息
uint expirydate; //貸款期限
uint amount; //貸款金額
uint rating; //信用評分
uint period; //分期
uint periodcount; //剩餘分期數
uint periodamount; //月收益
uint periodrepay; //每月還款金額
uint benefit; //投資人收益

//投資人
struct Investor{
string name;
address ethereum_address;
uint256 iamount;
uint256 benefit;
uint256 periodamount;
}
mapping(uint =>Investor)public Investors;

//借款人
struct Borrower{
string name;
address ethereum_address;
uint amount;
uint rating;
uint periodrepay;
uint periodcount;
}
mapping(uint=>Borrower) public Borrowers;

//抵押品
struct Collateral{
address own;
string location;
string buildID;
string use;
string storey;
string space;
string locateID;
}
mapping(uint=>Collateral)public asset;

LendingState lendingState = LendingState.Initial;
enum LendingState{
Initial,
Running,
Success,
Repayment,
Fail
}

function smartloan(address _debit, string memory _name, uint _loanamount, uint_period, uint_rating, string memory _location, string memory buildID, string memory _use, string memory _storey,string memory _space, string memory _locateID, uint _value)public{
own = msg.sender;
plateform = msg.sender;
debit = _debit;
amount = _amount;
rating =_rating;
period =_period;
periodcount = _period;
i = _amount /100;
periodrepay =(_amount + i ) / _period ;
asset[0] =Collateral(debit, _1ocation, _locateID, _use, _storey,_space,_locateID);
Borrowers[0] = Borrower(_name, _debit, _amount, _value, _rating,periodrepay, _period);
}

function Pledge (address _debitor, address _creditor) onlyInitialLoan public{
lien[0] = lien_info(_debitor, _creditor, msg.sender);
}

function Payfee() payable onlyInitialLoan public{
if(msg.value != (amount * 3)/100) {
revert();
}
platform.transfer(misg.value);
lendingState = LendingState.Running;
}

function Invest(string memory name, uint investAmount, uint _Numerator, uint _Denominator) payable onlyRunningLoan public{
if(investAmount * price != msg.value || investAmount > amount || msg.value > msg.sender.balance){
revert();
}
if((investAmount * _Denominator)/ _Numerator != amount){
revert();
}
beneit =(((amount * price) + i) * _Numerator)/_Denomnator;
periodamount = (benefit / period);
numcredit++;
credits[numcredit] = credit(name, msg.sender, msg.value, benefit, periodamount);
}

function lend()onlyRunningLoan onlyPlatform public{
if(this.balance >= amount){
debit.transfer(amount);
expirydate = now + 30 days;
lendingState = LendingState.Success;
}
}

function repay() payable onlySuccessfulLoan onlyDebit public{
if(now > expirydate){
revert();
}
else if(Borrower[0].periodcount = 0 ){
revertO;
}
else if( msg.value != periodrepay){
revertO;
}
else{
for(uint j=1; j <= numcredit; j++){
Investors[j].ethereum_address.transfer(Investors[i].periodamount);
}
expirydate += 30 days;
Borrowers[0].periodcount -= 1;
if (Borrowers[0].periodcount == 0){
lendingState = LendingState.Repayment;
}

}

}

function delay() payable public onlyPlatform{
asset[0].own = Platform;
for(uint j=1; j <= numcredit; j++){
credits[i].ethereum_address.transfer(Investors[i].periodamount * Borrowers[0].periodcount);
}
lendingState = LendingState.Fail;
}

//執行狀態Initial
modifier onlyInitialLoan(){
require(lendingState == LendingState.Initial);
_;
}
//執行狀態Running
modifier onlyRunningLoan(){
require(lendingState == LendingState.Running);
_;
}

//執行狀態Success
modifier onlySuccessLoan(){
require(lendingState == LendingState.Success);
_;
}
//執行狀態Repayment
modifier onlyRepaymentLoan(){
require(lendingState == LendingState.Repayment);
_;
}
//執行狀態Fail
modifier onlyFailLoan(){
require(lendingState == LendingState.Fail);
_;
}
//角色定義平台負責人
modifier onlyPlatform(){
require(msg.sender == own);
_;
}

//角色定義借款方
modifier onlyDebit(){
require (msg.sender == debit);
_;
}

}

froce iT邦大師 1 級 ‧ 2019-12-09 23:51:31 檢舉
護眼幫幫忙。

你變數/函數名稱不要取重複的,要有意義。
都取i當然跳一堆變數命名錯誤、重複變數...
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 個回答

0
阿展展展
iT邦好手 1 級 ‧ 2019-12-09 23:40:33

請把你的程式碼直接CP上來
這樣考驗大家的眼睛實在是... (點眼藥水中

0
海綿寶寶
iT邦大神 1 級 ‧ 2019-12-10 10:03:48

1.加 memory 修飾字(string 和 參數之間)

function smartloan(address _debit, string _name, uint _loanamount, uint_period, uint_rating, string _location, string buildID, string _use, string _storey,string _space, string _locateID, uint _value)public{      

改成

function smartloan(address _debit, string memory _name, uint _loanamount, uint_period, uint_rating, string memory _location, string memory buildID, string memory _use, string memory _storey,string memory _space, string  memory _locateID, uint _value)public{      

2.改函式名稱

function i(string name, uint investAmount, uint _Numerator, uint _Denominator) payable onlyRunningLoan public{ 

改成

function Invest(string memory name, uint investAmount, uint _Numerator, uint _Denominator) payable onlyRunningLoan public{ 

3.改變數名稱

uint i; //利息

改成

uint interest; //利息

4.改變數名稱

for(uint i=1; i <= numcredit; i++){

改成

for(uint j=1; j <= numcredit; j++){

選我最佳解答

我要發表回答

立即登入回答