-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkycContract.sol
152 lines (102 loc) · 4.91 KB
/
kycContract.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// SPDX-License-Identifier: MIT`
pragma solidity ^0.5.12;
contract kycContract{
struct account{
address accountAddr;
uint lockedBalance;
bool kycStatus;
bool isContract;
uint txCount;
}
mapping(address => account) private accountList;
event newAccountListed(address newAccountAddress,
uint newAccountLockedBalance,
bool newAccountkycStatus,
bool isContractAccount);
event balanceUnlocked(address accountAddress,
uint unlockedValue,
uint lockedBalance);
event accountRemoved(address accountAddress,
uint accountLockedBalance,
bool accountKycStatus,
bool isContractAccount,
uint accountTxCount);
event accountUpdated(address newAccountAddress,
uint newAccountLockedBalance,
bool newAccountkycStatus,
bool isContractAccount,
uint accountTxCount);
event transferSuccess(address senderAccountAddress,
address recieptAccountAddress,
uint transferredValue,
uint accountTxCount);
function addNewAccount(address requester , uint valueToLock) private {
if(tx.origin == requester){//To detect the requester is EOA or contract!
accountList[requester] = account(requester,valueToLock,true,false,0);
emit newAccountListed(requester,valueToLock,true,false);
}else{
accountList[requester] = account(requester,valueToLock,true,true,0);
emit newAccountListed(requester,valueToLock,true,true);
}
}
function transferBack(uint backValue) external {
require( accountList[msg.sender].lockedBalance >= backValue ,
"The requested value is more than locked value!"
);
if(tx.origin == msg.sender){
address(uint160(msg.sender)).transfer(backValue);
}else{
(bool success,bytes memory returnData) = (msg.sender).call.value(backValue)("");
require(success , "Transfer back failed!");
}
accountList[msg.sender].lockedBalance -= backValue;
emit balanceUnlocked(msg.sender,backValue,accountList[msg.sender].lockedBalance);
}
function removeAccount() external {
require( accountList[msg.sender].lockedBalance == 0 ,
"You need to withdraw your entire balance first!");
emit accountRemoved(msg.sender,
accountList[msg.sender].lockedBalance,
accountList[msg.sender].kycStatus,
accountList[msg.sender].isContract,
accountList[msg.sender].txCount
);
//this.transferBack(msg.sender,accountList[msg.sender].lockedBalance);
accountList[msg.sender].accountAddr=0x0000000000000000000000000000000000000000;
accountList[msg.sender].kycStatus=false;
accountList[msg.sender].isContract=false;
accountList[msg.sender].txCount=0;
}
function userView() external view returns(address,uint,bool,bool,uint){
return (accountList[msg.sender].accountAddr,
accountList[msg.sender].lockedBalance,
accountList[msg.sender].kycStatus,
accountList[msg.sender].isContract,
accountList[msg.sender].txCount
);
}
function kycCheck(address target) external view returns(bool){
return accountList[target].kycStatus;
}
function secureTransfer(address destination,uint sendValue) external {
require(accountList[msg.sender].lockedBalance >= sendValue ,
"The value for send is more than locked value!");
require(this.kycCheck(destination) , "The destination not verified!");
uint destinationSize;
assembly {
destinationSize := extcodesize(destination)
}
if( destinationSize > 0 ){
(bool success , bytes memory returnData) = destination.call.value(sendValue)("");
require( success , "Transfer to contract failed!");
}else{
address(uint160(destination)).transfer(sendValue);
}
accountList[msg.sender].lockedBalance -= sendValue;
accountList[msg.sender].txCount++;
emit transferSuccess(msg.sender,destination,sendValue,accountList[msg.sender].txCount);
}
function() external payable{
addNewAccount(msg.sender,msg.value);
}
}