diff --git a/contracts/Bank.sol b/contracts/Bank.sol new file mode 100644 index 0000000..8279964 --- /dev/null +++ b/contracts/Bank.sol @@ -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; + } +} diff --git a/contracts/SoulboundToken.sol b/contracts/SoulboundToken.sol index d6daf64..86565e7 100644 --- a/contracts/SoulboundToken.sol +++ b/contracts/SoulboundToken.sol @@ -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]; + } } \ No newline at end of file diff --git a/migrations/1685866933_migrate_credit_system.js b/migrations/1685866933_migrate_credit_system.js index 65377c2..b62bd00 100644 --- a/migrations/1685866933_migrate_credit_system.js +++ b/migrations/1685866933_migrate_credit_system.js @@ -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); + }) + }) };