Home Loans Based on Smart Contract for Banks

代码目的:

创造一个自运行的房屋贷款系统,减轻银行许多传统金融合约操作流程的负担

执行摘要:

  1. 贷款申请人在线登录或注册银行账户; 填写房产信息、个人信息并上传数字文件
  2. 智能合约验证身份,并根据确定的阈值评估资格
  3. 满足门槛后,申请人可以在线签署协议和条款
  4. 智能合约将计算贷款支付、转移贷款资金并向申请人收取贷款还款
  5. 最后,当贷款完成或发生贷款违约时,智能合约会自行销毁

目录

1)  Customer Registration/Login With Basic Information

2)  Loan Application

2.1 Property Information (Location, Price, Etc.)

2.2 Loan Application (Amount, Maximum Down Payment, Etc.)

2.3 Application Qualification (Income, Working Years, Etc.)

2.3 Identity Verification of Applicant

2.4 Pre-defined Condition Fulfilment & Result (Set Limit to Parameters)

2.5 Sign Contract With Digital Signature & Verify Signature(验证过程此处未实现)

3)  Loan Operation

3.1 Loan Payment Calculation and Distribution

3.2 Loan Repayment

3.3 Price Conversion

4)  Destruction of Smart Contract

4.1 Loan Repayment Completion4.2 Overdue Repayment & Loan Default


1)  Customer Registration/Login With Basic Information

pragma solidity >=0.7.0 <0.9.0; //指定编译器版本

创建合约一,让用户注册并输入个人信息

contract Customer_Detail {
enum gender {male, female}
enum Residence_Status {Permanant_residence_permit,
European_residence_permit,
Limited_resicence_permit,
No_German_residence_permit,
Others
}
struct customer_info{
string first_name;
string last_name;
int age;
address customer_address;
string residence_id;
string email;
int contact_number;
gender genders;
Residence_Status Residence_Status;
bool married;
}

(理论上应该先检查用户地址是否已经存在(mapping语句似乎没有成功,楼主已放弃),没有则继续注册过程,输入个人信息)

    mapping (address=>uint) registered_info;function getRegisteredInfo(address customer_address) public
view returns (string memory,string memory,int,
address,string memory,string
memory,int,gender,Residence_Status,bool) {return(registeredinfo[customer_address].first_name,registeredinfo[customer_address].last_name,registeredinfo[customer_address].age,registeredinfo[customer_address].customer_address,registeredinfo[customer_address].residence_id,registeredinfo[customer_address].email,registeredinfo[customer_address].contact_number,registeredinfo[customer_address].genders,registeredinfo[customer_address].Residence_Status,registeredinfo[customer_address].married,
);
}
// input new customer's basic informationfunction getNewCustomer(string first_name, string last_name,
int age, address customer_address, string residence_id,string email, int contact_number, gender
genders,ResidenceStatus Residence_Status,bool married) {
customerinfo[customer_address] = customerinfo(
{
first_name: first_name,
last_name: last_name,
age: age,
residence_id:residence_id,
email:email,
contact_number:contact_number,
genders:genders,
Residence_Status:Residence_Status,
married:married});
}

2)  Loan Application

2.1 Property Information (Location, Price, Etc.)

2.2 Loan Application (Amount, Maximum Down Payment, Etc.)

Contract Loan_Application {
enum employment_status{
Self_employed,
Freelance,
Civil_servant,
Independent_wealthy_person,
Retired,
Others
}
enum property_source{
developers,
resale
}
string applicantion_id;
address applicant;
// To prevent data overflow
library SafeMath {
function add(uint8 a, uint8 b) internal pure returns (uint8){
uint8 c=a+b;
}
assert (c>=a);
return c;
}
using SafeMath for uint8struct property_info {uint8 zipcodes;string city;else {
string property_source;uint size;}
uint price;struct loan_info {uint loan_amount;uint max_down_payment;uint8 loan_years;}if (loan_amount>1.4*price) {}
return "exceed maximum limits";return loan_amount;}if (loan_years > 60) {return "exceed maximum limits";}else {}
return loan_years;}

2.3 Application Qualification (Income, Working Years, Etc.)

struct applicant_qualification {uint debt;uint working_years;uint8 applicant_amount; //employment_status employment_status;uint total_monthly_net_income;uint assets;bool married;}contract applicantqualifiction{applicant_qualification qualification;constructor (uint debt, uint working_years, uint8 applicant_amount, uint total_monthly_net_income, uint assets, bool married) {qualification.debt = debt;qualification.working_years = working_years;qualification.applicant_amount = applicant_amount;qualification.total_monthly_net_income = total_monthly_net_income;qualification.assets = assets;qualification.married = married;}
}

2.3 Identity Verification of Applicant

这个步骤会上传文件并审核真实性(这里是需要联合其他官方数据库来认证的,此处代码未体现)

contract Verification {string file_info;string file_hash;string name;string idandfile_hash;function set_uploaded_file_info() public view returns(string memory)  {return file_info;}function get_uploaded_file_info (uint certificateid) public pure returns (uint) {return certificateid;
}function verifyHash () public view returns(string memory) {if(uint(keccak256(abi.encodePacked(file_hash))) == uint(keccak256(abi.encodePacked(file_hash)))) {return "successful verification";}else {return "fail verification";}}
}

2.4 Pre-defined Condition Fulfilment & Result (Set Limit to Parameters)

contract Examine_Qualification {    uint price;uint loan_amount;uint loan_years;uint applicant_amount;uint debt;uint assets;uint total_monthly_net_income;uint working_years;function set_limit() public view returns (string memory qualification) {uint loan_limit = price; // An applicant can request house price as maximum loan amount. This standard could be various from banks to banksuint256 total_monthly_net_income_min = (120 + 125) * loan_amount * applicant_amount/12/100; // at most 80% income are used to pay loan,this standard could be various from banks to banksuint256 debt_max = 4 * loan_amount/100; // at most 40% loan amount of existing debt is acceptable, this standard could be various from banks to banksuint asset_min = 8  * debt/100; // the applicant should own at least 80% assets(including fixed assets, current assets, etc.) of existing debt. This aims to lower the possibility of default.This standard could be various from banks to banks.uint working_years_min = 2; // the applicant is expected to have worked for at least two years. This aims to guarantee the applicant has a stable job. This standard could be various from banks to banks.if (loan_amount>loan_limit || debt>debt_max ||total_monthly_net_income < total_monthly_net_income_min ||assets < asset_min || working_years < working_years_min) {return qualification="notEligible";}else {return qualification="Eligible";}   }// Only when all the conditions are satisfied will the applicant be eligible. Otherwise it would terminate the process.}

2.5 Sign Contract With Digital Signature & Verify Signature(验证过程此处未实现)

contract homeLoanAgrement {//This Annexure and the terms and conditions hereunder shall come into force on the signing of the same by the Borrower and Bankfunction terms() public view returns (string memory borrowerNameChloe,string memory totalLoanAmountonelac,string memory date12December,uint loanDurationMonths30)
{}
}

3)  Loan Operation

在此,在计算前首先设置了以下指标:

a) 首付 = 10,00,000;

b) 贷款期限 = 10 年或 120 个月,

c) 利率 6%

当运行这个计算时,我们可以看到每月的 EMI 以及贷款人必须支付的年息

3.1 Loan Payment Calculation and Distribution

contract MortgageCalculator {uint256 PrincipalAmount = 1000000;//600 basis points = 6.0 pctuint256 monthlyInterestRate = 6;uint loanTenure = 10;uint adding;function yearlyInterest() public view returns (uint abc) {abc = PrincipalAmount * monthlyInterestRate * loanTenure;return abc/100;
}function emi() public view returns (uint def) {//from the above results (return abc/100) will add the PrincipalAmount and will divide by the duration 120(10Years*12) to het the Monthly EMI.def = 600000     + PrincipalAmount;return def/120;
}}

3.2 Loan Repayment

contract LoanDisbursement{// Bank will transferring the Ethers(after conversion) to the Smart Contractfunction sendviaCall(address payable _to) public payable {bool sent = _to.send(msg.value);require (sent, "Failed to sent Ether");}
}// Customer transferring monthly EMI to the Smart Contracts
contract LoanRepayment {uint256 num1;address owner;function payEmi () external payable{}function getBalance() external view returns (uint256) {return address(this).balance;}
}// Customer transferring monthly EMI to the Smart Contracts
contract LoanReceipts {address sender;string receiptNumber;function confirmation(string memory paymentReceiptNumber) public pure returns (string memory) {return paymentReceiptNumber;}
}

3.3 Price Conversion

对于货币转换,代码使用了 chainlink 文档中的以下代码https://docs.chain.link/docs/get-the-latest-price

4)  Destruction of Smart Contract

智能合约房屋贷款过程中的另一个关键要素是智能合约自毁。 这里考虑两种情况:

4.1:贷款人成功偿还了全部贷款金额。 之后,智能合约将立即销毁,客户将收到无异议证书。

4.2:如果贷款人未能归还贷款,系统将对两次逾期还款发出两次警告,如果贷款人仍不还款,将被宣布为违约人,智能合约将被终止,财产将被查封和拍卖。

4.1 Loan Repayment Completion
4.2 Overdue Repayment & Loan Default

