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 .

Last updated

Was this helpful?