├── CMakeLists.txt ├── CMakeModules └── wasm.cmake ├── currency ├── CMakeLists.txt ├── currency.abi ├── currency.cpp └── currency.hpp ├── eoslib ├── crypto.h ├── db.h ├── db.hpp ├── eos.hpp ├── math.h ├── math.hpp ├── message.h ├── message.hpp ├── print.h ├── print.hpp ├── token.hpp ├── types.h └── types.hpp └── exchange ├── CMakeLists.txt ├── exchange.abi ├── exchange.cpp ├── exchange.hpp ├── exchange.wast └── exchange.wast.hpp /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9) 2 | 3 | include_directories( "${CMAKE_CURRENT_SOURCE_DIR}" ) 4 | list( APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules" ) 5 | include(wasm) 6 | 7 | set( CONTRACT_INCLUDE_PATHS "${CMAKE_CURRENT_SOURCE_DIR}" ) 8 | 9 | add_subdirectory(currency) 10 | add_subdirectory(exchange) 11 | 12 | -------------------------------------------------------------------------------- /CMakeModules/wasm.cmake: -------------------------------------------------------------------------------- 1 | set(WASM_TOOLCHAIN FALSE) 2 | 3 | set(WASM_LLVM_CONFIG "$ENV{WASM_LLVM_CONFIG}" CACHE FILEPATH "Path to wasm llvm-config binary") 4 | 5 | if( NOT "${WASM_LLVM_CONFIG}" STREQUAL "" ) 6 | 7 | execute_process( 8 | COMMAND ${WASM_LLVM_CONFIG} --bindir 9 | RESULT_VARIABLE WASM_LLVM_CONFIG_OK 10 | OUTPUT_VARIABLE WASM_LLVM_BIN 11 | ) 12 | 13 | if("${WASM_LLVM_CONFIG_OK}" STREQUAL "0") 14 | string(STRIP "${WASM_LLVM_BIN}" WASM_LLVM_BIN) 15 | set(WASM_CLANG ${WASM_LLVM_BIN}/clang CACHE INTERNAL "Path to wasm clang binary") 16 | set(WASM_LLC ${WASM_LLVM_BIN}/llc CACHE INTERNAL "Path to wasm llc binary") 17 | set(WASM_LLVM_LINK ${WASM_LLVM_BIN}/llvm-link CACHE INTERNAL "Path to wasm llvm-link binary") 18 | endif() 19 | 20 | else() 21 | set(WASM_CLANG $ENV{WASM_CLANG} CACHE FILEPATH "Path to wasm clang binary") 22 | set(WASM_LLC $ENV{WASM_LLC} CACHE FILEPATH "Path to wasm llc binary") 23 | set(WASM_LLVM_LINK $ENV{WASM_LLVM_LINK} CACHE FILEPATH "Path to wasm llvm-link binary") 24 | endif() 25 | 26 | set(S2WASM $ENV{S2WASM} CACHE FILEPATH "Path to s2wasm binary") 27 | 28 | # TODO: Check if compiler is able to generate wasm32 29 | if( NOT ("${WASM_CLANG}" STREQUAL "" OR "${WASM_LLC}" STREQUAL "" OR "${WASM_LLVM_LINK}" STREQUAL "") ) 30 | set(WASM_TOOLCHAIN TRUE) 31 | MESSAGE(STATUS "Found WASM toolchain:") 32 | MESSAGE(STATUS " clang: ${WASM_CLANG}") 33 | MESSAGE(STATUS " llc: ${WASM_LLC}") 34 | MESSAGE(STATUS " llvm-link: ${WASM_LLVM_LINK}") 35 | else() 36 | MESSAGE(FATAL_ERROR "Could not find WASM toolchain. Try setting WASM_LLMV_CONFIG (env or cmake variable) with the path to the wasm toolchain llvm-config") 37 | endif() 38 | 39 | if( NOT ("${S2WASM}" STREQUAL "") ) 40 | MESSAGE(STATUS "Found s2wasm: ${S2WASM}") 41 | else() 42 | MESSAGE(FATAL_ERROR "Could not find s2wasm. Try setting S2WASM (env or cmake variable) with the path to the s2wasm binary") 43 | endif() 44 | 45 | macro(add_wast_target target SOURCE_FILES INCLUDE_FOLDERS DESTINATION_FOLDER) 46 | 47 | set(outfiles "") 48 | foreach(srcfile ${SOURCE_FILES}) 49 | 50 | get_filename_component(outfile ${srcfile} NAME) 51 | get_filename_component(infile ${srcfile} ABSOLUTE) 52 | 53 | set(outfile "${DESTINATION_FOLDER}/${outfile}") 54 | set(outtarget "${DESTINATION_FOLDER}/${target}") 55 | 56 | # -ffreestanding 57 | # Assert that compilation targets a freestanding environment. 58 | # This implies -fno-builtin. A freestanding environment is one in which the standard library may not exist, and program startup may not necessarily be at main. 59 | # The most obvious example is an OS kernel. 60 | 61 | # -nostdlib 62 | # Do not use the standard system startup files or libraries when linking. 63 | # No startup files and only the libraries you specify are passed to the linker, and options specifying linkage of the system libraries, such as -static-libgcc or -shared-libgcc, are ignored. 64 | # The compiler may generate calls to memcmp, memset, memcpy and memmove. 65 | # These entries are usually resolved by entries in libc. These entry points should be supplied through some other mechanism when this option is specified. 66 | 67 | # -fno-threadsafe-statics 68 | # Do not emit the extra code to use the routines specified in the C++ ABI for thread-safe initialization of local statics. 69 | # You can use this option to reduce code size slightly in code that doesn’t need to be thread-safe. 70 | 71 | # -fno-rtti 72 | # Disable generation of information about every class with virtual functions for use by the C++ run-time type identification features (dynamic_cast and typeid). 73 | 74 | # -fno-exceptions 75 | # Disable the generation of extra code needed to propagate exceptions 76 | 77 | add_custom_command(OUTPUT ${outfile}.bc 78 | DEPENDS ${infile} 79 | COMMAND ${WASM_CLANG} -emit-llvm -O3 --std=c++14 --target=wasm32 -ffreestanding -nostdlib -fno-threadsafe-statics -fno-rtti -fno-exceptions -I ${INCLUDE_FOLDERS} -c ${infile} -o ${outfile}.bc 80 | IMPLICIT_DEPENDS CXX ${infile} 81 | COMMENT "Building LLVM bitcode ${outfile}.bc" 82 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} 83 | VERBATIM 84 | ) 85 | set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${outfile}.bc) 86 | 87 | list(APPEND outfiles ${outfile}.bc) 88 | 89 | endforeach(srcfile) 90 | 91 | add_custom_command(OUTPUT ${outtarget}.bc 92 | DEPENDS ${outfiles} 93 | COMMAND ${WASM_LLVM_LINK} -o ${outtarget}.bc ${outfiles} 94 | COMMENT "Linking LLVM bitcode ${target}.bc" 95 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} 96 | VERBATIM 97 | ) 98 | set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${outtarget}.bc) 99 | 100 | add_custom_command(OUTPUT ${outtarget}.s 101 | DEPENDS ${outtarget}.bc 102 | COMMAND ${WASM_LLC} -asm-verbose=false -o ${outtarget}.s ${outtarget}.bc 103 | COMMENT "Generating textual assembly ${target}.s" 104 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} 105 | VERBATIM 106 | ) 107 | set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${outtarget}.s) 108 | 109 | add_custom_command(OUTPUT ${outtarget}.wast 110 | DEPENDS "${outtarget}.s" 111 | COMMAND ${S2WASM} -o ${outtarget}.wast -s 1024 "${outtarget}.s" 112 | COMMENT "Generating WAST ${target}.wast" 113 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} 114 | VERBATIM 115 | ) 116 | set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${outtarget}.wast) 117 | 118 | add_custom_command(OUTPUT ${DESTINATION_FOLDER}/${target}.wast.hpp 119 | DEPENDS ${DESTINATION_FOLDER}/${target}.wast 120 | COMMAND echo "const char* ${target}_wast = R\"=====(" > ${DESTINATION_FOLDER}/${target}.wast.hpp 121 | COMMAND cat ${DESTINATION_FOLDER}/${target}.wast >> ${DESTINATION_FOLDER}/${target}.wast.hpp 122 | COMMAND echo ")=====\";" >> ${DESTINATION_FOLDER}/${target}.wast.hpp 123 | COMMENT "Generating ${target}.wast.hpp" 124 | VERBATIM 125 | ) 126 | 127 | add_custom_target(${target} ALL DEPENDS ${outtarget}.wast.hpp) 128 | set_property(TARGET ${target} PROPERTY INCLUDE_DIRECTORIES ${INCLUDE_FOLDERS}) 129 | 130 | 131 | endmacro(add_wast_target) 132 | -------------------------------------------------------------------------------- /currency/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB SOURCE_FILES "*.cpp") 2 | add_wast_target(currency "${SOURCE_FILES}" "${CONTRACT_INCLUDE_PATHS}" ${CMAKE_CURRENT_BINARY_DIR}) 3 | -------------------------------------------------------------------------------- /currency/currency.abi: -------------------------------------------------------------------------------- 1 | { 2 | "types": [{ 3 | "newTypeName": "AccountName", 4 | "type": "Name" 5 | } 6 | ], 7 | "structs": [{ 8 | "name": "transfer", 9 | "base": "", 10 | "fields": { 11 | "from": "AccountName", 12 | "to": "AccountName", 13 | "quantity": "UInt64" 14 | } 15 | },{ 16 | "name" : "account", 17 | "fields" : { 18 | "key" : "UInt64", 19 | "balance" : "UInt64" 20 | } 21 | } 22 | ], 23 | "actions": [{ 24 | "action": "transfer", 25 | "type": "transfer" 26 | } 27 | ], 28 | "tables": [{"table":"account","type":"account"}] 29 | } 30 | -------------------------------------------------------------------------------- /currency/currency.cpp: -------------------------------------------------------------------------------- 1 | #include /// defines transfer struct (abi) 2 | 3 | namespace TOKEN_NAME { 4 | using namespace eos; 5 | 6 | /// When storing accounts, check for empty balance and remove account 7 | void storeAccount( AccountName account, const Account& a ) { 8 | if( a.isEmpty() ) { 9 | /// value, scope 10 | Accounts::remove( a, account ); 11 | } else { 12 | /// value, scope 13 | Accounts::store( a, account ); 14 | } 15 | } 16 | 17 | void apply_currency_transfer( const TOKEN_NAME::Transfer& transfer ) { 18 | eos::print("This appears to be a transfer of ", transfer.quantity, " from ", transfer.from, " to ", transfer.to); 19 | requireNotice( transfer.to, transfer.from ); 20 | requireAuth( transfer.from ); 21 | 22 | auto from = getAccount( transfer.from ); 23 | auto to = getAccount( transfer.to ); 24 | 25 | from.balance -= transfer.quantity; /// token subtraction has underflow assertion 26 | to.balance += transfer.quantity; /// token addition has overflow assertion 27 | 28 | storeAccount( transfer.from, from ); 29 | storeAccount( transfer.to, to ); 30 | } 31 | 32 | } // namespace TOKEN_NAME 33 | 34 | using namespace currency; 35 | 36 | extern "C" { 37 | void init() { 38 | storeAccount( N(currency), Account( CurrencyTokens(1000ll*1000ll*1000ll) ) ); 39 | } 40 | 41 | /// The apply method implements the dispatch of events to this contract 42 | void apply( uint64_t code, uint64_t action ) { 43 | if( code == N(currency) ) { 44 | if( action == N(transfer) ) 45 | currency::apply_currency_transfer( currentMessage< TOKEN_NAME::Transfer >() ); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /currency/currency.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /** 6 | * Make it easy to change the account name the currency is deployed to. 7 | */ 8 | #ifndef TOKEN_NAME 9 | #define TOKEN_NAME currency 10 | #endif 11 | 12 | namespace TOKEN_NAME { 13 | using eos::AccountName; 14 | 15 | typedef eos::token CurrencyTokens; 16 | 17 | /** 18 | * Transfer requires that the sender and receiver be the first two 19 | * accounts notified and that the sender has provided authorization. 20 | */ 21 | struct Transfer { 22 | AccountName from; 23 | AccountName to; 24 | CurrencyTokens quantity; 25 | }; 26 | 27 | /** 28 | * @brief row in Account table stored within each scope 29 | */ 30 | struct Account { 31 | Account( CurrencyTokens b = CurrencyTokens() ):balance(b){} 32 | 33 | /** 34 | * The key is constant because there is only one record per scope/currency/accounts 35 | */ 36 | const uint64_t key = N(account); 37 | CurrencyTokens balance; 38 | 39 | bool isEmpty()const { return balance.quantity == 0; } 40 | }; 41 | static_assert( sizeof(Account) == sizeof(uint64_t)+sizeof(CurrencyTokens), "unexpected packing" ); 42 | 43 | using Accounts = Table; 44 | 45 | /** 46 | * Accounts information for owner is stored: 47 | * 48 | * owner/TOKEN_NAME/account/account -> Account 49 | * 50 | * This API is made available for 3rd parties wanting read access to 51 | * the users balance. If the account doesn't exist a default constructed 52 | * account will be returned. 53 | */ 54 | inline Account getAccount( AccountName owner ) { 55 | Account account; 56 | /// scope, record 57 | Accounts::get( account, owner ); 58 | return account; 59 | } 60 | 61 | } /// namespace TOKEN_NAME 62 | 63 | -------------------------------------------------------------------------------- /eoslib/crypto.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | extern "C" { 4 | /** 5 | * This method is implemented as: 6 | * 7 | * uint256 calc_hash; 8 | * sha256( data, length, &calc_hash ); 9 | * assert( calc_hash == hash, "invalid hash" ); 10 | * 11 | * This method is optimized to a NO-OP when in fast evaluation mode 12 | */ 13 | void assert_sha256( char* data, uint32_t length, const uint256* hash ); 14 | 15 | /** 16 | * Calculates sha256( data,length) and stores result in memory pointed to by hash 17 | */ 18 | void sha256( char* data, uint32_t length, uint256* hash ); 19 | } -------------------------------------------------------------------------------- /eoslib/db.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file db.h 3 | * @brief Defines C API for interfacing with blockchain database 4 | */ 5 | #pragma once 6 | 7 | #include 8 | extern "C" { 9 | /** 10 | * @defgroup database Database API 11 | * @brief APIs that store and retreive data on the blockchain 12 | * @ingroup contractdev 13 | * 14 | * EOS.IO organizes data according to the following broad structure: 15 | * 16 | * - **scope** - an account where the data is stored 17 | * - **code** - the account name which has write permission 18 | * - **table** - a name for the table that is being stored 19 | * - **record** - a row in the table 20 | * 21 | * Every transaction specifies the set of valid scopes that may be read and/or written 22 | * to. The code that is running determines what can be written to; therefore, write operations 23 | * do not allow you to specify/configure the code. 24 | * 25 | * @note Attempts to read and/or write outside the valid scope and/or code sections will 26 | * cause your transaction to fail. 27 | * 28 | * 29 | * @section tabletypes Table Types 30 | * There are several supported table types identified by the number and 31 | * size of the index. 32 | * 33 | * 1. @ref dbi64 34 | * 2. @ref dbi128i128 35 | * 36 | * The database APIs assume that the first bytes of each record represent 37 | * the primary and/or secondary keys followed by an arbitrary amount of data. 38 | * 39 | * The @ref databaseCpp provides a simple interface for storing any fixed-size struct as 40 | * a database row. 41 | * 42 | */ 43 | 44 | /** 45 | * @defgroup databaseC Database C API 46 | * @brief C APIs for interfacing with the database. 47 | * @ingroup database 48 | */ 49 | 50 | /** 51 | * @defgroup databaseCpp Database C++ API 52 | * @brief C++ APIs for interfacing with the database. 53 | * @ingroup database 54 | */ 55 | 56 | /** 57 | * @defgroup dbi64 Single 64 bit Index Table 58 | * @brief These methods interface with a simple table with 64 bit unique primary key and arbitrary binary data value. 59 | * @ingroup databaseC 60 | * 61 | * @see Table class in C++ API 62 | * 63 | * @{ 64 | */ 65 | 66 | /** 67 | * @param scope - the account scope that will be read, must exist in the transaction scopes list 68 | * @param table - the ID/name of the table within the current scope/code context to modify 69 | * 70 | * @return 1 if a new record was created, 0 if an existing record was updated 71 | * 72 | * @pre datalen >= sizeof(uint64_t) 73 | * @pre data is a valid pointer to a range of memory at least datalen bytes long 74 | * @pre *((uint64_t*)data) stores the primary key 75 | * @pre scope is declared by the current transaction 76 | * @pre this method is being called from an apply context (not validate or precondition) 77 | * 78 | * @post a record is either created or updated with the given scope and table. 79 | * 80 | * @throw if called with an invalid precondition execution will be aborted 81 | * 82 | */ 83 | int32_t store_i64( uint64_t scope, TableName table, const void* data, uint32_t datalen ); 84 | 85 | /** 86 | * @return 1 if the record was updated, 0 if no record with key was found 87 | */ 88 | int32_t update_i64( uint64_t scope, TableName table, const void* data, uint32_t datalen ); 89 | 90 | /** 91 | * @param scope - the account scope that will be read, must exist in the transaction scopes list 92 | * @param code - identifies the code that controls write-access to the data 93 | * @param table - the ID/name of the table within the scope/code context to query 94 | * @param data - location to copy the stored record, should be initialized with the key to get 95 | * @param datalen - the maximum length of data to read, must be greater than sizeof(uint64_t) 96 | * 97 | * @return the number of bytes read or -1 if key was not found 98 | */ 99 | int32_t load_i64( uint64_t scope, uint64_t code, TableName table, void* data, uint32_t datalen ); 100 | int32_t front_i64( uint64_t scope, uint64_t code, TableName table, void* data, uint32_t datalen ); 101 | int32_t back_i64( uint64_t scope, uint64_t code, TableName table, void* data, uint32_t datalen ); 102 | int32_t next_i64( uint64_t scope, uint64_t code, TableName table, void* data, uint32_t datalen ); 103 | int32_t previous_i64( uint64_t scope, uint64_t code, TableName table, void* data, uint32_t datalen ); 104 | int32_t lower_bound_i64( uint64_t scope, uint64_t code, TableName table, void* data, uint32_t datalen ); 105 | int32_t upper_bound_i64( uint64_t scope, uint64_t code, TableName table, void* data, uint32_t datalen ); 106 | 107 | /** 108 | * @param data - must point to at lest 8 bytes containing primary key 109 | * 110 | * @return 1 if a record was removed, and 0 if no record with key was found 111 | */ 112 | int32_t remove_i64( uint64_t scope, TableName table, void* data ); 113 | 114 | ///@} db_i64 115 | 116 | 117 | 118 | /** 119 | * @defgroup dbi128i128 Dual 128 bit Index Table 120 | * @brief Interface to a database table with 128 bit primary and secondary keys and arbitary binary data value. 121 | * @ingroup databaseC 122 | * 123 | * @param scope - the account where table data will be found 124 | * @param code - the code which owns the table 125 | * @param table - the name of the table where record is stored 126 | * @param data - a pointer to memory that is at least 32 bytes long 127 | * @param len - the length of data, must be greater than or equal to 32 bytes 128 | * 129 | * @return the total number of bytes read or -1 for "not found" or "end" where bytes 130 | * read includes 32 bytes of the key 131 | * 132 | * These methods assume a database table with records of the form: 133 | * 134 | * ``` 135 | * struct Record { 136 | * uint128 primary; 137 | * uint128 secondary; 138 | * ... arbitrary data ... 139 | * }; 140 | * 141 | * ``` 142 | * 143 | * You can iterate over these indicies with primary index sorting records by { primary, secondary } and 144 | * the secondary index sorting records by { secondary, primary }. This means that duplicates of the primary or 145 | * secondary values are allowed so long as there are no duplicates of the combination {primary, secondary}. 146 | * 147 | * @see Table class in C++ API 148 | * 149 | * @{ 150 | */ 151 | 152 | int32_t load_primary_i128i128( uint64_t scope, uint64_t code, TableName table, void* data, uint32_t len ); 153 | int32_t front_primary_i128i128( uint64_t scope, uint64_t code, TableName table, void* data, uint32_t len ); 154 | int32_t back_primary_i128i128( uint64_t scope, uint64_t code, TableName table, void* data, uint32_t len ); 155 | int32_t next_primary_i128i128( uint64_t scope, uint64_t code, TableName table, void* data, uint32_t len ); 156 | int32_t previous_primary_i128i128( uint64_t scope, uint64_t code, TableName table, void* data, uint32_t len ); 157 | int32_t upper_bound_primary_i128i128( uint64_t scope, uint64_t code, TableName table, void* data, uint32_t len ); 158 | int32_t lower_bound_primary_i128i128( uint64_t scope, uint64_t code, TableName table, void* data, uint32_t len ); 159 | 160 | int32_t load_secondary_i128i128( uint64_t scope, uint64_t code, TableName table, void* data, uint32_t len ); 161 | int32_t front_secondary_i128i128( uint64_t scope, uint64_t code, TableName table, void* data, uint32_t len ); 162 | int32_t back_secondary_i128i128( uint64_t scope, uint64_t code, TableName table, void* data, uint32_t len ); 163 | int32_t next_secondary_i128i128( uint64_t scope, uint64_t code, TableName table, void* data, uint32_t len ); 164 | int32_t previous_secondary_i128i128( uint64_t scope, uint64_t code, TableName table, void* data, uint32_t len ); 165 | int32_t upper_bound_secondary_i128i128( uint64_t scope, uint64_t code, TableName table, void* data, uint32_t len ); 166 | int32_t lower_bound_secondary_i128i128( uint64_t scope, uint64_t code, TableName table, void* data, uint32_t len ); 167 | 168 | 169 | /** 170 | * @param data - must point to at lest 32 bytes containing {primary,secondary} 171 | * 172 | * @return 1 if a record was removed, and 0 if no record with key was found 173 | */ 174 | int32_t remove_i128i128( uint64_t scope, TableName table, const void* data ); 175 | /** 176 | * @return 1 if a new record was created, 0 if an existing record was updated 177 | */ 178 | int32_t store_i128i128( uint64_t scope, TableName table, const void* data, uint32_t len ); 179 | 180 | /** 181 | * @return 1 if the record was updated, 0 if no record with key was found 182 | */ 183 | int32_t update_i128i128( uint64_t scope, TableName table, const void* data, uint32_t len ); 184 | 185 | ///@} dbi128i128 186 | 187 | /** 188 | * @defgroup dbi64i64i64 Triple 64 bit Index Table 189 | * @brief Interface to a database table with 64 bit primary, secondary and tertiary keys and arbitary binary data value. 190 | * @ingroup databaseC 191 | * 192 | * @param scope - the account where table data will be found 193 | * @param code - the code which owns the table 194 | * @param table - the name of the table where record is stored 195 | * @param data - a pointer to memory that is at least 32 bytes long 196 | * @param len - the length of data, must be greater than or equal to 32 bytes 197 | * 198 | * @return the total number of bytes read or -1 for "not found" or "end" where bytes 199 | * read includes 24 bytes of the key 200 | * 201 | * These methods assume a database table with records of the form: 202 | * 203 | * ``` 204 | * struct Record { 205 | * uint64 primary; 206 | * uint64 secondary; 207 | * uint64 tertiary; 208 | * ... arbitrary data ... 209 | * }; 210 | * 211 | * ``` 212 | * 213 | * You can iterate over these indicies with primary index sorting records by { primary, secondary, tertiary }, 214 | * the secondary index sorting records by { secondary, tertiary } and the tertiary index sorting records by 215 | * { tertiary }. 216 | * 217 | * @see Table class in C++ API 218 | * 219 | * @{ 220 | */ 221 | 222 | int32_t load_primary_i64i64i64( uint64_t scope, uint64_t code, TableName table, void* data, uint32_t len ); 223 | int32_t front_primary_i64i64i64( uint64_t scope, uint64_t code, TableName table, void* data, uint32_t len ); 224 | int32_t back_primary_i64i64i64( uint64_t scope, uint64_t code, TableName table, void* data, uint32_t len ); 225 | int32_t next_primary_i64i64i64( uint64_t scope, uint64_t code, TableName table, void* data, uint32_t len ); 226 | int32_t previous_primary_i64i64i64( uint64_t scope, uint64_t code, TableName table, void* data, uint32_t len ); 227 | int32_t upper_bound_primary_i64i64i64( uint64_t scope, uint64_t code, TableName table, void* data, uint32_t len ); 228 | int32_t lower_bound_primary_i64i64i64( uint64_t scope, uint64_t code, TableName table, void* data, uint32_t len ); 229 | 230 | int32_t load_secondary_i64i64i64( uint64_t scope, uint64_t code, TableName table, void* data, uint32_t len ); 231 | int32_t front_secondary_i64i64i64( uint64_t scope, uint64_t code, TableName table, void* data, uint32_t len ); 232 | int32_t back_secondary_i64i64i64( uint64_t scope, uint64_t code, TableName table, void* data, uint32_t len ); 233 | int32_t next_secondary_i64i64i64( uint64_t scope, uint64_t code, TableName table, void* data, uint32_t len ); 234 | int32_t previous_secondary_i64i64i64( uint64_t scope, uint64_t code, TableName table, void* data, uint32_t len ); 235 | int32_t upper_bound_secondary_i64i64i64( uint64_t scope, uint64_t code, TableName table, void* data, uint32_t len ); 236 | int32_t lower_bound_secondary_i64i64i64( uint64_t scope, uint64_t code, TableName table, void* data, uint32_t len ); 237 | 238 | int32_t load_tertiary_i64i64i64( uint64_t scope, uint64_t code, TableName table, void* data, uint32_t len ); 239 | int32_t front_tertiary_i64i64i64( uint64_t scope, uint64_t code, TableName table, void* data, uint32_t len ); 240 | int32_t back_tertiary_i64i64i64( uint64_t scope, uint64_t code, TableName table, void* data, uint32_t len ); 241 | int32_t next_tertiary_i64i64i64( uint64_t scope, uint64_t code, TableName table, void* data, uint32_t len ); 242 | int32_t previous_tertiary_i64i64i64( uint64_t scope, uint64_t code, TableName table, void* data, uint32_t len ); 243 | int32_t upper_bound_tertiary_i64i64i64( uint64_t scope, uint64_t code, TableName table, void* data, uint32_t len ); 244 | int32_t lower_bound_tertiary_i64i64i64( uint64_t scope, uint64_t code, TableName table, void* data, uint32_t len ); 245 | 246 | /** 247 | * @param data - must point to at lest 24 bytes containing {primary,secondary,tertiary} 248 | * 249 | * @return 1 if a record was removed, and 0 if no record with key was found 250 | */ 251 | int32_t remove_i64i64i64( uint64_t scope, TableName table, const void* data ); 252 | /** 253 | * @return 1 if a new record was created, 0 if an existing record was updated 254 | */ 255 | int32_t store_i64i64i64( uint64_t scope, TableName table, const void* data, uint32_t len ); 256 | 257 | /** 258 | * @return 1 if the record was updated, 0 if no record with key was found 259 | */ 260 | int32_t update_i64i64i64( uint64_t scope, TableName table, const void* data, uint32_t len ); 261 | 262 | ///@} dbi64i64i64 263 | } 264 | -------------------------------------------------------------------------------- /eoslib/db.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | 6 | 7 | /** 8 | * @ingroup databaseCpp 9 | struct Db 10 | { 11 | 12 | template 13 | static bool get( TableName table, uint64_t key, T& value ){ 14 | return get( currentCode(), table, key, value ); 15 | } 16 | 17 | template 18 | static bool get( eos::AccountName scope, TableName table, uint64_t key, T& value ){ 19 | return get( scope, currentCode(), table, key, value ); 20 | } 21 | 22 | template 23 | static bool get( eos::AccountName scope, eos::AccountName code, TableName table, uint64_t key, T& result ) { 24 | auto read = load_i64( scope, code, table, key, &result, sizeof(result) ); 25 | return read > 0; 26 | } 27 | 28 | template 29 | static int32_t store( TableName table, uint64_t key, const T& value ) { 30 | return store( currentCode(), key, value ); 31 | } 32 | 33 | template 34 | static int32_t store( Name scope, TableName table, const T& value ) { 35 | return store_i64( scope, table, &value, sizeof(value) ); 36 | } 37 | 38 | static bool remove( Name scope, TableName table, uint64_t key ) { 39 | return remove_i64( scope, table, key ); 40 | } 41 | }; 42 | */ 43 | 44 | 45 | template 46 | struct table_impl{}; 47 | 48 | template<> 49 | struct table_impl { 50 | static int32_t front_primary( uint64_t scope, uint64_t code, uint64_t table, void* data, uint32_t len ) { 51 | return front_primary_i128i128( scope, code, table, data, len ); 52 | } 53 | static int32_t back_primary( uint64_t scope, uint64_t code, uint64_t table, void* data, uint32_t len ) { 54 | return back_primary_i128i128( scope, code, table, data, len ); 55 | } 56 | static int32_t load_primary( uint64_t scope, uint64_t code, uint64_t table, void* data, uint32_t len ) { 57 | return load_primary_i128i128( scope, code, table, data, len ); 58 | } 59 | static int32_t next_primary( uint64_t scope, uint64_t code, uint64_t table, void* data, uint32_t len ) { 60 | return next_primary_i128i128( scope, code, table, data, len ); 61 | } 62 | static int32_t previous_primary( uint64_t scope, uint64_t code, uint64_t table, void* data, uint32_t len ) { 63 | return previous_primary_i128i128( scope, code, table, data, len ); 64 | } 65 | static int32_t upper_bound_primary( uint64_t scope, uint64_t code, uint64_t table, void* data, uint32_t len ) { 66 | return upper_bound_primary_i128i128( scope, code, table, data, len ); 67 | } 68 | static int32_t lower_bound_primary( uint64_t scope, uint64_t code, uint64_t table, void* data, uint32_t len ) { 69 | return lower_bound_primary_i128i128( scope, code, table, data, len ); 70 | } 71 | 72 | static int32_t front_secondary( uint64_t scope, uint64_t code, uint64_t table, void* data, uint32_t len ) { 73 | return front_secondary_i128i128( scope, code, table, data, len ); 74 | } 75 | static int32_t back_secondary( uint64_t scope, uint64_t code, uint64_t table, void* data, uint32_t len ) { 76 | return back_secondary_i128i128( scope, code, table, data, len ); 77 | } 78 | static int32_t load_secondary( uint64_t scope, uint64_t code, uint64_t table, void* data, uint32_t len ) { 79 | return load_secondary_i128i128( scope, code, table, data, len ); 80 | } 81 | static int32_t next_secondary( uint64_t scope, uint64_t code, uint64_t table, void* data, uint32_t len ) { 82 | return next_secondary_i128i128( scope, code, table, data, len ); 83 | } 84 | static int32_t previous_secondary( uint64_t scope, uint64_t code, uint64_t table, void* data, uint32_t len ) { 85 | return previous_secondary_i128i128( scope, code, table, data, len ); 86 | } 87 | static int32_t upper_bound_secondary( uint64_t scope, uint64_t code, uint64_t table, void* data, uint32_t len ) { 88 | return upper_bound_secondary_i128i128( scope, code, table, data, len ); 89 | } 90 | static int32_t lower_bound_secondary( uint64_t scope, uint64_t code, uint64_t table, void* data, uint32_t len ) { 91 | return lower_bound_secondary_i128i128( scope, code, table, data, len ); 92 | } 93 | 94 | static int32_t remove( uint64_t scope, uint64_t table, const void* data ) { 95 | return remove_i128i128( scope, table, data ); 96 | } 97 | static int32_t store( eos::AccountName scope, TableName table, const void* data, uint32_t len ) { 98 | return store_i128i128( scope, table, data, len ); 99 | } 100 | static int32_t update( eos::AccountName scope, TableName table, const void* data, uint32_t len ) { 101 | return update_i128i128( scope, table, data, len ); 102 | } 103 | }; 104 | 105 | template<> 106 | struct table_impl { 107 | static int32_t front_primary( uint64_t scope, uint64_t code, uint64_t table, void* data, uint32_t len ) { 108 | return front_i64( scope, code, table, data, len ); 109 | } 110 | static int32_t back_primary( uint64_t scope, uint64_t code, uint64_t table, void* data, uint32_t len ) { 111 | return back_i64( scope, code, table, data, len ); 112 | } 113 | static int32_t load_primary( uint64_t scope, uint64_t code, uint64_t table, void* data, uint32_t len ) { 114 | return load_i64( scope, code, table, data, len ); 115 | } 116 | static int32_t next( uint64_t scope, uint64_t code, uint64_t table, void* data, uint32_t len ) { 117 | return next_i64( scope, code, table, data, len ); 118 | } 119 | static int32_t previous( uint64_t scope, uint64_t code, uint64_t table, void* data, uint32_t len ) { 120 | return previous_i64( scope, code, table, data, len ); 121 | } 122 | static int32_t lower_bound( uint64_t scope, uint64_t code, uint64_t table, void* data, uint32_t len ) { 123 | return lower_bound_i64( scope, code, table, data, len ); 124 | } 125 | static int32_t upper_bound( uint64_t scope, uint64_t code, uint64_t table, void* data, uint32_t len ) { 126 | return upper_bound_i64( scope, code, table, data, len ); 127 | } 128 | 129 | static int32_t remove( uint64_t scope, uint64_t table, const void* data ) { 130 | return remove_i64( scope, table, (uint64_t*)data); 131 | } 132 | static int32_t store( eos::AccountName scope, TableName table, const void* data, uint32_t len ) { 133 | return store_i64( scope, table, data, len ); 134 | } 135 | static int32_t update( eos::AccountName scope, TableName table, const void* data, uint32_t len ) { 136 | return update_i64( scope, table, data, len ); 137 | } 138 | }; 139 | 140 | 141 | /** 142 | * @class Table 143 | * @brief defines a type-safe C++ wrapper around the @ref databaseC 144 | * 145 | * @tparam scope - the default account name/scope that this table is located within 146 | * @tparam code - the code account name which has write permission to this table 147 | * @tparam table - a unique identifier (name) for this table 148 | * @tparam Record - the type of data stored in each row 149 | * @tparam PrimaryType - the type of the first field stored in @ref Record 150 | * @tparam SecondaryType - the type of the second field stored in @ref Record 151 | * 152 | * The primary and secondary indicies are sorted as N-bit unsigned integers from lowest to highest. 153 | * 154 | * @ingroup databaseCpp 155 | */ 156 | template 157 | struct Table { 158 | private: 159 | typedef table_impl impl; 160 | static_assert( sizeof(PrimaryType) + sizeof(SecondaryType) <= sizeof(Record), "invalid template parameters" ); 161 | 162 | public: 163 | typedef PrimaryType Primary; 164 | typedef SecondaryType Secondary; 165 | 166 | 167 | struct PrimaryIndex { 168 | 169 | static bool front( Record& r, uint64_t s = scope ) { 170 | return impl::front_primary( s, code, table, &r, sizeof(Record) ) == sizeof(Record); 171 | } 172 | static bool back( Record& r, uint64_t s = scope ) { 173 | return impl::back_primary( s, code, table, &r, sizeof(Record) ) == sizeof(Record); 174 | } 175 | static bool next( Record& r, uint64_t s = scope ) { 176 | return impl::next_primary( s, code, table, &r, sizeof(Record) ) == sizeof(Record); 177 | } 178 | static bool previous( Record& r, uint64_t s = scope ) { 179 | return impl::previous_primary( s, code, table, &r, sizeof(Record) ) == sizeof(Record); 180 | } 181 | static bool get( const PrimaryType& p, Record& r, uint64_t s = scope ) { 182 | *reinterpret_cast(&r) = p; 183 | return impl::load_primary( s, code, table, &r, sizeof(Record) ) == sizeof(Record); 184 | } 185 | static bool lower_bound( const PrimaryType& p, Record& r ) { 186 | return impl::lower_bound_primary( scope, code, table, &p &r, sizeof(Record) ) == sizeof(Record); 187 | } 188 | static bool upper_bound( const PrimaryType& p, Record& r ) { 189 | return impl::upper_bound_primary( scope, code, table, &p &r, sizeof(Record) ) == sizeof(Record); 190 | } 191 | static bool remove( const Record& r, uint64_t s = scope ) { 192 | return impl::remove( s, table, &r ) != 0; 193 | } 194 | }; 195 | 196 | struct SecondaryIndex { 197 | static bool front( Record& r, uint64_t s = scope ) { 198 | return impl::front_secondary( s, code, table, &r, sizeof(Record) ) == sizeof(Record); 199 | } 200 | static bool back( Record& r, uint64_t s = scope ) { 201 | return impl::back_secondary( s, code, table, &r, sizeof(Record) ) == sizeof(Record); 202 | } 203 | static bool next( Record& r, uint64_t s = scope ) { 204 | return impl::next_secondary( s, code, table, &r, sizeof(Record) ) == sizeof(Record); 205 | } 206 | static bool previous( Record& r, uint64_t s = scope ) { 207 | return impl::previous_secondary( s, code, table, &r, sizeof(Record) ) == sizeof(Record); 208 | } 209 | static bool get( const SecondaryType& p, Record& r, uint64_t s = scope ) { 210 | return impl::load_secondary( s, code, table, &p &r, sizeof(Record) ) == sizeof(Record); 211 | } 212 | static bool lower_bound( const SecondaryType& p, Record& r, uint64_t s = scope ) { 213 | return impl::lower_bound_secondary( s, code, table, &p &r, sizeof(Record) ) == sizeof(Record); 214 | } 215 | static bool upper_bound( const SecondaryType& p, Record& r, uint64_t s = scope ) { 216 | return impl::upper_bound_secondary( s, code, table, &p &r, sizeof(Record) ) == sizeof(Record); 217 | } 218 | static bool remove( const Record& r, uint64_t s = scope ) { 219 | return impl::remove( s, table, &r ) != 0; 220 | } 221 | }; 222 | 223 | static bool get( const PrimaryType& p, Record& r, uint64_t s = scope ) { 224 | *reinterpret_cast(&r) = p; 225 | return impl::load_primary( s, code, table, &r, sizeof(Record) ) == sizeof(Record); 226 | } 227 | 228 | static bool store( const Record& r, uint64_t s = scope ) { 229 | assert( impl::store( s, table, &r, sizeof(r) ), "error storing record" ); 230 | return true; 231 | } 232 | static bool update( const Record& r, uint64_t s = scope ) { 233 | assert( impl::update( s, table, &r, sizeof(r) ), "error updating record" ); 234 | return true; 235 | } 236 | static bool remove( const Record& r, uint64_t s = scope ) { 237 | return impl::remove( s, table, &r ) != 0; 238 | } 239 | }; 240 | 241 | 242 | /** 243 | * @brief this specialization of Table is for single-index tables 244 | * 245 | * @tparam scope - the default account name scope that this table is located within 246 | * @tparam code - the code account name which has write permission to this table 247 | * @tparam table - a unique identifier (name) for this table 248 | * @tparam Record - the type of data stored in each row 249 | * @tparam PrimaryType - the type of the first field stored in @ref Record 250 | * 251 | * @ingroup databaseCpp 252 | */ 253 | template 254 | struct Table { 255 | private: 256 | typedef table_impl impl; 257 | static_assert( sizeof(PrimaryType) <= sizeof(Record), "invalid template parameters" ); 258 | 259 | public: 260 | typedef PrimaryType Primary; 261 | 262 | struct PrimaryIndex { 263 | static bool front( Record& r ) { 264 | return impl::front_primary( scope, code, table, &r, sizeof(Record) ) == sizeof(Record); 265 | } 266 | static bool back( Record& r ) { 267 | return impl::back_primary( scope, code, table, &r, sizeof(Record) ) == sizeof(Record); 268 | } 269 | static bool next( Record& r ) { 270 | return impl::next_primary( scope, code, table, &r, sizeof(Record) ) == sizeof(Record); 271 | } 272 | static bool previous( Record& r ) { 273 | return impl::previous_primary( scope, code, table, &r, sizeof(Record) ) == sizeof(Record); 274 | } 275 | static bool get( const PrimaryType& p, Record& r, uint64_t s = scope ) { 276 | *reinterpret_cast(&r) = p; 277 | return impl::load_primary( s, code, table, &r, sizeof(Record) ) == sizeof(Record); 278 | } 279 | static bool lower_bound( const PrimaryType& p, Record& r ) { 280 | return impl::lower_bound_primary( scope, code, table, &p &r, sizeof(Record) ) == sizeof(Record); 281 | } 282 | static bool upper_bound( const PrimaryType& p, Record& r ) { 283 | return impl::upper_bound_primary( scope, code, table, &p &r, sizeof(Record) ) == sizeof(Record); 284 | } 285 | static bool remove( const Record& r ) { 286 | return impl::remove( scope, table, &r ) != 0; 287 | } 288 | }; 289 | 290 | static bool front( Record& r ) { return PrimaryIndex::front(r); } 291 | static bool back( Record& r ) { return PrimaryIndex::back(r); } 292 | 293 | static bool get( const PrimaryType& p, Record& r, uint64_t s = scope ) { 294 | *reinterpret_cast(&r) = p; 295 | return impl::load_primary( s, code, table, &r, sizeof(Record) ) == sizeof(Record); 296 | } 297 | 298 | static bool get( Record& r, uint64_t s = scope ) { 299 | return impl::load_primary( s, code, table, &r, sizeof(Record) ) == sizeof(Record); 300 | } 301 | 302 | static bool store( const Record& r, uint64_t s = scope ) { 303 | return impl::store( s, table, &r, sizeof(r) ) != 0; 304 | } 305 | 306 | static bool update( const Record& r, uint64_t s = scope ) { 307 | return impl::update( s, table, &r, sizeof(r) ) != 0; 308 | } 309 | 310 | static bool remove( const Record& r, uint64_t s = scope ) { 311 | return impl::remove( s, table, &r ) != 0; 312 | } 313 | 314 | }; 315 | 316 | 317 | /** 318 | * @ingroup databaseCpp 319 | */ 320 | #define TABLE2(NAME, SCOPE, CODE, TABLE, TYPE, PRIMARY_NAME, PRIMARY_TYPE, SECONDARY_NAME, SECONDARY_TYPE) \ 321 | using NAME = Table; \ 322 | typedef NAME::PrimaryIndex PRIMARY_NAME; \ 323 | typedef NAME::SecondaryIndex SECONDARY_NAME; 324 | 325 | -------------------------------------------------------------------------------- /eoslib/eos.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /eoslib/math.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | extern "C" { 4 | /** 5 | * @defgroup mathcapi Math C API 6 | * @brief defines builtin math functions 7 | * @ingroup mathapi 8 | */ 9 | void multeq_i128( uint128_t* self, const uint128_t* other ); 10 | void diveq_i128 ( uint128_t* self, const uint128_t* other ); 11 | } // extern "C" 12 | -------------------------------------------------------------------------------- /eoslib/math.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace eos { 5 | 6 | /** 7 | * @defgroup mathapi Math API 8 | * @brief Defines common math functions 9 | * @ingroup contractdev 10 | */ 11 | 12 | /** 13 | * @defgroup mathcppapi Math C++ API 14 | * @brief Defines common math functions and helper types 15 | * @ingroup mathapi 16 | * 17 | * @{ 18 | */ 19 | 20 | /** @brief wraps multeq_i128 from @ref mathcapi */ 21 | inline void multeq( uint128_t& self, const uint128_t& other ) { 22 | multeq_i128( &self, &other ); 23 | } 24 | 25 | /** @brief wraps diveq_i128 from @ref mathcapi */ 26 | inline void diveq( uint128_t& self, const uint128_t& other ) { 27 | diveq_i128( &self, &other ); 28 | } 29 | 30 | /** 31 | * @brief a struct that wraps uint128 integer and defines common operator overloads 32 | */ 33 | struct uint128 { 34 | public: 35 | uint128( uint128_t i = 0 ):value(i){} 36 | uint128( uint64_t i ):value(i){} 37 | uint128( uint32_t i ):value(i){} 38 | 39 | friend uint128 operator * ( uint128 a, const uint128& b ) { 40 | return a *= b; 41 | } 42 | 43 | friend uint128 operator / ( uint128 a, const uint128& b ) { 44 | return a /= b; 45 | } 46 | friend bool operator <= ( const uint128& a, const uint128& b ) { 47 | return a.value <= b.value; 48 | } 49 | friend bool operator >= ( const uint128& a, const uint128& b ) { 50 | return a.value >= b.value; 51 | } 52 | 53 | uint128& operator *= ( const uint128_t& other ) { 54 | multeq( value, other ); 55 | return *this; 56 | } 57 | uint128& operator *= ( const uint128& other ) { 58 | multeq( value, other.value ); 59 | return *this; 60 | } 61 | 62 | uint128& operator /= ( const uint128_t& other ) { 63 | diveq( value, other ); 64 | return *this; 65 | } 66 | uint128& operator /= ( const uint128& other ) { 67 | diveq( value, other.value ); 68 | return *this; 69 | } 70 | 71 | explicit operator uint64_t()const { 72 | assert( !(value >> 64), "cast to 64 bit loss of precision" ); 73 | return uint64_t(value); 74 | } 75 | 76 | private: 77 | uint128_t value = 0; 78 | }; 79 | 80 | /** 81 | * Define similar to std::min() 82 | */ 83 | template 84 | T min( const T& a, const T&b ) { 85 | return a < b ? a : b; 86 | } 87 | /** 88 | * Define similar to std::max() 89 | */ 90 | template 91 | T max( const T& a, const T&b ) { 92 | return a > b ? a : b; 93 | } 94 | 95 | /// @} /// mathcppapi 96 | } 97 | -------------------------------------------------------------------------------- /eoslib/message.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | extern "C" { 5 | /** 6 | * @defgroup messageapi Message API 7 | * @ingroup contractdev 8 | * @brief Define API for querying message properties 9 | * 10 | * A EOS.IO message has the following abstract structure: 11 | * 12 | * ``` 13 | * struct Message { 14 | * Name code; ///< primary account whose code defines the action 15 | * Name action; ///< the name of the action. 16 | * Name recipients[]; ///< accounts whose code will be notified (in addition to code) 17 | * Name authorization[]; ///< accounts that have approved this message 18 | * char data[]; 19 | * }; 20 | * ``` 21 | * 22 | * This API enables your contract to inspect the fields on the current message and act accordingly. 23 | * 24 | */ 25 | 26 | /** 27 | * @defgroup messagecapi Message C API 28 | * @ingroup messageapi 29 | * @brief Define API for querying message properties 30 | * 31 | * @{ 32 | */ 33 | 34 | /** 35 | * @param msg - a pointer where up to @ref len bytes of the current message will be coppied 36 | * @return the number of bytes copied to msg 37 | */ 38 | uint32_t readMessage( void* msg, uint32_t len ); 39 | 40 | /** 41 | * This method is useful for dynamicly sized messages 42 | * 43 | * @return the length of the current message's data field 44 | */ 45 | uint32_t messageSize(); 46 | 47 | /** 48 | * Verifies that @ref name exists in the set of notified accounts on a message. Throws if not found 49 | */ 50 | void requireNotice( uint64_t ); 51 | 52 | /** 53 | * Verifies that @ref name exists in the set of provided auths on a message. Throws if not found 54 | */ 55 | void requireAuth( uint64_t name ); 56 | 57 | /** 58 | * @return the account which specifes the code that is being run 59 | */ 60 | uint64_t currentCode(); 61 | 62 | 63 | /** 64 | * Aborts processing of this message and unwinds all pending changes 65 | * 66 | * @param test - 0 to abort, 1 to ignore 67 | * @param cstr - a null terminated message to explain the reason for failure 68 | */ 69 | void assert( uint32_t test, const char* cstr ); 70 | 71 | /** 72 | * Returns the time in seconds from 1970 of the last accepted block (not the block including this message) 73 | */ 74 | Time now(); 75 | 76 | ///@ } messagecapi 77 | } 78 | -------------------------------------------------------------------------------- /eoslib/message.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace eos { 6 | 7 | /** 8 | * @defgroup messagecppapi Message C++ API 9 | * @ingroup messageapi 10 | * @brief Type-safe C++ wrapers for Message C API 11 | * 12 | * @note There are some methods from the @ref messagecapi that can be used directly from C++ 13 | * 14 | * @{ 15 | */ 16 | 17 | /** 18 | * This method attempts to reinterpret the message body as type T. This will only work 19 | * if the message has no dynamic fields and the struct packing on type T is properly defined. 20 | */ 21 | template 22 | T currentMessage() { 23 | T value; 24 | auto read = readMessage( &value, sizeof(value) ); 25 | assert( read >= sizeof(value), "message shorter than expected" ); 26 | return value; 27 | } 28 | 29 | void requireNotice(eos::AccountName name) { 30 | ::requireNotice(name.value); 31 | } 32 | void requireAuth(eos::AccountName name) { 33 | ::requireAuth(name.value); 34 | } 35 | 36 | /** 37 | * All of the listed accounts must be specified on the message notice list or this method will throw 38 | * and end execution of the message. 39 | * 40 | * This helper method enables you to require notice of multiple accounts with a single 41 | * call rather than having to call the similar C API multiple times. 42 | * 43 | * @note message.code is also considered as part of the set of notified accounts 44 | */ 45 | template 46 | void requireNotice( eos::AccountName name, Accounts... accounts ){ 47 | requireNotice( name ); 48 | requireNotice( accounts... ); 49 | } 50 | 51 | 52 | ///@} messagecpp api 53 | 54 | } // namespace eos 55 | -------------------------------------------------------------------------------- /eoslib/print.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | extern "C" { 4 | /** 5 | * @defgroup consoleapi Console API 6 | * @brief Enables applications to log/print text messages 7 | * @ingroup contractdev 8 | * 9 | */ 10 | 11 | /** 12 | * @defgroup consolecapi Console C API 13 | * @ingroup consoleapi 14 | * 15 | * @{ 16 | */ 17 | 18 | /** 19 | * @param cstr - a null terminated string 20 | */ 21 | void prints( const char* cstr ); 22 | /** 23 | * Prints value as an integer 24 | */ 25 | void printi( uint64_t value ); 26 | 27 | void printi128( const uint128_t* value ); 28 | /** 29 | * Prints a 64 bit names as base32 encoded string 30 | */ 31 | void printn( uint64_t name ); 32 | /// @} 33 | } 34 | -------------------------------------------------------------------------------- /eoslib/print.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | namespace eos { 7 | 8 | static_assert( sizeof(long) == sizeof(int), "unexpected size difference" ); 9 | 10 | inline void print( const char* ptr ) { 11 | prints(ptr); 12 | } 13 | 14 | inline void print( uint64_t num ) { 15 | printi(num); 16 | } 17 | inline void print( uint32_t num ) { 18 | printi(num); 19 | } 20 | inline void print( int num ) { 21 | printi(num); 22 | } 23 | inline void print( unsigned int num ) { 24 | printi(num); 25 | } 26 | 27 | inline void print( uint128 num ) { 28 | printi128((uint128_t*)&num); 29 | } 30 | inline void print( uint128_t num ) { 31 | printi128((uint128_t*)&num); 32 | } 33 | 34 | inline void print( Name name ) { 35 | printn(name.value); 36 | } 37 | 38 | template 39 | inline void print( T&& t ) { 40 | t.print(); 41 | } 42 | 43 | 44 | /** 45 | * @defgroup consoleCppapi Console C++ API 46 | * @ingroup consoleapi 47 | * @brief C++ wrapper for Console C API 48 | * 49 | * This API uses C++ varidic templates and type detection to 50 | * make it easy to print any native type. You can even overload 51 | * the `print()` method for your own custom types. 52 | * 53 | * ### Example: 54 | * ``` 55 | * print( "hello world, this is a number: ", 5 ); 56 | * ``` 57 | * 58 | * @section override Overriding Print for your Types 59 | * 60 | * There are two ways to overload print: 61 | * 1. implement void print( const T& ) 62 | * 2. implement T::print()const 63 | * 64 | * @{ 65 | */ 66 | template 67 | void print( Arg a, Args... args ) { 68 | print(a); 69 | print(args...); 70 | } 71 | 72 | /** 73 | * Simulate C++ style streams 74 | */ 75 | class iostream {}; 76 | 77 | template 78 | inline iostream& operator<<( iostream& out, const T& v ) { 79 | print( v ); 80 | return out; 81 | } 82 | 83 | static iostream cout; 84 | 85 | /// @} consoleCppapi 86 | 87 | 88 | } 89 | -------------------------------------------------------------------------------- /eoslib/token.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file token.hpp 3 | * @brief Defines types and ABI for standard token messages and database tables 4 | * 5 | */ 6 | #pragma once 7 | #include 8 | #include 9 | 10 | /** 11 | * @defgroup tokens Token API 12 | * @brief Defines the ABI for interfacing with standard-compatible token messages and database tables. 13 | * @ingroup contractdev 14 | * 15 | * 16 | */ 17 | 18 | 19 | 20 | namespace eos { 21 | 22 | /** 23 | * @brief a uint64_t wrapper with checks for proper types and over/underflows. 24 | * 25 | * @ingroup tokens 26 | */ 27 | template 28 | struct token { 29 | static const uint64_t currency_type = CurrencyType; 30 | 31 | token(){} 32 | explicit token( NumberType v ):quantity(v){}; 33 | NumberType quantity = 0; 34 | 35 | token& operator-=( const token& a ) { 36 | assert( quantity >= a.quantity, "integer underflow subtracting token balance" ); 37 | quantity -= a.quantity; 38 | return *this; 39 | } 40 | 41 | token& operator+=( const token& a ) { 42 | assert( quantity + a.quantity >= a.quantity, "integer overflow adding token balance" ); 43 | quantity += a.quantity; 44 | return *this; 45 | } 46 | 47 | inline friend token operator+( const token& a, const token& b ) { 48 | token result = a; 49 | result += b; 50 | return result; 51 | } 52 | 53 | inline friend token operator-( const token& a, const token& b ) { 54 | token result = a; 55 | result -= b; 56 | return result; 57 | } 58 | 59 | friend bool operator <= ( const token& a, const token& b ) { return a.quantity <= b.quantity; } 60 | friend bool operator < ( const token& a, const token& b ) { return a.quantity < b.quantity; } 61 | friend bool operator >= ( const token& a, const token& b ) { return a.quantity >= b.quantity; } 62 | friend bool operator > ( const token& a, const token& b ) { return a.quantity > b.quantity; } 63 | friend bool operator == ( const token& a, const token& b ) { return a.quantity == b.quantity; } 64 | friend bool operator != ( const token& a, const token& b ) { return a.quantity != b.quantity; } 65 | 66 | explicit operator bool()const { return quantity != 0; } 67 | 68 | inline void print() { 69 | eos::print( quantity, " ", Name(CurrencyType) ); 70 | } 71 | }; 72 | 73 | /** 74 | * @brief defines a fixed precision price between two tokens. 75 | * 76 | * A price is written as X Base/Quote 77 | * 78 | * @ingroup tokens 79 | */ 80 | template 81 | struct price 82 | { 83 | typedef BaseToken base_token_type; 84 | typedef QuoteToken quote_token_type; 85 | /** 86 | * The largest base 10 integer that can be represented with 53 bits of 87 | * a double. This number keeps the math in range of JavaScript. By 88 | * being a power of 10 it makes it easier for developers to read and 89 | * interpret the integer by simply shifting the decimal. 90 | */ 91 | static const uint64_t precision = 1000ll*1000ll*1000ll*1000ll*1000ll; 92 | 93 | price():base_per_quote(1ul){} 94 | 95 | price( BaseToken base, QuoteToken quote ) { 96 | assert( base >= BaseToken(1ul), "invalid price" ); 97 | assert( quote >= QuoteToken(1ul), "invalid price" ); 98 | 99 | base_per_quote = base.quantity; 100 | base_per_quote *= precision; 101 | base_per_quote /= quote.quantity; 102 | } 103 | 104 | friend QuoteToken operator / ( BaseToken b, const price& q ) { 105 | eos::print( "operator/ ", uint128(b.quantity), " * ", uint128( precision ), " / ", q.base_per_quote, "\n" ); 106 | return QuoteToken( uint64_t((uint128(b.quantity) * uint128(precision) / q.base_per_quote)) ); 107 | } 108 | 109 | friend BaseToken operator * ( const QuoteToken& b, const price& q ) { 110 | eos::print( "b: ", b, " \n" ); 111 | eos::print( "operator* ", uint128(b.quantity), " * ", uint128( q.base_per_quote ), " / ", precision, "\n" ); 112 | //return QuoteToken( uint64_t( mult_div_i128( b.quantity, q.base_per_quote, precision ) ) ); 113 | return BaseToken( uint64_t((b.quantity * q.base_per_quote) / precision) ); 114 | } 115 | 116 | friend bool operator <= ( const price& a, const price& b ) { return a.base_per_quote <= b.base_per_quote; } 117 | friend bool operator < ( const price& a, const price& b ) { return a.base_per_quote < b.base_per_quote; } 118 | friend bool operator >= ( const price& a, const price& b ) { return a.base_per_quote >= b.base_per_quote; } 119 | friend bool operator > ( const price& a, const price& b ) { return a.base_per_quote > b.base_per_quote; } 120 | friend bool operator == ( const price& a, const price& b ) { return a.base_per_quote == b.base_per_quote; } 121 | friend bool operator != ( const price& a, const price& b ) { return a.base_per_quote != b.base_per_quote; } 122 | 123 | inline void print() { 124 | eos::print( base_per_quote, ".", " ", Name(base_token_type::currency_type), "/", Name(quote_token_type::currency_type) ); 125 | } 126 | private: 127 | /** 128 | * represented as number of base tokens to purchase 1 quote token 129 | */ 130 | eos::uint128 base_per_quote; 131 | }; 132 | 133 | typedef eos::token Tokens; 134 | 135 | 136 | /** 137 | * @brief the binary structure of the `transfer` message type for the `eos` contract. 138 | * 139 | * @ingroup tokens 140 | */ 141 | struct Transfer { 142 | static const uint64_t action_type = N(transfer); 143 | 144 | AccountName from; 145 | AccountName to; 146 | Tokens quantity; 147 | }; 148 | } // namespace eos 149 | -------------------------------------------------------------------------------- /eoslib/types.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | extern "C" { 4 | 5 | /** 6 | * @defgroup types Builtin Types 7 | * @ingroup contractdev 8 | * @brief Specifies typedefs and aliases 9 | */ 10 | typedef long long int64_t; 11 | typedef unsigned long long uint64_t; 12 | typedef unsigned long uint32_t; 13 | typedef long int32_t; 14 | typedef unsigned __int128 uint128_t; 15 | typedef __int128 int128_t; 16 | typedef unsigned char uint8_t; 17 | 18 | typedef uint64_t TokenName; 19 | typedef uint64_t TableName; 20 | typedef uint32_t Time; 21 | 22 | #define PACKED(X) __attribute((packed)) X 23 | 24 | struct uint256 { 25 | uint64_t words[4]; 26 | }; 27 | 28 | } /// extern "C" 29 | -------------------------------------------------------------------------------- /eoslib/types.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace eos { 5 | 6 | /** 7 | * Converts a base32 symbol into its binary representation, used by string_to_name() 8 | */ 9 | static constexpr char char_to_symbol( char c ) { 10 | if( c >= 'a' && c <= 'z' ) 11 | return (c - 'a') + 1; 12 | if( c >= '1' && c <= '5' ) 13 | return (c - '1') + 27; 14 | return 0; 15 | } 16 | 17 | /** 18 | * Converts a base32 string to a uint64_t. This is a constexpr so that 19 | * this method can be used in template arguments as well. 20 | * 21 | * @ingroup types 22 | */ 23 | static constexpr uint64_t string_to_name( const char* str ) { 24 | 25 | uint32_t len = 0; 26 | while( str[len] ) ++len; 27 | 28 | uint64_t value = 0; 29 | 30 | for( uint32_t i = 0; i <= 12; ++i ) { 31 | uint64_t c = 0; 32 | if( i < len && i <= 12 ) c = char_to_symbol( str[i] ); 33 | 34 | if( i < 12 ) { 35 | c &= 0x1f; 36 | c <<= 64-5*(i+1); 37 | } 38 | else { 39 | c &= 0x0f; 40 | } 41 | 42 | value |= c; 43 | } 44 | 45 | return value; 46 | } 47 | 48 | /** 49 | * @brief used to generate a compile time uint64_t from the base32 encoded string interpretation of X 50 | * @ingroup types 51 | */ 52 | #define N(X) ::eos::string_to_name(#X) 53 | 54 | /** 55 | * @class Name 56 | * @brief wraps a uint64_t to ensure it is only passed to methods that expect a Name and 57 | * that no mathematical operations occur. It also enables specialization of print 58 | * so that it is printed as a base32 string. 59 | * 60 | * @ingroup types 61 | */ 62 | struct Name { 63 | Name( uint64_t v = 0 ): value(v) {} 64 | operator uint64_t()const { return value; } 65 | 66 | friend bool operator==( const Name& a, const Name& b ) { return a.value == b.value; } 67 | friend bool operator==( const Name& a, uint64_t b) { return a.value == b; } 68 | friend bool operator==( uint64_t a, const Name& b) { return a == b.value; } 69 | uint64_t value = 0; 70 | }; 71 | 72 | 73 | /** 74 | * @ingroup types 75 | * 76 | * @{ 77 | */ 78 | template struct remove_reference { typedef T type; }; 79 | template struct remove_reference { typedef T type; }; 80 | template struct remove_reference { typedef T type; }; 81 | ///@} 82 | 83 | using AccountName = Name; 84 | 85 | } // namespace eos 86 | -------------------------------------------------------------------------------- /exchange/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB SOURCE_FILES "*.cpp") 2 | add_wast_target(exchange "${SOURCE_FILES}" "${CONTRACT_INCLUDE_PATHS}" ${CMAKE_CURRENT_BINARY_DIR}) 3 | add_dependencies( exchange currency ) 4 | -------------------------------------------------------------------------------- /exchange/exchange.abi: -------------------------------------------------------------------------------- 1 | { 2 | "types": [{ 3 | "newTypeName": "AccountName", 4 | "type": "Name" 5 | } 6 | ], 7 | "structs": [{ 8 | "name": "OrderID", 9 | "fields": { 10 | "name" : "AccountName", 11 | "id" : "UInt64" 12 | } 13 | },{ 14 | "name" : "Bid", 15 | "fields" : { 16 | "buyer" : "OrderID", 17 | "price" : "UInt128", 18 | "quantity" : "UInt64", 19 | "expiration" : "Time" 20 | } 21 | },{ 22 | "name" : "Ask", 23 | "fields" : { 24 | "seller" : "OrderID", 25 | "price" : "UInt128", 26 | "quantity" : "UInt64", 27 | "expiration" : "Time" 28 | } 29 | },{ 30 | "name" : "Account", 31 | "fields" : { 32 | "owner" : "AccountName", 33 | "eos_balance" : "UInt64", 34 | "currency_balance" : "UInt64", 35 | "open_orders" : "UInt32" 36 | } 37 | },{ 38 | "name" : "BuyOrder", 39 | "base" : "Bid", 40 | "fields" : { 41 | "fill_or_kill" : "UInt8" 42 | } 43 | },{ 44 | "name" : "SellOrder", 45 | "base" : "Ask", 46 | "fields" : { 47 | "fill_or_kill" : "UInt8" 48 | } 49 | } 50 | ], 51 | "actions": [{ 52 | "action": "buy", 53 | "type": "BuyOrder" 54 | },{ 55 | "action": "sell", 56 | "type": "SellOrder" 57 | },{ 58 | "action": "cancelbuy", 59 | "type": "OrderID" 60 | },{ 61 | "action": "cancelsell", 62 | "type": "OrderID" 63 | } 64 | ], 65 | "tables": [ 66 | {"table":"bids","type":"Bid"}, 67 | {"table":"asks","type":"Ask"}, 68 | {"table":"account","type":"Account"} 69 | ] 70 | } 71 | -------------------------------------------------------------------------------- /exchange/exchange.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file exchange.cpp 3 | * @brief defines an example exchange contract 4 | * 5 | * This exchange contract assumes the existence of two currency contracts 6 | * located at @currencya and @currencyb. These currency contracts have 7 | * provided an API header defined in currench.hpp which the exchange 8 | * contract will use to process messages related to deposits and withdraws. 9 | * 10 | * The exchange contract knows that the currency contracts requireNotice() 11 | * of both the sender and receiver; therefore, the exchange contract can 12 | * implement a message handler that will be called anytime funds are deposited 13 | * to or withdrawn from the exchange. 14 | * 15 | * When tokens are sent to @exchange from another account the exchange will 16 | * credit the user's balance of the proper currency. 17 | * 18 | * To withdraw from the exchange, the user simply reverses the "to" and "from" 19 | * fields of the currency contract transfer message. The currency contract will 20 | * require the "authority" of the exchange, but the exchange's init() function 21 | * configured this permission to allow *anyone* to transfer from the exchange. 22 | * 23 | * To prevent people from stealing all the money from the exchange, the 24 | * exchange's transfer handler requires both the authority of the receiver and 25 | * asserts that the user has a sufficient balance on the exchange. Lacking 26 | * both of these the exchange will kill the transfer. 27 | * 28 | * The exchange and one of the currency contracts are forced to execute in the same 29 | * thread anytime there is a deposit or withdraw. The transaction containing 30 | * the transfer are already required to include the exchange in the scope by 31 | * the currency contract. 32 | * 33 | * creating, canceling, and filling orders do not require blocking either currency 34 | * contract. Users can only deposit or withdraw to their own currency account. 35 | */ 36 | #include /// defines transfer struct 37 | #include 38 | 39 | using namespace exchange; 40 | using namespace eos; 41 | 42 | namespace exchange { 43 | inline void save( const Account& a ) { 44 | if( a.isEmpty() ) { 45 | print("remove"); 46 | Accounts::remove(a); 47 | } 48 | else { 49 | print("store"); 50 | Accounts::store(a); 51 | } 52 | } 53 | 54 | template 55 | inline void modifyAccount( AccountName a, Lambda&& modify ) { 56 | auto acnt = getAccount( a ); 57 | modify( acnt ); 58 | save( acnt ); 59 | } 60 | 61 | /** 62 | * This method is called after the "transfer" action of code 63 | * "currencya" is called and "exchange" is listed in the notifiers. 64 | */ 65 | void apply_currency_transfer( const currency::Transfer& transfer ) { 66 | if( transfer.to == N(exchange) ) { 67 | modifyAccount( transfer.from, [&]( Account& account ){ 68 | account.currency_balance += transfer.quantity; 69 | }); 70 | } else if( transfer.from == N(exchange) ) { 71 | requireAuth( transfer.to ); /// require the reciever of funds (account owner) to authorize this transfer 72 | 73 | modifyAccount( transfer.to, [&]( Account& account ){ 74 | account.currency_balance -= transfer.quantity; 75 | }); 76 | } else { 77 | assert( false, "notified on transfer that is not relevant to this exchange" ); 78 | } 79 | } 80 | 81 | /** 82 | * This method is called after the "transfer" action of code 83 | * "currencya" is called and "exchange" is listed in the notifiers. 84 | */ 85 | void apply_eos_transfer( const eos::Transfer& transfer ) { 86 | if( transfer.to == N(exchange) ) { 87 | modifyAccount( transfer.from, [&]( Account& account ){ 88 | account.eos_balance += transfer.quantity; 89 | }); 90 | } else if( transfer.from == N(exchange) ) { 91 | requireAuth( transfer.to ); /// require the reciever of funds (account owner) to authorize this transfer 92 | 93 | modifyAccount( transfer.to, [&]( Account& account ){ 94 | account.eos_balance -= transfer.quantity; 95 | }); 96 | } else { 97 | assert( false, "notified on transfer that is not relevant to this exchange" ); 98 | } 99 | } 100 | 101 | void match( Bid& bid, Account& buyer, Ask& ask, Account& seller ) { 102 | print( "match bid: ", bid, "\nmatch ask: ", ask, "\n"); 103 | 104 | eos::Tokens ask_eos = ask.quantity * ask.price; 105 | 106 | EosTokens fill_amount_eos = min( ask_eos, bid.quantity ); 107 | CurrencyTokens fill_amount_currency; 108 | 109 | if( fill_amount_eos == ask_eos ) { /// complete fill of ask 110 | fill_amount_currency = ask.quantity; 111 | } else { /// complete fill of buy 112 | fill_amount_currency = fill_amount_eos / ask.price; 113 | } 114 | 115 | print( "\n\nmatch bid: ", Name(bid.buyer.name), ":", bid.buyer.number, 116 | "match ask: ", Name(ask.seller.name), ":", ask.seller.number, "\n\n" ); 117 | 118 | 119 | bid.quantity -= fill_amount_eos; 120 | seller.eos_balance += fill_amount_eos; 121 | 122 | ask.quantity -= fill_amount_currency; 123 | buyer.currency_balance += fill_amount_currency; 124 | } 125 | 126 | /** 127 | * 128 | * 129 | */ 130 | void apply_exchange_buy( BuyOrder order ) { 131 | Bid& bid = order; 132 | requireAuth( bid.buyer.name ); 133 | 134 | assert( bid.quantity > eos::Tokens(0), "invalid quantity" ); 135 | assert( bid.expiration > now(), "order expired" ); 136 | 137 | print( Name(bid.buyer.name), " created bid for ", order.quantity, " currency at price: ", order.price, "\n" ); 138 | 139 | Bid existing_bid; 140 | assert( !BidsById::get( bid.buyer, existing_bid ), "order with this id already exists" ); 141 | print( __FILE__, __LINE__, "\n" ); 142 | 143 | auto buyer_account = getAccount( bid.buyer.name ); 144 | buyer_account.eos_balance -= bid.quantity; 145 | 146 | Ask lowest_ask; 147 | if( !AsksByPrice::front( lowest_ask ) ) { 148 | print( "\n No asks found, saving buyer account and storing bid\n" ); 149 | assert( !order.fill_or_kill, "order not completely filled" ); 150 | Bids::store( bid ); 151 | buyer_account.open_orders++; 152 | save( buyer_account ); 153 | return; 154 | } 155 | 156 | print( "ask: ", lowest_ask, "\n" ); 157 | print( "bid: ", bid, "\n" ); 158 | 159 | auto seller_account = getAccount( lowest_ask.seller.name ); 160 | 161 | while( lowest_ask.price <= bid.price ) { 162 | print( "lowest ask <= bid.price\n" ); 163 | match( bid, buyer_account, lowest_ask, seller_account ); 164 | 165 | if( lowest_ask.quantity == CurrencyTokens(0) ) { 166 | seller_account.open_orders--; 167 | save( seller_account ); 168 | save( buyer_account ); 169 | Asks::remove( lowest_ask ); 170 | if( !AsksByPrice::front( lowest_ask ) ) { 171 | break; 172 | } 173 | seller_account = getAccount( lowest_ask.seller.name ); 174 | } else { 175 | break; // buyer's bid should be filled 176 | } 177 | } 178 | print( "lowest_ask >= bid.price or buyer's bid has been filled\n" ); 179 | 180 | if( bid.quantity && !order.fill_or_kill ) buyer_account.open_orders++; 181 | save( buyer_account ); 182 | print( "saving buyer's account\n" ); 183 | if( bid.quantity ) { 184 | print( bid.quantity, " eos left over" ); 185 | assert( !order.fill_or_kill, "order not completely filled" ); 186 | Bids::store( bid ); 187 | return; 188 | } 189 | print( "bid filled\n" ); 190 | 191 | } 192 | 193 | void apply_exchange_sell( SellOrder order ) { 194 | Ask& ask = order; 195 | requireAuth( ask.seller.name ); 196 | 197 | assert( ask.quantity > CurrencyTokens(0), "invalid quantity" ); 198 | assert( ask.expiration > now(), "order expired" ); 199 | 200 | print( "\n\n", Name(ask.seller.name), " created sell for ", order.quantity, 201 | " currency at price: ", order.price, "\n"); 202 | 203 | Ask existing_ask; 204 | assert( !AsksById::get( ask.seller, existing_ask ), "order with this id already exists" ); 205 | 206 | auto seller_account = getAccount( ask.seller.name ); 207 | seller_account.currency_balance -= ask.quantity; 208 | 209 | 210 | Bid highest_bid; 211 | if( !BidsByPrice::back( highest_bid ) ) { 212 | assert( !order.fill_or_kill, "order not completely filled" ); 213 | print( "\n No bids found, saving seller account and storing ask\n" ); 214 | Asks::store( ask ); 215 | seller_account.open_orders++; 216 | save( seller_account ); 217 | return; 218 | } 219 | 220 | print( "\n bids found, lets see what matches\n" ); 221 | auto buyer_account = getAccount( highest_bid.buyer.name ); 222 | 223 | while( highest_bid.price >= ask.price ) { 224 | match( highest_bid, buyer_account, ask, seller_account ); 225 | 226 | if( highest_bid.quantity == EosTokens(0) ) { 227 | buyer_account.open_orders--; 228 | save( seller_account ); 229 | save( buyer_account ); 230 | Bids::remove( highest_bid ); 231 | if( !BidsByPrice::back( highest_bid ) ) { 232 | break; 233 | } 234 | buyer_account = getAccount( highest_bid.buyer.name ); 235 | } else { 236 | break; // buyer's bid should be filled 237 | } 238 | } 239 | 240 | if( ask.quantity && !order.fill_or_kill ) seller_account.open_orders++; 241 | save( seller_account ); 242 | if( ask.quantity ) { 243 | assert( !order.fill_or_kill, "order not completely filled" ); 244 | print( "saving ask\n" ); 245 | Asks::store( ask ); 246 | return; 247 | } 248 | 249 | print( "ask filled\n" ); 250 | } 251 | 252 | void apply_exchange_cancel_buy( OrderID order ) { 253 | requireAuth( order.name ); 254 | 255 | Bid bid_to_cancel; 256 | assert( BidsById::get( order, bid_to_cancel ), "bid with this id does not exists" ); 257 | 258 | auto buyer_account = getAccount( order.name ); 259 | buyer_account.eos_balance += bid_to_cancel.quantity; 260 | buyer_account.open_orders--; 261 | 262 | Bids::remove( bid_to_cancel ); 263 | save( buyer_account ); 264 | 265 | print( "bid removed\n" ); 266 | } 267 | 268 | void apply_exchange_cancel_sell( OrderID order ) { 269 | requireAuth( order.name ); 270 | 271 | Ask ask_to_cancel; 272 | assert( AsksById::get( order, ask_to_cancel ), "ask with this id does not exists" ); 273 | 274 | auto seller_account = getAccount( order.name ); 275 | seller_account.currency_balance += ask_to_cancel.quantity; 276 | seller_account.open_orders--; 277 | 278 | Asks::remove( ask_to_cancel ); 279 | save( seller_account ); 280 | 281 | print( "ask removed\n" ); 282 | } 283 | 284 | } // namespace exchange 285 | 286 | extern "C" { 287 | void init() { 288 | /* 289 | setAuthority( "currencya", "transfer", "anyone" ); 290 | setAuthority( "currencyb", "transfer", "anyone" ); 291 | registerHandler( "apply", "currencya", "transfer" ); 292 | registerHandler( "apply", "currencyb", "transfer" ); 293 | */ 294 | } 295 | 296 | // void validate( uint64_t code, uint64_t action ) { } 297 | // void precondition( uint64_t code, uint64_t action ) { } 298 | /** 299 | * The apply method implements the dispatch of events to this contract 300 | */ 301 | void apply( uint64_t code, uint64_t action ) { 302 | if( code == N(exchange) ) { 303 | switch( action ) { 304 | case N(buy): 305 | apply_exchange_buy( currentMessage() ); 306 | break; 307 | case N(sell): 308 | apply_exchange_sell( currentMessage() ); 309 | break; 310 | case N(cancelbuy): 311 | apply_exchange_cancel_buy( currentMessage() ); 312 | break; 313 | case N(cancelsell): 314 | apply_exchange_cancel_sell( currentMessage() ); 315 | break; 316 | default: 317 | assert( false, "unknown action" ); 318 | } 319 | } 320 | else if( code == N(currency) ) { 321 | if( action == N(transfer) ) 322 | apply_currency_transfer( currentMessage() ); 323 | } 324 | else if( code == N(eos) ) { 325 | if( action == N(transfer) ) 326 | apply_eos_transfer( currentMessage() ); 327 | } 328 | else { 329 | } 330 | } 331 | } 332 | -------------------------------------------------------------------------------- /exchange/exchange.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace exchange { 4 | 5 | using currency::CurrencyTokens; 6 | using EosTokens = eos::Tokens; 7 | using eos::AccountName; 8 | 9 | struct OrderID { 10 | AccountName name = 0; 11 | uint64_t number = 0; 12 | }; 13 | 14 | typedef eos::price Price; 15 | 16 | struct PACKED( Bid ) { 17 | OrderID buyer; 18 | Price price; 19 | eos::Tokens quantity; 20 | Time expiration; 21 | 22 | void print() { 23 | eos::print( "{ quantity: ", quantity, ", price: ", price, " }" ); 24 | } 25 | }; 26 | static_assert( sizeof(Bid) == 32+12, "unexpected padding" ); 27 | 28 | struct PACKED( Ask ) { 29 | OrderID seller; 30 | Price price; 31 | CurrencyTokens quantity; 32 | Time expiration; 33 | 34 | void print() { 35 | eos::print( "{ quantity: ", quantity, ", price: ", price, " }" ); 36 | } 37 | }; 38 | static_assert( sizeof(Ask) == 32+12, "unexpected padding" ); 39 | 40 | struct PACKED( Account ) { 41 | Account( AccountName o = AccountName() ):owner(o){} 42 | 43 | AccountName owner; 44 | EosTokens eos_balance; 45 | CurrencyTokens currency_balance; 46 | uint32_t open_orders = 0; 47 | 48 | bool isEmpty()const { return ! ( bool(eos_balance) | bool(currency_balance) | open_orders); } 49 | }; 50 | 51 | using Accounts = Table; 52 | 53 | TABLE2(Bids,exchange,exchange,bids,Bid,BidsById,OrderID,BidsByPrice,Price); 54 | TABLE2(Asks,exchange,exchange,asks,Ask,AsksById,OrderID,AsksByPrice,Price); 55 | 56 | 57 | struct BuyOrder : public Bid { uint8_t fill_or_kill = false; }; 58 | struct SellOrder : public Ask { uint8_t fill_or_kill = false; }; 59 | 60 | 61 | inline Account getAccount( AccountName owner ) { 62 | Account account(owner); 63 | Accounts::get( account ); 64 | return account; 65 | } 66 | } 67 | 68 | -------------------------------------------------------------------------------- /exchange/exchange.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (type $FUNCSIG$ijjjii (func (param i64 i64 i64 i32 i32) (result i32))) 3 | (type $FUNCSIG$vii (func (param i32 i32))) 4 | (type $FUNCSIG$vi (func (param i32))) 5 | (type $FUNCSIG$ijji (func (param i64 i64 i32) (result i32))) 6 | (type $FUNCSIG$ijjii (func (param i64 i64 i32 i32) (result i32))) 7 | (type $FUNCSIG$vj (func (param i64))) 8 | (type $FUNCSIG$i (func (result i32))) 9 | (type $FUNCSIG$iii (func (param i32 i32) (result i32))) 10 | (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) 11 | (import "env" "assert" (func $assert (param i32 i32))) 12 | (import "env" "back_secondary_i128i128" (func $back_secondary_i128i128 (param i64 i64 i64 i32 i32) (result i32))) 13 | (import "env" "diveq_i128" (func $diveq_i128 (param i32 i32))) 14 | (import "env" "front_secondary_i128i128" (func $front_secondary_i128i128 (param i64 i64 i64 i32 i32) (result i32))) 15 | (import "env" "load_i64" (func $load_i64 (param i64 i64 i64 i32 i32) (result i32))) 16 | (import "env" "load_primary_i128i128" (func $load_primary_i128i128 (param i64 i64 i64 i32 i32) (result i32))) 17 | (import "env" "memcpy" (func $memcpy (param i32 i32 i32) (result i32))) 18 | (import "env" "multeq_i128" (func $multeq_i128 (param i32 i32))) 19 | (import "env" "now" (func $now (result i32))) 20 | (import "env" "printi" (func $printi (param i64))) 21 | (import "env" "printi128" (func $printi128 (param i32))) 22 | (import "env" "printn" (func $printn (param i64))) 23 | (import "env" "prints" (func $prints (param i32))) 24 | (import "env" "readMessage" (func $readMessage (param i32 i32) (result i32))) 25 | (import "env" "remove_i128i128" (func $remove_i128i128 (param i64 i64 i32) (result i32))) 26 | (import "env" "remove_i64" (func $remove_i64 (param i64 i64 i32) (result i32))) 27 | (import "env" "requireAuth" (func $requireAuth (param i64))) 28 | (import "env" "store_i128i128" (func $store_i128i128 (param i64 i64 i32 i32) (result i32))) 29 | (import "env" "store_i64" (func $store_i64 (param i64 i64 i32 i32) (result i32))) 30 | (table 0 anyfunc) 31 | (memory $0 1) 32 | (data (i32.const 4) "\f0\t\00\00") 33 | (data (i32.const 16) "exchange\00") 34 | (data (i32.const 32) "integer overflow adding token balance\00") 35 | (data (i32.const 80) "remove\00") 36 | (data (i32.const 96) "store\00") 37 | (data (i32.const 112) "integer underflow subtracting token balance\00") 38 | (data (i32.const 160) "notified on transfer that is not relevant to this exchange\00") 39 | (data (i32.const 224) "match bid: \00") 40 | (data (i32.const 240) "{ quantity: \00") 41 | (data (i32.const 256) ", price: \00") 42 | (data (i32.const 272) " }\00") 43 | (data (i32.const 288) "\nmatch ask: \00") 44 | (data (i32.const 304) "\n\00") 45 | (data (i32.const 320) "\n\nmatch bid: \00") 46 | (data (i32.const 336) ":\00") 47 | (data (i32.const 352) "match ask: \00") 48 | (data (i32.const 368) "\n\n\00") 49 | (data (i32.const 384) "operator/ \00") 50 | (data (i32.const 400) " * \00") 51 | (data (i32.const 416) " / \00") 52 | (data (i32.const 432) "cast to 64 bit loss of precision\00") 53 | (data (i32.const 480) "b: \00") 54 | (data (i32.const 496) " \00") 55 | (data (i32.const 512) " \n\00") 56 | (data (i32.const 528) "operator* \00") 57 | (data (i32.const 544) ".\00") 58 | (data (i32.const 560) "/\00") 59 | (data (i32.const 576) "invalid quantity\00") 60 | (data (i32.const 608) "order expired\00") 61 | (data (i32.const 624) " created bid for \00") 62 | (data (i32.const 656) " currency at price: \00") 63 | (data (i32.const 688) "order with this id already exists\00") 64 | (data (i32.const 736) "/home/nathan/dev/eosio/eos/contracts/exchange/exchange.cpp\00") 65 | (data (i32.const 800) "\n No asks found, saving buyer account and storing bid\n\00") 66 | (data (i32.const 864) "order not completely filled\00") 67 | (data (i32.const 896) "error storing record\00") 68 | (data (i32.const 928) "ask: \00") 69 | (data (i32.const 944) "bid: \00") 70 | (data (i32.const 960) "lowest ask <= bid.price\n\00") 71 | (data (i32.const 992) "lowest_ask >= bid.price or buyer\'s bid has been filled\n\00") 72 | (data (i32.const 1056) "saving buyer\'s account\n\00") 73 | (data (i32.const 1088) " eos left over\00") 74 | (data (i32.const 1104) "bid filled\n\00") 75 | (data (i32.const 1120) " created sell for \00") 76 | (data (i32.const 1152) "\n No bids found, saving seller account and storing ask\n\00") 77 | (data (i32.const 1216) "\n bids found, lets see what matches\n\00") 78 | (data (i32.const 1264) "saving ask\n\00") 79 | (data (i32.const 1280) "ask filled\n\00") 80 | (data (i32.const 1296) "bid with this id does not exists\00") 81 | (data (i32.const 1344) "bid removed\n\00") 82 | (data (i32.const 1360) "ask with this id does not exists\00") 83 | (data (i32.const 1408) "ask removed\n\00") 84 | (data (i32.const 1424) "message shorter than expected\00") 85 | (data (i32.const 1456) "unknown action\00") 86 | (data (i32.const 1472) "currency\00") 87 | (data (i32.const 1488) "transfer\00") 88 | (data (i32.const 1504) "eos\00") 89 | (export "memory" (memory $0)) 90 | (export "_ZN8exchange23apply_currency_transferERKN8currency8TransferE" (func $_ZN8exchange23apply_currency_transferERKN8currency8TransferE)) 91 | (export "_ZN8exchange18apply_eos_transferERKN3eos8TransferE" (func $_ZN8exchange18apply_eos_transferERKN3eos8TransferE)) 92 | (export "_ZN8exchange5matchERNS_3BidERNS_7AccountERNS_3AskES3_" (func $_ZN8exchange5matchERNS_3BidERNS_7AccountERNS_3AskES3_)) 93 | (export "_ZN8exchange18apply_exchange_buyENS_8BuyOrderE" (func $_ZN8exchange18apply_exchange_buyENS_8BuyOrderE)) 94 | (export "_ZN8exchange19apply_exchange_sellENS_9SellOrderE" (func $_ZN8exchange19apply_exchange_sellENS_9SellOrderE)) 95 | (export "_ZN8exchange25apply_exchange_cancel_buyENS_7OrderIDE" (func $_ZN8exchange25apply_exchange_cancel_buyENS_7OrderIDE)) 96 | (export "_ZN8exchange26apply_exchange_cancel_sellENS_7OrderIDE" (func $_ZN8exchange26apply_exchange_cancel_sellENS_7OrderIDE)) 97 | (export "init" (func $init)) 98 | (export "apply" (func $apply)) 99 | (func $_ZN8exchange23apply_currency_transferERKN8currency8TransferE (param $0 i32) 100 | (local $1 i64) 101 | (local $2 i32) 102 | (local $3 i64) 103 | (local $4 i32) 104 | (local $5 i64) 105 | (local $6 i64) 106 | (local $7 i64) 107 | (local $8 i64) 108 | (local $9 i32) 109 | (i32.store offset=4 110 | (i32.const 0) 111 | (tee_local $9 112 | (i32.sub 113 | (i32.load offset=4 114 | (i32.const 0) 115 | ) 116 | (i32.const 32) 117 | ) 118 | ) 119 | ) 120 | (set_local $1 121 | (i64.load offset=8 122 | (get_local $0) 123 | ) 124 | ) 125 | (set_local $6 126 | (i64.const 0) 127 | ) 128 | (set_local $5 129 | (i64.const 59) 130 | ) 131 | (set_local $4 132 | (i32.const 16) 133 | ) 134 | (set_local $7 135 | (i64.const 0) 136 | ) 137 | (loop $label$0 138 | (block $label$1 139 | (block $label$2 140 | (block $label$3 141 | (block $label$4 142 | (block $label$5 143 | (br_if $label$5 144 | (i64.gt_u 145 | (get_local $6) 146 | (i64.const 7) 147 | ) 148 | ) 149 | (br_if $label$4 150 | (i32.gt_u 151 | (i32.and 152 | (i32.add 153 | (tee_local $2 154 | (i32.load8_s 155 | (get_local $4) 156 | ) 157 | ) 158 | (i32.const -97) 159 | ) 160 | (i32.const 255) 161 | ) 162 | (i32.const 25) 163 | ) 164 | ) 165 | (set_local $2 166 | (i32.add 167 | (get_local $2) 168 | (i32.const 160) 169 | ) 170 | ) 171 | (br $label$3) 172 | ) 173 | (set_local $8 174 | (i64.const 0) 175 | ) 176 | (br_if $label$2 177 | (i64.le_u 178 | (get_local $6) 179 | (i64.const 11) 180 | ) 181 | ) 182 | (br $label$1) 183 | ) 184 | (set_local $2 185 | (select 186 | (i32.add 187 | (get_local $2) 188 | (i32.const 234) 189 | ) 190 | (i32.const 0) 191 | (i32.lt_u 192 | (i32.and 193 | (i32.add 194 | (get_local $2) 195 | (i32.const -49) 196 | ) 197 | (i32.const 255) 198 | ) 199 | (i32.const 5) 200 | ) 201 | ) 202 | ) 203 | ) 204 | (set_local $8 205 | (i64.shr_s 206 | (i64.shl 207 | (i64.extend_u/i32 208 | (get_local $2) 209 | ) 210 | (i64.const 56) 211 | ) 212 | (i64.const 56) 213 | ) 214 | ) 215 | ) 216 | (set_local $8 217 | (i64.shl 218 | (i64.and 219 | (get_local $8) 220 | (i64.const 31) 221 | ) 222 | (i64.and 223 | (get_local $5) 224 | (i64.const 4294967295) 225 | ) 226 | ) 227 | ) 228 | ) 229 | (set_local $4 230 | (i32.add 231 | (get_local $4) 232 | (i32.const 1) 233 | ) 234 | ) 235 | (set_local $6 236 | (i64.add 237 | (get_local $6) 238 | (i64.const 1) 239 | ) 240 | ) 241 | (set_local $7 242 | (i64.or 243 | (get_local $8) 244 | (get_local $7) 245 | ) 246 | ) 247 | (br_if $label$0 248 | (i64.ne 249 | (tee_local $5 250 | (i64.add 251 | (get_local $5) 252 | (i64.const -5) 253 | ) 254 | ) 255 | (i64.const -6) 256 | ) 257 | ) 258 | ) 259 | (set_local $3 260 | (i64.load 261 | (get_local $0) 262 | ) 263 | ) 264 | (block $label$6 265 | (block $label$7 266 | (block $label$8 267 | (block $label$9 268 | (br_if $label$9 269 | (i64.ne 270 | (get_local $1) 271 | (get_local $7) 272 | ) 273 | ) 274 | (i64.store offset=8 275 | (get_local $9) 276 | (i64.const 0) 277 | ) 278 | (i64.store 279 | (get_local $9) 280 | (get_local $3) 281 | ) 282 | (i64.store offset=16 283 | (get_local $9) 284 | (i64.const 0) 285 | ) 286 | (i32.store offset=24 287 | (get_local $9) 288 | (i32.const 0) 289 | ) 290 | (drop 291 | (call $load_i64 292 | (i64.const 3316479707209269248) 293 | (i64.const 3316479707209269248) 294 | (i64.const 632468476610478080) 295 | (get_local $9) 296 | (i32.const 28) 297 | ) 298 | ) 299 | (call $assert 300 | (i64.ge_u 301 | (i64.add 302 | (tee_local $6 303 | (i64.load offset=16 304 | (get_local $0) 305 | ) 306 | ) 307 | (i64.load offset=16 308 | (get_local $9) 309 | ) 310 | ) 311 | (get_local $6) 312 | ) 313 | (i32.const 32) 314 | ) 315 | (i64.store offset=16 316 | (get_local $9) 317 | (tee_local $6 318 | (i64.add 319 | (i64.load offset=16 320 | (get_local $9) 321 | ) 322 | (i64.load offset=16 323 | (get_local $0) 324 | ) 325 | ) 326 | ) 327 | ) 328 | (br_if $label$8 329 | (i32.eqz 330 | (i32.or 331 | (i64.ne 332 | (i64.or 333 | (i64.load offset=8 334 | (get_local $9) 335 | ) 336 | (get_local $6) 337 | ) 338 | (i64.const 0) 339 | ) 340 | (i32.load offset=24 341 | (get_local $9) 342 | ) 343 | ) 344 | ) 345 | ) 346 | (call $prints 347 | (i32.const 96) 348 | ) 349 | (drop 350 | (call $store_i64 351 | (i64.const 3316479707209269248) 352 | (i64.const 632468476610478080) 353 | (get_local $9) 354 | (i32.const 28) 355 | ) 356 | ) 357 | (br $label$6) 358 | ) 359 | (set_local $6 360 | (i64.const 0) 361 | ) 362 | (set_local $5 363 | (i64.const 59) 364 | ) 365 | (set_local $4 366 | (i32.const 16) 367 | ) 368 | (set_local $7 369 | (i64.const 0) 370 | ) 371 | (loop $label$10 372 | (block $label$11 373 | (block $label$12 374 | (block $label$13 375 | (block $label$14 376 | (block $label$15 377 | (br_if $label$15 378 | (i64.gt_u 379 | (get_local $6) 380 | (i64.const 7) 381 | ) 382 | ) 383 | (br_if $label$14 384 | (i32.gt_u 385 | (i32.and 386 | (i32.add 387 | (tee_local $2 388 | (i32.load8_s 389 | (get_local $4) 390 | ) 391 | ) 392 | (i32.const -97) 393 | ) 394 | (i32.const 255) 395 | ) 396 | (i32.const 25) 397 | ) 398 | ) 399 | (set_local $2 400 | (i32.add 401 | (get_local $2) 402 | (i32.const 160) 403 | ) 404 | ) 405 | (br $label$13) 406 | ) 407 | (set_local $8 408 | (i64.const 0) 409 | ) 410 | (br_if $label$12 411 | (i64.le_u 412 | (get_local $6) 413 | (i64.const 11) 414 | ) 415 | ) 416 | (br $label$11) 417 | ) 418 | (set_local $2 419 | (select 420 | (i32.add 421 | (get_local $2) 422 | (i32.const 234) 423 | ) 424 | (i32.const 0) 425 | (i32.lt_u 426 | (i32.and 427 | (i32.add 428 | (get_local $2) 429 | (i32.const -49) 430 | ) 431 | (i32.const 255) 432 | ) 433 | (i32.const 5) 434 | ) 435 | ) 436 | ) 437 | ) 438 | (set_local $8 439 | (i64.shr_s 440 | (i64.shl 441 | (i64.extend_u/i32 442 | (get_local $2) 443 | ) 444 | (i64.const 56) 445 | ) 446 | (i64.const 56) 447 | ) 448 | ) 449 | ) 450 | (set_local $8 451 | (i64.shl 452 | (i64.and 453 | (get_local $8) 454 | (i64.const 31) 455 | ) 456 | (i64.and 457 | (get_local $5) 458 | (i64.const 4294967295) 459 | ) 460 | ) 461 | ) 462 | ) 463 | (set_local $4 464 | (i32.add 465 | (get_local $4) 466 | (i32.const 1) 467 | ) 468 | ) 469 | (set_local $6 470 | (i64.add 471 | (get_local $6) 472 | (i64.const 1) 473 | ) 474 | ) 475 | (set_local $7 476 | (i64.or 477 | (get_local $8) 478 | (get_local $7) 479 | ) 480 | ) 481 | (br_if $label$10 482 | (i64.ne 483 | (tee_local $5 484 | (i64.add 485 | (get_local $5) 486 | (i64.const -5) 487 | ) 488 | ) 489 | (i64.const -6) 490 | ) 491 | ) 492 | ) 493 | (block $label$16 494 | (br_if $label$16 495 | (i64.ne 496 | (get_local $3) 497 | (get_local $7) 498 | ) 499 | ) 500 | (call $requireAuth 501 | (get_local $1) 502 | ) 503 | (set_local $6 504 | (i64.load 505 | (i32.add 506 | (get_local $0) 507 | (i32.const 8) 508 | ) 509 | ) 510 | ) 511 | (i64.store offset=8 512 | (get_local $9) 513 | (i64.const 0) 514 | ) 515 | (i64.store 516 | (get_local $9) 517 | (get_local $6) 518 | ) 519 | (i64.store offset=16 520 | (get_local $9) 521 | (i64.const 0) 522 | ) 523 | (i32.store offset=24 524 | (get_local $9) 525 | (i32.const 0) 526 | ) 527 | (drop 528 | (call $load_i64 529 | (i64.const 3316479707209269248) 530 | (i64.const 3316479707209269248) 531 | (i64.const 632468476610478080) 532 | (get_local $9) 533 | (i32.const 28) 534 | ) 535 | ) 536 | (call $assert 537 | (i64.ge_u 538 | (i64.load offset=16 539 | (get_local $9) 540 | ) 541 | (i64.load offset=16 542 | (get_local $0) 543 | ) 544 | ) 545 | (i32.const 112) 546 | ) 547 | (i64.store offset=16 548 | (get_local $9) 549 | (tee_local $6 550 | (i64.sub 551 | (i64.load offset=16 552 | (get_local $9) 553 | ) 554 | (i64.load offset=16 555 | (get_local $0) 556 | ) 557 | ) 558 | ) 559 | ) 560 | (br_if $label$7 561 | (i32.eqz 562 | (i32.or 563 | (i64.ne 564 | (i64.or 565 | (i64.load offset=8 566 | (get_local $9) 567 | ) 568 | (get_local $6) 569 | ) 570 | (i64.const 0) 571 | ) 572 | (i32.load offset=24 573 | (get_local $9) 574 | ) 575 | ) 576 | ) 577 | ) 578 | (call $prints 579 | (i32.const 96) 580 | ) 581 | (drop 582 | (call $store_i64 583 | (i64.const 3316479707209269248) 584 | (i64.const 632468476610478080) 585 | (get_local $9) 586 | (i32.const 28) 587 | ) 588 | ) 589 | (br $label$6) 590 | ) 591 | (call $assert 592 | (i32.const 0) 593 | (i32.const 160) 594 | ) 595 | (br $label$6) 596 | ) 597 | (call $prints 598 | (i32.const 80) 599 | ) 600 | (drop 601 | (call $remove_i64 602 | (i64.const 3316479707209269248) 603 | (i64.const 632468476610478080) 604 | (get_local $9) 605 | ) 606 | ) 607 | (br $label$6) 608 | ) 609 | (call $prints 610 | (i32.const 80) 611 | ) 612 | (drop 613 | (call $remove_i64 614 | (i64.const 3316479707209269248) 615 | (i64.const 632468476610478080) 616 | (get_local $9) 617 | ) 618 | ) 619 | ) 620 | (i32.store offset=4 621 | (i32.const 0) 622 | (i32.add 623 | (get_local $9) 624 | (i32.const 32) 625 | ) 626 | ) 627 | ) 628 | (func $_ZN8exchange18apply_eos_transferERKN3eos8TransferE (param $0 i32) 629 | (local $1 i64) 630 | (local $2 i32) 631 | (local $3 i64) 632 | (local $4 i32) 633 | (local $5 i64) 634 | (local $6 i64) 635 | (local $7 i64) 636 | (local $8 i64) 637 | (local $9 i32) 638 | (i32.store offset=4 639 | (i32.const 0) 640 | (tee_local $9 641 | (i32.sub 642 | (i32.load offset=4 643 | (i32.const 0) 644 | ) 645 | (i32.const 32) 646 | ) 647 | ) 648 | ) 649 | (set_local $1 650 | (i64.load offset=8 651 | (get_local $0) 652 | ) 653 | ) 654 | (set_local $6 655 | (i64.const 0) 656 | ) 657 | (set_local $5 658 | (i64.const 59) 659 | ) 660 | (set_local $4 661 | (i32.const 16) 662 | ) 663 | (set_local $7 664 | (i64.const 0) 665 | ) 666 | (loop $label$0 667 | (block $label$1 668 | (block $label$2 669 | (block $label$3 670 | (block $label$4 671 | (block $label$5 672 | (br_if $label$5 673 | (i64.gt_u 674 | (get_local $6) 675 | (i64.const 7) 676 | ) 677 | ) 678 | (br_if $label$4 679 | (i32.gt_u 680 | (i32.and 681 | (i32.add 682 | (tee_local $2 683 | (i32.load8_s 684 | (get_local $4) 685 | ) 686 | ) 687 | (i32.const -97) 688 | ) 689 | (i32.const 255) 690 | ) 691 | (i32.const 25) 692 | ) 693 | ) 694 | (set_local $2 695 | (i32.add 696 | (get_local $2) 697 | (i32.const 160) 698 | ) 699 | ) 700 | (br $label$3) 701 | ) 702 | (set_local $8 703 | (i64.const 0) 704 | ) 705 | (br_if $label$2 706 | (i64.le_u 707 | (get_local $6) 708 | (i64.const 11) 709 | ) 710 | ) 711 | (br $label$1) 712 | ) 713 | (set_local $2 714 | (select 715 | (i32.add 716 | (get_local $2) 717 | (i32.const 234) 718 | ) 719 | (i32.const 0) 720 | (i32.lt_u 721 | (i32.and 722 | (i32.add 723 | (get_local $2) 724 | (i32.const -49) 725 | ) 726 | (i32.const 255) 727 | ) 728 | (i32.const 5) 729 | ) 730 | ) 731 | ) 732 | ) 733 | (set_local $8 734 | (i64.shr_s 735 | (i64.shl 736 | (i64.extend_u/i32 737 | (get_local $2) 738 | ) 739 | (i64.const 56) 740 | ) 741 | (i64.const 56) 742 | ) 743 | ) 744 | ) 745 | (set_local $8 746 | (i64.shl 747 | (i64.and 748 | (get_local $8) 749 | (i64.const 31) 750 | ) 751 | (i64.and 752 | (get_local $5) 753 | (i64.const 4294967295) 754 | ) 755 | ) 756 | ) 757 | ) 758 | (set_local $4 759 | (i32.add 760 | (get_local $4) 761 | (i32.const 1) 762 | ) 763 | ) 764 | (set_local $6 765 | (i64.add 766 | (get_local $6) 767 | (i64.const 1) 768 | ) 769 | ) 770 | (set_local $7 771 | (i64.or 772 | (get_local $8) 773 | (get_local $7) 774 | ) 775 | ) 776 | (br_if $label$0 777 | (i64.ne 778 | (tee_local $5 779 | (i64.add 780 | (get_local $5) 781 | (i64.const -5) 782 | ) 783 | ) 784 | (i64.const -6) 785 | ) 786 | ) 787 | ) 788 | (set_local $3 789 | (i64.load 790 | (get_local $0) 791 | ) 792 | ) 793 | (block $label$6 794 | (block $label$7 795 | (block $label$8 796 | (block $label$9 797 | (br_if $label$9 798 | (i64.ne 799 | (get_local $1) 800 | (get_local $7) 801 | ) 802 | ) 803 | (i64.store offset=8 804 | (get_local $9) 805 | (i64.const 0) 806 | ) 807 | (i64.store 808 | (get_local $9) 809 | (get_local $3) 810 | ) 811 | (i64.store offset=16 812 | (get_local $9) 813 | (i64.const 0) 814 | ) 815 | (i32.store offset=24 816 | (get_local $9) 817 | (i32.const 0) 818 | ) 819 | (drop 820 | (call $load_i64 821 | (i64.const 3316479707209269248) 822 | (i64.const 3316479707209269248) 823 | (i64.const 632468476610478080) 824 | (get_local $9) 825 | (i32.const 28) 826 | ) 827 | ) 828 | (call $assert 829 | (i64.ge_u 830 | (i64.add 831 | (tee_local $6 832 | (i64.load offset=16 833 | (get_local $0) 834 | ) 835 | ) 836 | (i64.load offset=8 837 | (get_local $9) 838 | ) 839 | ) 840 | (get_local $6) 841 | ) 842 | (i32.const 32) 843 | ) 844 | (i64.store offset=8 845 | (get_local $9) 846 | (tee_local $6 847 | (i64.add 848 | (i64.load offset=8 849 | (get_local $9) 850 | ) 851 | (i64.load offset=16 852 | (get_local $0) 853 | ) 854 | ) 855 | ) 856 | ) 857 | (br_if $label$8 858 | (i32.eqz 859 | (i32.or 860 | (i64.ne 861 | (i64.or 862 | (i64.load offset=16 863 | (get_local $9) 864 | ) 865 | (get_local $6) 866 | ) 867 | (i64.const 0) 868 | ) 869 | (i32.load offset=24 870 | (get_local $9) 871 | ) 872 | ) 873 | ) 874 | ) 875 | (call $prints 876 | (i32.const 96) 877 | ) 878 | (drop 879 | (call $store_i64 880 | (i64.const 3316479707209269248) 881 | (i64.const 632468476610478080) 882 | (get_local $9) 883 | (i32.const 28) 884 | ) 885 | ) 886 | (br $label$6) 887 | ) 888 | (set_local $6 889 | (i64.const 0) 890 | ) 891 | (set_local $5 892 | (i64.const 59) 893 | ) 894 | (set_local $4 895 | (i32.const 16) 896 | ) 897 | (set_local $7 898 | (i64.const 0) 899 | ) 900 | (loop $label$10 901 | (block $label$11 902 | (block $label$12 903 | (block $label$13 904 | (block $label$14 905 | (block $label$15 906 | (br_if $label$15 907 | (i64.gt_u 908 | (get_local $6) 909 | (i64.const 7) 910 | ) 911 | ) 912 | (br_if $label$14 913 | (i32.gt_u 914 | (i32.and 915 | (i32.add 916 | (tee_local $2 917 | (i32.load8_s 918 | (get_local $4) 919 | ) 920 | ) 921 | (i32.const -97) 922 | ) 923 | (i32.const 255) 924 | ) 925 | (i32.const 25) 926 | ) 927 | ) 928 | (set_local $2 929 | (i32.add 930 | (get_local $2) 931 | (i32.const 160) 932 | ) 933 | ) 934 | (br $label$13) 935 | ) 936 | (set_local $8 937 | (i64.const 0) 938 | ) 939 | (br_if $label$12 940 | (i64.le_u 941 | (get_local $6) 942 | (i64.const 11) 943 | ) 944 | ) 945 | (br $label$11) 946 | ) 947 | (set_local $2 948 | (select 949 | (i32.add 950 | (get_local $2) 951 | (i32.const 234) 952 | ) 953 | (i32.const 0) 954 | (i32.lt_u 955 | (i32.and 956 | (i32.add 957 | (get_local $2) 958 | (i32.const -49) 959 | ) 960 | (i32.const 255) 961 | ) 962 | (i32.const 5) 963 | ) 964 | ) 965 | ) 966 | ) 967 | (set_local $8 968 | (i64.shr_s 969 | (i64.shl 970 | (i64.extend_u/i32 971 | (get_local $2) 972 | ) 973 | (i64.const 56) 974 | ) 975 | (i64.const 56) 976 | ) 977 | ) 978 | ) 979 | (set_local $8 980 | (i64.shl 981 | (i64.and 982 | (get_local $8) 983 | (i64.const 31) 984 | ) 985 | (i64.and 986 | (get_local $5) 987 | (i64.const 4294967295) 988 | ) 989 | ) 990 | ) 991 | ) 992 | (set_local $4 993 | (i32.add 994 | (get_local $4) 995 | (i32.const 1) 996 | ) 997 | ) 998 | (set_local $6 999 | (i64.add 1000 | (get_local $6) 1001 | (i64.const 1) 1002 | ) 1003 | ) 1004 | (set_local $7 1005 | (i64.or 1006 | (get_local $8) 1007 | (get_local $7) 1008 | ) 1009 | ) 1010 | (br_if $label$10 1011 | (i64.ne 1012 | (tee_local $5 1013 | (i64.add 1014 | (get_local $5) 1015 | (i64.const -5) 1016 | ) 1017 | ) 1018 | (i64.const -6) 1019 | ) 1020 | ) 1021 | ) 1022 | (block $label$16 1023 | (br_if $label$16 1024 | (i64.ne 1025 | (get_local $3) 1026 | (get_local $7) 1027 | ) 1028 | ) 1029 | (call $requireAuth 1030 | (get_local $1) 1031 | ) 1032 | (set_local $6 1033 | (i64.load 1034 | (i32.add 1035 | (get_local $0) 1036 | (i32.const 8) 1037 | ) 1038 | ) 1039 | ) 1040 | (i64.store offset=8 1041 | (get_local $9) 1042 | (i64.const 0) 1043 | ) 1044 | (i64.store 1045 | (get_local $9) 1046 | (get_local $6) 1047 | ) 1048 | (i64.store offset=16 1049 | (get_local $9) 1050 | (i64.const 0) 1051 | ) 1052 | (i32.store offset=24 1053 | (get_local $9) 1054 | (i32.const 0) 1055 | ) 1056 | (drop 1057 | (call $load_i64 1058 | (i64.const 3316479707209269248) 1059 | (i64.const 3316479707209269248) 1060 | (i64.const 632468476610478080) 1061 | (get_local $9) 1062 | (i32.const 28) 1063 | ) 1064 | ) 1065 | (call $assert 1066 | (i64.ge_u 1067 | (i64.load offset=8 1068 | (get_local $9) 1069 | ) 1070 | (i64.load offset=16 1071 | (get_local $0) 1072 | ) 1073 | ) 1074 | (i32.const 112) 1075 | ) 1076 | (i64.store offset=8 1077 | (get_local $9) 1078 | (tee_local $6 1079 | (i64.sub 1080 | (i64.load offset=8 1081 | (get_local $9) 1082 | ) 1083 | (i64.load offset=16 1084 | (get_local $0) 1085 | ) 1086 | ) 1087 | ) 1088 | ) 1089 | (br_if $label$7 1090 | (i32.eqz 1091 | (i32.or 1092 | (i64.ne 1093 | (i64.or 1094 | (i64.load offset=16 1095 | (get_local $9) 1096 | ) 1097 | (get_local $6) 1098 | ) 1099 | (i64.const 0) 1100 | ) 1101 | (i32.load offset=24 1102 | (get_local $9) 1103 | ) 1104 | ) 1105 | ) 1106 | ) 1107 | (call $prints 1108 | (i32.const 96) 1109 | ) 1110 | (drop 1111 | (call $store_i64 1112 | (i64.const 3316479707209269248) 1113 | (i64.const 632468476610478080) 1114 | (get_local $9) 1115 | (i32.const 28) 1116 | ) 1117 | ) 1118 | (br $label$6) 1119 | ) 1120 | (call $assert 1121 | (i32.const 0) 1122 | (i32.const 160) 1123 | ) 1124 | (br $label$6) 1125 | ) 1126 | (call $prints 1127 | (i32.const 80) 1128 | ) 1129 | (drop 1130 | (call $remove_i64 1131 | (i64.const 3316479707209269248) 1132 | (i64.const 632468476610478080) 1133 | (get_local $9) 1134 | ) 1135 | ) 1136 | (br $label$6) 1137 | ) 1138 | (call $prints 1139 | (i32.const 80) 1140 | ) 1141 | (drop 1142 | (call $remove_i64 1143 | (i64.const 3316479707209269248) 1144 | (i64.const 632468476610478080) 1145 | (get_local $9) 1146 | ) 1147 | ) 1148 | ) 1149 | (i32.store offset=4 1150 | (i32.const 0) 1151 | (i32.add 1152 | (get_local $9) 1153 | (i32.const 32) 1154 | ) 1155 | ) 1156 | ) 1157 | (func $_ZN8exchange5matchERNS_3BidERNS_7AccountERNS_3AskES3_ (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) 1158 | (local $4 i32) 1159 | (local $5 i32) 1160 | (local $6 i64) 1161 | (local $7 i64) 1162 | (local $8 i64) 1163 | (local $9 i64) 1164 | (local $10 i64) 1165 | (local $11 i64) 1166 | (local $12 i32) 1167 | (i32.store offset=4 1168 | (i32.const 0) 1169 | (tee_local $12 1170 | (i32.sub 1171 | (i32.load offset=4 1172 | (i32.const 0) 1173 | ) 1174 | (i32.const 16) 1175 | ) 1176 | ) 1177 | ) 1178 | (set_local $6 1179 | (i64.load align=1 1180 | (i32.add 1181 | (get_local $2) 1182 | (i32.const 24) 1183 | ) 1184 | ) 1185 | ) 1186 | (set_local $11 1187 | (i64.load align=1 1188 | (i32.add 1189 | (get_local $0) 1190 | (i32.const 24) 1191 | ) 1192 | ) 1193 | ) 1194 | (set_local $7 1195 | (i64.load offset=16 align=1 1196 | (get_local $2) 1197 | ) 1198 | ) 1199 | (set_local $8 1200 | (i64.load offset=32 align=1 1201 | (get_local $2) 1202 | ) 1203 | ) 1204 | (set_local $9 1205 | (i64.load offset=16 align=1 1206 | (get_local $0) 1207 | ) 1208 | ) 1209 | (set_local $10 1210 | (i64.load offset=32 align=1 1211 | (get_local $0) 1212 | ) 1213 | ) 1214 | (call $prints 1215 | (i32.const 224) 1216 | ) 1217 | (call $_ZN3eos5printIPKcJNS_5tokenIyLy3163215788274352128EEES2_NS_5priceIS4_NS3_IyLy2118137375447056384EEEEES2_EEEvT_DpT0_ 1218 | (i32.const 240) 1219 | (get_local $10) 1220 | (i32.const 256) 1221 | (get_local $9) 1222 | (get_local $11) 1223 | (i32.const 272) 1224 | ) 1225 | (call $prints 1226 | (i32.const 288) 1227 | ) 1228 | (call $_ZN3eos5printIPKcJNS_5tokenIyLy2118137375447056384EEES2_NS_5priceINS3_IyLy3163215788274352128EEES4_EES2_EEEvT_DpT0_ 1229 | (i32.const 240) 1230 | (get_local $8) 1231 | (i32.const 256) 1232 | (get_local $7) 1233 | (get_local $6) 1234 | (i32.const 272) 1235 | ) 1236 | (call $prints 1237 | (i32.const 304) 1238 | ) 1239 | (i64.store offset=8 1240 | (get_local $12) 1241 | (tee_local $11 1242 | (call $_ZN3eosmlERKNS_5tokenIyLy2118137375447056384EEERKNS_5priceINS0_IyLy3163215788274352128EEES1_EE 1243 | (tee_local $4 1244 | (i32.add 1245 | (get_local $2) 1246 | (i32.const 32) 1247 | ) 1248 | ) 1249 | (tee_local $5 1250 | (i32.add 1251 | (get_local $2) 1252 | (i32.const 16) 1253 | ) 1254 | ) 1255 | ) 1256 | ) 1257 | ) 1258 | (block $label$0 1259 | (block $label$1 1260 | (br_if $label$1 1261 | (i64.ne 1262 | (get_local $11) 1263 | (tee_local $6 1264 | (i64.load 1265 | (select 1266 | (i32.add 1267 | (get_local $12) 1268 | (i32.const 8) 1269 | ) 1270 | (i32.add 1271 | (get_local $0) 1272 | (i32.const 32) 1273 | ) 1274 | (i64.lt_u 1275 | (get_local $11) 1276 | (i64.load offset=32 1277 | (get_local $0) 1278 | ) 1279 | ) 1280 | ) 1281 | ) 1282 | ) 1283 | ) 1284 | ) 1285 | (set_local $11 1286 | (i64.load 1287 | (get_local $4) 1288 | ) 1289 | ) 1290 | (br $label$0) 1291 | ) 1292 | (set_local $11 1293 | (call $_ZN3eosdvENS_5tokenIyLy3163215788274352128EEERKNS_5priceIS1_NS0_IyLy2118137375447056384EEEEE 1294 | (get_local $6) 1295 | (get_local $5) 1296 | ) 1297 | ) 1298 | ) 1299 | (set_local $7 1300 | (i64.load offset=8 align=1 1301 | (get_local $2) 1302 | ) 1303 | ) 1304 | (set_local $8 1305 | (i64.load align=1 1306 | (get_local $2) 1307 | ) 1308 | ) 1309 | (set_local $9 1310 | (i64.load offset=8 align=1 1311 | (get_local $0) 1312 | ) 1313 | ) 1314 | (set_local $10 1315 | (i64.load align=1 1316 | (get_local $0) 1317 | ) 1318 | ) 1319 | (call $prints 1320 | (i32.const 320) 1321 | ) 1322 | (call $printn 1323 | (get_local $10) 1324 | ) 1325 | (call $prints 1326 | (i32.const 336) 1327 | ) 1328 | (call $printi 1329 | (get_local $9) 1330 | ) 1331 | (call $prints 1332 | (i32.const 352) 1333 | ) 1334 | (call $printn 1335 | (get_local $8) 1336 | ) 1337 | (call $prints 1338 | (i32.const 336) 1339 | ) 1340 | (call $printi 1341 | (get_local $7) 1342 | ) 1343 | (call $prints 1344 | (i32.const 368) 1345 | ) 1346 | (call $assert 1347 | (i64.ge_u 1348 | (i64.load 1349 | (tee_local $0 1350 | (i32.add 1351 | (get_local $0) 1352 | (i32.const 32) 1353 | ) 1354 | ) 1355 | ) 1356 | (get_local $6) 1357 | ) 1358 | (i32.const 112) 1359 | ) 1360 | (i64.store 1361 | (get_local $0) 1362 | (i64.sub 1363 | (i64.load 1364 | (get_local $0) 1365 | ) 1366 | (get_local $6) 1367 | ) 1368 | ) 1369 | (call $assert 1370 | (i64.ge_u 1371 | (i64.add 1372 | (i64.load offset=8 1373 | (get_local $3) 1374 | ) 1375 | (get_local $6) 1376 | ) 1377 | (get_local $6) 1378 | ) 1379 | (i32.const 32) 1380 | ) 1381 | (i64.store offset=8 1382 | (get_local $3) 1383 | (i64.add 1384 | (i64.load offset=8 1385 | (get_local $3) 1386 | ) 1387 | (get_local $6) 1388 | ) 1389 | ) 1390 | (call $assert 1391 | (i64.ge_u 1392 | (i64.load 1393 | (tee_local $0 1394 | (i32.add 1395 | (get_local $2) 1396 | (i32.const 32) 1397 | ) 1398 | ) 1399 | ) 1400 | (get_local $11) 1401 | ) 1402 | (i32.const 112) 1403 | ) 1404 | (i64.store 1405 | (get_local $0) 1406 | (i64.sub 1407 | (i64.load 1408 | (get_local $0) 1409 | ) 1410 | (get_local $11) 1411 | ) 1412 | ) 1413 | (call $assert 1414 | (i64.ge_u 1415 | (i64.add 1416 | (i64.load offset=16 1417 | (get_local $1) 1418 | ) 1419 | (get_local $11) 1420 | ) 1421 | (get_local $11) 1422 | ) 1423 | (i32.const 32) 1424 | ) 1425 | (i64.store offset=16 1426 | (get_local $1) 1427 | (i64.add 1428 | (i64.load offset=16 1429 | (get_local $1) 1430 | ) 1431 | (get_local $11) 1432 | ) 1433 | ) 1434 | (i32.store offset=4 1435 | (i32.const 0) 1436 | (i32.add 1437 | (get_local $12) 1438 | (i32.const 16) 1439 | ) 1440 | ) 1441 | ) 1442 | (func $_ZN3eos5printIPKcJNS_5tokenIyLy3163215788274352128EEES2_NS_5priceIS4_NS3_IyLy2118137375447056384EEEEES2_EEEvT_DpT0_ (param $0 i32) (param $1 i64) (param $2 i32) (param $3 i64) (param $4 i64) (param $5 i32) 1443 | (local $6 i32) 1444 | (i32.store offset=4 1445 | (i32.const 0) 1446 | (tee_local $6 1447 | (i32.sub 1448 | (i32.load offset=4 1449 | (i32.const 0) 1450 | ) 1451 | (i32.const 16) 1452 | ) 1453 | ) 1454 | ) 1455 | (call $prints 1456 | (get_local $0) 1457 | ) 1458 | (call $printi 1459 | (get_local $1) 1460 | ) 1461 | (call $prints 1462 | (i32.const 496) 1463 | ) 1464 | (call $printn 1465 | (i64.const 3163215788274352128) 1466 | ) 1467 | (call $prints 1468 | (get_local $2) 1469 | ) 1470 | (i64.store offset=8 1471 | (get_local $6) 1472 | (get_local $4) 1473 | ) 1474 | (i64.store 1475 | (get_local $6) 1476 | (get_local $3) 1477 | ) 1478 | (call $printi128 1479 | (get_local $6) 1480 | ) 1481 | (call $prints 1482 | (i32.const 544) 1483 | ) 1484 | (call $prints 1485 | (i32.const 496) 1486 | ) 1487 | (call $printn 1488 | (i64.const 3163215788274352128) 1489 | ) 1490 | (call $prints 1491 | (i32.const 560) 1492 | ) 1493 | (call $printn 1494 | (i64.const 2118137375447056384) 1495 | ) 1496 | (call $prints 1497 | (get_local $5) 1498 | ) 1499 | (i32.store offset=4 1500 | (i32.const 0) 1501 | (i32.add 1502 | (get_local $6) 1503 | (i32.const 16) 1504 | ) 1505 | ) 1506 | ) 1507 | (func $_ZN3eos5printIPKcJNS_5tokenIyLy2118137375447056384EEES2_NS_5priceINS3_IyLy3163215788274352128EEES4_EES2_EEEvT_DpT0_ (param $0 i32) (param $1 i64) (param $2 i32) (param $3 i64) (param $4 i64) (param $5 i32) 1508 | (local $6 i32) 1509 | (i32.store offset=4 1510 | (i32.const 0) 1511 | (tee_local $6 1512 | (i32.sub 1513 | (i32.load offset=4 1514 | (i32.const 0) 1515 | ) 1516 | (i32.const 16) 1517 | ) 1518 | ) 1519 | ) 1520 | (call $prints 1521 | (get_local $0) 1522 | ) 1523 | (call $printi 1524 | (get_local $1) 1525 | ) 1526 | (call $prints 1527 | (i32.const 496) 1528 | ) 1529 | (call $printn 1530 | (i64.const 2118137375447056384) 1531 | ) 1532 | (call $prints 1533 | (get_local $2) 1534 | ) 1535 | (i64.store offset=8 1536 | (get_local $6) 1537 | (get_local $4) 1538 | ) 1539 | (i64.store 1540 | (get_local $6) 1541 | (get_local $3) 1542 | ) 1543 | (call $printi128 1544 | (get_local $6) 1545 | ) 1546 | (call $prints 1547 | (i32.const 544) 1548 | ) 1549 | (call $prints 1550 | (i32.const 496) 1551 | ) 1552 | (call $printn 1553 | (i64.const 3163215788274352128) 1554 | ) 1555 | (call $prints 1556 | (i32.const 560) 1557 | ) 1558 | (call $printn 1559 | (i64.const 2118137375447056384) 1560 | ) 1561 | (call $prints 1562 | (get_local $5) 1563 | ) 1564 | (i32.store offset=4 1565 | (i32.const 0) 1566 | (i32.add 1567 | (get_local $6) 1568 | (i32.const 16) 1569 | ) 1570 | ) 1571 | ) 1572 | (func $_ZN3eosmlERKNS_5tokenIyLy2118137375447056384EEERKNS_5priceINS0_IyLy3163215788274352128EEES1_EE (param $0 i32) (param $1 i32) (result i64) 1573 | (local $2 i64) 1574 | (local $3 i64) 1575 | (local $4 i64) 1576 | (local $5 i32) 1577 | (i32.store offset=4 1578 | (i32.const 0) 1579 | (tee_local $5 1580 | (i32.sub 1581 | (i32.load offset=4 1582 | (i32.const 0) 1583 | ) 1584 | (i32.const 32) 1585 | ) 1586 | ) 1587 | ) 1588 | (set_local $2 1589 | (i64.load 1590 | (get_local $0) 1591 | ) 1592 | ) 1593 | (call $prints 1594 | (i32.const 480) 1595 | ) 1596 | (call $printi 1597 | (get_local $2) 1598 | ) 1599 | (call $prints 1600 | (i32.const 496) 1601 | ) 1602 | (call $printn 1603 | (i64.const 2118137375447056384) 1604 | ) 1605 | (call $prints 1606 | (i32.const 512) 1607 | ) 1608 | (set_local $2 1609 | (i64.load 1610 | (i32.add 1611 | (get_local $1) 1612 | (i32.const 8) 1613 | ) 1614 | ) 1615 | ) 1616 | (set_local $3 1617 | (i64.load 1618 | (get_local $1) 1619 | ) 1620 | ) 1621 | (set_local $4 1622 | (i64.load 1623 | (get_local $0) 1624 | ) 1625 | ) 1626 | (call $prints 1627 | (i32.const 528) 1628 | ) 1629 | (i64.store offset=24 1630 | (get_local $5) 1631 | (i64.const 0) 1632 | ) 1633 | (i64.store offset=16 1634 | (get_local $5) 1635 | (get_local $4) 1636 | ) 1637 | (call $printi128 1638 | (i32.add 1639 | (get_local $5) 1640 | (i32.const 16) 1641 | ) 1642 | ) 1643 | (call $prints 1644 | (i32.const 400) 1645 | ) 1646 | (i64.store offset=24 1647 | (get_local $5) 1648 | (get_local $2) 1649 | ) 1650 | (i64.store offset=16 1651 | (get_local $5) 1652 | (get_local $3) 1653 | ) 1654 | (call $printi128 1655 | (i32.add 1656 | (get_local $5) 1657 | (i32.const 16) 1658 | ) 1659 | ) 1660 | (call $prints 1661 | (i32.const 416) 1662 | ) 1663 | (call $printi 1664 | (i64.const 1000000000000000) 1665 | ) 1666 | (call $prints 1667 | (i32.const 304) 1668 | ) 1669 | (set_local $2 1670 | (i64.load 1671 | (get_local $0) 1672 | ) 1673 | ) 1674 | (i64.store offset=24 1675 | (get_local $5) 1676 | (i64.const 0) 1677 | ) 1678 | (i64.store offset=16 1679 | (get_local $5) 1680 | (get_local $2) 1681 | ) 1682 | (call $multeq_i128 1683 | (i32.add 1684 | (get_local $5) 1685 | (i32.const 16) 1686 | ) 1687 | (get_local $1) 1688 | ) 1689 | (set_local $2 1690 | (i64.load offset=16 1691 | (get_local $5) 1692 | ) 1693 | ) 1694 | (set_local $3 1695 | (i64.load offset=24 1696 | (get_local $5) 1697 | ) 1698 | ) 1699 | (i64.store offset=8 1700 | (get_local $5) 1701 | (i64.const 0) 1702 | ) 1703 | (i64.store 1704 | (get_local $5) 1705 | (i64.const 1000000000000000) 1706 | ) 1707 | (i64.store offset=24 1708 | (get_local $5) 1709 | (get_local $3) 1710 | ) 1711 | (i64.store offset=16 1712 | (get_local $5) 1713 | (get_local $2) 1714 | ) 1715 | (call $diveq_i128 1716 | (i32.add 1717 | (get_local $5) 1718 | (i32.const 16) 1719 | ) 1720 | (get_local $5) 1721 | ) 1722 | (set_local $2 1723 | (i64.load offset=16 1724 | (get_local $5) 1725 | ) 1726 | ) 1727 | (call $assert 1728 | (i64.eqz 1729 | (i64.load offset=24 1730 | (get_local $5) 1731 | ) 1732 | ) 1733 | (i32.const 432) 1734 | ) 1735 | (i32.store offset=4 1736 | (i32.const 0) 1737 | (i32.add 1738 | (get_local $5) 1739 | (i32.const 32) 1740 | ) 1741 | ) 1742 | (get_local $2) 1743 | ) 1744 | (func $_ZN3eosdvENS_5tokenIyLy3163215788274352128EEERKNS_5priceIS1_NS0_IyLy2118137375447056384EEEEE (param $0 i64) (param $1 i32) (result i64) 1745 | (local $2 i64) 1746 | (local $3 i64) 1747 | (local $4 i32) 1748 | (i32.store offset=4 1749 | (i32.const 0) 1750 | (tee_local $4 1751 | (i32.sub 1752 | (i32.load offset=4 1753 | (i32.const 0) 1754 | ) 1755 | (i32.const 32) 1756 | ) 1757 | ) 1758 | ) 1759 | (set_local $2 1760 | (i64.load 1761 | (i32.add 1762 | (get_local $1) 1763 | (i32.const 8) 1764 | ) 1765 | ) 1766 | ) 1767 | (set_local $3 1768 | (i64.load 1769 | (get_local $1) 1770 | ) 1771 | ) 1772 | (call $prints 1773 | (i32.const 384) 1774 | ) 1775 | (i64.store offset=24 1776 | (get_local $4) 1777 | (i64.const 0) 1778 | ) 1779 | (i64.store offset=16 1780 | (get_local $4) 1781 | (get_local $0) 1782 | ) 1783 | (call $printi128 1784 | (i32.add 1785 | (get_local $4) 1786 | (i32.const 16) 1787 | ) 1788 | ) 1789 | (call $prints 1790 | (i32.const 400) 1791 | ) 1792 | (i64.store offset=24 1793 | (get_local $4) 1794 | (i64.const 0) 1795 | ) 1796 | (i64.store offset=16 1797 | (get_local $4) 1798 | (i64.const 1000000000000000) 1799 | ) 1800 | (call $printi128 1801 | (i32.add 1802 | (get_local $4) 1803 | (i32.const 16) 1804 | ) 1805 | ) 1806 | (call $prints 1807 | (i32.const 416) 1808 | ) 1809 | (i64.store offset=24 1810 | (get_local $4) 1811 | (get_local $2) 1812 | ) 1813 | (i64.store offset=16 1814 | (get_local $4) 1815 | (get_local $3) 1816 | ) 1817 | (call $printi128 1818 | (i32.add 1819 | (get_local $4) 1820 | (i32.const 16) 1821 | ) 1822 | ) 1823 | (call $prints 1824 | (i32.const 304) 1825 | ) 1826 | (i64.store offset=8 1827 | (get_local $4) 1828 | (i64.const 0) 1829 | ) 1830 | (i64.store 1831 | (get_local $4) 1832 | (i64.const 1000000000000000) 1833 | ) 1834 | (i64.store offset=24 1835 | (get_local $4) 1836 | (i64.const 0) 1837 | ) 1838 | (i64.store offset=16 1839 | (get_local $4) 1840 | (get_local $0) 1841 | ) 1842 | (call $multeq_i128 1843 | (i32.add 1844 | (get_local $4) 1845 | (i32.const 16) 1846 | ) 1847 | (get_local $4) 1848 | ) 1849 | (set_local $0 1850 | (i64.load offset=16 1851 | (get_local $4) 1852 | ) 1853 | ) 1854 | (i64.store offset=24 1855 | (get_local $4) 1856 | (i64.load offset=24 1857 | (get_local $4) 1858 | ) 1859 | ) 1860 | (i64.store offset=16 1861 | (get_local $4) 1862 | (get_local $0) 1863 | ) 1864 | (call $diveq_i128 1865 | (i32.add 1866 | (get_local $4) 1867 | (i32.const 16) 1868 | ) 1869 | (get_local $1) 1870 | ) 1871 | (set_local $0 1872 | (i64.load offset=16 1873 | (get_local $4) 1874 | ) 1875 | ) 1876 | (call $assert 1877 | (i64.eqz 1878 | (i64.load offset=24 1879 | (get_local $4) 1880 | ) 1881 | ) 1882 | (i32.const 432) 1883 | ) 1884 | (i32.store offset=4 1885 | (i32.const 0) 1886 | (i32.add 1887 | (get_local $4) 1888 | (i32.const 32) 1889 | ) 1890 | ) 1891 | (get_local $0) 1892 | ) 1893 | (func $_ZN8exchange18apply_exchange_buyENS_8BuyOrderE (param $0 i32) 1894 | (local $1 i64) 1895 | (local $2 i64) 1896 | (local $3 i32) 1897 | (local $4 i32) 1898 | (local $5 i32) 1899 | (local $6 i32) 1900 | (local $7 i32) 1901 | (local $8 i32) 1902 | (local $9 i32) 1903 | (local $10 i32) 1904 | (local $11 i32) 1905 | (local $12 i32) 1906 | (local $13 i64) 1907 | (local $14 i64) 1908 | (local $15 i32) 1909 | (i32.store offset=4 1910 | (i32.const 0) 1911 | (tee_local $15 1912 | (i32.sub 1913 | (i32.load offset=4 1914 | (i32.const 0) 1915 | ) 1916 | (i32.const 192) 1917 | ) 1918 | ) 1919 | ) 1920 | (call $requireAuth 1921 | (tee_local $13 1922 | (i64.load align=1 1923 | (get_local $0) 1924 | ) 1925 | ) 1926 | ) 1927 | (call $assert 1928 | (i64.ne 1929 | (tee_local $14 1930 | (i64.load offset=32 1931 | (get_local $0) 1932 | ) 1933 | ) 1934 | (i64.const 0) 1935 | ) 1936 | (i32.const 576) 1937 | ) 1938 | (call $assert 1939 | (i32.gt_u 1940 | (i32.load offset=40 align=1 1941 | (get_local $0) 1942 | ) 1943 | (call $now) 1944 | ) 1945 | (i32.const 608) 1946 | ) 1947 | (set_local $1 1948 | (i64.load align=1 1949 | (tee_local $7 1950 | (i32.add 1951 | (get_local $0) 1952 | (i32.const 24) 1953 | ) 1954 | ) 1955 | ) 1956 | ) 1957 | (set_local $2 1958 | (i64.load offset=16 align=1 1959 | (get_local $0) 1960 | ) 1961 | ) 1962 | (call $printn 1963 | (get_local $13) 1964 | ) 1965 | (call $_ZN3eos5printIPKcJNS_5tokenIyLy3163215788274352128EEES2_NS_5priceIS4_NS3_IyLy2118137375447056384EEEEES2_EEEvT_DpT0_ 1966 | (i32.const 624) 1967 | (get_local $14) 1968 | (i32.const 656) 1969 | (get_local $2) 1970 | (get_local $1) 1971 | (i32.const 304) 1972 | ) 1973 | (i64.store 1974 | (i32.add 1975 | (i32.add 1976 | (get_local $15) 1977 | (i32.const 144) 1978 | ) 1979 | (i32.const 24) 1980 | ) 1981 | (i64.const 0) 1982 | ) 1983 | (i32.store 1984 | (i32.add 1985 | (i32.add 1986 | (get_local $15) 1987 | (i32.const 144) 1988 | ) 1989 | (i32.const 12) 1990 | ) 1991 | (i32.load 1992 | (i32.add 1993 | (get_local $0) 1994 | (i32.const 12) 1995 | ) 1996 | ) 1997 | ) 1998 | (i32.store 1999 | (i32.add 2000 | (i32.add 2001 | (get_local $15) 2002 | (i32.const 144) 2003 | ) 2004 | (i32.const 8) 2005 | ) 2006 | (i32.load 2007 | (i32.add 2008 | (get_local $0) 2009 | (i32.const 8) 2010 | ) 2011 | ) 2012 | ) 2013 | (i64.store offset=160 2014 | (get_local $15) 2015 | (i64.const 1) 2016 | ) 2017 | (i64.store offset=176 2018 | (get_local $15) 2019 | (i64.const 0) 2020 | ) 2021 | (i32.store offset=148 2022 | (get_local $15) 2023 | (i32.load 2024 | (i32.add 2025 | (get_local $0) 2026 | (i32.const 4) 2027 | ) 2028 | ) 2029 | ) 2030 | (i32.store offset=144 2031 | (get_local $15) 2032 | (i32.load 2033 | (get_local $0) 2034 | ) 2035 | ) 2036 | (call $assert 2037 | (i32.ne 2038 | (call $load_primary_i128i128 2039 | (i64.const 3316479707209269248) 2040 | (i64.const 3316479707209269248) 2041 | (i64.const 1317637142540713984) 2042 | (i32.add 2043 | (get_local $15) 2044 | (i32.const 144) 2045 | ) 2046 | (i32.const 44) 2047 | ) 2048 | (i32.const 44) 2049 | ) 2050 | (i32.const 688) 2051 | ) 2052 | (call $prints 2053 | (i32.const 736) 2054 | ) 2055 | (call $printi 2056 | (i64.const 141) 2057 | ) 2058 | (call $prints 2059 | (i32.const 304) 2060 | ) 2061 | (i64.store offset=120 2062 | (get_local $15) 2063 | (i64.const 0) 2064 | ) 2065 | (i64.store offset=112 2066 | (get_local $15) 2067 | (get_local $13) 2068 | ) 2069 | (i64.store offset=128 2070 | (get_local $15) 2071 | (i64.const 0) 2072 | ) 2073 | (i32.store offset=136 2074 | (get_local $15) 2075 | (i32.const 0) 2076 | ) 2077 | (drop 2078 | (call $load_i64 2079 | (i64.const 3316479707209269248) 2080 | (i64.const 3316479707209269248) 2081 | (i64.const 632468476610478080) 2082 | (i32.add 2083 | (get_local $15) 2084 | (i32.const 112) 2085 | ) 2086 | (i32.const 28) 2087 | ) 2088 | ) 2089 | (call $assert 2090 | (i64.ge_u 2091 | (i64.load offset=120 2092 | (get_local $15) 2093 | ) 2094 | (get_local $14) 2095 | ) 2096 | (i32.const 112) 2097 | ) 2098 | (i64.store offset=120 2099 | (get_local $15) 2100 | (i64.sub 2101 | (i64.load offset=120 2102 | (get_local $15) 2103 | ) 2104 | (get_local $14) 2105 | ) 2106 | ) 2107 | (i64.store 2108 | (tee_local $9 2109 | (i32.add 2110 | (i32.add 2111 | (get_local $15) 2112 | (i32.const 64) 2113 | ) 2114 | (i32.const 24) 2115 | ) 2116 | ) 2117 | (i64.const 0) 2118 | ) 2119 | (i64.store offset=80 2120 | (get_local $15) 2121 | (i64.const 1) 2122 | ) 2123 | (i64.store offset=72 2124 | (get_local $15) 2125 | (i64.const 0) 2126 | ) 2127 | (i64.store offset=64 2128 | (get_local $15) 2129 | (i64.const 0) 2130 | ) 2131 | (i64.store offset=96 2132 | (get_local $15) 2133 | (i64.const 0) 2134 | ) 2135 | (block $label$0 2136 | (block $label$1 2137 | (block $label$2 2138 | (block $label$3 2139 | (block $label$4 2140 | (block $label$5 2141 | (br_if $label$5 2142 | (i32.ne 2143 | (call $front_secondary_i128i128 2144 | (i64.const 3316479707209269248) 2145 | (i64.const 3316479707209269248) 2146 | (i64.const 925261025006059520) 2147 | (i32.add 2148 | (get_local $15) 2149 | (i32.const 64) 2150 | ) 2151 | (i32.const 44) 2152 | ) 2153 | (i32.const 44) 2154 | ) 2155 | ) 2156 | (set_local $14 2157 | (i64.load 2158 | (get_local $9) 2159 | ) 2160 | ) 2161 | (set_local $13 2162 | (i64.load 2163 | (tee_local $3 2164 | (i32.add 2165 | (i32.add 2166 | (get_local $15) 2167 | (i32.const 64) 2168 | ) 2169 | (i32.const 16) 2170 | ) 2171 | ) 2172 | ) 2173 | ) 2174 | (set_local $1 2175 | (i64.load 2176 | (tee_local $4 2177 | (i32.add 2178 | (i32.add 2179 | (get_local $15) 2180 | (i32.const 64) 2181 | ) 2182 | (i32.const 32) 2183 | ) 2184 | ) 2185 | ) 2186 | ) 2187 | (call $prints 2188 | (i32.const 928) 2189 | ) 2190 | (call $_ZN3eos5printIPKcJNS_5tokenIyLy2118137375447056384EEES2_NS_5priceINS3_IyLy3163215788274352128EEES4_EES2_EEEvT_DpT0_ 2191 | (i32.const 240) 2192 | (get_local $1) 2193 | (i32.const 256) 2194 | (get_local $13) 2195 | (get_local $14) 2196 | (i32.const 272) 2197 | ) 2198 | (call $prints 2199 | (i32.const 304) 2200 | ) 2201 | (set_local $14 2202 | (i64.load align=1 2203 | (get_local $7) 2204 | ) 2205 | ) 2206 | (set_local $13 2207 | (i64.load align=1 2208 | (tee_local $5 2209 | (i32.add 2210 | (get_local $0) 2211 | (i32.const 16) 2212 | ) 2213 | ) 2214 | ) 2215 | ) 2216 | (set_local $1 2217 | (i64.load align=1 2218 | (tee_local $6 2219 | (i32.add 2220 | (get_local $0) 2221 | (i32.const 32) 2222 | ) 2223 | ) 2224 | ) 2225 | ) 2226 | (call $prints 2227 | (i32.const 944) 2228 | ) 2229 | (call $_ZN3eos5printIPKcJNS_5tokenIyLy3163215788274352128EEES2_NS_5priceIS4_NS3_IyLy2118137375447056384EEEEES2_EEEvT_DpT0_ 2230 | (i32.const 240) 2231 | (get_local $1) 2232 | (i32.const 256) 2233 | (get_local $13) 2234 | (get_local $14) 2235 | (i32.const 272) 2236 | ) 2237 | (call $prints 2238 | (i32.const 304) 2239 | ) 2240 | (i64.store offset=40 2241 | (get_local $15) 2242 | (i64.const 0) 2243 | ) 2244 | (i64.store offset=48 2245 | (get_local $15) 2246 | (i64.const 0) 2247 | ) 2248 | (i32.store offset=56 2249 | (get_local $15) 2250 | (i32.const 0) 2251 | ) 2252 | (i64.store offset=32 2253 | (get_local $15) 2254 | (i64.load offset=64 2255 | (get_local $15) 2256 | ) 2257 | ) 2258 | (drop 2259 | (call $load_i64 2260 | (i64.const 3316479707209269248) 2261 | (i64.const 3316479707209269248) 2262 | (i64.const 632468476610478080) 2263 | (i32.add 2264 | (get_local $15) 2265 | (i32.const 32) 2266 | ) 2267 | (i32.const 28) 2268 | ) 2269 | ) 2270 | (block $label$6 2271 | (br_if $label$6 2272 | (select 2273 | (i64.gt_u 2274 | (i64.load 2275 | (get_local $3) 2276 | ) 2277 | (i64.load 2278 | (get_local $5) 2279 | ) 2280 | ) 2281 | (i64.gt_u 2282 | (tee_local $14 2283 | (i64.load 2284 | (get_local $9) 2285 | ) 2286 | ) 2287 | (tee_local $13 2288 | (i64.load 2289 | (get_local $7) 2290 | ) 2291 | ) 2292 | ) 2293 | (i64.eq 2294 | (get_local $14) 2295 | (get_local $13) 2296 | ) 2297 | ) 2298 | ) 2299 | (set_local $7 2300 | (i32.add 2301 | (i32.add 2302 | (get_local $15) 2303 | (i32.const 32) 2304 | ) 2305 | (i32.const 24) 2306 | ) 2307 | ) 2308 | (set_local $9 2309 | (i32.add 2310 | (i32.add 2311 | (get_local $15) 2312 | (i32.const 32) 2313 | ) 2314 | (i32.const 8) 2315 | ) 2316 | ) 2317 | (set_local $10 2318 | (i32.add 2319 | (i32.add 2320 | (get_local $15) 2321 | (i32.const 32) 2322 | ) 2323 | (i32.const 16) 2324 | ) 2325 | ) 2326 | (loop $label$7 2327 | (call $prints 2328 | (i32.const 960) 2329 | ) 2330 | (call $_ZN8exchange5matchERNS_3BidERNS_7AccountERNS_3AskES3_ 2331 | (get_local $0) 2332 | (i32.add 2333 | (get_local $15) 2334 | (i32.const 112) 2335 | ) 2336 | (i32.add 2337 | (get_local $15) 2338 | (i32.const 64) 2339 | ) 2340 | (i32.add 2341 | (get_local $15) 2342 | (i32.const 32) 2343 | ) 2344 | ) 2345 | (br_if $label$6 2346 | (i64.ne 2347 | (i64.load 2348 | (get_local $4) 2349 | ) 2350 | (i64.const 0) 2351 | ) 2352 | ) 2353 | (i32.store 2354 | (get_local $7) 2355 | (tee_local $8 2356 | (i32.add 2357 | (i32.load 2358 | (get_local $7) 2359 | ) 2360 | (i32.const -1) 2361 | ) 2362 | ) 2363 | ) 2364 | (block $label$8 2365 | (block $label$9 2366 | (br_if $label$9 2367 | (i32.eqz 2368 | (i32.or 2369 | (i64.ne 2370 | (i64.or 2371 | (i64.load 2372 | (get_local $10) 2373 | ) 2374 | (i64.load 2375 | (get_local $9) 2376 | ) 2377 | ) 2378 | (i64.const 0) 2379 | ) 2380 | (get_local $8) 2381 | ) 2382 | ) 2383 | ) 2384 | (call $prints 2385 | (i32.const 96) 2386 | ) 2387 | (drop 2388 | (call $store_i64 2389 | (i64.const 3316479707209269248) 2390 | (i64.const 632468476610478080) 2391 | (i32.add 2392 | (get_local $15) 2393 | (i32.const 32) 2394 | ) 2395 | (i32.const 28) 2396 | ) 2397 | ) 2398 | (br $label$8) 2399 | ) 2400 | (call $prints 2401 | (i32.const 80) 2402 | ) 2403 | (drop 2404 | (call $remove_i64 2405 | (i64.const 3316479707209269248) 2406 | (i64.const 632468476610478080) 2407 | (i32.add 2408 | (get_local $15) 2409 | (i32.const 32) 2410 | ) 2411 | ) 2412 | ) 2413 | ) 2414 | (block $label$10 2415 | (block $label$11 2416 | (br_if $label$11 2417 | (i32.eqz 2418 | (i32.or 2419 | (i64.ne 2420 | (i64.or 2421 | (i64.load 2422 | (i32.add 2423 | (i32.add 2424 | (get_local $15) 2425 | (i32.const 112) 2426 | ) 2427 | (i32.const 16) 2428 | ) 2429 | ) 2430 | (i64.load 2431 | (i32.add 2432 | (i32.add 2433 | (get_local $15) 2434 | (i32.const 112) 2435 | ) 2436 | (i32.const 8) 2437 | ) 2438 | ) 2439 | ) 2440 | (i64.const 0) 2441 | ) 2442 | (i32.load 2443 | (i32.add 2444 | (i32.add 2445 | (get_local $15) 2446 | (i32.const 112) 2447 | ) 2448 | (i32.const 24) 2449 | ) 2450 | ) 2451 | ) 2452 | ) 2453 | ) 2454 | (call $prints 2455 | (i32.const 96) 2456 | ) 2457 | (drop 2458 | (call $store_i64 2459 | (i64.const 3316479707209269248) 2460 | (i64.const 632468476610478080) 2461 | (i32.add 2462 | (get_local $15) 2463 | (i32.const 112) 2464 | ) 2465 | (i32.const 28) 2466 | ) 2467 | ) 2468 | (br $label$10) 2469 | ) 2470 | (call $prints 2471 | (i32.const 80) 2472 | ) 2473 | (drop 2474 | (call $remove_i64 2475 | (i64.const 3316479707209269248) 2476 | (i64.const 632468476610478080) 2477 | (i32.add 2478 | (get_local $15) 2479 | (i32.const 112) 2480 | ) 2481 | ) 2482 | ) 2483 | ) 2484 | (drop 2485 | (call $remove_i128i128 2486 | (i64.const 3316479707209269248) 2487 | (i64.const 925261025006059520) 2488 | (i32.add 2489 | (get_local $15) 2490 | (i32.const 64) 2491 | ) 2492 | ) 2493 | ) 2494 | (br_if $label$6 2495 | (i32.ne 2496 | (call $front_secondary_i128i128 2497 | (i64.const 3316479707209269248) 2498 | (i64.const 3316479707209269248) 2499 | (i64.const 925261025006059520) 2500 | (i32.add 2501 | (get_local $15) 2502 | (i32.const 64) 2503 | ) 2504 | (i32.const 44) 2505 | ) 2506 | (i32.const 44) 2507 | ) 2508 | ) 2509 | (i64.store 2510 | (tee_local $8 2511 | (i32.add 2512 | (get_local $15) 2513 | (i32.const 8) 2514 | ) 2515 | ) 2516 | (i64.const 0) 2517 | ) 2518 | (i64.store 2519 | (tee_local $11 2520 | (i32.add 2521 | (get_local $15) 2522 | (i32.const 16) 2523 | ) 2524 | ) 2525 | (i64.const 0) 2526 | ) 2527 | (i32.store 2528 | (tee_local $12 2529 | (i32.add 2530 | (get_local $15) 2531 | (i32.const 24) 2532 | ) 2533 | ) 2534 | (i32.const 0) 2535 | ) 2536 | (i64.store 2537 | (get_local $15) 2538 | (i64.load offset=64 2539 | (get_local $15) 2540 | ) 2541 | ) 2542 | (drop 2543 | (call $load_i64 2544 | (i64.const 3316479707209269248) 2545 | (i64.const 3316479707209269248) 2546 | (i64.const 632468476610478080) 2547 | (get_local $15) 2548 | (i32.const 28) 2549 | ) 2550 | ) 2551 | (i32.store 2552 | (get_local $7) 2553 | (i32.load 2554 | (get_local $12) 2555 | ) 2556 | ) 2557 | (i64.store 2558 | (get_local $10) 2559 | (i64.load 2560 | (get_local $11) 2561 | ) 2562 | ) 2563 | (i64.store 2564 | (get_local $9) 2565 | (i64.load 2566 | (get_local $8) 2567 | ) 2568 | ) 2569 | (i64.store offset=32 2570 | (get_local $15) 2571 | (i64.load 2572 | (get_local $15) 2573 | ) 2574 | ) 2575 | (br_if $label$7 2576 | (select 2577 | (i64.le_u 2578 | (i64.load 2579 | (get_local $3) 2580 | ) 2581 | (i64.load 2582 | (get_local $5) 2583 | ) 2584 | ) 2585 | (i64.le_u 2586 | (tee_local $14 2587 | (i64.load 2588 | (i32.add 2589 | (i32.add 2590 | (get_local $15) 2591 | (i32.const 64) 2592 | ) 2593 | (i32.const 24) 2594 | ) 2595 | ) 2596 | ) 2597 | (tee_local $13 2598 | (i64.load 2599 | (i32.add 2600 | (get_local $0) 2601 | (i32.const 24) 2602 | ) 2603 | ) 2604 | ) 2605 | ) 2606 | (i64.eq 2607 | (get_local $14) 2608 | (get_local $13) 2609 | ) 2610 | ) 2611 | ) 2612 | ) 2613 | ) 2614 | (call $prints 2615 | (i32.const 992) 2616 | ) 2617 | (block $label$12 2618 | (br_if $label$12 2619 | (i64.eqz 2620 | (i64.load 2621 | (get_local $6) 2622 | ) 2623 | ) 2624 | ) 2625 | (br_if $label$12 2626 | (i32.load8_u offset=44 2627 | (get_local $0) 2628 | ) 2629 | ) 2630 | (i32.store 2631 | (tee_local $7 2632 | (i32.add 2633 | (get_local $15) 2634 | (i32.const 136) 2635 | ) 2636 | ) 2637 | (i32.add 2638 | (i32.load 2639 | (get_local $7) 2640 | ) 2641 | (i32.const 1) 2642 | ) 2643 | ) 2644 | ) 2645 | (br_if $label$4 2646 | (i32.eqz 2647 | (i32.or 2648 | (i64.ne 2649 | (i64.or 2650 | (i64.load 2651 | (i32.add 2652 | (get_local $15) 2653 | (i32.const 128) 2654 | ) 2655 | ) 2656 | (i64.load 2657 | (i32.add 2658 | (get_local $15) 2659 | (i32.const 120) 2660 | ) 2661 | ) 2662 | ) 2663 | (i64.const 0) 2664 | ) 2665 | (i32.load 2666 | (i32.add 2667 | (get_local $15) 2668 | (i32.const 136) 2669 | ) 2670 | ) 2671 | ) 2672 | ) 2673 | ) 2674 | (call $prints 2675 | (i32.const 96) 2676 | ) 2677 | (drop 2678 | (call $store_i64 2679 | (i64.const 3316479707209269248) 2680 | (i64.const 632468476610478080) 2681 | (i32.add 2682 | (get_local $15) 2683 | (i32.const 112) 2684 | ) 2685 | (i32.const 28) 2686 | ) 2687 | ) 2688 | (br $label$3) 2689 | ) 2690 | (call $prints 2691 | (i32.const 800) 2692 | ) 2693 | (call $assert 2694 | (i32.eqz 2695 | (i32.load8_u offset=44 2696 | (get_local $0) 2697 | ) 2698 | ) 2699 | (i32.const 864) 2700 | ) 2701 | (call $assert 2702 | (call $store_i128i128 2703 | (i64.const 3316479707209269248) 2704 | (i64.const 1317637142540713984) 2705 | (get_local $0) 2706 | (i32.const 44) 2707 | ) 2708 | (i32.const 896) 2709 | ) 2710 | (i32.store 2711 | (tee_local $0 2712 | (i32.add 2713 | (i32.add 2714 | (get_local $15) 2715 | (i32.const 112) 2716 | ) 2717 | (i32.const 24) 2718 | ) 2719 | ) 2720 | (tee_local $0 2721 | (i32.add 2722 | (i32.load 2723 | (get_local $0) 2724 | ) 2725 | (i32.const 1) 2726 | ) 2727 | ) 2728 | ) 2729 | (br_if $label$2 2730 | (i32.eqz 2731 | (i32.or 2732 | (i64.ne 2733 | (i64.or 2734 | (i64.load 2735 | (i32.add 2736 | (get_local $15) 2737 | (i32.const 128) 2738 | ) 2739 | ) 2740 | (i64.load 2741 | (i32.add 2742 | (i32.add 2743 | (get_local $15) 2744 | (i32.const 112) 2745 | ) 2746 | (i32.const 8) 2747 | ) 2748 | ) 2749 | ) 2750 | (i64.const 0) 2751 | ) 2752 | (get_local $0) 2753 | ) 2754 | ) 2755 | ) 2756 | (call $prints 2757 | (i32.const 96) 2758 | ) 2759 | (drop 2760 | (call $store_i64 2761 | (i64.const 3316479707209269248) 2762 | (i64.const 632468476610478080) 2763 | (i32.add 2764 | (get_local $15) 2765 | (i32.const 112) 2766 | ) 2767 | (i32.const 28) 2768 | ) 2769 | ) 2770 | (br $label$0) 2771 | ) 2772 | (call $prints 2773 | (i32.const 80) 2774 | ) 2775 | (drop 2776 | (call $remove_i64 2777 | (i64.const 3316479707209269248) 2778 | (i64.const 632468476610478080) 2779 | (i32.add 2780 | (get_local $15) 2781 | (i32.const 112) 2782 | ) 2783 | ) 2784 | ) 2785 | ) 2786 | (call $prints 2787 | (i32.const 1056) 2788 | ) 2789 | (br_if $label$1 2790 | (i64.eqz 2791 | (tee_local $14 2792 | (i64.load 2793 | (i32.add 2794 | (get_local $0) 2795 | (i32.const 32) 2796 | ) 2797 | ) 2798 | ) 2799 | ) 2800 | ) 2801 | (call $printi 2802 | (get_local $14) 2803 | ) 2804 | (call $prints 2805 | (i32.const 496) 2806 | ) 2807 | (call $printn 2808 | (i64.const 3163215788274352128) 2809 | ) 2810 | (call $prints 2811 | (i32.const 1088) 2812 | ) 2813 | (call $assert 2814 | (i32.eqz 2815 | (i32.load8_u offset=44 2816 | (get_local $0) 2817 | ) 2818 | ) 2819 | (i32.const 864) 2820 | ) 2821 | (call $assert 2822 | (call $store_i128i128 2823 | (i64.const 3316479707209269248) 2824 | (i64.const 1317637142540713984) 2825 | (get_local $0) 2826 | (i32.const 44) 2827 | ) 2828 | (i32.const 896) 2829 | ) 2830 | (br $label$0) 2831 | ) 2832 | (call $prints 2833 | (i32.const 80) 2834 | ) 2835 | (drop 2836 | (call $remove_i64 2837 | (i64.const 3316479707209269248) 2838 | (i64.const 632468476610478080) 2839 | (i32.add 2840 | (get_local $15) 2841 | (i32.const 112) 2842 | ) 2843 | ) 2844 | ) 2845 | (br $label$0) 2846 | ) 2847 | (call $prints 2848 | (i32.const 1104) 2849 | ) 2850 | ) 2851 | (i32.store offset=4 2852 | (i32.const 0) 2853 | (i32.add 2854 | (get_local $15) 2855 | (i32.const 192) 2856 | ) 2857 | ) 2858 | ) 2859 | (func $_ZN8exchange19apply_exchange_sellENS_9SellOrderE (param $0 i32) 2860 | (local $1 i64) 2861 | (local $2 i64) 2862 | (local $3 i32) 2863 | (local $4 i32) 2864 | (local $5 i32) 2865 | (local $6 i32) 2866 | (local $7 i32) 2867 | (local $8 i32) 2868 | (local $9 i32) 2869 | (local $10 i32) 2870 | (local $11 i32) 2871 | (local $12 i32) 2872 | (local $13 i32) 2873 | (local $14 i64) 2874 | (local $15 i64) 2875 | (local $16 i32) 2876 | (i32.store offset=4 2877 | (i32.const 0) 2878 | (tee_local $16 2879 | (i32.sub 2880 | (i32.load offset=4 2881 | (i32.const 0) 2882 | ) 2883 | (i32.const 192) 2884 | ) 2885 | ) 2886 | ) 2887 | (call $requireAuth 2888 | (tee_local $14 2889 | (i64.load align=1 2890 | (get_local $0) 2891 | ) 2892 | ) 2893 | ) 2894 | (call $assert 2895 | (i64.ne 2896 | (tee_local $15 2897 | (i64.load offset=32 2898 | (get_local $0) 2899 | ) 2900 | ) 2901 | (i64.const 0) 2902 | ) 2903 | (i32.const 576) 2904 | ) 2905 | (call $assert 2906 | (i32.gt_u 2907 | (i32.load offset=40 align=1 2908 | (get_local $0) 2909 | ) 2910 | (call $now) 2911 | ) 2912 | (i32.const 608) 2913 | ) 2914 | (set_local $1 2915 | (i64.load align=1 2916 | (tee_local $6 2917 | (i32.add 2918 | (get_local $0) 2919 | (i32.const 24) 2920 | ) 2921 | ) 2922 | ) 2923 | ) 2924 | (set_local $2 2925 | (i64.load offset=16 align=1 2926 | (get_local $0) 2927 | ) 2928 | ) 2929 | (call $prints 2930 | (i32.const 368) 2931 | ) 2932 | (call $printn 2933 | (get_local $14) 2934 | ) 2935 | (call $_ZN3eos5printIPKcJNS_5tokenIyLy2118137375447056384EEES2_NS_5priceINS3_IyLy3163215788274352128EEES4_EES2_EEEvT_DpT0_ 2936 | (i32.const 1120) 2937 | (get_local $15) 2938 | (i32.const 656) 2939 | (get_local $2) 2940 | (get_local $1) 2941 | (i32.const 304) 2942 | ) 2943 | (i64.store 2944 | (i32.add 2945 | (i32.add 2946 | (get_local $16) 2947 | (i32.const 144) 2948 | ) 2949 | (i32.const 24) 2950 | ) 2951 | (i64.const 0) 2952 | ) 2953 | (i32.store 2954 | (i32.add 2955 | (i32.add 2956 | (get_local $16) 2957 | (i32.const 144) 2958 | ) 2959 | (i32.const 12) 2960 | ) 2961 | (i32.load 2962 | (i32.add 2963 | (get_local $0) 2964 | (i32.const 12) 2965 | ) 2966 | ) 2967 | ) 2968 | (i32.store 2969 | (i32.add 2970 | (i32.add 2971 | (get_local $16) 2972 | (i32.const 144) 2973 | ) 2974 | (i32.const 8) 2975 | ) 2976 | (i32.load 2977 | (i32.add 2978 | (get_local $0) 2979 | (i32.const 8) 2980 | ) 2981 | ) 2982 | ) 2983 | (i64.store offset=160 2984 | (get_local $16) 2985 | (i64.const 1) 2986 | ) 2987 | (i64.store offset=176 2988 | (get_local $16) 2989 | (i64.const 0) 2990 | ) 2991 | (i32.store offset=148 2992 | (get_local $16) 2993 | (i32.load 2994 | (i32.add 2995 | (get_local $0) 2996 | (i32.const 4) 2997 | ) 2998 | ) 2999 | ) 3000 | (i32.store offset=144 3001 | (get_local $16) 3002 | (i32.load 3003 | (get_local $0) 3004 | ) 3005 | ) 3006 | (call $assert 3007 | (i32.ne 3008 | (call $load_primary_i128i128 3009 | (i64.const 3316479707209269248) 3010 | (i64.const 3316479707209269248) 3011 | (i64.const 925261025006059520) 3012 | (i32.add 3013 | (get_local $16) 3014 | (i32.const 144) 3015 | ) 3016 | (i32.const 44) 3017 | ) 3018 | (i32.const 44) 3019 | ) 3020 | (i32.const 688) 3021 | ) 3022 | (i64.store offset=120 3023 | (get_local $16) 3024 | (i64.const 0) 3025 | ) 3026 | (i64.store offset=112 3027 | (get_local $16) 3028 | (get_local $14) 3029 | ) 3030 | (i64.store offset=128 3031 | (get_local $16) 3032 | (i64.const 0) 3033 | ) 3034 | (i32.store offset=136 3035 | (get_local $16) 3036 | (i32.const 0) 3037 | ) 3038 | (drop 3039 | (call $load_i64 3040 | (i64.const 3316479707209269248) 3041 | (i64.const 3316479707209269248) 3042 | (i64.const 632468476610478080) 3043 | (i32.add 3044 | (get_local $16) 3045 | (i32.const 112) 3046 | ) 3047 | (i32.const 28) 3048 | ) 3049 | ) 3050 | (call $assert 3051 | (i64.ge_u 3052 | (i64.load offset=128 3053 | (get_local $16) 3054 | ) 3055 | (get_local $15) 3056 | ) 3057 | (i32.const 112) 3058 | ) 3059 | (i64.store offset=128 3060 | (get_local $16) 3061 | (i64.sub 3062 | (i64.load offset=128 3063 | (get_local $16) 3064 | ) 3065 | (get_local $15) 3066 | ) 3067 | ) 3068 | (i64.store 3069 | (tee_local $10 3070 | (i32.add 3071 | (i32.add 3072 | (get_local $16) 3073 | (i32.const 64) 3074 | ) 3075 | (i32.const 24) 3076 | ) 3077 | ) 3078 | (i64.const 0) 3079 | ) 3080 | (i64.store offset=80 3081 | (get_local $16) 3082 | (i64.const 1) 3083 | ) 3084 | (i64.store offset=72 3085 | (get_local $16) 3086 | (i64.const 0) 3087 | ) 3088 | (i64.store offset=64 3089 | (get_local $16) 3090 | (i64.const 0) 3091 | ) 3092 | (i64.store offset=96 3093 | (get_local $16) 3094 | (i64.const 0) 3095 | ) 3096 | (block $label$0 3097 | (block $label$1 3098 | (block $label$2 3099 | (block $label$3 3100 | (block $label$4 3101 | (block $label$5 3102 | (br_if $label$5 3103 | (i32.ne 3104 | (call $back_secondary_i128i128 3105 | (i64.const 3316479707209269248) 3106 | (i64.const 3316479707209269248) 3107 | (i64.const 1317637142540713984) 3108 | (i32.add 3109 | (get_local $16) 3110 | (i32.const 64) 3111 | ) 3112 | (i32.const 44) 3113 | ) 3114 | (i32.const 44) 3115 | ) 3116 | ) 3117 | (call $prints 3118 | (i32.const 1216) 3119 | ) 3120 | (i64.store offset=40 3121 | (get_local $16) 3122 | (i64.const 0) 3123 | ) 3124 | (i64.store offset=48 3125 | (get_local $16) 3126 | (i64.const 0) 3127 | ) 3128 | (i32.store offset=56 3129 | (get_local $16) 3130 | (i32.const 0) 3131 | ) 3132 | (i64.store offset=32 3133 | (get_local $16) 3134 | (i64.load offset=64 3135 | (get_local $16) 3136 | ) 3137 | ) 3138 | (drop 3139 | (call $load_i64 3140 | (i64.const 3316479707209269248) 3141 | (i64.const 3316479707209269248) 3142 | (i64.const 632468476610478080) 3143 | (i32.add 3144 | (get_local $16) 3145 | (i32.const 32) 3146 | ) 3147 | (i32.const 28) 3148 | ) 3149 | ) 3150 | (block $label$6 3151 | (br_if $label$6 3152 | (select 3153 | (i64.lt_u 3154 | (i64.load 3155 | (tee_local $4 3156 | (i32.add 3157 | (i32.add 3158 | (get_local $16) 3159 | (i32.const 64) 3160 | ) 3161 | (i32.const 16) 3162 | ) 3163 | ) 3164 | ) 3165 | (i64.load 3166 | (tee_local $3 3167 | (i32.add 3168 | (get_local $0) 3169 | (i32.const 16) 3170 | ) 3171 | ) 3172 | ) 3173 | ) 3174 | (i64.lt_u 3175 | (tee_local $15 3176 | (i64.load 3177 | (get_local $10) 3178 | ) 3179 | ) 3180 | (tee_local $14 3181 | (i64.load 3182 | (get_local $6) 3183 | ) 3184 | ) 3185 | ) 3186 | (i64.eq 3187 | (get_local $15) 3188 | (get_local $14) 3189 | ) 3190 | ) 3191 | ) 3192 | (set_local $5 3193 | (i32.add 3194 | (get_local $16) 3195 | (i32.const 96) 3196 | ) 3197 | ) 3198 | (set_local $7 3199 | (i32.add 3200 | (i32.add 3201 | (get_local $16) 3202 | (i32.const 112) 3203 | ) 3204 | (i32.const 8) 3205 | ) 3206 | ) 3207 | (set_local $8 3208 | (i32.add 3209 | (i32.add 3210 | (get_local $16) 3211 | (i32.const 112) 3212 | ) 3213 | (i32.const 16) 3214 | ) 3215 | ) 3216 | (loop $label$7 3217 | (call $_ZN8exchange5matchERNS_3BidERNS_7AccountERNS_3AskES3_ 3218 | (i32.add 3219 | (get_local $16) 3220 | (i32.const 64) 3221 | ) 3222 | (i32.add 3223 | (get_local $16) 3224 | (i32.const 32) 3225 | ) 3226 | (get_local $0) 3227 | (i32.add 3228 | (get_local $16) 3229 | (i32.const 112) 3230 | ) 3231 | ) 3232 | (br_if $label$6 3233 | (i64.ne 3234 | (i64.load 3235 | (get_local $5) 3236 | ) 3237 | (i64.const 0) 3238 | ) 3239 | ) 3240 | (i32.store 3241 | (tee_local $6 3242 | (i32.add 3243 | (i32.add 3244 | (get_local $16) 3245 | (i32.const 32) 3246 | ) 3247 | (i32.const 24) 3248 | ) 3249 | ) 3250 | (i32.add 3251 | (i32.load 3252 | (get_local $6) 3253 | ) 3254 | (i32.const -1) 3255 | ) 3256 | ) 3257 | (block $label$8 3258 | (block $label$9 3259 | (br_if $label$9 3260 | (i32.eqz 3261 | (i32.or 3262 | (i64.ne 3263 | (i64.or 3264 | (i64.load 3265 | (get_local $8) 3266 | ) 3267 | (i64.load 3268 | (get_local $7) 3269 | ) 3270 | ) 3271 | (i64.const 0) 3272 | ) 3273 | (i32.load 3274 | (i32.add 3275 | (i32.add 3276 | (get_local $16) 3277 | (i32.const 112) 3278 | ) 3279 | (i32.const 24) 3280 | ) 3281 | ) 3282 | ) 3283 | ) 3284 | ) 3285 | (call $prints 3286 | (i32.const 96) 3287 | ) 3288 | (drop 3289 | (call $store_i64 3290 | (i64.const 3316479707209269248) 3291 | (i64.const 632468476610478080) 3292 | (i32.add 3293 | (get_local $16) 3294 | (i32.const 112) 3295 | ) 3296 | (i32.const 28) 3297 | ) 3298 | ) 3299 | (br $label$8) 3300 | ) 3301 | (call $prints 3302 | (i32.const 80) 3303 | ) 3304 | (drop 3305 | (call $remove_i64 3306 | (i64.const 3316479707209269248) 3307 | (i64.const 632468476610478080) 3308 | (i32.add 3309 | (get_local $16) 3310 | (i32.const 112) 3311 | ) 3312 | ) 3313 | ) 3314 | ) 3315 | (block $label$10 3316 | (block $label$11 3317 | (br_if $label$11 3318 | (i32.eqz 3319 | (i32.or 3320 | (i64.ne 3321 | (i64.or 3322 | (i64.load 3323 | (tee_local $10 3324 | (i32.add 3325 | (i32.add 3326 | (get_local $16) 3327 | (i32.const 32) 3328 | ) 3329 | (i32.const 16) 3330 | ) 3331 | ) 3332 | ) 3333 | (i64.load 3334 | (tee_local $9 3335 | (i32.add 3336 | (i32.add 3337 | (get_local $16) 3338 | (i32.const 32) 3339 | ) 3340 | (i32.const 8) 3341 | ) 3342 | ) 3343 | ) 3344 | ) 3345 | (i64.const 0) 3346 | ) 3347 | (i32.load 3348 | (get_local $6) 3349 | ) 3350 | ) 3351 | ) 3352 | ) 3353 | (call $prints 3354 | (i32.const 96) 3355 | ) 3356 | (drop 3357 | (call $store_i64 3358 | (i64.const 3316479707209269248) 3359 | (i64.const 632468476610478080) 3360 | (i32.add 3361 | (get_local $16) 3362 | (i32.const 32) 3363 | ) 3364 | (i32.const 28) 3365 | ) 3366 | ) 3367 | (br $label$10) 3368 | ) 3369 | (call $prints 3370 | (i32.const 80) 3371 | ) 3372 | (drop 3373 | (call $remove_i64 3374 | (i64.const 3316479707209269248) 3375 | (i64.const 632468476610478080) 3376 | (i32.add 3377 | (get_local $16) 3378 | (i32.const 32) 3379 | ) 3380 | ) 3381 | ) 3382 | ) 3383 | (drop 3384 | (call $remove_i128i128 3385 | (i64.const 3316479707209269248) 3386 | (i64.const 1317637142540713984) 3387 | (i32.add 3388 | (get_local $16) 3389 | (i32.const 64) 3390 | ) 3391 | ) 3392 | ) 3393 | (br_if $label$6 3394 | (i32.ne 3395 | (call $back_secondary_i128i128 3396 | (i64.const 3316479707209269248) 3397 | (i64.const 3316479707209269248) 3398 | (i64.const 1317637142540713984) 3399 | (i32.add 3400 | (get_local $16) 3401 | (i32.const 64) 3402 | ) 3403 | (i32.const 44) 3404 | ) 3405 | (i32.const 44) 3406 | ) 3407 | ) 3408 | (i64.store 3409 | (tee_local $11 3410 | (i32.add 3411 | (get_local $16) 3412 | (i32.const 8) 3413 | ) 3414 | ) 3415 | (i64.const 0) 3416 | ) 3417 | (i64.store 3418 | (tee_local $12 3419 | (i32.add 3420 | (get_local $16) 3421 | (i32.const 16) 3422 | ) 3423 | ) 3424 | (i64.const 0) 3425 | ) 3426 | (i32.store 3427 | (tee_local $13 3428 | (i32.add 3429 | (get_local $16) 3430 | (i32.const 24) 3431 | ) 3432 | ) 3433 | (i32.const 0) 3434 | ) 3435 | (i64.store 3436 | (get_local $16) 3437 | (i64.load offset=64 3438 | (get_local $16) 3439 | ) 3440 | ) 3441 | (drop 3442 | (call $load_i64 3443 | (i64.const 3316479707209269248) 3444 | (i64.const 3316479707209269248) 3445 | (i64.const 632468476610478080) 3446 | (get_local $16) 3447 | (i32.const 28) 3448 | ) 3449 | ) 3450 | (i32.store 3451 | (get_local $6) 3452 | (i32.load 3453 | (get_local $13) 3454 | ) 3455 | ) 3456 | (i64.store 3457 | (get_local $10) 3458 | (i64.load 3459 | (get_local $12) 3460 | ) 3461 | ) 3462 | (i64.store 3463 | (get_local $9) 3464 | (i64.load 3465 | (get_local $11) 3466 | ) 3467 | ) 3468 | (i64.store offset=32 3469 | (get_local $16) 3470 | (i64.load 3471 | (get_local $16) 3472 | ) 3473 | ) 3474 | (br_if $label$7 3475 | (select 3476 | (i64.ge_u 3477 | (i64.load 3478 | (get_local $4) 3479 | ) 3480 | (i64.load 3481 | (get_local $3) 3482 | ) 3483 | ) 3484 | (i64.ge_u 3485 | (tee_local $15 3486 | (i64.load 3487 | (i32.add 3488 | (i32.add 3489 | (get_local $16) 3490 | (i32.const 64) 3491 | ) 3492 | (i32.const 24) 3493 | ) 3494 | ) 3495 | ) 3496 | (tee_local $14 3497 | (i64.load 3498 | (i32.add 3499 | (get_local $0) 3500 | (i32.const 24) 3501 | ) 3502 | ) 3503 | ) 3504 | ) 3505 | (i64.eq 3506 | (get_local $15) 3507 | (get_local $14) 3508 | ) 3509 | ) 3510 | ) 3511 | ) 3512 | ) 3513 | (block $label$12 3514 | (br_if $label$12 3515 | (i64.eqz 3516 | (i64.load 3517 | (i32.add 3518 | (get_local $0) 3519 | (i32.const 32) 3520 | ) 3521 | ) 3522 | ) 3523 | ) 3524 | (br_if $label$12 3525 | (i32.load8_u offset=44 3526 | (get_local $0) 3527 | ) 3528 | ) 3529 | (i32.store 3530 | (tee_local $6 3531 | (i32.add 3532 | (get_local $16) 3533 | (i32.const 136) 3534 | ) 3535 | ) 3536 | (i32.add 3537 | (i32.load 3538 | (get_local $6) 3539 | ) 3540 | (i32.const 1) 3541 | ) 3542 | ) 3543 | ) 3544 | (br_if $label$4 3545 | (i32.eqz 3546 | (i32.or 3547 | (i64.ne 3548 | (i64.or 3549 | (i64.load 3550 | (i32.add 3551 | (get_local $16) 3552 | (i32.const 128) 3553 | ) 3554 | ) 3555 | (i64.load 3556 | (i32.add 3557 | (get_local $16) 3558 | (i32.const 120) 3559 | ) 3560 | ) 3561 | ) 3562 | (i64.const 0) 3563 | ) 3564 | (i32.load 3565 | (i32.add 3566 | (get_local $16) 3567 | (i32.const 136) 3568 | ) 3569 | ) 3570 | ) 3571 | ) 3572 | ) 3573 | (call $prints 3574 | (i32.const 96) 3575 | ) 3576 | (drop 3577 | (call $store_i64 3578 | (i64.const 3316479707209269248) 3579 | (i64.const 632468476610478080) 3580 | (i32.add 3581 | (get_local $16) 3582 | (i32.const 112) 3583 | ) 3584 | (i32.const 28) 3585 | ) 3586 | ) 3587 | (br $label$3) 3588 | ) 3589 | (call $assert 3590 | (i32.eqz 3591 | (i32.load8_u offset=44 3592 | (get_local $0) 3593 | ) 3594 | ) 3595 | (i32.const 864) 3596 | ) 3597 | (call $prints 3598 | (i32.const 1152) 3599 | ) 3600 | (call $assert 3601 | (call $store_i128i128 3602 | (i64.const 3316479707209269248) 3603 | (i64.const 925261025006059520) 3604 | (get_local $0) 3605 | (i32.const 44) 3606 | ) 3607 | (i32.const 896) 3608 | ) 3609 | (i32.store 3610 | (tee_local $0 3611 | (i32.add 3612 | (i32.add 3613 | (get_local $16) 3614 | (i32.const 112) 3615 | ) 3616 | (i32.const 24) 3617 | ) 3618 | ) 3619 | (tee_local $0 3620 | (i32.add 3621 | (i32.load 3622 | (get_local $0) 3623 | ) 3624 | (i32.const 1) 3625 | ) 3626 | ) 3627 | ) 3628 | (br_if $label$2 3629 | (i32.eqz 3630 | (i32.or 3631 | (i64.ne 3632 | (i64.or 3633 | (i64.load 3634 | (i32.add 3635 | (get_local $16) 3636 | (i32.const 128) 3637 | ) 3638 | ) 3639 | (i64.load 3640 | (i32.add 3641 | (i32.add 3642 | (get_local $16) 3643 | (i32.const 112) 3644 | ) 3645 | (i32.const 8) 3646 | ) 3647 | ) 3648 | ) 3649 | (i64.const 0) 3650 | ) 3651 | (get_local $0) 3652 | ) 3653 | ) 3654 | ) 3655 | (call $prints 3656 | (i32.const 96) 3657 | ) 3658 | (drop 3659 | (call $store_i64 3660 | (i64.const 3316479707209269248) 3661 | (i64.const 632468476610478080) 3662 | (i32.add 3663 | (get_local $16) 3664 | (i32.const 112) 3665 | ) 3666 | (i32.const 28) 3667 | ) 3668 | ) 3669 | (br $label$0) 3670 | ) 3671 | (call $prints 3672 | (i32.const 80) 3673 | ) 3674 | (drop 3675 | (call $remove_i64 3676 | (i64.const 3316479707209269248) 3677 | (i64.const 632468476610478080) 3678 | (i32.add 3679 | (get_local $16) 3680 | (i32.const 112) 3681 | ) 3682 | ) 3683 | ) 3684 | ) 3685 | (br_if $label$1 3686 | (i64.eqz 3687 | (i64.load 3688 | (i32.add 3689 | (get_local $0) 3690 | (i32.const 32) 3691 | ) 3692 | ) 3693 | ) 3694 | ) 3695 | (call $assert 3696 | (i32.eqz 3697 | (i32.load8_u offset=44 3698 | (get_local $0) 3699 | ) 3700 | ) 3701 | (i32.const 864) 3702 | ) 3703 | (call $prints 3704 | (i32.const 1264) 3705 | ) 3706 | (call $assert 3707 | (call $store_i128i128 3708 | (i64.const 3316479707209269248) 3709 | (i64.const 925261025006059520) 3710 | (get_local $0) 3711 | (i32.const 44) 3712 | ) 3713 | (i32.const 896) 3714 | ) 3715 | (br $label$0) 3716 | ) 3717 | (call $prints 3718 | (i32.const 80) 3719 | ) 3720 | (drop 3721 | (call $remove_i64 3722 | (i64.const 3316479707209269248) 3723 | (i64.const 632468476610478080) 3724 | (i32.add 3725 | (get_local $16) 3726 | (i32.const 112) 3727 | ) 3728 | ) 3729 | ) 3730 | (br $label$0) 3731 | ) 3732 | (call $prints 3733 | (i32.const 1280) 3734 | ) 3735 | ) 3736 | (i32.store offset=4 3737 | (i32.const 0) 3738 | (i32.add 3739 | (get_local $16) 3740 | (i32.const 192) 3741 | ) 3742 | ) 3743 | ) 3744 | (func $_ZN8exchange25apply_exchange_cancel_buyENS_7OrderIDE (param $0 i32) 3745 | (local $1 i64) 3746 | (local $2 i32) 3747 | (i32.store offset=4 3748 | (i32.const 0) 3749 | (tee_local $2 3750 | (i32.sub 3751 | (i32.load offset=4 3752 | (i32.const 0) 3753 | ) 3754 | (i32.const 80) 3755 | ) 3756 | ) 3757 | ) 3758 | (call $requireAuth 3759 | (tee_local $1 3760 | (i64.load 3761 | (get_local $0) 3762 | ) 3763 | ) 3764 | ) 3765 | (i64.store 3766 | (i32.add 3767 | (get_local $2) 3768 | (i32.const 56) 3769 | ) 3770 | (i64.const 0) 3771 | ) 3772 | (i32.store 3773 | (i32.add 3774 | (i32.add 3775 | (get_local $2) 3776 | (i32.const 32) 3777 | ) 3778 | (i32.const 12) 3779 | ) 3780 | (i32.load 3781 | (i32.add 3782 | (get_local $0) 3783 | (i32.const 12) 3784 | ) 3785 | ) 3786 | ) 3787 | (i32.store 3788 | (i32.add 3789 | (i32.add 3790 | (get_local $2) 3791 | (i32.const 32) 3792 | ) 3793 | (i32.const 8) 3794 | ) 3795 | (i32.load 3796 | (i32.add 3797 | (get_local $0) 3798 | (i32.const 8) 3799 | ) 3800 | ) 3801 | ) 3802 | (i64.store offset=48 3803 | (get_local $2) 3804 | (i64.const 1) 3805 | ) 3806 | (i64.store offset=64 3807 | (get_local $2) 3808 | (i64.const 0) 3809 | ) 3810 | (i32.store offset=36 3811 | (get_local $2) 3812 | (i32.load 3813 | (i32.add 3814 | (get_local $0) 3815 | (i32.const 4) 3816 | ) 3817 | ) 3818 | ) 3819 | (i32.store offset=32 3820 | (get_local $2) 3821 | (i32.load 3822 | (get_local $0) 3823 | ) 3824 | ) 3825 | (call $assert 3826 | (i32.eq 3827 | (call $load_primary_i128i128 3828 | (i64.const 3316479707209269248) 3829 | (i64.const 3316479707209269248) 3830 | (i64.const 1317637142540713984) 3831 | (i32.add 3832 | (get_local $2) 3833 | (i32.const 32) 3834 | ) 3835 | (i32.const 44) 3836 | ) 3837 | (i32.const 44) 3838 | ) 3839 | (i32.const 1296) 3840 | ) 3841 | (i64.store offset=8 3842 | (get_local $2) 3843 | (i64.const 0) 3844 | ) 3845 | (i64.store 3846 | (get_local $2) 3847 | (get_local $1) 3848 | ) 3849 | (i64.store offset=16 3850 | (get_local $2) 3851 | (i64.const 0) 3852 | ) 3853 | (i32.store offset=24 3854 | (get_local $2) 3855 | (i32.const 0) 3856 | ) 3857 | (drop 3858 | (call $load_i64 3859 | (i64.const 3316479707209269248) 3860 | (i64.const 3316479707209269248) 3861 | (i64.const 632468476610478080) 3862 | (get_local $2) 3863 | (i32.const 28) 3864 | ) 3865 | ) 3866 | (call $assert 3867 | (i64.ge_u 3868 | (i64.add 3869 | (tee_local $1 3870 | (i64.load offset=64 3871 | (get_local $2) 3872 | ) 3873 | ) 3874 | (i64.load offset=8 3875 | (get_local $2) 3876 | ) 3877 | ) 3878 | (get_local $1) 3879 | ) 3880 | (i32.const 32) 3881 | ) 3882 | (i64.store offset=8 3883 | (get_local $2) 3884 | (i64.add 3885 | (i64.load offset=8 3886 | (get_local $2) 3887 | ) 3888 | (i64.load offset=64 3889 | (get_local $2) 3890 | ) 3891 | ) 3892 | ) 3893 | (i32.store offset=24 3894 | (get_local $2) 3895 | (i32.add 3896 | (i32.load offset=24 3897 | (get_local $2) 3898 | ) 3899 | (i32.const -1) 3900 | ) 3901 | ) 3902 | (drop 3903 | (call $remove_i128i128 3904 | (i64.const 3316479707209269248) 3905 | (i64.const 1317637142540713984) 3906 | (i32.add 3907 | (get_local $2) 3908 | (i32.const 32) 3909 | ) 3910 | ) 3911 | ) 3912 | (block $label$0 3913 | (block $label$1 3914 | (br_if $label$1 3915 | (i32.eqz 3916 | (i32.or 3917 | (i64.ne 3918 | (i64.or 3919 | (i64.load offset=16 3920 | (get_local $2) 3921 | ) 3922 | (i64.load offset=8 3923 | (get_local $2) 3924 | ) 3925 | ) 3926 | (i64.const 0) 3927 | ) 3928 | (i32.load offset=24 3929 | (get_local $2) 3930 | ) 3931 | ) 3932 | ) 3933 | ) 3934 | (call $prints 3935 | (i32.const 96) 3936 | ) 3937 | (drop 3938 | (call $store_i64 3939 | (i64.const 3316479707209269248) 3940 | (i64.const 632468476610478080) 3941 | (get_local $2) 3942 | (i32.const 28) 3943 | ) 3944 | ) 3945 | (br $label$0) 3946 | ) 3947 | (call $prints 3948 | (i32.const 80) 3949 | ) 3950 | (drop 3951 | (call $remove_i64 3952 | (i64.const 3316479707209269248) 3953 | (i64.const 632468476610478080) 3954 | (get_local $2) 3955 | ) 3956 | ) 3957 | ) 3958 | (call $prints 3959 | (i32.const 1344) 3960 | ) 3961 | (i32.store offset=4 3962 | (i32.const 0) 3963 | (i32.add 3964 | (get_local $2) 3965 | (i32.const 80) 3966 | ) 3967 | ) 3968 | ) 3969 | (func $_ZN8exchange26apply_exchange_cancel_sellENS_7OrderIDE (param $0 i32) 3970 | (local $1 i64) 3971 | (local $2 i32) 3972 | (i32.store offset=4 3973 | (i32.const 0) 3974 | (tee_local $2 3975 | (i32.sub 3976 | (i32.load offset=4 3977 | (i32.const 0) 3978 | ) 3979 | (i32.const 80) 3980 | ) 3981 | ) 3982 | ) 3983 | (call $requireAuth 3984 | (tee_local $1 3985 | (i64.load 3986 | (get_local $0) 3987 | ) 3988 | ) 3989 | ) 3990 | (i64.store 3991 | (i32.add 3992 | (get_local $2) 3993 | (i32.const 56) 3994 | ) 3995 | (i64.const 0) 3996 | ) 3997 | (i32.store 3998 | (i32.add 3999 | (i32.add 4000 | (get_local $2) 4001 | (i32.const 32) 4002 | ) 4003 | (i32.const 12) 4004 | ) 4005 | (i32.load 4006 | (i32.add 4007 | (get_local $0) 4008 | (i32.const 12) 4009 | ) 4010 | ) 4011 | ) 4012 | (i32.store 4013 | (i32.add 4014 | (i32.add 4015 | (get_local $2) 4016 | (i32.const 32) 4017 | ) 4018 | (i32.const 8) 4019 | ) 4020 | (i32.load 4021 | (i32.add 4022 | (get_local $0) 4023 | (i32.const 8) 4024 | ) 4025 | ) 4026 | ) 4027 | (i64.store offset=48 4028 | (get_local $2) 4029 | (i64.const 1) 4030 | ) 4031 | (i64.store offset=64 4032 | (get_local $2) 4033 | (i64.const 0) 4034 | ) 4035 | (i32.store offset=36 4036 | (get_local $2) 4037 | (i32.load 4038 | (i32.add 4039 | (get_local $0) 4040 | (i32.const 4) 4041 | ) 4042 | ) 4043 | ) 4044 | (i32.store offset=32 4045 | (get_local $2) 4046 | (i32.load 4047 | (get_local $0) 4048 | ) 4049 | ) 4050 | (call $assert 4051 | (i32.eq 4052 | (call $load_primary_i128i128 4053 | (i64.const 3316479707209269248) 4054 | (i64.const 3316479707209269248) 4055 | (i64.const 925261025006059520) 4056 | (i32.add 4057 | (get_local $2) 4058 | (i32.const 32) 4059 | ) 4060 | (i32.const 44) 4061 | ) 4062 | (i32.const 44) 4063 | ) 4064 | (i32.const 1360) 4065 | ) 4066 | (i64.store offset=8 4067 | (get_local $2) 4068 | (i64.const 0) 4069 | ) 4070 | (i64.store 4071 | (get_local $2) 4072 | (get_local $1) 4073 | ) 4074 | (i64.store offset=16 4075 | (get_local $2) 4076 | (i64.const 0) 4077 | ) 4078 | (i32.store offset=24 4079 | (get_local $2) 4080 | (i32.const 0) 4081 | ) 4082 | (drop 4083 | (call $load_i64 4084 | (i64.const 3316479707209269248) 4085 | (i64.const 3316479707209269248) 4086 | (i64.const 632468476610478080) 4087 | (get_local $2) 4088 | (i32.const 28) 4089 | ) 4090 | ) 4091 | (call $assert 4092 | (i64.ge_u 4093 | (i64.add 4094 | (tee_local $1 4095 | (i64.load offset=64 4096 | (get_local $2) 4097 | ) 4098 | ) 4099 | (i64.load offset=16 4100 | (get_local $2) 4101 | ) 4102 | ) 4103 | (get_local $1) 4104 | ) 4105 | (i32.const 32) 4106 | ) 4107 | (i64.store offset=16 4108 | (get_local $2) 4109 | (i64.add 4110 | (i64.load offset=16 4111 | (get_local $2) 4112 | ) 4113 | (i64.load offset=64 4114 | (get_local $2) 4115 | ) 4116 | ) 4117 | ) 4118 | (i32.store offset=24 4119 | (get_local $2) 4120 | (i32.add 4121 | (i32.load offset=24 4122 | (get_local $2) 4123 | ) 4124 | (i32.const -1) 4125 | ) 4126 | ) 4127 | (drop 4128 | (call $remove_i128i128 4129 | (i64.const 3316479707209269248) 4130 | (i64.const 925261025006059520) 4131 | (i32.add 4132 | (get_local $2) 4133 | (i32.const 32) 4134 | ) 4135 | ) 4136 | ) 4137 | (block $label$0 4138 | (block $label$1 4139 | (br_if $label$1 4140 | (i32.eqz 4141 | (i32.or 4142 | (i64.ne 4143 | (i64.or 4144 | (i64.load offset=16 4145 | (get_local $2) 4146 | ) 4147 | (i64.load offset=8 4148 | (get_local $2) 4149 | ) 4150 | ) 4151 | (i64.const 0) 4152 | ) 4153 | (i32.load offset=24 4154 | (get_local $2) 4155 | ) 4156 | ) 4157 | ) 4158 | ) 4159 | (call $prints 4160 | (i32.const 96) 4161 | ) 4162 | (drop 4163 | (call $store_i64 4164 | (i64.const 3316479707209269248) 4165 | (i64.const 632468476610478080) 4166 | (get_local $2) 4167 | (i32.const 28) 4168 | ) 4169 | ) 4170 | (br $label$0) 4171 | ) 4172 | (call $prints 4173 | (i32.const 80) 4174 | ) 4175 | (drop 4176 | (call $remove_i64 4177 | (i64.const 3316479707209269248) 4178 | (i64.const 632468476610478080) 4179 | (get_local $2) 4180 | ) 4181 | ) 4182 | ) 4183 | (call $prints 4184 | (i32.const 1408) 4185 | ) 4186 | (i32.store offset=4 4187 | (i32.const 0) 4188 | (i32.add 4189 | (get_local $2) 4190 | (i32.const 80) 4191 | ) 4192 | ) 4193 | ) 4194 | (func $init 4195 | ) 4196 | (func $apply (param $0 i64) (param $1 i64) 4197 | (local $2 i32) 4198 | (local $3 i32) 4199 | (local $4 i64) 4200 | (local $5 i64) 4201 | (local $6 i64) 4202 | (local $7 i64) 4203 | (local $8 i32) 4204 | (i32.store offset=4 4205 | (i32.const 0) 4206 | (tee_local $8 4207 | (i32.sub 4208 | (i32.load offset=4 4209 | (i32.const 0) 4210 | ) 4211 | (i32.const 288) 4212 | ) 4213 | ) 4214 | ) 4215 | (set_local $5 4216 | (i64.const 0) 4217 | ) 4218 | (set_local $4 4219 | (i64.const 59) 4220 | ) 4221 | (set_local $3 4222 | (i32.const 16) 4223 | ) 4224 | (set_local $6 4225 | (i64.const 0) 4226 | ) 4227 | (loop $label$0 4228 | (block $label$1 4229 | (block $label$2 4230 | (block $label$3 4231 | (block $label$4 4232 | (block $label$5 4233 | (br_if $label$5 4234 | (i64.gt_u 4235 | (get_local $5) 4236 | (i64.const 7) 4237 | ) 4238 | ) 4239 | (br_if $label$4 4240 | (i32.gt_u 4241 | (i32.and 4242 | (i32.add 4243 | (tee_local $2 4244 | (i32.load8_s 4245 | (get_local $3) 4246 | ) 4247 | ) 4248 | (i32.const -97) 4249 | ) 4250 | (i32.const 255) 4251 | ) 4252 | (i32.const 25) 4253 | ) 4254 | ) 4255 | (set_local $2 4256 | (i32.add 4257 | (get_local $2) 4258 | (i32.const 160) 4259 | ) 4260 | ) 4261 | (br $label$3) 4262 | ) 4263 | (set_local $7 4264 | (i64.const 0) 4265 | ) 4266 | (br_if $label$2 4267 | (i64.le_u 4268 | (get_local $5) 4269 | (i64.const 11) 4270 | ) 4271 | ) 4272 | (br $label$1) 4273 | ) 4274 | (set_local $2 4275 | (select 4276 | (i32.add 4277 | (get_local $2) 4278 | (i32.const 234) 4279 | ) 4280 | (i32.const 0) 4281 | (i32.lt_u 4282 | (i32.and 4283 | (i32.add 4284 | (get_local $2) 4285 | (i32.const -49) 4286 | ) 4287 | (i32.const 255) 4288 | ) 4289 | (i32.const 5) 4290 | ) 4291 | ) 4292 | ) 4293 | ) 4294 | (set_local $7 4295 | (i64.shr_s 4296 | (i64.shl 4297 | (i64.extend_u/i32 4298 | (get_local $2) 4299 | ) 4300 | (i64.const 56) 4301 | ) 4302 | (i64.const 56) 4303 | ) 4304 | ) 4305 | ) 4306 | (set_local $7 4307 | (i64.shl 4308 | (i64.and 4309 | (get_local $7) 4310 | (i64.const 31) 4311 | ) 4312 | (i64.and 4313 | (get_local $4) 4314 | (i64.const 4294967295) 4315 | ) 4316 | ) 4317 | ) 4318 | ) 4319 | (set_local $3 4320 | (i32.add 4321 | (get_local $3) 4322 | (i32.const 1) 4323 | ) 4324 | ) 4325 | (set_local $5 4326 | (i64.add 4327 | (get_local $5) 4328 | (i64.const 1) 4329 | ) 4330 | ) 4331 | (set_local $6 4332 | (i64.or 4333 | (get_local $7) 4334 | (get_local $6) 4335 | ) 4336 | ) 4337 | (br_if $label$0 4338 | (i64.ne 4339 | (tee_local $4 4340 | (i64.add 4341 | (get_local $4) 4342 | (i64.const -5) 4343 | ) 4344 | ) 4345 | (i64.const -6) 4346 | ) 4347 | ) 4348 | ) 4349 | (block $label$6 4350 | (block $label$7 4351 | (block $label$8 4352 | (block $label$9 4353 | (block $label$10 4354 | (block $label$11 4355 | (block $label$12 4356 | (br_if $label$12 4357 | (i64.ne 4358 | (get_local $6) 4359 | (get_local $0) 4360 | ) 4361 | ) 4362 | (br_if $label$11 4363 | (i64.gt_s 4364 | (get_local $1) 4365 | (i64.const 1755333687702454271) 4366 | ) 4367 | ) 4368 | (br_if $label$9 4369 | (i64.eq 4370 | (get_local $1) 4371 | (i64.const -7396951281723506688) 4372 | ) 4373 | ) 4374 | (br_if $label$7 4375 | (i64.ne 4376 | (get_local $1) 4377 | (i64.const 1545297622141501440) 4378 | ) 4379 | ) 4380 | (i64.store 4381 | (i32.add 4382 | (get_local $8) 4383 | (i32.const 264) 4384 | ) 4385 | (i64.const 0) 4386 | ) 4387 | (i64.store offset=256 4388 | (get_local $8) 4389 | (i64.const 1) 4390 | ) 4391 | (i64.store offset=248 4392 | (get_local $8) 4393 | (i64.const 0) 4394 | ) 4395 | (i64.store offset=240 4396 | (get_local $8) 4397 | (i64.const 0) 4398 | ) 4399 | (i64.store offset=272 4400 | (get_local $8) 4401 | (i64.const 0) 4402 | ) 4403 | (i32.store8 offset=284 4404 | (get_local $8) 4405 | (i32.const 0) 4406 | ) 4407 | (call $assert 4408 | (i32.gt_u 4409 | (call $readMessage 4410 | (i32.add 4411 | (get_local $8) 4412 | (i32.const 240) 4413 | ) 4414 | (i32.const 45) 4415 | ) 4416 | (i32.const 44) 4417 | ) 4418 | (i32.const 1424) 4419 | ) 4420 | (drop 4421 | (call $memcpy 4422 | (i32.add 4423 | (get_local $8) 4424 | (i32.const 14) 4425 | ) 4426 | (i32.add 4427 | (get_local $8) 4428 | (i32.const 240) 4429 | ) 4430 | (i32.const 45) 4431 | ) 4432 | ) 4433 | (call $_ZN8exchange18apply_exchange_buyENS_8BuyOrderE 4434 | (i32.add 4435 | (get_local $8) 4436 | (i32.const 14) 4437 | ) 4438 | ) 4439 | (br $label$6) 4440 | ) 4441 | (set_local $5 4442 | (i64.const 0) 4443 | ) 4444 | (set_local $4 4445 | (i64.const 59) 4446 | ) 4447 | (set_local $3 4448 | (i32.const 1472) 4449 | ) 4450 | (set_local $6 4451 | (i64.const 0) 4452 | ) 4453 | (loop $label$13 4454 | (block $label$14 4455 | (block $label$15 4456 | (block $label$16 4457 | (block $label$17 4458 | (block $label$18 4459 | (br_if $label$18 4460 | (i64.gt_u 4461 | (get_local $5) 4462 | (i64.const 7) 4463 | ) 4464 | ) 4465 | (br_if $label$17 4466 | (i32.gt_u 4467 | (i32.and 4468 | (i32.add 4469 | (tee_local $2 4470 | (i32.load8_s 4471 | (get_local $3) 4472 | ) 4473 | ) 4474 | (i32.const -97) 4475 | ) 4476 | (i32.const 255) 4477 | ) 4478 | (i32.const 25) 4479 | ) 4480 | ) 4481 | (set_local $2 4482 | (i32.add 4483 | (get_local $2) 4484 | (i32.const 160) 4485 | ) 4486 | ) 4487 | (br $label$16) 4488 | ) 4489 | (set_local $7 4490 | (i64.const 0) 4491 | ) 4492 | (br_if $label$15 4493 | (i64.le_u 4494 | (get_local $5) 4495 | (i64.const 11) 4496 | ) 4497 | ) 4498 | (br $label$14) 4499 | ) 4500 | (set_local $2 4501 | (select 4502 | (i32.add 4503 | (get_local $2) 4504 | (i32.const 234) 4505 | ) 4506 | (i32.const 0) 4507 | (i32.lt_u 4508 | (i32.and 4509 | (i32.add 4510 | (get_local $2) 4511 | (i32.const -49) 4512 | ) 4513 | (i32.const 255) 4514 | ) 4515 | (i32.const 5) 4516 | ) 4517 | ) 4518 | ) 4519 | ) 4520 | (set_local $7 4521 | (i64.shr_s 4522 | (i64.shl 4523 | (i64.extend_u/i32 4524 | (get_local $2) 4525 | ) 4526 | (i64.const 56) 4527 | ) 4528 | (i64.const 56) 4529 | ) 4530 | ) 4531 | ) 4532 | (set_local $7 4533 | (i64.shl 4534 | (i64.and 4535 | (get_local $7) 4536 | (i64.const 31) 4537 | ) 4538 | (i64.and 4539 | (get_local $4) 4540 | (i64.const 4294967295) 4541 | ) 4542 | ) 4543 | ) 4544 | ) 4545 | (set_local $3 4546 | (i32.add 4547 | (get_local $3) 4548 | (i32.const 1) 4549 | ) 4550 | ) 4551 | (set_local $5 4552 | (i64.add 4553 | (get_local $5) 4554 | (i64.const 1) 4555 | ) 4556 | ) 4557 | (set_local $6 4558 | (i64.or 4559 | (get_local $7) 4560 | (get_local $6) 4561 | ) 4562 | ) 4563 | (br_if $label$13 4564 | (i64.ne 4565 | (tee_local $4 4566 | (i64.add 4567 | (get_local $4) 4568 | (i64.const -5) 4569 | ) 4570 | ) 4571 | (i64.const -6) 4572 | ) 4573 | ) 4574 | ) 4575 | (br_if $label$10 4576 | (i64.ne 4577 | (get_local $6) 4578 | (get_local $0) 4579 | ) 4580 | ) 4581 | (set_local $5 4582 | (i64.const 0) 4583 | ) 4584 | (set_local $4 4585 | (i64.const 59) 4586 | ) 4587 | (set_local $3 4588 | (i32.const 1488) 4589 | ) 4590 | (set_local $6 4591 | (i64.const 0) 4592 | ) 4593 | (loop $label$19 4594 | (block $label$20 4595 | (block $label$21 4596 | (block $label$22 4597 | (block $label$23 4598 | (block $label$24 4599 | (br_if $label$24 4600 | (i64.gt_u 4601 | (get_local $5) 4602 | (i64.const 7) 4603 | ) 4604 | ) 4605 | (br_if $label$23 4606 | (i32.gt_u 4607 | (i32.and 4608 | (i32.add 4609 | (tee_local $2 4610 | (i32.load8_s 4611 | (get_local $3) 4612 | ) 4613 | ) 4614 | (i32.const -97) 4615 | ) 4616 | (i32.const 255) 4617 | ) 4618 | (i32.const 25) 4619 | ) 4620 | ) 4621 | (set_local $2 4622 | (i32.add 4623 | (get_local $2) 4624 | (i32.const 160) 4625 | ) 4626 | ) 4627 | (br $label$22) 4628 | ) 4629 | (set_local $7 4630 | (i64.const 0) 4631 | ) 4632 | (br_if $label$21 4633 | (i64.le_u 4634 | (get_local $5) 4635 | (i64.const 11) 4636 | ) 4637 | ) 4638 | (br $label$20) 4639 | ) 4640 | (set_local $2 4641 | (select 4642 | (i32.add 4643 | (get_local $2) 4644 | (i32.const 234) 4645 | ) 4646 | (i32.const 0) 4647 | (i32.lt_u 4648 | (i32.and 4649 | (i32.add 4650 | (get_local $2) 4651 | (i32.const -49) 4652 | ) 4653 | (i32.const 255) 4654 | ) 4655 | (i32.const 5) 4656 | ) 4657 | ) 4658 | ) 4659 | ) 4660 | (set_local $7 4661 | (i64.shr_s 4662 | (i64.shl 4663 | (i64.extend_u/i32 4664 | (get_local $2) 4665 | ) 4666 | (i64.const 56) 4667 | ) 4668 | (i64.const 56) 4669 | ) 4670 | ) 4671 | ) 4672 | (set_local $7 4673 | (i64.shl 4674 | (i64.and 4675 | (get_local $7) 4676 | (i64.const 31) 4677 | ) 4678 | (i64.and 4679 | (get_local $4) 4680 | (i64.const 4294967295) 4681 | ) 4682 | ) 4683 | ) 4684 | ) 4685 | (set_local $3 4686 | (i32.add 4687 | (get_local $3) 4688 | (i32.const 1) 4689 | ) 4690 | ) 4691 | (set_local $5 4692 | (i64.add 4693 | (get_local $5) 4694 | (i64.const 1) 4695 | ) 4696 | ) 4697 | (set_local $6 4698 | (i64.or 4699 | (get_local $7) 4700 | (get_local $6) 4701 | ) 4702 | ) 4703 | (br_if $label$19 4704 | (i64.ne 4705 | (tee_local $4 4706 | (i64.add 4707 | (get_local $4) 4708 | (i64.const -5) 4709 | ) 4710 | ) 4711 | (i64.const -6) 4712 | ) 4713 | ) 4714 | ) 4715 | (br_if $label$6 4716 | (i64.ne 4717 | (get_local $6) 4718 | (get_local $1) 4719 | ) 4720 | ) 4721 | (i64.store offset=152 4722 | (get_local $8) 4723 | (i64.const 0) 4724 | ) 4725 | (call $assert 4726 | (i32.gt_u 4727 | (call $readMessage 4728 | (i32.add 4729 | (get_local $8) 4730 | (i32.const 136) 4731 | ) 4732 | (i32.const 24) 4733 | ) 4734 | (i32.const 23) 4735 | ) 4736 | (i32.const 1424) 4737 | ) 4738 | (call $_ZN8exchange23apply_currency_transferERKN8currency8TransferE 4739 | (i32.add 4740 | (get_local $8) 4741 | (i32.const 136) 4742 | ) 4743 | ) 4744 | (br $label$6) 4745 | ) 4746 | (br_if $label$8 4747 | (i64.eq 4748 | (get_local $1) 4749 | (i64.const 1755333687702454272) 4750 | ) 4751 | ) 4752 | (br_if $label$7 4753 | (i64.ne 4754 | (get_local $1) 4755 | (i64.const 1755333696554205184) 4756 | ) 4757 | ) 4758 | (i64.store offset=168 4759 | (get_local $8) 4760 | (i64.const 0) 4761 | ) 4762 | (i64.store offset=160 4763 | (get_local $8) 4764 | (i64.const 0) 4765 | ) 4766 | (call $assert 4767 | (i32.gt_u 4768 | (call $readMessage 4769 | (i32.add 4770 | (get_local $8) 4771 | (i32.const 160) 4772 | ) 4773 | (i32.const 16) 4774 | ) 4775 | (i32.const 15) 4776 | ) 4777 | (i32.const 1424) 4778 | ) 4779 | (i64.store 4780 | (i32.add 4781 | (get_local $8) 4782 | (i32.const 128) 4783 | ) 4784 | (i64.load offset=168 4785 | (get_local $8) 4786 | ) 4787 | ) 4788 | (i64.store offset=120 4789 | (get_local $8) 4790 | (i64.load offset=160 4791 | (get_local $8) 4792 | ) 4793 | ) 4794 | (call $_ZN8exchange26apply_exchange_cancel_sellENS_7OrderIDE 4795 | (i32.add 4796 | (get_local $8) 4797 | (i32.const 120) 4798 | ) 4799 | ) 4800 | (br $label$6) 4801 | ) 4802 | (set_local $5 4803 | (i64.const 0) 4804 | ) 4805 | (set_local $4 4806 | (i64.const 59) 4807 | ) 4808 | (set_local $3 4809 | (i32.const 1504) 4810 | ) 4811 | (set_local $6 4812 | (i64.const 0) 4813 | ) 4814 | (loop $label$25 4815 | (block $label$26 4816 | (block $label$27 4817 | (block $label$28 4818 | (block $label$29 4819 | (block $label$30 4820 | (br_if $label$30 4821 | (i64.gt_u 4822 | (get_local $5) 4823 | (i64.const 2) 4824 | ) 4825 | ) 4826 | (br_if $label$29 4827 | (i32.gt_u 4828 | (i32.and 4829 | (i32.add 4830 | (tee_local $2 4831 | (i32.load8_s 4832 | (get_local $3) 4833 | ) 4834 | ) 4835 | (i32.const -97) 4836 | ) 4837 | (i32.const 255) 4838 | ) 4839 | (i32.const 25) 4840 | ) 4841 | ) 4842 | (set_local $2 4843 | (i32.add 4844 | (get_local $2) 4845 | (i32.const 160) 4846 | ) 4847 | ) 4848 | (br $label$28) 4849 | ) 4850 | (set_local $7 4851 | (i64.const 0) 4852 | ) 4853 | (br_if $label$27 4854 | (i64.le_u 4855 | (get_local $5) 4856 | (i64.const 11) 4857 | ) 4858 | ) 4859 | (br $label$26) 4860 | ) 4861 | (set_local $2 4862 | (select 4863 | (i32.add 4864 | (get_local $2) 4865 | (i32.const 234) 4866 | ) 4867 | (i32.const 0) 4868 | (i32.lt_u 4869 | (i32.and 4870 | (i32.add 4871 | (get_local $2) 4872 | (i32.const -49) 4873 | ) 4874 | (i32.const 255) 4875 | ) 4876 | (i32.const 5) 4877 | ) 4878 | ) 4879 | ) 4880 | ) 4881 | (set_local $7 4882 | (i64.shr_s 4883 | (i64.shl 4884 | (i64.extend_u/i32 4885 | (get_local $2) 4886 | ) 4887 | (i64.const 56) 4888 | ) 4889 | (i64.const 56) 4890 | ) 4891 | ) 4892 | ) 4893 | (set_local $7 4894 | (i64.shl 4895 | (i64.and 4896 | (get_local $7) 4897 | (i64.const 31) 4898 | ) 4899 | (i64.and 4900 | (get_local $4) 4901 | (i64.const 4294967295) 4902 | ) 4903 | ) 4904 | ) 4905 | ) 4906 | (set_local $3 4907 | (i32.add 4908 | (get_local $3) 4909 | (i32.const 1) 4910 | ) 4911 | ) 4912 | (set_local $5 4913 | (i64.add 4914 | (get_local $5) 4915 | (i64.const 1) 4916 | ) 4917 | ) 4918 | (set_local $6 4919 | (i64.or 4920 | (get_local $7) 4921 | (get_local $6) 4922 | ) 4923 | ) 4924 | (br_if $label$25 4925 | (i64.ne 4926 | (tee_local $4 4927 | (i64.add 4928 | (get_local $4) 4929 | (i64.const -5) 4930 | ) 4931 | ) 4932 | (i64.const -6) 4933 | ) 4934 | ) 4935 | ) 4936 | (br_if $label$6 4937 | (i64.ne 4938 | (get_local $6) 4939 | (get_local $0) 4940 | ) 4941 | ) 4942 | (set_local $5 4943 | (i64.const 0) 4944 | ) 4945 | (set_local $4 4946 | (i64.const 59) 4947 | ) 4948 | (set_local $3 4949 | (i32.const 1488) 4950 | ) 4951 | (set_local $6 4952 | (i64.const 0) 4953 | ) 4954 | (loop $label$31 4955 | (block $label$32 4956 | (block $label$33 4957 | (block $label$34 4958 | (block $label$35 4959 | (block $label$36 4960 | (br_if $label$36 4961 | (i64.gt_u 4962 | (get_local $5) 4963 | (i64.const 7) 4964 | ) 4965 | ) 4966 | (br_if $label$35 4967 | (i32.gt_u 4968 | (i32.and 4969 | (i32.add 4970 | (tee_local $2 4971 | (i32.load8_s 4972 | (get_local $3) 4973 | ) 4974 | ) 4975 | (i32.const -97) 4976 | ) 4977 | (i32.const 255) 4978 | ) 4979 | (i32.const 25) 4980 | ) 4981 | ) 4982 | (set_local $2 4983 | (i32.add 4984 | (get_local $2) 4985 | (i32.const 160) 4986 | ) 4987 | ) 4988 | (br $label$34) 4989 | ) 4990 | (set_local $7 4991 | (i64.const 0) 4992 | ) 4993 | (br_if $label$33 4994 | (i64.le_u 4995 | (get_local $5) 4996 | (i64.const 11) 4997 | ) 4998 | ) 4999 | (br $label$32) 5000 | ) 5001 | (set_local $2 5002 | (select 5003 | (i32.add 5004 | (get_local $2) 5005 | (i32.const 234) 5006 | ) 5007 | (i32.const 0) 5008 | (i32.lt_u 5009 | (i32.and 5010 | (i32.add 5011 | (get_local $2) 5012 | (i32.const -49) 5013 | ) 5014 | (i32.const 255) 5015 | ) 5016 | (i32.const 5) 5017 | ) 5018 | ) 5019 | ) 5020 | ) 5021 | (set_local $7 5022 | (i64.shr_s 5023 | (i64.shl 5024 | (i64.extend_u/i32 5025 | (get_local $2) 5026 | ) 5027 | (i64.const 56) 5028 | ) 5029 | (i64.const 56) 5030 | ) 5031 | ) 5032 | ) 5033 | (set_local $7 5034 | (i64.shl 5035 | (i64.and 5036 | (get_local $7) 5037 | (i64.const 31) 5038 | ) 5039 | (i64.and 5040 | (get_local $4) 5041 | (i64.const 4294967295) 5042 | ) 5043 | ) 5044 | ) 5045 | ) 5046 | (set_local $3 5047 | (i32.add 5048 | (get_local $3) 5049 | (i32.const 1) 5050 | ) 5051 | ) 5052 | (set_local $5 5053 | (i64.add 5054 | (get_local $5) 5055 | (i64.const 1) 5056 | ) 5057 | ) 5058 | (set_local $6 5059 | (i64.or 5060 | (get_local $7) 5061 | (get_local $6) 5062 | ) 5063 | ) 5064 | (br_if $label$31 5065 | (i64.ne 5066 | (tee_local $4 5067 | (i64.add 5068 | (get_local $4) 5069 | (i64.const -5) 5070 | ) 5071 | ) 5072 | (i64.const -6) 5073 | ) 5074 | ) 5075 | ) 5076 | (br_if $label$6 5077 | (i64.ne 5078 | (get_local $6) 5079 | (get_local $1) 5080 | ) 5081 | ) 5082 | (i64.store offset=152 5083 | (get_local $8) 5084 | (i64.const 0) 5085 | ) 5086 | (call $assert 5087 | (i32.gt_u 5088 | (call $readMessage 5089 | (i32.add 5090 | (get_local $8) 5091 | (i32.const 136) 5092 | ) 5093 | (i32.const 24) 5094 | ) 5095 | (i32.const 23) 5096 | ) 5097 | (i32.const 1424) 5098 | ) 5099 | (call $_ZN8exchange18apply_eos_transferERKN3eos8TransferE 5100 | (i32.add 5101 | (get_local $8) 5102 | (i32.const 136) 5103 | ) 5104 | ) 5105 | (br $label$6) 5106 | ) 5107 | (i64.store 5108 | (i32.add 5109 | (get_local $8) 5110 | (i32.const 216) 5111 | ) 5112 | (i64.const 0) 5113 | ) 5114 | (i64.store offset=208 5115 | (get_local $8) 5116 | (i64.const 1) 5117 | ) 5118 | (i64.store offset=200 5119 | (get_local $8) 5120 | (i64.const 0) 5121 | ) 5122 | (i64.store offset=192 5123 | (get_local $8) 5124 | (i64.const 0) 5125 | ) 5126 | (i64.store offset=224 5127 | (get_local $8) 5128 | (i64.const 0) 5129 | ) 5130 | (i32.store8 offset=236 5131 | (get_local $8) 5132 | (i32.const 0) 5133 | ) 5134 | (call $assert 5135 | (i32.gt_u 5136 | (call $readMessage 5137 | (i32.add 5138 | (get_local $8) 5139 | (i32.const 192) 5140 | ) 5141 | (i32.const 45) 5142 | ) 5143 | (i32.const 44) 5144 | ) 5145 | (i32.const 1424) 5146 | ) 5147 | (drop 5148 | (call $memcpy 5149 | (i32.add 5150 | (get_local $8) 5151 | (i32.const 59) 5152 | ) 5153 | (i32.add 5154 | (get_local $8) 5155 | (i32.const 192) 5156 | ) 5157 | (i32.const 45) 5158 | ) 5159 | ) 5160 | (call $_ZN8exchange19apply_exchange_sellENS_9SellOrderE 5161 | (i32.add 5162 | (get_local $8) 5163 | (i32.const 59) 5164 | ) 5165 | ) 5166 | (br $label$6) 5167 | ) 5168 | (i64.store offset=184 5169 | (get_local $8) 5170 | (i64.const 0) 5171 | ) 5172 | (i64.store offset=176 5173 | (get_local $8) 5174 | (i64.const 0) 5175 | ) 5176 | (call $assert 5177 | (i32.gt_u 5178 | (call $readMessage 5179 | (i32.add 5180 | (get_local $8) 5181 | (i32.const 176) 5182 | ) 5183 | (i32.const 16) 5184 | ) 5185 | (i32.const 15) 5186 | ) 5187 | (i32.const 1424) 5188 | ) 5189 | (i64.store 5190 | (i32.add 5191 | (get_local $8) 5192 | (i32.const 112) 5193 | ) 5194 | (i64.load offset=184 5195 | (get_local $8) 5196 | ) 5197 | ) 5198 | (i64.store offset=104 5199 | (get_local $8) 5200 | (i64.load offset=176 5201 | (get_local $8) 5202 | ) 5203 | ) 5204 | (call $_ZN8exchange25apply_exchange_cancel_buyENS_7OrderIDE 5205 | (i32.add 5206 | (get_local $8) 5207 | (i32.const 104) 5208 | ) 5209 | ) 5210 | (br $label$6) 5211 | ) 5212 | (call $assert 5213 | (i32.const 0) 5214 | (i32.const 1456) 5215 | ) 5216 | ) 5217 | (i32.store offset=4 5218 | (i32.const 0) 5219 | (i32.add 5220 | (get_local $8) 5221 | (i32.const 288) 5222 | ) 5223 | ) 5224 | ) 5225 | ) 5226 | --------------------------------------------------------------------------------