Skip to content

Instantly share code, notes, and snippets.

@tmuskal
Created October 18, 2020 07:07
Show Gist options
  • Save tmuskal/1cd564b364d1b2c1723f5ccc6ec91dfa to your computer and use it in GitHub Desktop.
Save tmuskal/1cd564b364d1b2c1723f5ccc6ec91dfa to your computer and use it in GitHub Desktop.
#include <eosio/eosio.hpp>
using namespace eosio;
class [[eosio::contract]] testmeta : public contract {
public:
using contract::contract;
[[eosio::action]]
void hi( name user ) {
print( "Hello, ", user);
}
TABLE meta {
name key;
std::string value;
uint64_t primary_key() const { return key.value; }
};
typedef eosio::multi_index<"meta"_n, meta> _t_meta;
[[eosio::action]]
void setmeta(
name key,
std::string value
){
require_auth(_self);
_t_meta items( _self, _self.value );
auto existing = items.find( key.value );
if(existing == items.end()) {
items.emplace(_self, [&]( auto& a ){
a.key = key;
a.value = value;
});
} else {
items.modify( *existing, eosio::same_payer, [&]( auto& a ) {
a.value = value;
});
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment