Created
August 26, 2018 11:02
-
-
Save nsjames/a2ddc0eff4c21f6c8db12be6338dc5e6 to your computer and use it in GitHub Desktop.
Account Has Code - Basic EOS oracle for checking if an account has code on it.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <eosiolib/eosio.hpp> | |
#include <eosiolib/singleton.hpp> | |
using namespace eosio; | |
class acchascode : contract { | |
private: | |
// @abi table trustees | |
struct Trustee { | |
account_name account; | |
account_name primary_key() const { return account; } | |
EOSLIB_SERIALIZE( Trustee, (account) ) | |
}; | |
// @abi table accounts | |
struct Account { | |
account_name account; | |
account_name primary_key() const { return account; } | |
EOSLIB_SERIALIZE( Account, (account) ) | |
}; | |
typedef multi_index<N(trustees), Trustee> Trustees; | |
typedef singleton<N(accounts), Account> Accounts; | |
public: | |
using contract::contract; | |
acchascode( name self ) : contract(self){} | |
// @abi action | |
void trustee(account_name account){ | |
require_auth(_self); | |
Trustees trustees(_self, _self); | |
auto exists = trustees.find(account); | |
if(exists != trustees.end()) trustees.erase(exists); | |
else trustees.emplace(_self, [&](auto& record){ | |
record.account = account; | |
}); | |
} | |
// @abi action | |
void add(account_name account, account_name trustee){ | |
require_auth(trustee); | |
Trustees trustees(_self, _self); | |
eosio_assert(trustees.find(trustee) != trustees.end(), "Trustee is not a trusted oracle seeder"); | |
if(Accounts(_self, account).exists()) Accounts(_self, account).remove(); | |
else Accounts(_self, account).set(Account{account}, _self); | |
} | |
}; | |
EOSIO_ABI( acchascode, (trustee)(add) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment