wasm_interface.cpp 60.2 KB
Newer Older
B
Bart Wyatt 已提交
1 2
#include <eosio/chain/wasm_interface.hpp>
#include <eosio/chain/apply_context.hpp>
3
#include <eosio/chain/chain_controller.hpp>
4
#include <eosio/chain/producer_schedule.hpp>
5
#include <eosio/chain/asset.hpp>
6
#include <eosio/chain/exceptions.hpp>
D
Daniel Larimer 已提交
7
#include <boost/core/ignore_unused.hpp>
8
#include <boost/multiprecision/cpp_bin_float.hpp>
9 10
#include <eosio/chain/wasm_interface_private.hpp>
#include <fc/exception/exception.hpp>
11
#include <fc/crypto/sha256.hpp>
12
#include <fc/crypto/sha1.hpp>
13
#include <fc/io/raw.hpp>
14
#include <fc/utf8.hpp>
D
Daniel Larimer 已提交
15 16 17

#include <Runtime/Runtime.h>
#include "IR/Module.h"
18 19 20 21
#include "Platform/Platform.h"
#include "WAST/WAST.h"
#include "IR/Operators.h"
#include "IR/Validate.h"
22
#include "IR/Types.h"
23 24 25
#include "Runtime/Runtime.h"
#include "Runtime/Linker.h"
#include "Runtime/Intrinsics.h"
D
Daniel Larimer 已提交
26

27 28 29
#include <boost/asio.hpp>
#include <boost/bind.hpp>

30
#include <mutex>
31 32 33
#include <thread>
#include <condition_variable>

34
namespace eosio { namespace chain {
35
   using namespace contracts;
36 37
   using namespace webassembly;
   using namespace webassembly::common;
M
Matias Romeo 已提交
38

39 40 41 42 43 44 45 46
   /**
    *  Implementation class for the wasm cache
    *  it is responsible for compiling and storing instances of wasm code for use
    *
    */
   struct wasm_cache_impl {
      wasm_cache_impl()
      {
47
         check_wasm_opcode_dispositions();
48
         Runtime::init();
49
      }
M
Matias Romeo 已提交
50

51 52 53 54 55 56 57 58
      /**
       * this must wait for all work to be done otherwise it may destroy memory
       * referenced by other threads
       *
       * Expectations on wasm_cache dictate that all available code has been
       * returned before this can be destroyed
       */
      ~wasm_cache_impl() {
59
         Runtime::freeUnreferencedObjects({});
60
      }
M
Matias Romeo 已提交
61

62 63 64 65 66 67 68 69 70 71 72 73 74
      /**
       * internal tracking structure which deduplicates memory images
       * and tracks available vs in-use entries.
       *
       * The instances array has two sections, "available" instances
       * are in the front of the vector and anything at an index of
       * available_instances or greater is considered "in use"
       *
       * instances are stored as pointers so that their positions
       * in the array can be moved without invaliding references to
       * the instance handed out to other threads
       */
      struct code_info {
75
         explicit code_info(wavm::info&& wavm_info, binaryen::info&& binaryen_info)
B
Bart Wyatt 已提交
76 77
         : wavm_info(std::forward<wavm::info>(wavm_info))
         , binaryen_info(std::forward<binaryen::info>(binaryen_info))
78 79
         {}

80

81
         wavm::info   wavm_info;
82
         binaryen::info binaryen_info;
83 84 85 86 87 88

         // all existing instances of this code
         vector<unique_ptr<wasm_cache::entry>> instances;
         size_t available_instances = 0;
      };

89 90 91
      using optional_info_ref = optional<std::reference_wrapper<code_info>>;
      using optional_entry_ref = optional<std::reference_wrapper<wasm_cache::entry>>;

92 93 94 95 96 97 98 99
      /**
       * Convenience method for running code with the _cache_lock and releaseint that lock
       * when the code completes
       *
       * @param f - lambda to execute
       * @return - varies depending on the signature of the lambda
       */
      template<typename F>
100 101
      auto with_lock(std::mutex &l, F f) {
         std::lock_guard<std::mutex> lock(l);
102 103 104 105 106 107 108 109 110
         return f();
      };

      /**
       * Fetch the tracking struct given a code_id if it exists
       *
       * @param code_id
       * @return
       */
111
      optional_info_ref fetch_info(const digest_type& code_id) {
112
         return with_lock(_cache_lock, [&,this](){
113 114
            auto iter = _cache.find(code_id);
            if (iter != _cache.end()) {
115
               return optional_info_ref(iter->second);
116 117
            }

118
            return optional_info_ref();
119 120
         });
      }
M
Matias Romeo 已提交
121

122 123 124 125 126
      /**
       * Opportunistically fetch an available instance of the code;
       * @param code_id - the id of the code to fetch
       * @return - reference to the entry when one is available
       */
127
      optional_entry_ref try_fetch_entry(const digest_type& code_id) {
128
         return with_lock(_cache_lock, [&,this](){
129 130
            auto iter = _cache.find(code_id);
            if (iter != _cache.end() && iter->second.available_instances > 0) {
131
               auto &ptr = iter->second.instances.at(--(iter->second.available_instances));
132
               return optional_entry_ref(*ptr);
133 134
            }

135
            return optional_entry_ref();
136
         });
D
Daniel Larimer 已提交
137
      }
M
Matias Romeo 已提交
138

139 140 141 142 143 144 145 146 147 148 149 150
      /**
       * Fetch a copy of the code, this is guaranteed to return an entry IF the code is compilable.
       * In order to do that in safe way this code may cause the calling thread to sleep while a new
       * version of the code is compiled and inserted into the cache
       *
       * @param code_id - the id of the code to fetch
       * @param wasm_binary - the binary for the wasm
       * @param wasm_binary_size - the size of the binary
       * @return reference to a usable cache entry
       */
      wasm_cache::entry& fetch_entry(const digest_type& code_id, const char* wasm_binary, size_t wasm_binary_size) {
         std::condition_variable condition;
151
         optional_entry_ref result;
152 153 154 155
         std::exception_ptr error;

         // compilation is not thread safe, so we dispatch it to a io_service running on a single thread to
         // queue up and synchronize compilations
156
         with_lock(_compile_lock, [&,this](){
157 158 159 160 161 162
            // check to see if someone returned what we need before making a new one
            auto pending_result = try_fetch_entry(code_id);
            std::exception_ptr pending_error;

            if (!pending_result) {
               // time to compile a brand new (maybe first) copy of this code
B
Bart Wyatt 已提交
163

164 165
               fc::optional<wavm::entry> wavm;
               fc::optional<wavm::info> wavm_info;
166 167
               fc::optional<binaryen::entry> binaryen;
               fc::optional<binaryen::info> binaryen_info;
168 169

               try {
B
Bart Wyatt 已提交
170
                  /// TODO: make validation generic
171 172
                  wavm = wavm::entry::build(wasm_binary, wasm_binary_size);
                  wavm_info.emplace(*wavm);
173 174 175

                  binaryen = binaryen::entry::build(wasm_binary, wasm_binary_size);
                  binaryen_info.emplace(*binaryen);
176 177 178 179 180 181
               } catch (...) {
                  pending_error = std::current_exception();
               }

               if (pending_error == nullptr) {
                  // grab the lock and put this in the cache as unavailble
182
                  with_lock(_cache_lock, [&,this]() {
183
                     // find or create a new entry
184
                     auto iter = _cache.emplace(code_id, code_info(std::move(*wavm_info),std::move(*binaryen_info))).first;
185

186
                     iter->second.instances.emplace_back(std::make_unique<wasm_cache::entry>(std::move(*wavm), std::move(*binaryen)));
187
                     pending_result = optional_entry_ref(*iter->second.instances.back().get());
188 189 190 191
                  });
               }
            }

192 193 194 195 196
           if (pending_error != nullptr) {
              error = pending_error;
           } else {
              result = pending_result;
           }
197

198 199
         });

200

201 202 203 204
         try {
            if (error != nullptr) {
               std::rethrow_exception(error);
            } else {
205
               return (*result).get();
206 207
            }
         } FC_RETHROW_EXCEPTIONS(error, "error compiling WASM for code with hash: ${code_id}", ("code_id", code_id));
D
Daniel Larimer 已提交
208
      }
209

210 211 212 213 214 215 216 217 218
      /**
       * return an entry to the cache.  The entry is presumed to come back in a "dirty" state and must be
       * sanitized before returning to the "available" state.  This sanitization is done asynchronously so
       * as not to delay the current executing thread.
       *
       * @param code_id - the code Id associated with the instance
       * @param entry - the entry to return
       */
      void return_entry(const digest_type& code_id, wasm_cache::entry& entry) {
219 220 221 222 223 224 225 226 227 228 229 230
         // sanitize by reseting the memory that may now be dirty
         auto& info = (*fetch_info(code_id)).get();
         entry.wavm.reset(info.wavm_info);
         entry.binaryen.reset(info.binaryen_info);

         // under a lock, put this entry back in the available instances side of the instances vector
         with_lock(_cache_lock, [&,this](){
            // walk the vector and find this entry
            auto iter = info.instances.begin();
            while (iter->get() != &entry) {
               ++iter;
            }
231

232
            FC_ASSERT(iter != info.instances.end(), "Checking in a WASM enty that was not created properly!");
233

234 235 236 237 238 239
            auto first_unavailable = (info.instances.begin() + info.available_instances);
            if (iter != first_unavailable) {
               std::swap(iter, first_unavailable);
            }
            info.available_instances++;
         });
D
Daniel Larimer 已提交
240
      }
241

242 243
      //initialize the memory for a cache entry
      wasm_cache::entry& prepare_wasm_instance(wasm_cache::entry& wasm_cache_entry, const digest_type& code_id) {
B
Bart Wyatt 已提交
244 245 246
         auto& info = (*fetch_info(code_id)).get();
         wasm_cache_entry.wavm.prepare(info.wavm_info);
         wasm_cache_entry.binaryen.prepare(info.binaryen_info);
247 248 249
         return wasm_cache_entry;
      }

250 251 252
      // mapping of digest to an entry for the code
      map<digest_type, code_info> _cache;
      std::mutex _cache_lock;
B
Brian Johnson 已提交
253

254 255
      // compilation lock
      std::mutex _compile_lock;
256
   };
B
Brian Johnson 已提交
257

258 259 260
   wasm_cache::wasm_cache()
      :_my( new wasm_cache_impl() ) {
   }
261

262 263
   wasm_cache::~wasm_cache() = default;

264
   wasm_cache::entry &wasm_cache::checkout( const digest_type& code_id, const char* wasm_binary, size_t wasm_binary_size ) {
265
      // see if there is an available entry in the cache
266
      auto result = _my->try_fetch_entry(code_id);
267
      if (result) {
268 269
         wasm_cache::entry& wasm_cache_entry = (*result).get();
         return _my->prepare_wasm_instance(wasm_cache_entry, code_id);
D
Daniel Larimer 已提交
270
      }
271
      return _my->prepare_wasm_instance(_my->fetch_entry(code_id, wasm_binary, wasm_binary_size), code_id);
272 273 274 275 276
   }


   void wasm_cache::checkin(const digest_type& code_id, entry& code ) {
      _my->return_entry(code_id, code);
277
   }
278

279 280 281 282 283
   /**
    * RAII wrapper to make sure that the context is cleaned up on exception
    */
   struct scoped_context {
      template<typename ...Args>
B
Bart Wyatt 已提交
284
      scoped_context(optional<wasm_context> &context, Args&&... args)
285 286
      :context(context)
      {
287
         context.emplace( std::forward<Args>(args)... );
288 289 290 291 292 293 294 295 296
      }

      ~scoped_context() {
         context.reset();
      }

      optional<wasm_context>& context;
   };

297 298 299 300
   wasm_interface::wasm_interface()
      :my( new wasm_interface_impl() ) {
   }

301 302 303 304 305 306 307 308
   wasm_interface& wasm_interface::get() {
      thread_local wasm_interface* single = nullptr;
      if( !single ) {
         single = new wasm_interface();
      }
      return *single;
   }

309 310 311 312 313 314 315 316 317 318
   void wasm_interface::apply( wasm_cache::entry& code, apply_context& context, vm_type vm ) {
      auto context_guard = scoped_context(my->current_context, code, context, vm);
      switch (vm) {
         case vm_type::wavm:
            code.wavm.call_apply(context);
            break;
         case vm_type::binaryen:
            code.binaryen.call_apply(context);
            break;
      }
319 320
   }

321 322 323 324 325 326 327 328 329 330
   void wasm_interface::error( wasm_cache::entry& code, apply_context& context, vm_type vm ) {
      auto context_guard = scoped_context(my->current_context, code, context, vm);
      switch (vm) {
         case vm_type::wavm:
            code.wavm.call_error(context);
            break;
         case vm_type::binaryen:
            code.binaryen.call_error(context);
            break;
      }
331 332
   }

333 334 335
   wasm_context& common::intrinsics_accessor::get_context(wasm_interface &wasm) {
      FC_ASSERT(wasm.my->current_context.valid());
      return *wasm.my->current_context;
336 337
   }

338 339
   const wavm::entry& wavm::entry::get(wasm_interface& wasm) {
      return common::intrinsics_accessor::get_context(wasm).code.wavm;
340 341
   }

342 343 344

   const binaryen::entry& binaryen::entry::get(wasm_interface& wasm) {
      return common::intrinsics_accessor::get_context(wasm).code.binaryen;
345 346
   }

347
#if defined(assert)
348
   #undef assert
349
#endif
350

B
Bart Wyatt 已提交
351
class context_aware_api {
352
   public:
D
Daniel Larimer 已提交
353
      context_aware_api(wasm_interface& wasm, bool context_free = false )
B
Bart Wyatt 已提交
354
      :code(intrinsics_accessor::get_context(wasm).code),
D
Daniel Larimer 已提交
355
       context(intrinsics_accessor::get_context(wasm).context)
356
      ,vm(intrinsics_accessor::get_context(wasm).vm)
D
Daniel Larimer 已提交
357 358 359 360 361
      {
         if( context.context_free )
            FC_ASSERT( context_free, "only context free api's can be used in this context" );
         context.used_context_free_api |= !context_free;
      }
362

B
Bart Wyatt 已提交
363
   protected:
364
      apply_context&             context;
B
Bart Wyatt 已提交
365
      wasm_cache::entry&         code;
366
      wasm_interface::vm_type    vm;
B
Bart Wyatt 已提交
367

B
Bart Wyatt 已提交
368
};
369

D
Daniel Larimer 已提交
370 371 372
class context_free_api : public context_aware_api {
   public:
      context_free_api( wasm_interface& wasm )
A
arhag 已提交
373
      :context_aware_api(wasm, true) {
D
Daniel Larimer 已提交
374 375 376 377 378 379 380 381
         /* the context_free_data is not available during normal application because it is prunable */
         FC_ASSERT( context.context_free, "this API may only be called from context_free apply" );
      }

      int get_context_free_data( uint32_t index, array_ptr<char> buffer, size_t buffer_size )const {
         return context.get_context_free_data( index, buffer, buffer_size );
      }
};
D
Daniel Larimer 已提交
382 383
class privileged_api : public context_aware_api {
   public:
384 385 386 387 388
      privileged_api( wasm_interface& wasm )
      :context_aware_api(wasm)
      {
         FC_ASSERT( context.privileged, "${code} does not have permission to call this API", ("code",context.receiver) );
      }
389

D
Daniel Larimer 已提交
390 391 392 393 394
      /**
       *  This should schedule the feature to be activated once the
       *  block that includes this call is irreversible. It should
       *  fail if the feature is already pending.
       *
395
       *  Feature name should be base32 encoded name.
D
Daniel Larimer 已提交
396
       */
397
      void activate_feature( int64_t feature_name ) {
B
Bucky Kittinger 已提交
398
         FC_ASSERT( !"Unsupported Hardfork Detected" );
D
Daniel Larimer 已提交
399
      }
400

D
Daniel Larimer 已提交
401 402 403 404 405 406
      /**
       * This should return true if a feature is active and irreversible, false if not.
       *
       * Irreversiblity by fork-database is not consensus safe, therefore, this defines
       * irreversiblity only by block headers not by BFT short-cut.
       */
407
      int is_feature_active( int64_t feature_name ) {
D
Daniel Larimer 已提交
408 409
         return false;
      }
410

411
      void set_resource_limits( account_name account,
412 413
                                int64_t ram_bytes, int64_t net_weight, int64_t cpu_weight,
                                int64_t cpu_usec_per_period ) {
414
         auto& buo = context.db.get<bandwidth_usage_object,by_owner>( account );
B
Bucky Kittinger 已提交
415
         FC_ASSERT( buo.db_usage <= ram_bytes, "attempt to free too much space" );
416 417 418 419 420 421 422 423 424 425

         auto& gdp = context.controller.get_dynamic_global_properties();
         context.mutable_db.modify( gdp, [&]( auto& p ) {
           p.total_net_weight -= buo.net_weight;
           p.total_net_weight += net_weight;
           p.total_cpu_weight -= buo.cpu_weight;
           p.total_cpu_weight += cpu_weight;
           p.total_db_reserved -= buo.db_reserved_capacity;
           p.total_db_reserved += ram_bytes;
         });
426

427 428 429 430 431
         context.mutable_db.modify( buo, [&]( auto& o ){
            o.net_weight = net_weight;
            o.cpu_weight = cpu_weight;
            o.db_reserved_capacity = ram_bytes;
         });
D
Daniel Larimer 已提交
432
      }
433

434

435
      void get_resource_limits( account_name account,
436
                                uint64_t& ram_bytes, uint64_t& net_weight, uint64_t cpu_weight ) {
D
Daniel Larimer 已提交
437
      }
438

439
      void set_active_producers( array_ptr<char> packed_producer_schedule, size_t datalen) {
440 441 442
         datastream<const char*> ds( packed_producer_schedule, datalen );
         producer_schedule_type psch;
         fc::raw::unpack(ds, psch);
443
         context.mutable_db.modify( context.controller.get_global_properties(),
444 445 446
            [&]( auto& gprops ) {
                 gprops.new_active_producers = psch;
         });
D
Daniel Larimer 已提交
447
      }
448

449 450 451 452 453 454 455 456 457 458 459
      bool is_privileged( account_name n )const {
         return context.db.get<account_object, by_name>( n ).privileged;
      }
      bool is_frozen( account_name n )const {
         return context.db.get<account_object, by_name>( n ).frozen;
      }
      void set_privileged( account_name n, bool is_priv ) {
         const auto& a = context.db.get<account_object, by_name>( n );
         context.mutable_db.modify( a, [&]( auto& ma ){
            ma.privileged = is_priv;
         });
D
Daniel Larimer 已提交
460
      }
461

462 463 464 465 466
      void freeze_account( account_name n , bool should_freeze ) {
         const auto& a = context.db.get<account_object, by_name>( n );
         context.mutable_db.modify( a, [&]( auto& ma ){
            ma.frozen = should_freeze;
         });
D
Daniel Larimer 已提交
467 468 469 470
      }

      /// TODO: add inline/deferred with support for arbitrary permissions rather than code/current auth
};
B
Brian Johnson 已提交
471

472 473 474 475
class checktime_api : public context_aware_api {
public:
   using context_aware_api::context_aware_api;

476 477
   void checktime(uint32_t instruction_count) {
      context.checktime(instruction_count);
B
Brian Johnson 已提交
478
   }
479
};
480

481 482 483
class producer_api : public context_aware_api {
   public:
      using context_aware_api::context_aware_api;
484

485
      int get_active_producers(array_ptr<chain::account_name> producers, size_t datalen) {
486
         auto active_producers = context.get_active_producers();
487
         size_t len = active_producers.size();
488
         size_t cpy_len = std::min(datalen, len);
A
Anton Perkov 已提交
489
         memcpy(producers, active_producers.data(), cpy_len * sizeof(chain::account_name));
490
         return len;
491 492 493 494
      }
};

class crypto_api : public context_aware_api {
495
   public:
496
      using context_aware_api::context_aware_api;
497

498 499
      /**
       * This method can be optimized out during replay as it has
500
       * no possible side effects other than "passing".
501
       */
502
      void assert_recover_key( fc::sha256& digest,
503 504 505 506 507 508 509 510
                        array_ptr<char> sig, size_t siglen,
                        array_ptr<char> pub, size_t publen ) {
         fc::crypto::signature s;
         fc::crypto::public_key p;
         datastream<const char*> ds( sig, siglen );
         datastream<const char*> pubds( pub, publen );

         fc::raw::unpack(ds, s);
B
Bucky Kittinger 已提交
511
         fc::raw::unpack(pubds, p);
512 513 514 515 516

         auto check = fc::crypto::public_key( s, digest, false );
         FC_ASSERT( check == p, "Error expected key different than recovered key" );
      }

517
      int recover_key( fc::sha256& digest,
518 519 520 521 522 523 524 525 526 527 528
                        array_ptr<char> sig, size_t siglen,
                        array_ptr<char> pub, size_t publen ) {
         fc::crypto::signature s;
         datastream<const char*> ds( sig, siglen );
         datastream<char*> pubds( pub, publen );

         fc::raw::unpack(ds, s);
         fc::raw::pack( pubds, fc::crypto::public_key( s, digest, false ) );
         return pubds.tellp();
      }

529 530 531 532 533
      void assert_sha256(array_ptr<char> data, size_t datalen, const fc::sha256& hash_val) {
         auto result = fc::sha256::hash( data, datalen );
         FC_ASSERT( result == hash_val, "hash miss match" );
      }

B
Bucky Kittinger 已提交
534
      void assert_sha1(array_ptr<char> data, size_t datalen, const fc::sha1& hash_val) {
B
Bucky Kittinger 已提交
535 536 537 538
         auto result = fc::sha1::hash( data, datalen );
         FC_ASSERT( result == hash_val, "hash miss match" );
      }

B
Bucky Kittinger 已提交
539
      void assert_sha512(array_ptr<char> data, size_t datalen, const fc::sha512& hash_val) {
B
Bucky Kittinger 已提交
540 541 542 543
         auto result = fc::sha512::hash( data, datalen );
         FC_ASSERT( result == hash_val, "hash miss match" );
      }

B
Bucky Kittinger 已提交
544
      void assert_ripemd160(array_ptr<char> data, size_t datalen, const fc::ripemd160& hash_val) {
B
Bucky Kittinger 已提交
545 546 547 548 549
         auto result = fc::ripemd160::hash( data, datalen );
         FC_ASSERT( result == hash_val, "hash miss match" );
      }


550 551 552 553
      void sha1(array_ptr<char> data, size_t datalen, fc::sha1& hash_val) {
         hash_val = fc::sha1::hash( data, datalen );
      }

554 555 556
      void sha256(array_ptr<char> data, size_t datalen, fc::sha256& hash_val) {
         hash_val = fc::sha256::hash( data, datalen );
      }
557 558 559 560 561 562 563 564

      void sha512(array_ptr<char> data, size_t datalen, fc::sha512& hash_val) {
         hash_val = fc::sha512::hash( data, datalen );
      }

      void ripemd160(array_ptr<char> data, size_t datalen, fc::ripemd160& hash_val) {
         hash_val = fc::ripemd160::hash( data, datalen );
      }
565 566 567 568 569 570 571 572 573 574 575
};

class string_api : public context_aware_api {
   public:
      using context_aware_api::context_aware_api;

      void assert_is_utf8(array_ptr<const char> str, size_t datalen, null_terminated_ptr msg) {
         const bool test = fc::is_utf8(std::string( str, datalen ));

         FC_ASSERT( test, "assertion failed: ${s}", ("s",msg.value) );
      }
B
Bart Wyatt 已提交
576 577 578 579 580 581
};

class system_api : public context_aware_api {
   public:
      using context_aware_api::context_aware_api;

582 583
      void abort() {
         edump(("abort() called"));
584
         FC_ASSERT( false, "abort() called");
585 586
      }

587
      void eosio_assert(bool condition, null_terminated_ptr str) {
588 589 590 591 592
         if( !condition ) {
            std::string message( str );
            edump((message));
            FC_ASSERT( condition, "assertion failed: ${s}", ("s",message));
         }
B
Bart Wyatt 已提交
593
      }
594 595 596 597

      fc::time_point_sec now() {
         return context.controller.head_block_time();
      }
B
Bart Wyatt 已提交
598 599 600 601 602 603
};

class action_api : public context_aware_api {
   public:
      using context_aware_api::context_aware_api;

604 605
      int read_action(array_ptr<char> memory, size_t size) {
         FC_ASSERT(size > 0);
606
         int minlen = std::min<size_t>(context.act.data.size(), size);
607 608 609 610
         memcpy((void *)memory, context.act.data.data(), minlen);
         return minlen;
      }

B
Bart Wyatt 已提交
611 612
      int action_size() {
         return context.act.data.size();
613 614
      }

B
Bart Wyatt 已提交
615 616 617
      const name& current_receiver() {
         return context.receiver;
      }
618 619

      fc::time_point_sec publication_time() {
B
Bart Wyatt 已提交
620
         return context.trx_meta.published;
621 622 623
      }

      name current_sender() {
B
Bart Wyatt 已提交
624 625
         if (context.trx_meta.sender) {
            return *context.trx_meta.sender;
626 627 628 629
         } else {
            return name();
         }
      }
630
};
B
Brian Johnson 已提交
631

B
Bart Wyatt 已提交
632 633 634 635
class console_api : public context_aware_api {
   public:
      using context_aware_api::context_aware_api;

636 637
      void prints(null_terminated_ptr str) {
         context.console_append<const char*>(str);
B
Bart Wyatt 已提交
638 639 640
      }

      void prints_l(array_ptr<const char> str, size_t str_len ) {
641
         context.console_append(string(str, str_len));
B
Bart Wyatt 已提交
642 643 644
      }

      void printi(uint64_t val) {
645
         context.console_append(val);
B
Bart Wyatt 已提交
646 647 648 649
      }

      void printi128(const unsigned __int128& val) {
         fc::uint128_t v(val>>64, uint64_t(val) );
650
         context.console_append(fc::variant(v).get_string());
B
Bart Wyatt 已提交
651 652 653
      }

      void printd( wasm_double val ) {
654
         context.console_append(val.str());
B
Bart Wyatt 已提交
655 656 657
      }

      void printn(const name& value) {
658
         context.console_append(value.to_string());
B
Bart Wyatt 已提交
659 660 661
      }

      void printhex(array_ptr<const char> data, size_t data_len ) {
662
         context.console_append(fc::to_hex(data, data_len));
B
Bart Wyatt 已提交
663 664 665
      }
};

A
arhag 已提交
666
#define DB_API_METHOD_WRAPPERS_SIMPLE_SECONDARY(IDX, TYPE)\
667 668 669 670 671 672 673 674 675
      int db_##IDX##_store( uint64_t scope, uint64_t table, uint64_t payer, uint64_t id, const TYPE& secondary ) {\
         return context.IDX.store( scope, table, payer, id, secondary );\
      }\
      void db_##IDX##_update( int iterator, uint64_t payer, const TYPE& secondary ) {\
         return context.IDX.update( iterator, payer, secondary );\
      }\
      void db_##IDX##_remove( int iterator ) {\
         return context.IDX.remove( iterator );\
      }\
A
arhag 已提交
676
      int db_##IDX##_find_secondary( uint64_t code, uint64_t scope, uint64_t table, const TYPE& secondary, uint64_t& primary ) {\
677 678 679
         return context.IDX.find_secondary(code, scope, table, secondary, primary);\
      }\
      int db_##IDX##_find_primary( uint64_t code, uint64_t scope, uint64_t table, TYPE& secondary, uint64_t primary ) {\
A
arhag 已提交
680
         return context.IDX.find_primary(code, scope, table, secondary, primary);\
681 682 683 684 685 686 687
      }\
      int db_##IDX##_lowerbound( uint64_t code, uint64_t scope, uint64_t table,  TYPE& secondary, uint64_t& primary ) {\
         return context.IDX.lowerbound_secondary(code, scope, table, secondary, primary);\
      }\
      int db_##IDX##_upperbound( uint64_t code, uint64_t scope, uint64_t table,  TYPE& secondary, uint64_t& primary ) {\
         return context.IDX.upperbound_secondary(code, scope, table, secondary, primary);\
      }\
688 689 690
      int db_##IDX##_end( uint64_t code, uint64_t scope, uint64_t table ) {\
         return context.IDX.end_secondary(code, scope, table);\
      }\
691 692 693 694 695 696 697
      int db_##IDX##_next( int iterator, uint64_t& primary  ) {\
         return context.IDX.next_secondary(iterator, primary);\
      }\
      int db_##IDX##_previous( int iterator, uint64_t& primary ) {\
         return context.IDX.previous_secondary(iterator, primary);\
      }

A
arhag 已提交
698 699
#define DB_API_METHOD_WRAPPERS_ARRAY_SECONDARY(IDX, ARR_SIZE, ARR_ELEMENT_TYPE)\
      int db_##IDX##_store( uint64_t scope, uint64_t table, uint64_t payer, uint64_t id, array_ptr<const ARR_ELEMENT_TYPE> data, size_t data_len) {\
A
arhag 已提交
700 701 702 703 704
         FC_ASSERT( data_len == ARR_SIZE,\
                    "invalid size of secondary key array for " #IDX ": given ${given} bytes but expected ${expected} bytes",\
                    ("given",data_len)("expected",ARR_SIZE) );\
         return context.IDX.store(scope, table, payer, id, data.value);\
      }\
A
arhag 已提交
705
      void db_##IDX##_update( int iterator, uint64_t payer, array_ptr<const ARR_ELEMENT_TYPE> data, size_t data_len ) {\
A
arhag 已提交
706 707 708 709 710 711 712 713
         FC_ASSERT( data_len == ARR_SIZE,\
                    "invalid size of secondary key array for " #IDX ": given ${given} bytes but expected ${expected} bytes",\
                    ("given",data_len)("expected",ARR_SIZE) );\
         return context.IDX.update(iterator, payer, data.value);\
      }\
      void db_##IDX##_remove( int iterator ) {\
         return context.IDX.remove(iterator);\
      }\
A
arhag 已提交
714
      int db_##IDX##_find_secondary( uint64_t code, uint64_t scope, uint64_t table, array_ptr<const ARR_ELEMENT_TYPE> data, size_t data_len, uint64_t& primary ) {\
A
arhag 已提交
715 716 717 718 719
         FC_ASSERT( data_len == ARR_SIZE,\
                    "invalid size of secondary key array for " #IDX ": given ${given} bytes but expected ${expected} bytes",\
                    ("given",data_len)("expected",ARR_SIZE) );\
         return context.IDX.find_secondary(code, scope, table, data, primary);\
      }\
A
arhag 已提交
720
      int db_##IDX##_find_primary( uint64_t code, uint64_t scope, uint64_t table, array_ptr<ARR_ELEMENT_TYPE> data, size_t data_len, uint64_t primary ) {\
A
arhag 已提交
721 722 723 724 725
         FC_ASSERT( data_len == ARR_SIZE,\
                    "invalid size of secondary key array for " #IDX ": given ${given} bytes but expected ${expected} bytes",\
                    ("given",data_len)("expected",ARR_SIZE) );\
         return context.IDX.find_primary(code, scope, table, data.value, primary);\
      }\
A
arhag 已提交
726
      int db_##IDX##_lowerbound( uint64_t code, uint64_t scope, uint64_t table, array_ptr<ARR_ELEMENT_TYPE> data, size_t data_len, uint64_t& primary ) {\
A
arhag 已提交
727 728 729 730 731
         FC_ASSERT( data_len == ARR_SIZE,\
                    "invalid size of secondary key array for " #IDX ": given ${given} bytes but expected ${expected} bytes",\
                    ("given",data_len)("expected",ARR_SIZE) );\
         return context.IDX.lowerbound_secondary(code, scope, table, data.value, primary);\
      }\
A
arhag 已提交
732
      int db_##IDX##_upperbound( uint64_t code, uint64_t scope, uint64_t table, array_ptr<ARR_ELEMENT_TYPE> data, size_t data_len, uint64_t& primary ) {\
A
arhag 已提交
733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748
         FC_ASSERT( data_len == ARR_SIZE,\
                    "invalid size of secondary key array for " #IDX ": given ${given} bytes but expected ${expected} bytes",\
                    ("given",data_len)("expected",ARR_SIZE) );\
         return context.IDX.upperbound_secondary(code, scope, table, data.value, primary);\
      }\
      int db_##IDX##_end( uint64_t code, uint64_t scope, uint64_t table ) {\
         return context.IDX.end_secondary(code, scope, table);\
      }\
      int db_##IDX##_next( int iterator, uint64_t& primary  ) {\
         return context.IDX.next_secondary(iterator, primary);\
      }\
      int db_##IDX##_previous( int iterator, uint64_t& primary ) {\
         return context.IDX.previous_secondary(iterator, primary);\
      }


D
Daniel Larimer 已提交
749 750 751 752 753 754 755 756 757 758 759 760 761
class database_api : public context_aware_api {
   public:
      using context_aware_api::context_aware_api;

      int db_store_i64( uint64_t scope, uint64_t table, uint64_t payer, uint64_t id, array_ptr<const char> buffer, size_t buffer_size ) {
         return context.db_store_i64( scope, table, payer, id, buffer, buffer_size );
      }
      void db_update_i64( int itr, uint64_t payer, array_ptr<const char> buffer, size_t buffer_size ) {
         context.db_update_i64( itr, payer, buffer, buffer_size );
      }
      void db_remove_i64( int itr ) {
         context.db_remove_i64( itr );
      }
762 763 764
      int db_get_i64( int itr, array_ptr<char> buffer, size_t buffer_size ) {
         return context.db_get_i64( itr, buffer, buffer_size );
      }
765 766
      int db_next_i64( int itr, uint64_t& primary ) {
         return context.db_next_i64(itr, primary);
767
      }
768 769
      int db_previous_i64( int itr, uint64_t& primary ) {
         return context.db_previous_i64(itr, primary);
D
Daniel Larimer 已提交
770
      }
771 772
      int db_find_i64( uint64_t code, uint64_t scope, uint64_t table, uint64_t id ) {
         return context.db_find_i64( code, scope, table, id );
D
Daniel Larimer 已提交
773
      }
774 775
      int db_lowerbound_i64( uint64_t code, uint64_t scope, uint64_t table, uint64_t id ) {
         return context.db_lowerbound_i64( code, scope, table, id );
D
Daniel Larimer 已提交
776
      }
777
      int db_upperbound_i64( uint64_t code, uint64_t scope, uint64_t table, uint64_t id ) {
A
arhag 已提交
778
         return context.db_upperbound_i64( code, scope, table, id );
D
Daniel Larimer 已提交
779
      }
780 781 782
      int db_end_i64( uint64_t code, uint64_t scope, uint64_t table ) {
         return context.db_end_i64( code, scope, table );
      }
783

A
arhag 已提交
784 785
      DB_API_METHOD_WRAPPERS_SIMPLE_SECONDARY(idx64,  uint64_t)
      DB_API_METHOD_WRAPPERS_SIMPLE_SECONDARY(idx128, uint128_t)
A
arhag 已提交
786
      DB_API_METHOD_WRAPPERS_ARRAY_SECONDARY(idx256, 2, uint128_t)
D
Daniel Larimer 已提交
787 788 789 790
};



791 792 793 794 795
template<typename ObjectType>
class db_api : public context_aware_api {
   using KeyType = typename ObjectType::key_type;
   static constexpr int KeyCount = ObjectType::number_of_keys;
   using KeyArrayType = KeyType[KeyCount];
796
   using ContextMethodType = int(apply_context::*)(const table_id_object&, const account_name&, const KeyType*, const char*, size_t);
797 798

   private:
799 800
      int call(ContextMethodType method, const scope_name& scope, const name& table, account_name bta, array_ptr<const char> data, size_t data_len) {
         const auto& t_id = context.find_or_create_table(context.receiver, scope, table);
801 802 803 804 805
         FC_ASSERT(data_len >= KeyCount * sizeof(KeyType), "Data is not long enough to contain keys");
         const KeyType* keys = reinterpret_cast<const KeyType *>((const char *)data);

         const char* record_data =  ((const char*)data) + sizeof(KeyArrayType);
         size_t record_len = data_len - sizeof(KeyArrayType);
806
         return (context.*(method))(t_id, bta, keys, record_data, record_len) + sizeof(KeyArrayType);
807 808 809 810 811
      }

   public:
      using context_aware_api::context_aware_api;

812 813
      int store(const scope_name& scope, const name& table, const account_name& bta, array_ptr<const char> data, size_t data_len) {
         auto res = call(&apply_context::store_record<ObjectType>, scope, table, bta, data, data_len);
814 815
         //ilog("STORE [${scope},${code},${table}] => ${res} :: ${HEX}", ("scope",scope)("code",context.receiver)("table",table)("res",res)("HEX", fc::to_hex(data, data_len)));
         return res;
816 817
      }

818 819
      int update(const scope_name& scope, const name& table, const account_name& bta, array_ptr<const char> data, size_t data_len) {
         return call(&apply_context::update_record<ObjectType>, scope, table, bta, data, data_len);
820 821 822
      }

      int remove(const scope_name& scope, const name& table, const KeyArrayType &keys) {
823
         const auto& t_id = context.find_or_create_table(context.receiver, scope, table);
824 825 826 827
         return context.remove_record<ObjectType>(t_id, keys);
      }
};

B
Bucky Kittinger 已提交
828 829 830 831 832 833 834
template<>
class db_api<keystr_value_object> : public context_aware_api {
   using KeyType = std::string;
   static constexpr int KeyCount = 1;
   using KeyArrayType = KeyType[KeyCount];
   using ContextMethodType = int(apply_context::*)(const table_id_object&, const KeyType*, const char*, size_t);

A
arhag 已提交
835
/* TODO something weird is going on here, will maybe fix before DB changes or this might get
836
 * totally changed anyway
B
Bucky Kittinger 已提交
837
   private:
838 839 840
      int call(ContextMethodType method, const scope_name& scope, const name& table, account_name bta,
            null_terminated_ptr key, size_t key_len, array_ptr<const char> data, size_t data_len) {
         const auto& t_id = context.find_or_create_table(context.receiver, scope, table);
A
arhag 已提交
841
         const KeyType keys((const char*)key.value, key_len);
B
Bucky Kittinger 已提交
842

A
arhag 已提交
843 844
         const char* record_data =  ((const char*)data);
         size_t record_len = data_len;
845
         return (context.*(method))(t_id, bta, &keys, record_data, record_len);
B
Bucky Kittinger 已提交
846
      }
847
*/
B
Bucky Kittinger 已提交
848 849 850
   public:
      using context_aware_api::context_aware_api;

851 852 853
      int store_str(const scope_name& scope, const name& table, const account_name& bta,
            null_terminated_ptr key, uint32_t key_len, array_ptr<const char> data, size_t data_len) {
         const auto& t_id = context.find_or_create_table(context.receiver, scope, table);
A
arhag 已提交
854 855 856
         const KeyType keys(key.value, key_len);
         const char* record_data =  ((const char*)data);
         size_t record_len = data_len;
857 858
         return context.store_record<keystr_value_object>(t_id, bta, &keys, record_data, record_len);
         //return call(&apply_context::store_record<keystr_value_object>, scope, table, bta, key, key_len, data, data_len);
B
Bucky Kittinger 已提交
859 860
      }

A
arhag 已提交
861
      int update_str(const scope_name& scope,  const name& table, const account_name& bta,
862 863
            null_terminated_ptr key, uint32_t key_len, array_ptr<const char> data, size_t data_len) {
         const auto& t_id = context.find_or_create_table(context.receiver, scope, table);
A
arhag 已提交
864 865 866
         const KeyType keys((const char*)key, key_len);
         const char* record_data =  ((const char*)data);
         size_t record_len = data_len;
867 868
         return context.update_record<keystr_value_object>(t_id, bta, &keys, record_data, record_len);
         //return call(&apply_context::update_record<keystr_value_object>, scope, table, bta, key, key_len, data, data_len);
B
Bucky Kittinger 已提交
869
      }
A
arhag 已提交
870

B
Bucky Kittinger 已提交
871 872 873 874 875 876
      int remove_str(const scope_name& scope, const name& table, array_ptr<const char> &key, uint32_t key_len) {
         const auto& t_id = context.find_or_create_table(scope, context.receiver, table);
         const KeyArrayType k = {std::string(key, key_len)};
         return context.remove_record<keystr_value_object>(t_id, k);
      }
};
877

878 879 880 881 882 883 884 885
template<typename IndexType, typename Scope>
class db_index_api : public context_aware_api {
   using KeyType = typename IndexType::value_type::key_type;
   static constexpr int KeyCount = IndexType::value_type::number_of_keys;
   using KeyArrayType = KeyType[KeyCount];
   using ContextMethodType = int(apply_context::*)(const table_id_object&, KeyType*, char*, size_t);


886
   int call(ContextMethodType method, const account_name& code, const scope_name& scope, const name& table, array_ptr<char> data, size_t data_len) {
887
      auto maybe_t_id = context.find_table(code, scope, table);
888
      if (maybe_t_id == nullptr) {
889
         return -1;
890 891 892 893 894 895 896 897 898
      }

      const auto& t_id = *maybe_t_id;
      FC_ASSERT(data_len >= KeyCount * sizeof(KeyType), "Data is not long enough to contain keys");
      KeyType* keys = reinterpret_cast<KeyType *>((char *)data);

      char* record_data =  ((char*)data) + sizeof(KeyArrayType);
      size_t record_len = data_len - sizeof(KeyArrayType);

899 900 901 902 903
      auto res = (context.*(method))(t_id, keys, record_data, record_len);
      if (res != -1) {
         res += sizeof(KeyArrayType);
      }
      return res;
904 905 906 907 908 909
   }

   public:
      using context_aware_api::context_aware_api;

      int load(const scope_name& scope, const account_name& code, const name& table, array_ptr<char> data, size_t data_len) {
910 911
         auto res = call(&apply_context::load_record<IndexType, Scope>, scope, code, table, data, data_len);
         return res;
912 913 914
      }

      int front(const scope_name& scope, const account_name& code, const name& table, array_ptr<char> data, size_t data_len) {
B
Bucky Kittinger 已提交
915
         auto res = call(&apply_context::front_record<IndexType, Scope>, scope, code, table, data, data_len);
B
Bucky Kittinger 已提交
916
         return res;
917 918 919
      }

      int back(const scope_name& scope, const account_name& code, const name& table, array_ptr<char> data, size_t data_len) {
B
Bucky Kittinger 已提交
920
         auto res = call(&apply_context::back_record<IndexType, Scope>, scope, code, table, data, data_len);
B
Bucky Kittinger 已提交
921
         return res;
922 923 924
      }

      int next(const scope_name& scope, const account_name& code, const name& table, array_ptr<char> data, size_t data_len) {
B
Bucky Kittinger 已提交
925
         auto res = call(&apply_context::next_record<IndexType, Scope>, scope, code, table, data, data_len);
B
Bucky Kittinger 已提交
926
         return res;
927 928 929
      }

      int previous(const scope_name& scope, const account_name& code, const name& table, array_ptr<char> data, size_t data_len) {
B
Bucky Kittinger 已提交
930
         auto res = call(&apply_context::previous_record<IndexType, Scope>, scope, code, table, data, data_len);
B
Bucky Kittinger 已提交
931
         return res;
932 933 934
      }

      int lower_bound(const scope_name& scope, const account_name& code, const name& table, array_ptr<char> data, size_t data_len) {
B
Bucky Kittinger 已提交
935
         auto res = call(&apply_context::lower_bound_record<IndexType, Scope>, scope, code, table, data, data_len);
B
Bucky Kittinger 已提交
936
         return res;
937 938 939
      }

      int upper_bound(const scope_name& scope, const account_name& code, const name& table, array_ptr<char> data, size_t data_len) {
B
Bucky Kittinger 已提交
940
         auto res = call(&apply_context::upper_bound_record<IndexType, Scope>, scope, code, table, data, data_len);
B
Bucky Kittinger 已提交
941
         return res;
942 943 944 945
      }

};

B
Bucky Kittinger 已提交
946 947 948 949 950 951 952 953
template<>
class db_index_api<keystr_value_index, by_scope_primary> : public context_aware_api {
   using KeyType = std::string;
   static constexpr int KeyCount = 1;
   using KeyArrayType = KeyType[KeyCount];
   using ContextMethodType = int(apply_context::*)(const table_id_object&, KeyType*, char*, size_t);


A
arhag 已提交
954
   int call(ContextMethodType method, const scope_name& scope, const account_name& code, const name& table,
B
Bucky Kittinger 已提交
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970
         array_ptr<char> &key, uint32_t key_len, array_ptr<char> data, size_t data_len) {
      auto maybe_t_id = context.find_table(scope, context.receiver, table);
      if (maybe_t_id == nullptr) {
         return 0;
      }

      const auto& t_id = *maybe_t_id;
      //FC_ASSERT(data_len >= KeyCount * sizeof(KeyType), "Data is not long enough to contain keys");
      KeyType keys((const char*)key, key_len); // = reinterpret_cast<KeyType *>((char *)data);

      char* record_data =  ((char*)data); // + sizeof(KeyArrayType);
      size_t record_len = data_len; // - sizeof(KeyArrayType);

      return (context.*(method))(t_id, &keys, record_data, record_len); // + sizeof(KeyArrayType);
   }

971
   public:
B
Bucky Kittinger 已提交
972
      using context_aware_api::context_aware_api;
973

B
Bucky Kittinger 已提交
974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003
      int load_str(const scope_name& scope, const account_name& code, const name& table, array_ptr<char> key, size_t key_len, array_ptr<char> data, size_t data_len) {
         auto res = call(&apply_context::load_record<keystr_value_index, by_scope_primary>, scope, code, table, key, key_len, data, data_len);
         return res;
      }

      int front_str(const scope_name& scope, const account_name& code, const name& table, array_ptr<char> key, size_t key_len, array_ptr<char> data, size_t data_len) {
         return call(&apply_context::front_record<keystr_value_index, by_scope_primary>, scope, code, table, key, key_len, data, data_len);
      }

      int back_str(const scope_name& scope, const account_name& code, const name& table, array_ptr<char> key, size_t key_len, array_ptr<char> data, size_t data_len) {
         return call(&apply_context::back_record<keystr_value_index, by_scope_primary>, scope, code, table, key, key_len, data, data_len);
      }

      int next_str(const scope_name& scope, const account_name& code, const name& table, array_ptr<char> key, size_t key_len, array_ptr<char> data, size_t data_len) {
         return call(&apply_context::next_record<keystr_value_index, by_scope_primary>, scope, code, table, key, key_len, data, data_len);
      }

      int previous_str(const scope_name& scope, const account_name& code, const name& table, array_ptr<char> key, size_t key_len, array_ptr<char> data, size_t data_len) {
         return call(&apply_context::previous_record<keystr_value_index, by_scope_primary>, scope, code, table, key, key_len, data, data_len);
      }

      int lower_bound_str(const scope_name& scope, const account_name& code, const name& table, array_ptr<char> key, size_t key_len, array_ptr<char> data, size_t data_len) {
         return call(&apply_context::lower_bound_record<keystr_value_index, by_scope_primary>, scope, code, table, key, key_len, data, data_len);
      }

      int upper_bound_str(const scope_name& scope, const account_name& code, const name& table, array_ptr<char> key, size_t key_len, array_ptr<char> data, size_t data_len) {
         return call(&apply_context::upper_bound_record<keystr_value_index, by_scope_primary>, scope, code, table, key, key_len, data, data_len);
      }
};

1004
class memory_api : public context_aware_api {
1005
   public:
D
Daniel Larimer 已提交
1006 1007
      memory_api( wasm_interface& wasm )
      :context_aware_api(wasm,true){}
A
arhag 已提交
1008

1009 1010 1011 1012
      char* memcpy( array_ptr<char> dest, array_ptr<const char> src, size_t length) {
         return (char *)::memcpy(dest, src, length);
      }

1013 1014 1015 1016
      char* memmove( array_ptr<char> dest, array_ptr<const char> src, size_t length) {
         return (char *)::memmove(dest, src, length);
      }

1017 1018 1019 1020
      int memcmp( array_ptr<const char> dest, array_ptr<const char> src, size_t length) {
         return ::memcmp(dest, src, length);
      }

B
Bucky Kittinger 已提交
1021
      char* memset( array_ptr<char> dest, int value, size_t length ) {
B
Bucky Kittinger 已提交
1022
         return (char *)::memset( dest, value, length );
B
Bucky Kittinger 已提交
1023 1024
      }

M
Matt Witherspoon 已提交
1025
      int sbrk(int num_bytes) {
1026 1027 1028
         // sbrk should only allow for memory to grow
         if (num_bytes < 0)
            throw eosio::chain::page_memory_error();
1029

1030 1031 1032 1033 1034 1035
         switch(vm) {
            case wasm_interface::vm_type::wavm:
               return (uint32_t)code.wavm.sbrk(num_bytes);
            case wasm_interface::vm_type::binaryen:
               return (uint32_t)code.binaryen.sbrk(num_bytes);
         }
1036
      }
1037 1038
};

1039 1040 1041 1042
class transaction_api : public context_aware_api {
   public:
      using context_aware_api::context_aware_api;

D
Daniel Larimer 已提交
1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072
      void send_inline( array_ptr<char> data, size_t data_len ) {
         // TODO: use global properties object for dynamic configuration of this default_max_gen_trx_size
         FC_ASSERT( data_len < config::default_max_inline_action_size, "inline action too big" );

         action act;
         fc::raw::unpack<action>(data, data_len, act);
         context.execute_inline(std::move(act));
      }

      void send_deferred( uint32_t sender_id, const fc::time_point_sec& execute_after, array_ptr<char> data, size_t data_len ) {
         try {
            // TODO: use global properties object for dynamic configuration of this default_max_gen_trx_size
            FC_ASSERT(data_len < config::default_max_gen_trx_size, "generated transaction too big");

            deferred_transaction dtrx;
            fc::raw::unpack<transaction>(data, data_len, dtrx);
            dtrx.sender = context.receiver;
            dtrx.sender_id = sender_id;
            dtrx.execute_after = execute_after;
            context.execute_deferred(std::move(dtrx));
         } FC_CAPTURE_AND_RETHROW((fc::to_hex(data, data_len)));
      }
};


class context_free_transaction_api : public context_aware_api {
   public:
      context_free_transaction_api( wasm_interface& wasm )
      :context_aware_api(wasm,true){}

1073 1074 1075 1076 1077 1078 1079 1080 1081 1082
      int read_transaction( array_ptr<char> data, size_t data_len ) {
         bytes trx = context.get_packed_transaction();
         if (data_len >= trx.size()) {
            memcpy(data, trx.data(), trx.size());
         }
         return trx.size();
      }

      int transaction_size() {
         return context.get_packed_transaction().size();
1083 1084 1085
      }

      int expiration() {
1086
        return context.trx_meta.trx().expiration.sec_since_epoch();
1087 1088 1089
      }

      int tapos_block_num() {
1090
        return context.trx_meta.trx().ref_block_num;
1091
      }
1092
      int tapos_block_prefix() {
1093
        return context.trx_meta.trx().ref_block_prefix;
1094 1095
      }

D
Daniel Larimer 已提交
1096 1097
      int get_action( uint32_t type, uint32_t index, array_ptr<char> buffer, size_t buffer_size )const {
         return context.get_action( type, index, buffer, buffer_size );
1098 1099 1100 1101
      }

};

1102 1103 1104
class compiler_builtins : public context_aware_api {
   public:
      using context_aware_api::context_aware_api;
1105
      void __ashlti3(__int128& ret, uint64_t low, uint64_t high, uint32_t shift) {
1106 1107 1108
         fc::uint128_t i(high, low);
         i <<= shift;
         ret = (unsigned __int128)i;
1109 1110
      }

1111
      void __ashrti3(__int128& ret, uint64_t low, uint64_t high, uint32_t shift) {
B
oops  
Bucky Kittinger 已提交
1112 1113 1114 1115 1116
         // retain the signedness
         ret = high;
         ret <<= 64;
         ret |= low;
         ret >>= shift;
1117
      }
1118

1119 1120 1121 1122 1123
      void __lshlti3(__int128& ret, uint64_t low, uint64_t high, uint32_t shift) {
         fc::uint128_t i(high, low);
         i <<= shift;
         ret = (unsigned __int128)i;
      }
1124

1125 1126 1127 1128 1129
      void __lshrti3(__int128& ret, uint64_t low, uint64_t high, uint32_t shift) {
         fc::uint128_t i(high, low);
         i >>= shift;
         ret = (unsigned __int128)i;
      }
A
arhag 已提交
1130

1131
      void __divti3(__int128& ret, uint64_t la, uint64_t ha, uint64_t lb, uint64_t hb) {
B
oops  
Bucky Kittinger 已提交
1132 1133
         __int128 lhs = ha;
         __int128 rhs = hb;
A
arhag 已提交
1134

B
oops  
Bucky Kittinger 已提交
1135 1136
         lhs <<= 64;
         lhs |=  la;
1137

B
oops  
Bucky Kittinger 已提交
1138 1139
         rhs <<= 64;
         rhs |=  lb;
1140

A
arhag 已提交
1141
         FC_ASSERT(rhs != 0, "divide by zero");
1142

A
arhag 已提交
1143
         lhs /= rhs;
1144

B
oops  
Bucky Kittinger 已提交
1145
         ret = lhs;
A
arhag 已提交
1146
      }
1147

B
oops  
Bucky Kittinger 已提交
1148 1149 1150
      void __udivti3(unsigned __int128& ret, uint64_t la, uint64_t ha, uint64_t lb, uint64_t hb) {
         unsigned __int128 lhs = ha;
         unsigned __int128 rhs = hb;
A
arhag 已提交
1151

B
oops  
Bucky Kittinger 已提交
1152 1153 1154 1155 1156
         lhs <<= 64;
         lhs |=  la;

         rhs <<= 64;
         rhs |=  lb;
1157

A
arhag 已提交
1158
         FC_ASSERT(rhs != 0, "divide by zero");
1159

A
arhag 已提交
1160
         lhs /= rhs;
B
oops  
Bucky Kittinger 已提交
1161 1162 1163 1164 1165 1166
         ret = lhs;
      }

      void __multi3(__int128& ret, uint64_t la, uint64_t ha, uint64_t lb, uint64_t hb) {
         __int128 lhs = ha;
         __int128 rhs = hb;
1167

B
oops  
Bucky Kittinger 已提交
1168 1169
         lhs <<= 64;
         lhs |=  la;
1170

B
oops  
Bucky Kittinger 已提交
1171 1172
         rhs <<= 64;
         rhs |=  lb;
1173

A
arhag 已提交
1174
         lhs *= rhs;
B
oops  
Bucky Kittinger 已提交
1175
         ret = lhs;
A
arhag 已提交
1176
      }
1177 1178

      void __modti3(__int128& ret, uint64_t la, uint64_t ha, uint64_t lb, uint64_t hb) {
B
oops  
Bucky Kittinger 已提交
1179 1180 1181 1182 1183
         __int128 lhs = ha;
         __int128 rhs = hb;

         lhs <<= 64;
         lhs |=  la;
A
arhag 已提交
1184

B
oops  
Bucky Kittinger 已提交
1185 1186
         rhs <<= 64;
         rhs |=  lb;
A
arhag 已提交
1187

B
oops  
Bucky Kittinger 已提交
1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199
         FC_ASSERT(rhs != 0, "divide by zero");

         lhs %= rhs;
         ret = lhs;
      }

      void __umodti3(unsigned __int128& ret, uint64_t la, uint64_t ha, uint64_t lb, uint64_t hb) {
         unsigned __int128 lhs = ha;
         unsigned __int128 rhs = hb;

         lhs <<= 64;
         lhs |=  la;
A
arhag 已提交
1200

B
oops  
Bucky Kittinger 已提交
1201 1202
         rhs <<= 64;
         rhs |=  lb;
A
arhag 已提交
1203

B
oops  
Bucky Kittinger 已提交
1204
         FC_ASSERT(rhs != 0, "divide by zero");
1205

B
oops  
Bucky Kittinger 已提交
1206 1207
         lhs %= rhs;
         ret = lhs;
1208 1209
      }

B
Bucky Kittinger 已提交
1210
      static constexpr uint32_t SHIFT_WIDTH = (sizeof(uint64_t)*8)-1;
1211 1212 1213 1214 1215
};

