📁
shine
  • Introduction to the Shine Blockchain platform
  • Shine overview
  • Shine USP
  • About EOSIO
  • Consensus mechanisms
  • Shine Proof of Authority consensus
  • Data privacy
  • Scalability
  • Business details
    • Why Blockchain
    • Why another Blockchain platform
    • Applications of Shine
      • Assumptions
      • Precious metals traceability
      • Food traceability
        • Spices
        • Perishables
        • Seafood
      • Carbon footprint monitoring
  • Tools, Technologies, and Architecture
    • Docker
    • MongoDB
    • Encryption
    • Server Security
    • Server requirements
    • Architecture
    • Transaction flows
  • Protocol
    • Microservices and APIs
    • Account management
  • Shine Blockchain Setup
    • SHINE Software Installation
    • Create Private/Public key pairs
    • Start the Blockchain node
    • Deploying System Smart Contracts
    • Add Producer/Validator Nodes
    • Node Security Setup
    • Deploying Traceability Smart Contracts
  • Backend Setup
    • Installing Prerequisites
    • Starting The Application
  • Front end Setup
    • User Interface
Powered by GitBook
On this page

Was this helpful?

  1. Shine Blockchain Setup

Deploying Traceability Smart Contracts

Below is part of the header file of our Shine traceability contract. The full code is on our private repo.

  class [[eosio::contract("shinetrace")]] shinetrace : public contract
  {
  public:
    using contract::contract;

    [[eosio::action]] void addorg(const name org_name, const bool is_admin, const string info);

    [[eosio::action]] void adduser(const name creator, const name account_name, const bool is_admin, const uint64_t org_id, const string info);

    [[eosio::action]] void addactions(const name user, const uint64_t org_id, const std::vector<name> &action_names);

    [[eosio::action]] void mapactions(const name user, const uint64_t org_id, const std::vector<name> &action_names);

    [[eosio::action]] void addnewtrace(const name account_name, const uint64_t org_id, const name action, const string meta_data);

    [[eosio::action]] void addtrace(const name account_name, const uint64_t org_id, const name action, const checksum256 trace_id, const string meta_data);

    using addorg_action = eosio::action_wrapper<"addorg"_n, &shinetrace::addorg>;
    using adduser_action = eosio::action_wrapper<"adduser"_n, &shinetrace::adduser>;
    using addactions_action = eosio::action_wrapper<"addactions"_n, &shinetrace::addactions>;
    using mapactions_action = eosio::action_wrapper<"mapactions"_n, &shinetrace::mapactions>;
    using addtrace_action = eosio::action_wrapper<"addtrace"_n, &shinetrace::addtrace>;

  private:
    struct [[eosio::table]] org
    {
      uint64_t id;
      name org_name;
      bool is_admin;
      string info;
      std::map<uint64_t, bool> actions;

      uint64_t primary_key() const { return id; }
      uint64_t by_org_name() const { return org_name.value; }
    };

.....
.....

    checksum256 get_trx_id()
    {
      size_t size = transaction_size();
      char buf[size];
      size_t read = read_transaction(buf, size);
      check(size == read, "read_transaction failed");
      return sha256(buf, read);
    }
  };
} 

Creating the account to deploy the contract

cleos create account ADMIN_ACCOUNT shinetrace PUBLIC_KEY1 PUBLIC_KEY2

We will follow the same steps we did when adding node to create the public keys.

Compiling the contract

eosio-cpp -I include -o shinetrace.wasm src/shinetrace.cpp --abigen

Deploying the contract

cleos set contract shinetrace .

PreviousNode Security SetupNextInstalling Prerequisites

Last updated 4 years ago

Was this helpful?