feat: Bank register

This commit is contained in:
snsd0805 2023-06-05 22:52:32 +08:00
parent 380c4acb09
commit 2b241a1995
Signed by: snsd0805
GPG Key ID: 569349933C77A854
3 changed files with 42 additions and 2 deletions

29
contracts/Bank.sol Normal file
View File

@ -0,0 +1,29 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;
import "@openzeppelin/contracts/utils/Counters.sol";
import "./SoulboundToken.sol";
contract Bank {
using Counters for Counters.Counter;
Counters.Counter private id_counter;
SoulboundToken SBT;
address owner;
mapping(address => uint) arrears;
mapping(address => uint) SBTNumbers;
constructor(address SBT_addr) {
SBT = SoulboundToken(SBT_addr);
}
modifier onlyBank {
require(msg.sender == owner, "Only the owner can access this function.");
_;
}
function register(uint number) public {
uint target = SBT.getAccountNumber(msg.sender);
require(target == number, "This is not your SBT number.");
SBTNumbers[msg.sender] = target;
}
}

View File

@ -17,6 +17,7 @@ contract SoulboundToken is ERC721, Ownable {
mapping(address => bool) private isReliableBank;
mapping(address => Certificate[]) private certificates;
mapping(address => uint) private address_to_number;
event Borrow(address client, address bank, uint id, uint amount);
event Repay(address client, address bank, uint id, uint amount, bool finish);
@ -28,6 +29,7 @@ contract SoulboundToken is ERC721, Ownable {
_tokenIds.increment();
uint256 newItemId = _tokenIds.current();
_mint(player, newItemId);
address_to_number[player] = newItemId;
return newItemId;
}
@ -103,4 +105,8 @@ contract SoulboundToken is ERC721, Ownable {
function listCertificate(address client) public view onlyBank returns (Certificate[] memory){
return certificates[client];
}
function getAccountNumber(address client) public view onlyBank returns (uint) {
return address_to_number[client];
}
}

View File

@ -1,6 +1,11 @@
var MyNFT = artifacts.require("SoulboundToken");
var SBT = artifacts.require("SoulboundToken");
var Bank = artifacts.require("Bank");
module.exports = function(_deployer) {
// Use deployer to state migration tasks.
_deployer.deploy(MyNFT, );
_deployer.deploy(SBT).then((SBT_instance) => {
return _deployer.deploy(Bank, SBT_instance.address).then((Bank_instance) => {
return SBT_instance.addReliableBank(Bank_instance.address);
})
})
};