class math_api : public context_aware_api {
   public:
      using context_aware_api::context_aware_api;
A
arhag 已提交
1216

1217 1218 1219 1220 1221

      void diveq_i128(unsigned __int128* self, const unsigned __int128* other) {
         fc::uint128_t s(*self);
         const fc::uint128_t o(*other);
         FC_ASSERT( o != 0, "divide by zero" );
A
arhag 已提交
1222

1223 1224
         s = s/o;
         *self = (unsigned __int128)s;
1225 1226
      }

1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275
      void multeq_i128(unsigned __int128* self, const unsigned __int128* other) {
         fc::uint128_t s(*self);
         const fc::uint128_t o(*other);
         s *= o;
         *self = (unsigned __int128)s;
      }

      uint64_t double_add(uint64_t a, uint64_t b) {
         using DOUBLE = boost::multiprecision::cpp_bin_float_50;
         DOUBLE c = DOUBLE(*reinterpret_cast<double *>(&a))
                  + DOUBLE(*reinterpret_cast<double *>(&b));
         double res = c.convert_to<double>();
         return *reinterpret_cast<uint64_t *>(&res);
      }

      uint64_t double_mult(uint64_t a, uint64_t b) {
         using DOUBLE = boost::multiprecision::cpp_bin_float_50;
         DOUBLE c = DOUBLE(*reinterpret_cast<double *>(&a))
                  * DOUBLE(*reinterpret_cast<double *>(&b));
         double res = c.convert_to<double>();
         return *reinterpret_cast<uint64_t *>(&res);
      }

      uint64_t double_div(uint64_t a, uint64_t b) {
         using DOUBLE = boost::multiprecision::cpp_bin_float_50;
         DOUBLE divisor = DOUBLE(*reinterpret_cast<double *>(&b));
         FC_ASSERT(divisor != 0, "divide by zero");
         DOUBLE c = DOUBLE(*reinterpret_cast<double *>(&a)) / divisor;
         double res = c.convert_to<double>();
         return *reinterpret_cast<uint64_t *>(&res);
      }

      uint32_t double_eq(uint64_t a, uint64_t b) {
         using DOUBLE = boost::multiprecision::cpp_bin_float_50;
         return DOUBLE(*reinterpret_cast<double *>(&a)) == DOUBLE(*reinterpret_cast<double *>(&b));
      }

      uint32_t double_lt(uint64_t a, uint64_t b) {
         using DOUBLE = boost::multiprecision::cpp_bin_float_50;
         return DOUBLE(*reinterpret_cast<double *>(&a)) < DOUBLE(*reinterpret_cast<double *>(&b));
      }

      uint32_t double_gt(uint64_t a, uint64_t b) {
         using DOUBLE = boost::multiprecision::cpp_bin_float_50;
         return DOUBLE(*reinterpret_cast<double *>(&a)) > DOUBLE(*reinterpret_cast<double *>(&b));
      }

      uint64_t double_to_i64(uint64_t n) {
         using DOUBLE = boost::multiprecision::cpp_bin_float_50;
B
Bucky Kittinger 已提交
1276
         return DOUBLE(*reinterpret_cast<double *>(&n)).convert_to<int64_t>();
1277 1278
      }

B
Bucky Kittinger 已提交
1279
      uint64_t i64_to_double(int64_t n) {
1280 1281 1282 1283
         using DOUBLE = boost::multiprecision::cpp_bin_float_50;
         double res = DOUBLE(n).convert_to<double>();
         return *reinterpret_cast<uint64_t *>(&res);
      }
1284 1285
};

1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297
REGISTER_INTRINSICS(math_api,
   (diveq_i128,    void(int, int)            )
   (multeq_i128,   void(int, int)            )
   (double_add,    int64_t(int64_t, int64_t) )
   (double_mult,   int64_t(int64_t, int64_t) )
   (double_div,    int64_t(int64_t, int64_t) )
   (double_eq,     int32_t(int64_t, int64_t) )
   (double_lt,     int32_t(int64_t, int64_t) )
   (double_gt,     int32_t(int64_t, int64_t) )
   (double_to_i64, int64_t(int64_t)          )
   (i64_to_double, int64_t(int64_t)          )
);
B
Bucky Kittinger 已提交
1298

1299
REGISTER_INTRINSICS(compiler_builtins,
B
Bucky Kittinger 已提交
1300 1301 1302 1303 1304 1305 1306 1307 1308
   (__ashlti3,     void(int, int64_t, int64_t, int)               )
   (__ashrti3,     void(int, int64_t, int64_t, int)               )
   (__lshlti3,     void(int, int64_t, int64_t, int)               )
   (__lshrti3,     void(int, int64_t, int64_t, int)               )
   (__divti3,      void(int, int64_t, int64_t, int64_t, int64_t)  )
   (__udivti3,     void(int, int64_t, int64_t, int64_t, int64_t)  )
   (__modti3,      void(int, int64_t, int64_t, int64_t, int64_t)  )
   (__umodti3,     void(int, int64_t, int64_t, int64_t, int64_t)  )
   (__multi3,      void(int, int64_t, int64_t, int64_t, int64_t)  )
B
Bucky Kittinger 已提交
1309
);
1310 1311

REGISTER_INTRINSICS(privileged_api,
B
Bucky Kittinger 已提交
1312 1313 1314 1315 1316 1317 1318 1319
   (activate_feature,          void(int64_t)                                 )
   (is_feature_active,         int(int64_t)                                  )
   (set_resource_limits,       void(int64_t,int64_t,int64_t,int64_t,int64_t) )
   (set_active_producers,      void(int,int)                                 )
   (is_privileged,             int(int64_t)                                  )
   (set_privileged,            void(int64_t, int)                            )
   (freeze_account,            void(int64_t, int)                            )
   (is_frozen,                 int(int64_t)                                  )
1320
);
1321 1322

REGISTER_INTRINSICS(checktime_api,
1323
   (checktime,      void(int))
1324 1325
);

1326
REGISTER_INTRINSICS(producer_api,
B
Bucky Kittinger 已提交
1327
   (get_active_producers,      int(int, int) )
1328 1329
);

