reccoin-backend

所属分类:区块链开发
开发工具:JavaScript
文件大小:0KB
下载次数:0
上传日期:2023-08-09 19:02:12
上 传 者sh-1993
说明:  recylox去中心化应用程序的后端(智能合约)存储库,
(Back-End(Smart Contract) repository of recylox decentralized application,)

文件列表:
contracts/ (0, 2023-08-09)
contracts/Recycle.sol (20306, 2023-08-09)
contracts/Recylox.sol (6716, 2023-08-09)
env.example (125, 2023-08-09)
hardhat.config.js (397, 2023-08-09)
package.json (985, 2023-08-09)
scripts/ (0, 2023-08-09)
scripts/deploy.js (1637, 2023-08-09)
test/ (0, 2023-08-09)
test/Recycle.js (25424, 2023-08-09)
test/Recylox.js (15518, 2023-08-09)
utils/ (0, 2023-08-09)
utils/verify.js (526, 2023-08-09)

#Section 1 # Recylox Token Contract Documentation ## Table of Contents - [Token Information](https://github.com/Grandida-Projects/reccoin-backend/blob/master/#token-information) - [Balances and Allowances](https://github.com/Grandida-Projects/reccoin-backend/blob/master/#balances-and-allowances) - [Constructor](https://github.com/Grandida-Projects/reccoin-backend/blob/master/#constructor) - [Transfer Functions](https://github.com/Grandida-Projects/reccoin-backend/blob/master/#transfer-functions) - [Approval Functions](https://github.com/Grandida-Projects/reccoin-backend/blob/master/#approval-functions) - [Minting and Burning](https://github.com/Grandida-Projects/reccoin-backend/blob/master/#minting-and-burning) - [Internal Functions](https://github.com/Grandida-Projects/reccoin-backend/blob/master/#internal-functions) 1. [Contract Overview](https://github.com/Grandida-Projects/reccoin-backend/blob/master/#contract-overview) 2. [Contract Structure](https://github.com/Grandida-Projects/reccoin-backend/blob/master/#contract-structure) - [State Variables](https://github.com/Grandida-Projects/reccoin-backend/blob/master/#state-variables) - [Structs](https://github.com/Grandida-Projects/reccoin-backend/blob/master/#structs) - [Modifiers](https://github.com/Grandida-Projects/reccoin-backend/blob/master/#modifiers) - [Events](https://github.com/Grandida-Projects/reccoin-backend/blob/master/#events) 3. [Public Functions](https://github.com/Grandida-Projects/reccoin-backend/blob/master/#public-functions) - [balanceOf()](https://github.com/Grandida-Projects/reccoin-backend/blob/master/#balanceof) - [registerCompany()](https://github.com/Grandida-Projects/reccoin-backend/blob/master/#registercompany) - [getRegisteredCompanyCount()](https://github.com/Grandida-Projects/reccoin-backend/blob/master/#getregisteredcompanycount) - [editCompany()](https://github.com/Grandida-Projects/reccoin-backend/blob/master/#editcompany) - [updateCompanyName()](https://github.com/Grandida-Projects/reccoin-backend/blob/master/#updatecompanyname) - [updateCompanyMinWeightRequirement()](https://github.com/Grandida-Projects/reccoin-backend/blob/master/#updatecompanyminweightrequirement) - [updateCompanyMaxPricePerKg()](https://github.com/Grandida-Projects/reccoin-backend/blob/master/#updatecompanymaxpriceperkg) - [updateCompanyActiveStatus()](https://github.com/Grandida-Projects/reccoin-backend/blob/master/#updatecompanyactivestatus) - [registerPicker()](https://github.com/Grandida-Projects/reccoin-backend/blob/master/#registerpicker) - [getPicker()](https://github.com/Grandida-Projects/reccoin-backend/blob/master/#getpicker) - [getRegisteredPickerCount()](https://github.com/Grandida-Projects/reccoin-backend/blob/master/#getregisteredpickercount) - [editPicker()](https://github.com/Grandida-Projects/reccoin-backend/blob/master/#editpicker) 4. [Internal Functions](https://github.com/Grandida-Projects/reccoin-backend/blob/master/#internal-functions) 5. [Usage](https://github.com/Grandida-Projects/reccoin-backend/blob/master/#usage) 6. [Security Considerations](https://github.com/Grandida-Projects/reccoin-backend/blob/master/#security-considerations) ## Token Information The Recylox token contract is an implementation of the ERC20 token standard in Solidity. It represents a token that can be used within the Ethereum ecosystem for various purposes. The contract defines the following token information: - `name`: The name of the token. - `symbol`: The symbol of the token. - `decimals`: The number of decimal places for token display. - `totalSupply`: The total supply of the token. ## Balances and Allowances The contract maintains a mapping to track the balance of tokens for each token holder. Additionally, it includes a mapping to track the allowances granted by token holders to other addresses. The following functions are available to interact with balances and allowances: - `balanceOf(address account)`: Returns the balance of tokens for a specified account. - `allowance(address owner, address spender)`: Returns the allowance granted by the owner to the spender. ## Constructor The constructor function initializes the token contract with the provided initial supply of tokens. The initial supply is assigned to the contract deployer. ## Transfer Functions The contract provides functions to transfer tokens between accounts: - `transfer(address recipient, uint256 amount)`: Transfers tokens from the sender's account to the specified recipient. - `transferFrom(address sender, address recipient, uint256 amount)`: Transfers tokens from the sender's account to the specified recipient on behalf of the token owner. ## Approval Functions The contract includes an approval mechanism to allow token holders to grant allowances to other addresses: - `approve(address spender, uint256 amount)`: Sets the allowance for the spender to spend tokens on behalf of the owner. ## Minting and Burning The contract includes functions for minting and burning tokens. These functions can only be called by the contract owner: - `mint(address account, uint256 amount)`: Mints new tokens and adds them to the specified account. - `burn(address account, uint256 amount)`: Burns tokens from the specified account. ## Internal Functions The contract defines the following internal functions: - `_transfer(address sender, address recipient, uint256 amount)`: Internal function to transfer tokens from one account to another. - `_approve(address owner, address spender, uint256 amount)`: Internal function to approve the spender to spend tokens on behalf of the owner. - `_burn(address account, uint256 amount)`: Internal function to burn tokens from the specified account. For a more detailed explanation of the Solidity language and how to use contracts, you can refer to the official Solidity documentation [^1^]. The Solidity documentation provides an overview of the language, examples, and guides on writing and deploying smart contracts. [1]: https://docs.soliditylang.org/ #Section 2 # Recycle Smart Contract Documentation ## Contract Overview The Recycle smart contract facilitates the exchange between recycling companies and plastic pickers. It provides functions to manage company and picker registrations, track transactions, handle plastic deposits, validation, and payment. This documentation provides an overview of the contract's structure, functionality, and usage. ## Contract Structure The Recycle smart contract consists of the following components: ### State Variables - `recyloxAddress`: Immutable address representing the token smart contract address. - `companyAddresses`: Array of addresses representing registered company addresses. - `pickerAddresses`: Array of addresses representing registered picker addresses. - `companies`: Mapping storing information about registered companies. - `pickers`: Mapping storing information about registered pickers. - `totalTransactions`: Counter variable to track the total number of transactions. - `transactions`: Mapping storing information about individual transactions. - `locked`: Boolean variable used to track the reentrancy status of the contract. ### Structs - `Company`: Represents information about a registered company, including name, minimum weight requirement, maximum price per kilogram, and active status. - `Picker`: Represents information about a registered picker, including name, email, weight deposited, and transaction history. - `Transaction`: Represents a transaction between a company and a picker, including the transaction ID, company and picker addresses, weight, price, and approval status. ### Modifiers - `onlyCompany`: Allows only registered companies to perform certain actions. - `onlyActiveCompany`: Allows only active companies to perform certain actions. - `onlyPicker`: Allows only registered pickers to perform certain actions. - `transactionExists`: Checks if a transaction with the given ID exists. - `transactionApproved`: Checks if a transaction with the given ID is approved. - `noReentrancy`: Prevents reentrancy attacks by allowing a function to be called only when not already in progress. ### Events The contract emits various events to provide information about important contract actions and state changes. These events can be subscribed to by external applications to track the contract's activities. ## Public Functions The Recycle smart contract exposes the following public functions for external interaction: ### `balanceOf()` ```solidity function balanceOf() public view returns (uint256) ``` Retrieve the balance of tokens for the caller (company or picker). ### `registerCompany()` ```solidity function registerCompany(string memory name, uint256 minWeightRequirement, uint256 maxPricePerKg) public ``` Registers a new company with the provided information. The caller's address is used as the company address. ### `getRegisteredCompanyCount()` ```solidity function getRegisteredCompanyCount() public view returns (uint256) ``` Retrieves the count of registered companies. ### `editCompany()` ```solidity function editCompany(uint256 index, uint256 minWeightRequirement, uint256 maxPricePerKg) public onlyCompany ``` Edits an existing company's information. The caller must be the owner of the company. ### `updateCompanyName()` ```solidity function updateCompanyName(string memory newName) public onlyCompany ``` Updates the name of the company for the calling address. The caller must be the owner of the company. ### `updateCompanyMinWeightRequirement()` ```solidity function updateCompanyMinWeightRequirement(uint256 newRequirement) public onlyCompany ``` Updates the minimum weight requirement of the company for the calling address. The caller must be the owner of the company. ### `updateCompanyMaxPricePerKg()` ```solidity function updateCompanyMaxPricePerKg(uint256 newPrice) public onlyCompany ``` Updates the maximum price per kilogram of the company for the calling address. The caller must be the owner of the company. ### `updateCompanyActiveStatus()` ```solidity function updateCompanyActiveStatus(bool isActive) public onlyCompany ``` Updates the active status of the company for the calling address. The caller must be the owner of the company. ### `registerPicker()` ```solidity function registerPicker(string memory name, string memory email) public ``` Registers a new picker with the provided information. The caller's address is used as the picker address. ### `getPicker()` ```solidity function getPicker(address pickerAddress) public view returns (string memory, string memory, uint256, uint256[]) ``` Retrieves the information about a registered picker, including name, email, weight deposited, and transaction history. ### `getRegisteredPickerCount()` ```solidity function getRegisteredPickerCount() public view returns (uint256) ``` Retrieves the count of registered pickers. ### `editPicker()` ```solidity function editPicker(uint256 index, string memory newName, string memory newEmail) public onlyPicker ``` Edits an existing picker's information. The caller must be the owner of the picker. ## Internal Functions The Recycle smart contract also includes several internal functions that are used for plastic deposit, validation, and payment processes. These functions handle the core logic of the contract and are not meant to be directly called by external users. ## Usage To use the Recycle smart contract, the following steps can be followed: 1. Deploy the smart contract on a compatible blockchain network. 2. Companies and pickers can register using the `registerCompany()` and `registerPicker()` functions, respectively. 3. Registered companies can manage their information using functions like `editCompany()`, `updateCompanyName()`, `updateCompanyMinWeightRequirement()`, `updateCompanyMaxPricePerKg()`, and `updateCompanyActiveStatus()`. 4. Registered pickers can manage their information using the `editPicker()` function. 5. Companies can deposit plastic and initiate transactions using appropriate functions. 6. Pickers can validate and confirm transactions using appropriate functions. 7. Companies can approve or reject transactions using the `approveTransaction()` and `rejectTransaction()` functions. 8. Once a transaction is approved, the picker can withdraw their payment using the `withdrawPayment()` function. 9. The `balanceOf()` function can be used by companies and pickers to check their token balances. It's important to ensure that only authorized entities interact with the contract and that appropriate security measures are implemented. ## Security Considerations When using the Recycle smart contract, it's essential to consider the following security aspects: 1. Carefully review and audit the contract code to identify and address potential vulnerabilities. 2. Protect private keys associated with company and picker addresses to prevent unauthorized access. 3. Implement proper access control mechanisms to ensure that only authorized entities can perform specific actions. 4. Use secure communication channels and protocols when interacting with the contract. 5. Be cautious of potential reentrancy attacks and ensure the `noReentrancy` modifier is correctly applied to susceptible functions. 6. Regularly update and patch the smart contract as needed to address any identified security issues or improvements. By following these security considerations, you can enhance the overall security and reliability of the Recycle smart contract in your application.

近期下载者

相关文件


收藏者