Skip to content

Instantly share code, notes, and snippets.

@DMantis
Created June 3, 2018 14:09
Show Gist options
  • Save DMantis/9945ec620ed628cd6c050b88b2a1f95f to your computer and use it in GitHub Desktop.
Save DMantis/9945ec620ed628cd6c050b88b2a1f95f to your computer and use it in GitHub Desktop.
part of eos contract
// @abi_action
void addheir(account_name testator, account_name heir) {
auto header = "======== add_heir function ========";
print(header, "\n" );
heir_table_type heir_table( code_account, testator );
eosio_assert(testator == _self, "you can't add heir to another person!");
heir_table.emplace(testator, [&]( auto& h_rec ) {
h_rec.pkey = heir_table.available_primary_key();
h_rec.name = heir;
h_rec.testator = testator;
h_rec.share = 0;
// h_rec.is_testator_dead = false;
});
}
/*
Claim that account_name is dead (run by one of the heirs)
*/
// @abi_action
void claimdead(account_name testator) {
auto header = "======== claim_dead function ========";
bool authorised = false;
print(header, "\n" );
heir_table_type heir_table( code_account, testator );
auto testator_index = heir_table.template get_index<N(bytestator)>();
auto testator_itr = testator_index.find(testator);
eosio_assert(testator_itr == testator_index.end(), "is not registered as testator");
while (testator_itr != testator_index.end() && testator_itr->testator == testator) {
if (_self != testator_itr->name) {
testator_itr++;
}
else {
authorised = true;
}
}
// Nobody but heirs has right to claim that testator is dead!
eosio_assert(authorised == false, "run not by one of the heirs");
heir_table.modify(testator_itr, 0, [&]( auto& h_rec ) {
h_rec.is_testator_dead = true;
});
print(eosio::name{_self}, " claims that ", eosio::name{testator}, " is dead!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment