From da26a89b2bca4f433ea5d10847e585d2be8fa17f Mon Sep 17 00:00:00 2001 From: Vincent Mwendwa Date: Fri, 19 Apr 2019 18:57:19 +0300 Subject: [PATCH] added comments --- sc/smtsbusiness/smtsbusiness.hpp | 67 +++++++++++++++++++++++++++++++- web-app/webapp.js | 2 +- 2 files changed, 67 insertions(+), 2 deletions(-) diff --git a/sc/smtsbusiness/smtsbusiness.hpp b/sc/smtsbusiness/smtsbusiness.hpp index 94f78d0..94e3a8b 100644 --- a/sc/smtsbusiness/smtsbusiness.hpp +++ b/sc/smtsbusiness/smtsbusiness.hpp @@ -31,26 +31,83 @@ namespace SmtsBusiness { // The units for all Commodities (EOS tokens representing a basic good used in commerce) is pounds (lbs). // Therefore, "10.0 IRON" means 10.0 lbs of IRON. // - // A currency, in the context of this smart contract, is a EOS token that + // A currency, in the context of this smart contract, is a EOS token that is used as a medium of exchange. + // This SC has one currency / token, YELOS and it's created and issued by the contract owner. class [[eosio::contract("smtsbusiness")]] SmtsBusiness : public contract { public: SmtsBusiness(name self, name code, datastream ds) : contract(self, code, ds) {} + // Creates a New Token. + // + // @param maxSupply - an asset variable that defines the total amount of YELOS all the participants can hold [[eosio::action("createcurr")]] void CreateToken(const asset& maxSupply); + + // Creates a commodity - a type of a scrap metal + // + // @param issuer - the EOS acct associated with the creator of the token + // @param maxSupply - an asset variable that defines the total amount of YELOS all the participants can hold + // @param unitPrice - an asset defining the amount of YELOS that each unit (default unit is pounds) of a certain commodity [[eosio::action("createcomm")]] void CreateCmmdty(const name& issuer, const asset& maxSupply, const asset& unitPrice); + + // Distributes a token. + // + // @param to - source EOS acct of the token + // @param quantity - amount of a certain token to be allocated to a certain EOS acct + // @param memo - a short description of the transaction [[eosio::action("issue")]] void Issue(const name& to, const asset& quantity, const std::string& memo); + + // Moves a specified number of tokens from one acct to another. + // + // @param from - source EOS acct name + // @param to - destination EOS acct name + // @param quantity - amount to transfer + // @param memo - a short description of the transaction [[eosio::action("transfer")]] void Transfer(const name& from, const name& to, const asset& quantity, const std::string& memo); + + // Sends a inventory request to a scrap metal dealer. + // + // @param from - EOS acct name of the customer placing the order + // @param to - EOS acct name of the merchant receiving the order + // @param quantity - amount needed [[eosio::action("inventoryreq")]] void InvRequest(const name& from, const name& to, const asset& quantity); + + // Fulfills an inventory request by transfering the required amount of tokens to the customer's EOS acct + // + // @param merchantAcct - EOS acct name of the merchant receiving the order + // @param irId - The Primary Key for the inventory request [[eosio::action("fulfill")]] void Fulfill(const name& merchantAcct, uint64_t irId); + + // Settles a fulfilled inventory request by transfering the appropriate amount of YELOS from a customers acct to the + // scrap metal merchant's acct. + // + // @param customerAcct - EOS acct name of the customer who placed the order + // @param irId - The Primary Key for the inventory request [[eosio::action("pay")]] void Pay(const name& customerAcct, uint64_t irId); + + // Minimum Stock Levels - The minimum balance for a certain commodity (a token representing a certain type of a scrap metal) that's + // needed to automatically trigger an Inventory Request. + // + // Creates / Updates Minimum Stock Level for a specified commodity. + // + // @param payer - EOS acct name of the customer. + // @param supplier - EOS acct name of the merchant to receive the automated Inventory Requests. + // @param minBal - The minimum asset / token / commodity balance (This is in pounds) required to trigger an nventory Request + // @param invreqAmnt - Number / amount of pounds worth of a specified commodity to be ordered automatically. [[eosio::action("upsertmsl")]] void UpsertMsl(const name& payer, const name& supplier, const asset& minBal, const asset& invreqAmnt); + + // Burns a commodity (token) in order to simulate stock sell out. This is the ACTION that triggers the automated inventory requests. + // + // @param payer - EOS acct name of the holder of a specified token (commodity). + // @param quantity - Amount to burn [[eosio::action("sell")]] void Sell(const name& payer, const asset& quantity); + // Clears the Smart Contract Data -- All the tables. USE WISELY. [[eosio::action("deletedata")]] void DeleteData(); private: + // Helper methods. void Create(const name& issuer, const asset& maxSupply); void AddBalance(const name& from, const name& to, const asset& value); void SubBalance(const name& owner, const asset& value); @@ -61,6 +118,7 @@ namespace SmtsBusiness { uint64_t primary_key() const { return balance.symbol.code().raw(); } }; + // Keeps record about the amount of a certain token that's in supply. struct [[eosio::table("assetstats")]] AssetStats { asset supply; asset max_supply; @@ -69,19 +127,26 @@ namespace SmtsBusiness { uint64_t primary_key() const { return supply.symbol.code().raw(); } }; + // Defines the value of a commodity against YELOS struct [[eosio::table("cunitprice")]] CommodityUnitPrice { symbol_code comm_name; + // YELOS / lbs asset unit_price; uint64_t primary_key() const { return comm_name.raw(); } }; + // Inventory Requests struct [[eosio::table("inventoryreq")]] InventoryReq { uint64_t id; + // customer name from; + // merchant name to; asset quantity; + // YELOS / lbs asset unit_price; + // PENDING -> FULFILLED -> PAID std::string status; uint64_t primary_key() const { return id; } diff --git a/web-app/webapp.js b/web-app/webapp.js index f6aa123..3185055 100644 --- a/web-app/webapp.js +++ b/web-app/webapp.js @@ -50,7 +50,7 @@ app.get('/assets_bal', async (req, res) => { }) app.post('/transact', async (req, res) => { - console.log(req.body) + // console.log(req.body) const {actor, action, data} = req.body res.json(await teloseosapi.transact(actor, action, data)) })