contract smartContractDefault_Destruct{import random;address applicant;string private_key;uint total_default = 0;struct default_info {bool overdue_repayment;uint total_default;bool loan_default;}struct capital_private_key{}
string wallet_private_key;
string assets_private_key;function get_default_info(uint id) public pure returns(bool) {return default_info[id].overdue_repayment;
for (id=1; id<=960;id++){
if (default_info[id].overdue_repayment=true) {
total_default++;
continue;
}
if (total_default>=5) {
break;
return loan_default=true;else {return total_default=false;}}

在违约情况下,智能合约通过更改贷款人财产的私人密钥来夺取控制权:

function modify_private_key public pure returns (string) {
if (loan_default=true) {
bits = random.getrandbits(256)
bits_hex = hex(bits)
wallet_private_key = bits_hex[2:];
}
bits = random.getrandbits(256)
bits_hex = hex(bits)
assets_private_key = bits_hex[2:];
}contract smartContractSelf_Destruct{address owner_addr;function destroySmartContract(address payable _to) public{require(msg.sender == owner_addr);selfdestruct(_to);}
}

Solidity入门级别|用智能合约实现房屋贷款系统相关推荐

  1. Solidity入门-开发众筹智能合约

    前言 本文要求你对Solidity开发有一点基础的了解. 我会使用Solidity开发一个简单的众筹智能合约,合约的主要功能就是向希望给我捐赠的人收钱,然后我再将钱从合约账户里取出来. 因为程序简单, ...

  2. 不同步节点在线使用Remix开发以太坊Dapp及solidity学习入门 ( 一 ):智能合约HelloWorld

    有问题可以点击–>加群互相学习 本人本来想自己写公链,结果发现任重道远: 遂,开始写Dapp,顺便写的时候搞个教程吧... 通过系列教程学习将会: 1.基本使用solidity 语言开发智能合约 ...

  3. 采用以太坊智能合约技术的报名系统源码

    刚开始的时候我们想解决的问题是上次BeyondBlock 研讨会时出现率过低的问题,这也是免费活动经常会遇到的情况,通常出席率会落在六成到七成之间.而Taipei Ethereum Meetup 是因 ...

  4. solidity语言开发智能合约

    2019独角兽企业重金招聘Python工程师标准>>> 一个简单的智能合约 在Solidity中,一个智能合约由一组代码(合约的函数)和数据(合约的状态)组成.智能合约位于以太坊区块 ...

  5. truffle (ETH以太坊智能合约集成开发工具) 入门教程

    truffle (ETH以太坊智能合约集成开发工具) 入门教程 前言 在你了解区块链开发之前,你有必要了解区块链的一些基础知识,什么是DApp,DApp与传统app的区别, 什么是以太坊,以太坊中的智 ...

  6. 区块链技术:智能合约入门

    什么是智能合约 一个智能合约是一套以数字形式定义的承诺(promises) ,包括合约参与方可以在上面执行这些承诺的协议.一个合约由一组代码(合约的函数)和数据(合约的状态)组成,并且运行在以太坊虚拟 ...

  7. 区块链之智能合约入门

    区块链之智能合约入门 第一步 安装环境 首先这里写的合约是指solidity合约,使用Remix IDE.所以我们第一步就是安装Remix IDE.remix ide是开发以太坊智能合约的神器,支持网 ...

  8. solidity payable_以太坊区块链搭建与使用(五)-智能合约Solidity

    一.智能合约Solidity开发工具 1.remix-ide http://remix.ethereum.org/ 在线版本,也可以去github下载安装到本地.开发.编译.发布.执行.测试 2.re ...

  9. 智能合约开发solidity编程语言实例

    智能合约开发用solidity编程语言部署在以太坊这个区块链平台,本文提供一个官方实战示例快速入门,用例子深入浅出智能合约开发,体会以太坊构建去中心化可信交易技术魅力.智能合约其实是"执行合 ...

最新文章

  1. maven在idea的配置
  2. mysql主从复制原理详解_MySQL主从复制没使用过?三大步骤让你从原理、业务上理解透彻...
  3. Qos和区分服务(DiffServ)
  4. python 字符串变量 组合列表_Python智慧编程——第3讲 字符串与列表
  5. HDU1066--高精度求阶乘最后非零位
  6. 创业必经之路——Paul Graham创业曲线
  7. 常用公差配合表图_ER弹簧夹头配套BT刀柄常用规格型号表
  8. mysql触发器可以使用正则表达式_SQL 正则表达式及mybatis中使用正则表达式
  9. 基于visual Studio2013解决C语言竞赛题之0608水仙花函数
  10. 万年历24节气C语言,电子万年历24节气c程序
  11. AsyncTask使用须知
  12. 数据结构C语言版稀疏矩阵实验报告,数据结构稀疏矩阵基本运算实验报告..doc
  13. 爬虫python下载电影_python爬虫--爬取某网站电影下载地址
  14. 必读开发规范之阿里巴巴开发手册(个人整理版)
  15. Windows服务器IE浏览器无法下载文件解决方法
  16. 杂凑算法md5c语言代码,MD5杂凑算法
  17. Erlang 游戏开发经验总结
  18. [0CTF 2016]piapiapia WP
  19. springcloud config非对称加密
  20. 【产品经理】日活跃用户「MAU」 和月活跃用户「DAU」

热门文章

  1. java中的pojo是什么意思
  2. The application of backtracking
  3. corosync+pacemaker高可用
  4. 【小甲鱼】python零基础入门学习笔记 03讲~43讲
  5. c++常见面试问题总结
  6. Win10 日期/时间修改
  7. 聊一聊JAVA指针压缩的实现原理(图文并茂,让你秒懂)
  8. 一周热图|黄晓明、刘亦菲走进瑞士天梭工厂;卡特彼勒牵手CBA联赛;爱马仕匠心工坊登陆西安...
  9. keep-alive:
  10. 【电路仿真01】bandgap