feat: Bank register
This commit is contained in:
parent
380c4acb09
commit
2b241a1995
29
contracts/Bank.sol
Normal file
29
contracts/Bank.sol
Normal 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;
|
||||
}
|
||||
}
|
||||
@ -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];
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
})
|
||||
})
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user