/** * No authority required on this message so long as it is properly revealed */ void apply_reveal( const reveal& offer ) { assert_sha256( &offer.source, sizeof(offer.source), &offer.commitment ); /** * assert offer already exists * assert offer has a gameid > 0 * * Lookup game by gameid * assert game.player[x].reveal is 0 hasn't already been revealed * set game.player[x].reveal to revealed * * if( game.player[!x].reveal != 0 ) { * uint256_t result; * sha256( &game.player1, sizeof(player)*2, result); * if( result.words[1] < result.words[0] ) { * pay_player1 by incrementing account by bet and decrement open games * } * else * pay_player2 by incrmenting account by bet and decrement open games * delete game, and both offers * } * else { * set game.deadline = now() + timeout (5 minutes) * } * */ }
void test_action::test_cf_action() { eosio::action act = eosio::get_action( 0, 0 ); cf_action cfa = act.data_as<cf_action>(); if ( cfa.payload == 100 ) { // verify read of get_context_free_data, also verifies system api access int size = get_context_free_data( cfa.cfd_idx, nullptr, 0 ); eosio_assert( size > 0, "size determination failed" ); eosio::bytes cfd( static_cast<size_t>(size) ); size = get_context_free_data( cfa.cfd_idx, &cfd[0], static_cast<size_t>(size) ); eosio_assert(static_cast<size_t>(size) == cfd.size(), "get_context_free_data failed" ); uint32_t v = eosio::unpack<uint32_t>( &cfd[0], cfd.size() ); eosio_assert( v == cfa.payload, "invalid value" ); // verify crypto api access checksum256 hash; char test[] = "test"; sha256( test, sizeof(test), &hash ); assert_sha256( test, sizeof(test), &hash ); // verify action api access action_data_size(); // verify console api access eosio::print("test\n"); // verify memory api access uint32_t i = 42; memccpy(&v, &i, sizeof(i), sizeof(i)); // verify transaction api access eosio_assert(transaction_size() > 0, "transaction_size failed"); // verify softfloat api access float f1 = 1.0f, f2 = 2.0f; float f3 = f1 + f2; eosio_assert( f3 > 2.0f, "Unable to add float."); // verify compiler builtin api access __int128 ret; __divti3(ret, 2, 2, 2, 2); // verify context_free_system_api eosio_assert( true, "verify eosio_assert can be called" ); } else if ( cfa.payload == 200 ) { // attempt to access non context free api, privileged_api is_privileged(act.name); eosio_assert( false, "privileged_api should not be allowed" ); } else if ( cfa.payload == 201 ) { // attempt to access non context free api, producer_api get_active_producers( nullptr, 0 ); eosio_assert( false, "producer_api should not be allowed" ); } else if ( cfa.payload == 202 ) { // attempt to access non context free api, db_api db_store_i64( N(testapi), N(testapi), N(testapi), 0, "test", 4 ); eosio_assert( false, "db_api should not be allowed" ); } else if ( cfa.payload == 203 ) { // attempt to access non context free api, db_api uint64_t i = 0; db_idx64_store( N(testapi), N(testapi), N(testapi), 0, &i ); eosio_assert( false, "db_api should not be allowed" ); } else if ( cfa.payload == 204 ) { db_find_i64( N(testapi), N(testapi), N(testapi), 1); eosio_assert( false, "db_api should not be allowed" ); } else if ( cfa.payload == 205 ) { // attempt to access non context free api, send action eosio::action dum_act; dum_act.send(); eosio_assert( false, "action send should not be allowed" ); } else if ( cfa.payload == 206 ) { eosio::require_auth(N(test)); eosio_assert( false, "authorization_api should not be allowed" ); } else if ( cfa.payload == 207 ) { now(); eosio_assert( false, "system_api should not be allowed" ); } else if ( cfa.payload == 208 ) { current_time(); eosio_assert( false, "system_api should not be allowed" ); } else if ( cfa.payload == 209 ) { publication_time(); eosio_assert( false, "system_api should not be allowed" ); } else if ( cfa.payload == 210 ) { send_inline( "hello", 6 ); eosio_assert( false, "transaction_api should not be allowed" ); } else if ( cfa.payload == 211 ) { send_deferred( N(testapi), N(testapi), "hello", 6 ); eosio_assert( false, "transaction_api should not be allowed" ); } }