feat: add some getter function
This commit is contained in:
parent
c231926431
commit
7b11748282
@ -3,15 +3,16 @@ pragma solidity >=0.4.22 <0.9.0;
|
|||||||
import "@openzeppelin/contracts/utils/Counters.sol";
|
import "@openzeppelin/contracts/utils/Counters.sol";
|
||||||
import "./SoulboundToken.sol";
|
import "./SoulboundToken.sol";
|
||||||
|
|
||||||
|
struct Order {
|
||||||
|
bool isFinished;
|
||||||
|
uint amount;
|
||||||
|
address shop;
|
||||||
|
}
|
||||||
|
|
||||||
contract Bank {
|
contract Bank {
|
||||||
using Counters for Counters.Counter;
|
using Counters for Counters.Counter;
|
||||||
Counters.Counter private id_counter;
|
Counters.Counter private id_counter;
|
||||||
|
|
||||||
struct Order {
|
|
||||||
bool isFinished;
|
|
||||||
uint amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
SoulboundToken public sbt;
|
SoulboundToken public sbt;
|
||||||
address public owner;
|
address public owner;
|
||||||
bool public recv = false;
|
bool public recv = false;
|
||||||
@ -61,7 +62,7 @@ contract Bank {
|
|||||||
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);
|
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, id, amount);
|
sbt.logBorrowing(msg.sender, id, amount);
|
||||||
@ -104,4 +105,20 @@ contract Bank {
|
|||||||
function stop_recv() public onlyBank {
|
function stop_recv() public onlyBank {
|
||||||
recv = false;
|
recv = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getCredit(address client) public view onlySelfOrBank(client) returns (uint) {
|
||||||
|
return credits[client];
|
||||||
|
}
|
||||||
|
|
||||||
|
function getArrear(address client) public view onlySelfOrBank(client) return (uint) {
|
||||||
|
return arrears[client];
|
||||||
|
}
|
||||||
|
|
||||||
|
function getClientOrders(address client) public view onlySelfOrBank(client) returns (Order[] memory){
|
||||||
|
Order[] memory orders = new Order[]( client_orders[client].length );
|
||||||
|
for(uint i=0; i<client_orders[client].length; i++){
|
||||||
|
orders[i] = order_info[client_orders[client][i]];
|
||||||
|
}
|
||||||
|
return orders;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user