A
arhag 已提交
1330
#define DB_SECONDARY_INDEX_METHODS_SIMPLE(IDX) \
1331 1332 1333 1334 1335 1336 1337
   (db_##IDX##_store,          int(int64_t,int64_t,int64_t,int64_t,int))\
   (db_##IDX##_remove,         void(int))\
   (db_##IDX##_update,         void(int,int64_t,int))\
   (db_##IDX##_find_primary,   int(int64_t,int64_t,int64_t,int,int64_t))\
   (db_##IDX##_find_secondary, int(int64_t,int64_t,int64_t,int,int))\
   (db_##IDX##_lowerbound,     int(int64_t,int64_t,int64_t,int,int))\
   (db_##IDX##_upperbound,     int(int64_t,int64_t,int64_t,int,int))\
1338
   (db_##IDX##_end,            int(int64_t,int64_t,int64_t))\
1339 1340 1341
   (db_##IDX##_next,           int(int, int))\
   (db_##IDX##_previous,       int(int, int))

A
arhag 已提交
1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353
#define DB_SECONDARY_INDEX_METHODS_ARRAY(IDX) \
      (db_##IDX##_store,          int(int64_t,int64_t,int64_t,int64_t,int,int))\
      (db_##IDX##_remove,         void(int))\
      (db_##IDX##_update,         void(int,int64_t,int,int))\
      (db_##IDX##_find_primary,   int(int64_t,int64_t,int64_t,int,int,int64_t))\
      (db_##IDX##_find_secondary, int(int64_t,int64_t,int64_t,int,int,int))\
      (db_##IDX##_lowerbound,     int(int64_t,int64_t,int64_t,int,int,int))\
      (db_##IDX##_upperbound,     int(int64_t,int64_t,int64_t,int,int,int))\
      (db_##IDX##_end,            int(int64_t,int64_t,int64_t))\
      (db_##IDX##_next,           int(int, int))\
      (db_##IDX##_previous,       int(int, int))

D
Daniel Larimer 已提交
1354 1355 1356 1357
REGISTER_INTRINSICS( database_api,
   (db_store_i64,        int(int64_t,int64_t,int64_t,int64_t,int,int))
   (db_update_i64,       void(int,int64_t,int,int))
   (db_remove_i64,       void(int))
1358
   (db_get_i64,          int(int, int, int))
1359 1360
   (db_next_i64,         int(int, int))
   (db_previous_i64,     int(int, int))
D
Daniel Larimer 已提交
1361 1362
   (db_find_i64,         int(int64_t,int64_t,int64_t,int64_t))
   (db_lowerbound_i64,   int(int64_t,int64_t,int64_t,int64_t))
1363
   (db_upperbound_i64,   int(int64_t,int64_t,int64_t,int64_t))
A
arhag 已提交
1364
   (db_end_i64,          int(int64_t,int64_t,int64_t))
1365

A
arhag 已提交
1366 1367 1368
   DB_SECONDARY_INDEX_METHODS_SIMPLE(idx64)
   DB_SECONDARY_INDEX_METHODS_SIMPLE(idx128)
   DB_SECONDARY_INDEX_METHODS_ARRAY(idx256)
1369
);
D
Daniel Larimer 已提交
1370

1371
REGISTER_INTRINSICS(crypto_api,
B
Bucky Kittinger 已提交
1372 1373
   (assert_recover_key,     void(int, int, int, int, int) )
   (recover_key,            int(int, int, int, int, int)  )
B
Bucky Kittinger 已提交
1374 1375 1376 1377
   (assert_sha256,          void(int, int, int)           )
   (assert_sha1,            void(int, int, int)           )
   (assert_sha512,          void(int, int, int)           )
   (assert_ripemd160,       void(int, int, int)           )
B
Bucky Kittinger 已提交
1378 1379 1380 1381
   (sha1,                   void(int, int, int)           )
   (sha256,                 void(int, int, int)           )
   (sha512,                 void(int, int, int)           )
   (ripemd160,              void(int, int, int)           )
1382 1383 1384
);

REGISTER_INTRINSICS(string_api,
B
Bucky Kittinger 已提交
1385
   (assert_is_utf8,  void(int, int, int) )
1386 1387
);

B
Bart Wyatt 已提交
1388
REGISTER_INTRINSICS(system_api,
1389 1390
   (abort,        void())
   (eosio_assert, void(int, int))
1391
   (now,          int())
B
Bart Wyatt 已提交
1392 1393 1394 1395 1396 1397
);

REGISTER_INTRINSICS(action_api,
   (read_action,            int(int, int)  )
   (action_size,            int()          )
   (current_receiver,   int64_t()          )
1398 1399
   (publication_time,   int32_t()          )
   (current_sender,     int64_t()          )
B
Bart Wyatt 已提交
1400 1401 1402
);

REGISTER_INTRINSICS(apply_context,
B
Bucky Kittinger 已提交
1403 1404 1405
   (require_write_lock,    void(int64_t)          )
   (require_read_lock,     void(int64_t, int64_t) )
   (require_recipient,     void(int64_t)          )
1406
   (require_authorization, void(int64_t), "require_auth", void(apply_context::*)(const account_name&)const)
B
Bucky Kittinger 已提交
1407
   (is_account,            int(int64_t)           )
B
Bart Wyatt 已提交
1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419
);

REGISTER_INTRINSICS(console_api,
   (prints,                void(int)       )
   (prints_l,              void(int, int)  )
   (printi,                void(int64_t)   )
   (printi128,             void(int)       )
   (printd,                void(int64_t)   )
   (printn,                void(int64_t)   )
   (printhex,              void(int, int)  )
);

D
Daniel Larimer 已提交
1420
REGISTER_INTRINSICS(context_free_transaction_api,
1421 1422 1423 1424 1425
   (read_transaction,       int(int, int)            )
   (transaction_size,       int()                    )
   (expiration,             int()                    )
   (tapos_block_prefix,     int()                    )
   (tapos_block_num,        int()                    )
D
Daniel Larimer 已提交
1426 1427 1428 1429
   (get_action,            int (int, int, int, int)  )
);

REGISTER_INTRINSICS(transaction_api,
1430
   (send_inline,           void(int, int)            )
1431 1432 1433
   (send_deferred,         void(int, int, int, int)  )
);

D
Daniel Larimer 已提交
1434 1435 1436 1437
REGISTER_INTRINSICS(context_free_api,
   (get_context_free_data, int(int, int, int) )
)

1438
REGISTER_INTRINSICS(memory_api,
B
Bucky Kittinger 已提交
1439 1440 1441 1442 1443
   (memcpy,                 int(int, int, int)  )
   (memmove,                int(int, int, int)  )
   (memcmp,                 int(int, int, int)  )
   (memset,                 int(int, int, int)  )
   (sbrk,                   int(int)            )
1444 1445
);

1446
#define DB_METHOD_SEQ(SUFFIX) \
K
Khaled Al-Hassanieh 已提交
1447 1448
   (store,        int32_t(int64_t, int64_t, int64_t, int, int),   "store_"#SUFFIX ) \
   (update,       int32_t(int64_t, int64_t, int64_t, int, int),   "update_"#SUFFIX ) \
1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461
   (remove,       int32_t(int64_t, int64_t, int),                 "remove_"#SUFFIX )

#define DB_INDEX_METHOD_SEQ(SUFFIX)\
   (load,         int32_t(int64_t, int64_t, int64_t, int, int),   "load_"#SUFFIX )\
   (front,        int32_t(int64_t, int64_t, int64_t, int, int),   "front_"#SUFFIX )\
   (back,         int32_t(int64_t, int64_t, int64_t, int, int),   "back_"#SUFFIX )\
   (previous,     int32_t(int64_t, int64_t, int64_t, int, int),   "previous_"#SUFFIX )\
   (lower_bound,  int32_t(int64_t, int64_t, int64_t, int, int),   "lower_bound_"#SUFFIX )\
   (upper_bound,  int32_t(int64_t, int64_t, int64_t, int, int),   "upper_bound_"#SUFFIX )\

using db_api_key_value_object                                 = db_api<key_value_object>;
using db_api_keystr_value_object                              = db_api<keystr_value_object>;
using db_api_key128x128_value_object                          = db_api<key128x128_value_object>;
1462
using db_api_key64x64_value_object                            = db_api<key64x64_value_object>;
1463 1464 1465 1466 1467
using db_api_key64x64x64_value_object                         = db_api<key64x64x64_value_object>;
using db_index_api_key_value_index_by_scope_primary           = db_index_api<key_value_index,by_scope_primary>;
using db_index_api_keystr_value_index_by_scope_primary        = db_index_api<keystr_value_index,by_scope_primary>;
using db_index_api_key128x128_value_index_by_scope_primary    = db_index_api<key128x128_value_index,by_scope_primary>;
using db_index_api_key128x128_value_index_by_scope_secondary  = db_index_api<key128x128_value_index,by_scope_secondary>;
1468 1469
using db_index_api_key64x64_value_index_by_scope_primary      = db_index_api<key64x64_value_index,by_scope_primary>;
using db_index_api_key64x64_value_index_by_scope_secondary    = db_index_api<key64x64_value_index,by_scope_secondary>;
1470 1471 1472 1473 1474 1475
using db_index_api_key64x64x64_value_index_by_scope_primary   = db_index_api<key64x64x64_value_index,by_scope_primary>;
using db_index_api_key64x64x64_value_index_by_scope_secondary = db_index_api<key64x64x64_value_index,by_scope_secondary>;
using db_index_api_key64x64x64_value_index_by_scope_tertiary  = db_index_api<key64x64x64_value_index,by_scope_tertiary>;

REGISTER_INTRINSICS(db_api_key_value_object,         DB_METHOD_SEQ(i64));
REGISTER_INTRINSICS(db_api_key128x128_value_object,  DB_METHOD_SEQ(i128i128));
1476
REGISTER_INTRINSICS(db_api_key64x64_value_object,    DB_METHOD_SEQ(i64i64));
1477
REGISTER_INTRINSICS(db_api_key64x64x64_value_object, DB_METHOD_SEQ(i64i64i64));
B
Bucky Kittinger 已提交
1478
REGISTER_INTRINSICS(db_api_keystr_value_object,
1479 1480
   (store_str,                int32_t(int64_t, int64_t, int64_t, int, int, int, int)  )
   (update_str,               int32_t(int64_t, int64_t, int64_t, int, int, int, int)  )
B
Bucky Kittinger 已提交
1481
   (remove_str,               int32_t(int64_t, int64_t, int, int)  ));
1482 1483

REGISTER_INTRINSICS(db_index_api_key_value_index_by_scope_primary,           DB_INDEX_METHOD_SEQ(i64));
B
Bucky Kittinger 已提交
1484 1485 1486 1487 1488 1489 1490 1491
REGISTER_INTRINSICS(db_index_api_keystr_value_index_by_scope_primary,
   (load_str,            int32_t(int64_t, int64_t, int64_t, int, int, int, int)  )
   (front_str,           int32_t(int64_t, int64_t, int64_t, int, int, int, int)  )
   (back_str,            int32_t(int64_t, int64_t, int64_t, int, int, int, int)  )
   (next_str,            int32_t(int64_t, int64_t, int64_t, int, int, int, int)  )
   (previous_str,        int32_t(int64_t, int64_t, int64_t, int, int, int, int)  )
   (lower_bound_str,     int32_t(int64_t, int64_t, int64_t, int, int, int, int)  )
   (upper_bound_str,     int32_t(int64_t, int64_t, int64_t, int, int, int, int)  ));
1492

1493 1494
REGISTER_INTRINSICS(db_index_api_key128x128_value_index_by_scope_primary,    DB_INDEX_METHOD_SEQ(primary_i128i128));
REGISTER_INTRINSICS(db_index_api_key128x128_value_index_by_scope_secondary,  DB_INDEX_METHOD_SEQ(secondary_i128i128));
1495 1496
REGISTER_INTRINSICS(db_index_api_key64x64_value_index_by_scope_primary,      DB_INDEX_METHOD_SEQ(primary_i64i64));
REGISTER_INTRINSICS(db_index_api_key64x64_value_index_by_scope_secondary,    DB_INDEX_METHOD_SEQ(secondary_i64i64));
1497
REGISTER_INTRINSICS(db_index_api_key64x64x64_value_index_by_scope_primary,   DB_INDEX_METHOD_SEQ(primary_i64i64i64));
1498
REGISTER_INTRINSICS(db_index_api_key64x64x64_value_index_by_scope_secondary, DB_INDEX_METHOD_SEQ(secondary_i64i64i64));
1499 1500
REGISTER_INTRINSICS(db_index_api_key64x64x64_value_index_by_scope_tertiary,  DB_INDEX_METHOD_SEQ(tertiary_i64i64i64));

B
Brian Johnson 已提交
1501

D
Daniel Larimer 已提交
1502
} } /// eosio::chain