EULA

StrongBlock offers a EULA smart contract in the Marketplace for users to install and DApp developers to select as a dependency for their smart contracts.

For a smart contract to incorporate the EULA smart contract it needs to first include the following header file:

can_proceed.hpp
// v2.0.0
#pragma once
#include <eosio/eosio.hpp>
#include <eosio/time.hpp>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
using namespace eosio;
using std::string;
using std::vector;
struct eulatable
{
name id;
uint16_t version;
string content;
time_point_sec timestamp;
uint64_t primary_key() const { return id.value; }
};
typedef multi_index<"eulatable"_n, eulatable> eulatable_index;
struct signer
{
name id;
vector<name> signed_eula_ids;
vector<uint16_t> signed_eula_versions;
vector<time_point_sec> signed_eula_timestamps;
uint64_t primary_key() const { return id.value; }
};
typedef multi_index<"signer"_n, signer> signer_index;
bool can_proceed(name eula_id, name signer, name actual_eula_account_name)
{
eulatable_index eulatables(actual_eula_account_name, actual_eula_account_name.value);
signer_index signers(actual_eula_account_name, actual_eula_account_name.value);
auto e_itr = eulatables.find(eula_id.value);
if (e_itr == eulatables.end())
{
return true;
}
auto s_itr = signers.find(signer.value);
if (s_itr == signers.end())
{
return false;
}
vector<name> signed_eula_ids = s_itr->signed_eula_ids;
vector<name>::iterator signed_eula_ids_itr = std::find(signed_eula_ids.begin(), signed_eula_ids.end(), eula_id);
if (signed_eula_ids_itr == signed_eula_ids.end())
{
return false;
}
int index = std::distance(signed_eula_ids.begin(), signed_eula_ids_itr);
if (s_itr->signed_eula_versions[index] == e_itr->version)
{
return true;
}
return false;
}

Secondly, the following lines of codes should be added to any action needing to be protected by a EULA:

check(dependencies.exists(), "need to call setdep");
string err_msg = "need to sign " + get_self().to_string() + "'s EULA";
check(can_proceed(get_self(), who, get_dependency_name(0) /* eulaeulaeula */), err_msg.c_str());

Note that the EULA smart contract is a dependency so the documentation found in Dependencies needs to be followed.

An example of the EULA smart contract being used as a dependency can be found here.