Compare commits
No commits in common. "e207b779b873f3726a6495614380f691677bca02" and "7051eafe368e9599cb4e53792416842c4429b6f0" have entirely different histories.
e207b779b8
...
7051eafe36
@ -11,7 +11,7 @@ struct Order {
|
|||||||
|
|
||||||
contract Bank {
|
contract Bank {
|
||||||
using Counters for Counters.Counter;
|
using Counters for Counters.Counter;
|
||||||
// Counters.Counter private id_counter;
|
Counters.Counter private id_counter;
|
||||||
|
|
||||||
SoulboundToken public sbt;
|
SoulboundToken public sbt;
|
||||||
address public owner;
|
address public owner;
|
||||||
@ -55,42 +55,47 @@ contract Bank {
|
|||||||
require(target == number, "This is not your SBT number.");
|
require(target == number, "This is not your SBT number.");
|
||||||
require(sbt_number[msg.sender] == 0, "You have registered.");
|
require(sbt_number[msg.sender] == 0, "You have registered.");
|
||||||
sbt_number[msg.sender] = target;
|
sbt_number[msg.sender] = target;
|
||||||
credits[msg.sender] = 1000000000000000000;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function pay(uint id, address shop, uint amount) public onlyClient {
|
function pay(address shop, uint amount) public onlyClient {
|
||||||
require(amount <= (credits[msg.sender]-arrears[msg.sender]), "You don't have enough credit.");
|
require(amount <= (credits[msg.sender]-arrears[msg.sender]), "You don't have enough credit.");
|
||||||
// id_counter.increment();
|
id_counter.increment();
|
||||||
// uint id = id_counter.current();
|
uint id = id_counter.current();
|
||||||
arrears[msg.sender] += amount;
|
arrears[msg.sender] += amount;
|
||||||
order_info[id] = Order(false, amount, shop);
|
order_info[id] = Order(false, amount, shop);
|
||||||
client_orders[msg.sender].push(id);
|
client_orders[msg.sender].push(id);
|
||||||
payable(shop).transfer(amount);
|
payable(shop).transfer(amount);
|
||||||
sbt.logBorrowing(msg.sender, shop, id, amount);
|
sbt.logBorrowing(msg.sender, id, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
function repay() public payable onlyClient {
|
function repay() public payable onlyClient returns (uint, uint) {
|
||||||
require(recv, "It's not the time to repay.");
|
require(recv, "It's not the time to repay.");
|
||||||
uint value = msg.value;
|
uint value = msg.value;
|
||||||
// uint repay_amount = 0;
|
uint repay_amount = 0;
|
||||||
uint should_pay = 0;
|
uint should_pay;
|
||||||
// uint refund;
|
uint refund;
|
||||||
// uint item_counter = 0;
|
uint item_counter = 0;
|
||||||
|
|
||||||
for (uint i=0; i<client_orders[msg.sender].length; i++) {
|
for (uint i=0; i<client_orders[msg.sender].length; i++) {
|
||||||
should_pay += order_info[client_orders[msg.sender][i]].amount;
|
should_pay = order_info[client_orders[msg.sender][i]].amount;
|
||||||
|
if ((value - repay_amount) >= should_pay){
|
||||||
|
repay_amount += should_pay;
|
||||||
|
order_info[client_orders[msg.sender][i]].isFinished = true;
|
||||||
|
sbt.logRepaying(msg.sender, client_orders[msg.sender][i], should_pay);
|
||||||
|
} else {
|
||||||
|
client_orders[msg.sender][item_counter] = client_orders[msg.sender][i];
|
||||||
|
item_counter += 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
require(value>=should_pay, "You dont have enough ETH to repay");
|
for(uint i=0; i<(client_orders[msg.sender].length-item_counter); i++){
|
||||||
for (uint i=0; i<client_orders[msg.sender].length; i++) {
|
client_orders[msg.sender].pop();
|
||||||
order_info[client_orders[msg.sender][i]].isFinished = true;
|
|
||||||
sbt.logRepaying(msg.sender, client_orders[msg.sender][i], should_pay);
|
|
||||||
}
|
}
|
||||||
client_orders[msg.sender] = new uint[](0);
|
refund = value - repay_amount;
|
||||||
arrears[msg.sender] = 0;
|
arrears[msg.sender] -= repay_amount;
|
||||||
}
|
if (refund != 0){
|
||||||
|
payable(msg.sender).transfer(refund);
|
||||||
function warning(address client) public onlyBank {
|
}
|
||||||
sbt.logWarning(client);
|
return (client_orders[msg.sender].length, refund);
|
||||||
}
|
}
|
||||||
|
|
||||||
function start_recv() public onlyBank {
|
function start_recv() public onlyBank {
|
||||||
@ -105,19 +110,15 @@ contract Bank {
|
|||||||
return credits[client];
|
return credits[client];
|
||||||
}
|
}
|
||||||
|
|
||||||
function getArrear(address client) public view onlySelfOrBank(client) returns (uint) {
|
function getArrear(address client) public view onlySelfOrBank(client) return (uint) {
|
||||||
return arrears[client];
|
return arrears[client];
|
||||||
}
|
}
|
||||||
|
|
||||||
function getClientOrders(address client) public view onlySelfOrBank(client) returns (uint[] memory){
|
function getClientOrders(address client) public view onlySelfOrBank(client) returns (Order[] memory){
|
||||||
// Order[] memory orders = new Order[]( client_orders[client].length );
|
Order[] memory orders = new Order[]( client_orders[client].length );
|
||||||
// for(uint i=0; i<client_orders[client].length; i++){
|
for(uint i=0; i<client_orders[client].length; i++){
|
||||||
// orders[i] = order_info[client_orders[client][i]];
|
orders[i] = order_info[client_orders[client][i]];
|
||||||
// }
|
}
|
||||||
return client_orders[client];
|
return orders;
|
||||||
}
|
|
||||||
|
|
||||||
function getSBTNumber(address client) public view onlySelfOrBank(client) returns (uint) {
|
|
||||||
return sbt_number[client];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,13 +19,13 @@ contract SoulboundToken is ERC721, Ownable {
|
|||||||
mapping(address => Certificate[]) private certificates;
|
mapping(address => Certificate[]) private certificates;
|
||||||
mapping(address => uint) private address_to_number;
|
mapping(address => uint) private address_to_number;
|
||||||
|
|
||||||
event Borrow(address indexed client, address indexed shop, address indexed bank, uint id, uint amount);
|
event Borrow(address client, address bank, uint id, uint amount);
|
||||||
event Repay(address indexed client, address indexed bank, uint id, uint amount);
|
event Repay(address client, address bank, uint id, uint amount);
|
||||||
event Warning(address indexed client, address indexed bank);
|
event Warning(address client, address bank);
|
||||||
|
|
||||||
constructor() ERC721("Credit System Soulbound Token", "CS_SBT") {}
|
constructor() ERC721("Credit System Soulbound Token", "CS_SBT") {}
|
||||||
|
|
||||||
function mint(address player) public returns (uint256) {
|
function mint(address player) public onlyOwner returns (uint256) {
|
||||||
_tokenIds.increment();
|
_tokenIds.increment();
|
||||||
uint256 newItemId = _tokenIds.current();
|
uint256 newItemId = _tokenIds.current();
|
||||||
_mint(player, newItemId);
|
_mint(player, newItemId);
|
||||||
@ -72,9 +72,11 @@ contract SoulboundToken is ERC721, Ownable {
|
|||||||
require(isReliableBank[msg.sender] == true, "Only bank can access this function");
|
require(isReliableBank[msg.sender] == true, "Only bank can access this function");
|
||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
|
event HERE(address);
|
||||||
|
|
||||||
modifier onlySelfOrBank(address addr) {
|
modifier onlySelfOrBank(address addr) {
|
||||||
require(isReliableBank[msg.sender] == true || (msg.sender == addr), "Only the owner can access this function.");
|
emit HERE(addr);
|
||||||
|
require((msg.sender == owner()) || (msg.sender == addr), "Only the owner can access this function.");
|
||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,8 +93,8 @@ contract SoulboundToken is ERC721, Ownable {
|
|||||||
isReliableBank[bank] = false;
|
isReliableBank[bank] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function logBorrowing(address client, address shop, uint id, uint amount) public onlyBank {
|
function logBorrowing(address client, uint id, uint amount) public onlyBank {
|
||||||
emit Borrow(client, shop, msg.sender, id, amount);
|
emit Borrow(client, msg.sender, id, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
function logRepaying(address client, uint id, uint amount) public onlyBank {
|
function logRepaying(address client, uint id, uint amount) public onlyBank {
|
||||||
@ -111,7 +113,8 @@ contract SoulboundToken is ERC721, Ownable {
|
|||||||
return certificates[client];
|
return certificates[client];
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAccountNumber(address client) public view onlySelfOrBank(client) returns (uint) {
|
function getAccountNumber(address client) public onlySelfOrBank(client) returns (uint) {
|
||||||
|
|
||||||
return address_to_number[client];
|
return address_to_number[client];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user