提交 15cdca6c 编写于 作者: P Paul Yang

Merge branch 'master' of https://github.com/InfoHunter/eos

......@@ -13,7 +13,6 @@ add_subdirectory(eosio.msig)
add_subdirectory(multi_index_test)
add_subdirectory(eosio.system)
add_subdirectory(identity)
add_subdirectory(currency)
add_subdirectory(stltest)
add_subdirectory(exchange)
add_subdirectory(test.inline)
......
file(GLOB ABI_FILES "*.abi")
configure_file("${ABI_FILES}" "${CMAKE_CURRENT_BINARY_DIR}" COPYONLY)
add_wast_executable(TARGET currency
INCLUDE_FOLDERS "${STANDARD_INCLUDE_FOLDERS}"
LIBRARIES libc++ libc eosiolib
DESTINATION_FOLDER ${CMAKE_CURRENT_BINARY_DIR}
)
{
"types": [{
"new_type_name": "account_name",
"type": "name"
}
],
"structs": [{
"name": "transfer",
"base": "",
"fields": [
{"name":"from", "type":"account_name"},
{"name":"to", "type":"account_name"},
{"name":"quantity", "type":"asset"},
{"name":"memo", "type":"string"}
]
},{
"name": "create",
"base": "",
"fields": [
{"name":"issuer", "type":"account_name"},
{"name":"maximum_supply", "type":"asset"},
{"name":"can_freeze", "type":"uint8"},
{"name":"can_recall", "type":"uint8"},
{"name":"can_whitelist", "type":"uint8"}
]
},{
"name": "issue",
"base": "",
"fields": [
{"name":"to", "type":"account_name"},
{"name":"quantity", "type":"asset"},
{"name":"memo", "type":"string"}
]
},{
"name": "account",
"base": "",
"fields": [
{"name":"balance", "type":"asset"},
{"name":"frozen", "type":"uint8"},
{"name":"whitelist", "type":"uint8"}
]
},{
"name": "currency_stats",
"base": "",
"fields": [
{"name":"supply", "type":"asset"},
{"name":"max_supply", "type":"asset"},
{"name":"issuer", "type":"account_name"},
{"name":"can_freeze", "type":"uint8"},
{"name":"can_recall", "type":"uint8"},
{"name":"can_whitelist", "type":"uint8"},
{"name":"is_frozen", "type":"uint8"},
{"name":"enforce_whitelist", "type":"uint8"}
]
}
],
"actions": [{
"name": "transfer",
"type": "transfer",
"ricardian_contract": ""
},{
"name": "issue",
"type": "issue",
"ricardian_contract": ""
}, {
"name": "create",
"type": "create",
"ricardian_contract": ""
}
],
"tables": [{
"name": "accounts",
"type": "account",
"index_type": "i64",
"key_names" : ["currency"],
"key_types" : ["uint64"]
},{
"name": "stat",
"type": "currency_stats",
"index_type": "i64",
"key_names" : ["currency"],
"key_types" : ["uint64"]
}
],
"ricardian_clauses": []
}
/**
* @file
* @copyright defined in eos/LICENSE.txt
*/
#include <eosiolib/currency.hpp>
extern "C" {
/// The apply method implements the dispatch of events to this contract
void apply( uint64_t receiver, uint64_t code, uint64_t action ) {
eosio::currency(receiver).apply( code, action );
}
}
......@@ -64,6 +64,14 @@ namespace eosio {
void sub_balance( account_name owner, asset value, const currency_stats& st );
void add_balance( account_name owner, asset value, const currency_stats& st,
account_name ram_payer );
public:
struct transfer_args {
account_name from;
account_name to;
asset quantity;
string memo;
};
};
asset token::get_supply( symbol_name sym )const
......
#pragma once
#include <eosiolib/multi_index.hpp>
#include <eosiolib/token.hpp>
#include <eosiolib/asset.hpp>
#include <eosiolib/dispatcher.hpp>
#include <eosiolib/serialize.hpp>
#include <eosiolib/action.hpp>
#include <string>
#define N(X) ::eosio::string_to_name(#X)
namespace eosio {
using std::string;
template<typename Token>
class generic_currency {
public:
typedef Token token_type;
static const uint64_t code = token_type::code;
static const uint64_t symbol = token_type::symbol;
static const uint64_t accounts_table_name = N(account);
static const uint64_t stats_table_name = N(stat);
ACTION( code, issue ) {
typedef action_meta<code,N(issue)> meta;
issue() { }
issue(account_name a, asset q): to(a), quantity(q) { }
account_name to;
asset quantity;
EOSLIB_SERIALIZE( issue, (to)(quantity) )
};
ACTION( code, transfer ) {
transfer(){}
transfer( account_name f, account_name t, token_type q ):from(f),to(t),quantity(q){}
account_name from;
account_name to;
asset quantity;
template<typename DataStream>
friend DataStream& operator << ( DataStream& ds, const transfer& t ){
return ds << t.from << t.to << t.quantity;
}
template<typename DataStream>
friend DataStream& operator >> ( DataStream& ds, transfer& t ){
ds >> t.from >> t.to >> t.quantity;
eosio_assert( t.quantity.symbol== token_type::symbol, "unexpected asset type" );
return ds;
}
};
struct transfer_memo : public transfer {
transfer_memo(){}
transfer_memo( account_name f, account_name t, token_type q, string m )
:transfer( f, t, q ), memo( std::move(m) ){}
string memo;
EOSLIB_SERIALIZE_DERIVED( transfer_memo, transfer, (memo) )
};
struct account {
token_type balance;
uint64_t symbol = token_type::symbol;
auto primary_key() const { return symbol; }
EOSLIB_SERIALIZE( account, (balance)(symbol) )
};
struct currency_stats {
token_type supply;
uint64_t symbol = token_type::symbol;
auto primary_key() const { return symbol; }
EOSLIB_SERIALIZE( currency_stats, (supply)(symbol) )
};
/**
* Each user stores their balance in the singleton table under the
* scope of their account name.
*/
typedef eosio::multi_index<accounts_table_name, account> accounts;
typedef eosio::multi_index<stats_table_name, currency_stats> stats;
static token_type get_balance( account_name owner ) {
accounts t( code, owner );
auto itr = t.find( symbol );
return itr != t.end() ? itr->balance : token_type( asset(0, symbol) );
}
static void set_balance( account_name owner, token_type balance, account_name create_bill_to, account_name update_bill_to ) {
accounts t( code, owner );
auto f = [&](account& acc) {
acc.symbol = symbol;
acc.balance = balance;
};
auto itr = t.find( symbol );
if( itr != t.end() ) {
t.modify( itr, update_bill_to, f);
} else {
t.emplace( create_bill_to, f);
}
}
static void on( const issue& act ) {
require_auth( code );
stats t( code, code );
auto itr = t.find( symbol );
if( itr != t.end() ) {
t.modify(itr, 0, [&](currency_stats& s) { s.supply += act.quantity; });
} else {
t.emplace(code, [&](currency_stats& s) { s.supply = act.quantity; });
}
set_balance( code, get_balance( code ) + token_type(act.quantity), code, 0 );
inline_transfer( code, act.to, act.quantity );
}
static void on( const transfer& act ) {
require_auth( act.from );
require_recipient(act.to,act.from);
set_balance( act.from, get_balance( act.from ) - token_type(act.quantity), act.from, act.from );
set_balance( act.to, get_balance( act.to ) + token_type(act.quantity), act.from, 0 );
}
static void inline_transfer( account_name from, account_name to, token_type quantity,
string memo = string() )
{
action act( permission_level(from,N(active)), transfer_memo( from, to, asset(quantity), move(memo) ));
act.send();
}
static void inline_issue(account_name to, token_type quantity)
{
action act(permission_level(code, N(active)), issue(to, asset(quantity)));
act.send();
}
static token_type get_total_supply() {
stats t( code, code );
auto ptr = t.find( symbol );
return ptr != t.end() ? ptr->supply : token_type(0);
}
static void apply( account_name c, action_name act) {
eosio::dispatch<generic_currency, transfer, issue>(c,act);
}
};
} /// namespace eosio
#pragma once
#include <eosiolib/generic_currency.hpp>
namespace eosio {
/* TODO: make native currency match generic currency, requires changes in the native code
struct native_token_def {
static const uint64_t code = N(eosio);
static const uint64_t symbol = N(eos);
};
using native_currency = generic_currency<native_token_def>;
*/
struct native_currency {
struct transfer : public action_meta<N(eosio),N(transfer)> {
account_name from;
account_name to;
uint64_t quantity;
string memo;
template<typename DataStream>
friend DataStream& operator << ( DataStream& ds, const transfer& t ){
return ds << t.from << t.to << t.quantity << t.memo;
}
template<typename DataStream>
friend DataStream& operator >> ( DataStream& ds, transfer& t ){
return ds >> t.from >> t.to >> t.quantity >> t.memo;
}
};
};
} /// namespace eosio
/**
* @file token.hpp
* @copyright defined in eos/LICENSE.txt
* @brief Defines types and ABI for standard token messages and database tables
*
*/
#pragma once
#include <eosiolib/math.hpp>
#include <eosiolib/print.hpp>
#include <eosiolib/reflect.hpp>
#include <eosiolib/asset.hpp>
#include <eosiolib/serialize.hpp>
namespace eosio {
/**
* @defgroup tokens Token API
* @brief Defines the ABI for interfacing with standard-compatible token messages and database tables.
* @ingroup contractdev
*
* @{
*/
template<typename BaseToken, typename QuoteToken>
struct price;
template< uint64_t Code,
uint64_t Symbol,
typename NumberType = uint64_t
>
struct token {
/**
* Type of the currency (e.g. eos) represented as an unsigned 64 bit integer
* @brief Type of the currency
*/
static const uint64_t code = Code;
static const uint64_t symbol = Symbol;
/**
* Default constructor
* @brief Default constructor
*/
token(){}
template<typename Base, typename Quote>
friend price<Base,Quote> operator / ( const Base& b, const Quote& q );
explicit operator asset()const { return asset( int64_t(quantity), Symbol ); }
token( const asset& a ):quantity(NumberType(a.amount)) {
eosio_assert( a.symbol == Symbol, "attempt to construct token from asset with different symbol" );
eosio_assert( 0 <= a.amount, "attemt to convert asset with negative value to token" );
}
/**
* Constructor for token given quantity of tokens available
* @brief Constructor for token given quantity of tokens available
* @param v - quantity of tokens available
*/
explicit token( NumberType v ):quantity(v){}
/**
* Quantity of tokens available
* @brief Quantity of tokens available
*/
NumberType quantity = 0;
/**
* Subtracts quantity of token from this object
* Throws an exception if underflow
* @brief Subtracts quantity of token from this object
* @param a token to be subtracted
* @return this token after subtraction
*/
token& operator-=( const token& a ) {
eosio_assert( quantity >= a.quantity, "integer underflow subtracting token balance" );
quantity -= a.quantity;
return *this;
}
/**
* Adds quantity of token to this object
* Throws an exception if overflow
* @brief Adds quantity of token to this object
* @param a token to be added
* @return this token after addition
*/
token& operator+=( const token& a ) {
eosio_assert( quantity + a.quantity >= a.quantity, "integer overflow adding token balance" );
quantity += a.quantity;
return *this;
}
/**
* Adds quantity of two tokens and return a new token
* Throws an exception if overflow
* @brief Adds quantity of two tokens and return a new token
* @param a token to be added
* @param b token to be added
* @return result of addition as a new token
*/
inline friend token operator+( const token& a, const token& b ) {
token result = a;
result += b;
return result;
}
/**
* Subtracts quantity of two tokens and return a new token
* Throws an exception if underflow
* @brief Subtracts quantity of two tokens and return a new token
* @param a token to be subtracted
* @param b token to be subtracted
* @return result of subtraction as a new token
*/
inline friend token operator-( const token& a, const token& b ) {
token result = a;
result -= b;
return result;
}
/**
* Multiplies quantity of token by an integer
* Throws an exception if overflow
* @brief Multiplies quantity of token by an integer
* @param a multipier
* @return this token after addition
*/
token& operator*=( uint64_t a ) {
eosio_assert( a == 0 || (quantity * a) / a == quantity, "integer overflow multiplying token balance" );
quantity *= a;
return *this;
}
/**
* Multiplies token and integer
* Throws an exception if overflow
* @brief Multiplies quantity of two tokens and return a new token
* @param a token to be multiplied
* @param b multipier
* @return result of addition as a new token
*/
inline friend token operator*( const token& a, uint64_t b ) {
token result = a;
result *= b;
return result;
}
/**
* Multiplies token and integer
* Throws an exception if overflow
* @brief Multiplies quantity of two tokens and return a new token
* @param a token to be multiplied
* @param b multipier
* @return result of addition as a new token
*/
inline friend token operator*( uint64_t b, const token& a ) {
token result = a;
result *= b;
return result;
}
/**
* Divides quantity of token by an integer
* Throws an exception if overflow
* @brief Divides quantity of token by an integer
* @param a multipier
* @return this token after addition
*/
token& operator/=( uint64_t a ) {
quantity /= a;
return *this;
}
/**
* Divides token and integer
* Throws an exception if overflow
* @brief Divides quantity of two tokens and return a new token
* @param a token to be multiplied
* @param b multipier
* @return result of addition as a new token
*/
inline friend token operator/( const token& a, uint64_t b ) {
token result = a;
result /= b;
return result;
}
/**
* Divides two tokens
* Throws an exception if overflow
* @brief Divides quantity of two tokens and return a new token
* @param a token
* @param b token
* @return result of addition as a new token
*/
inline friend NumberType operator/( const token& a, const token& b ) {
return a.quantity / b.quantity;
}
/**
* Less than or equal to comparison operator
* @brief Less than or equal to comparison operator
* @param a token to be compared
* @param b token to be compared
* @return true if quantity of a is less than or equal to quantity of b
*/
friend bool operator <= ( const token& a, const token& b ) { return a.quantity <= b.quantity; }
/**
* Less than comparison operator
* @brief Less than comparison operator
* @param a token to be compared
* @param b token to be compared
* @return true if quantity of a is less than quantity of b
*/
friend bool operator < ( const token& a, const token& b ) { return a.quantity < b.quantity; }
/**
* Greater than or equal to comparison operator
* @brief Greater than or equal to comparison operator
* @param a token to be compared
* @param b token to be compared
* @return true if quantity of a is greater than or equal to quantity of b
*/
friend bool operator >= ( const token& a, const token& b ) { return a.quantity >= b.quantity; }
/**
* Greater than comparison operator
* @brief Greater than comparison operator
* @param a token to be compared
* @param b token to be compared
* @return true if quantity of a is greater than quantity of b
*/
friend bool operator > ( const token& a, const token& b ) { return a.quantity > b.quantity; }
/**
* Equality comparison operator
* @brief Equality comparison operator
* @param a token to be compared
* @param b token to be compared
* @return true if quantity of a is equal to quantity of b
*/
friend bool operator == ( const token& a, const token& b ) { return a.quantity == b.quantity; }
/**
* Inequality comparison operator
* @brief Inequality comparison operator
* @param a token to be compared
* @param b token to be compared
* @return true if quantity of a is not equal to quantity of b
*/
friend bool operator != ( const token& a, const token& b ) { return a.quantity != b.quantity; }
/**
* Boolean conversion operator
* @brief Boolean conversion operator
* @return true if quantity is not zero
*/
explicit operator bool()const { return quantity != 0; }
template<typename DataStream>
friend DataStream& operator << ( DataStream& ds, const token& t ){
return ds << t.quantity;
}
template<typename DataStream>
friend DataStream& operator >> ( DataStream& ds, token& t ){
return ds >> t.quantity;
}
};
/// @}
template<typename BaseToken, typename QuoteToken>
struct price_ratio {
BaseToken base;
QuoteToken quote;
};
template<typename Base, typename Quote>
price<Base,Quote> operator / ( const Base& b, const Quote& q ) {
return price<Base,Quote>(b,q);
}
/**
*
* @brief Defines a fixed precision price between two tokens.
* @tparam BaseToken - represents the type of the base token
* @tparam QuoteToken - represents the type of the quote token
* @ingroup tokens
*
* @details Defines a fixed precision price between two tokens.
* A price is written as X Base/Quote. Where X is a power of 10 which makes it simpler to just shift the decimal.
* It supports the following operator: /, \, <=, <, ==, !=, >=, > and also print functionality
*
* Example:
* @code
* typedef eosio::token<uint64_t, N(MyBaseToken)> MyBaseToken;
* typedef eosio::token<uint64_t, N(MyQuoteToken)> MyQuoteToken;
* typedef price<MyBaseToken, MyQuoteToken> MyBaseToQuotePrice;
* MyBaseToken zeroBaseToken;
* MyQuoteToken zeroQuoteToken;
* MyBaseToQuotePrice zeroBaseToQuote(zeroBaseToken, zeroQuoteToken); // throws invalid price exception
* MyBaseToken baseToken(128);
* MyQuoteToken quoteToken(128);
* MyBaseToQuotePrice aPrice(baseToken, quoteToken);
* aPrice.print(); // Output: 1e+15. MyBaseToken / MyQuoteToken
* MyQuoteToken anotherQuote = baseToken / price;
* std::cout << (anotherQuote == quoteToken); // Output: true
* MyBaseToken anotherBase = quoteToken * price;
* std::cout << (anotherBase == baseToken); // Output: true
* MyBaseToQuotePrice anotherPrice(baseToken, quoteToken);
* std::cout << (aPrice == anotherPrice); // Output: true
* std::cout << (aPrice != anotherPrice); // Output: false
* MyBaseToken base256(256);
* MyBaseToQuotePrice price2(base256, quoteToken);
* std::cout << (price2 > aPrice); // Output: true
* std::cout << (aPrice < price2); // Output: true
* @endcode
*
* @{
*/
template<typename BaseToken, typename QuoteToken>
struct price
{
typedef BaseToken base_token_type;
typedef QuoteToken quote_token_type;
/**
* The largest base 10 integer that can be represented with 53 bits of
* a double. This number keeps the math in range of JavaScript. By
* being a power of 10 it makes it easier for developers to read and
* interpret the integer by simply shifting the decimal.
* @brief Precision of the price.
*/
static const uint64_t precision = 1000ll*1000ll*1000ll*1000ll*1000ll;
/**
* Default constructor.
* Initialize base per quote to be 1.
* @brief Default constructor.
*/
price():base_per_quote(1ul){}
explicit price( uint128_t b ):base_per_quote(b){}
price& operator=( uint128_t b ) {
base_per_quote = b;
return *this;
}
/**
* Construction for price given the base token and quote token.
* @brief Construction for price given the base token and quote token.
* @param base - base token
* @param quote - quote token
*/
price( BaseToken base, QuoteToken quote ) {
eosio_assert( base >= BaseToken(1ul), "invalid price" );
eosio_assert( quote >= QuoteToken(1ul), "invalid price" );
base_per_quote = base.quantity;
base_per_quote *= precision;
base_per_quote /= quote.quantity;
}
/**
* Operator returns a quote token given a base token and the conversion price.
* @brief Operator returns a quote token given a base token and the conversion price.
* @param b - base token
* @param q - price
* @return quote token
*/
friend QuoteToken operator / ( BaseToken b, const price& q ) {
return QuoteToken( uint64_t((uint128(b.quantity) * uint128(precision) / q.base_per_quote)) );
}
/**
* Operator returns a base token given a quote token and the conversion price.
* @brief Operator returns a base token given a quote token and the conversion price.
* @param b - quote token
* @param q - price
* @return base token
*/
friend BaseToken operator * ( const QuoteToken& b, const price& q ) {
//return QuoteToken( uint64_t( mult_div_i128( b.quantity, q.base_per_quote, precision ) ) );
return BaseToken( uint64_t((b.quantity * q.base_per_quote) / precision) );
}
/**
* Less than or equal to comparison operator.
* @brief Less than or equal to comparison operator.
* @param a price to be compared
* @param b price to be compared
* @return true if base per quote of a is less than or equal to base per quote of b
*/
friend bool operator <= ( const price& a, const price& b ) { return a.base_per_quote <= b.base_per_quote; }
/**
* Less than comparison operator.
* @brief Less than comparison operator.
* @param a price to be compared
* @param b price to be compared
* @return true if base per quote of a is less than base per quote of b
*/
friend bool operator < ( const price& a, const price& b ) { return a.base_per_quote < b.base_per_quote; }
/**
* Greater than or equal to comparison operator.
* @brief Greater than or equal to comparison operator.
* @param a price to be compared
* @param b price to be compared
* @return true if base per quote of a is greater than or equal to base per quote of b
*/
friend bool operator >= ( const price& a, const price& b ) { return a.base_per_quote >= b.base_per_quote; }
/**
* Greater than comparison operator.
* @brief Greater than comparison operator.
* @param a price to be compared
* @param b price to be compared
* @return true if base per quote of a is greater than base per quote of b
*/
friend bool operator > ( const price& a, const price& b ) { return a.base_per_quote > b.base_per_quote; }
/**
* Equality comparison operator.
* @brief Equality comparison operator.
* @param a price to be compared
* @param b price to be compared
* @return true if base per quote of a is equal to base per quote of b
*/
friend bool operator == ( const price& a, const price& b ) { return a.base_per_quote == b.base_per_quote; }
/**
* Inequality comparison operator.
* @brief Inequality comparison operator.
* @param a price to be compared
* @param b price to be compared
* @return true if base per quote of a is not equal to base per quote of b
*/
friend bool operator != ( const price& a, const price& b ) { return a.base_per_quote != b.base_per_quote; }
operator uint128_t()const { return base_per_quote; }
EOSLIB_SERIALIZE( price, (base_per_quote) )
private:
/**
* Represents as number of base tokens to purchase 1 quote token.
* @brief Represents number of base tokens to purchase 1 quote token.
*/
uint128_t base_per_quote;
};
/// @}
/// @} tokenhppapi
}
......@@ -5,7 +5,6 @@ add_wast_executable(TARGET exchange
DESTINATION_FOLDER ${CMAKE_CURRENT_BINARY_DIR}
)
configure_file("${ABI_FILES}" "${CMAKE_CURRENT_BINARY_DIR}" COPYONLY)
add_dependencies( exchange currency )
add_executable(test_exchange test_exchange.cpp )
#bfp/lib/pack.c bfp/lib/posit.cpp bfp/lib/util.c bfp/lib/op2.c)
......
......@@ -3,13 +3,21 @@
* @copyright defined in eos/LICENSE.txt
*/
#include <noop/noop.hpp>
namespace noop {
extern "C" {
/// The apply method implements the dispatch of events to this contract
void apply( uint64_t receiver, uint64_t code, uint64_t action ) {
eosio::dispatch<noop, noop::anyaction>(code, action);
}
}
}
#include <eosiolib/eosio.hpp>
namespace eosio {
class noop: public contract {
public:
noop( account_name self ): contract( self ) { }
void anyaction( account_name from,
const std::string& /*type*/,
const std::string& /*data*/ )
{
require_auth( from );
}
};
EOSIO_ABI( noop, ( anyaction ) )
} /// eosio
/**
* @file
* @copyright defined in eos/LICENSE.txt
*/
#pragma once
#include <eosiolib/eosio.hpp>
#include <eosiolib/dispatcher.hpp>
namespace noop {
using std::string;
/**
noop contract
All it does is require sender authorization.
Actions: anyaction
*/
class noop {
public:
ACTION(N(noop), anyaction) {
anyaction() { }
anyaction(account_name f, const string& t, const string& d): from(f), type(t), data(d) { }
account_name from;
string type;
string data;
EOSLIB_SERIALIZE(anyaction, (from)(type)(data))
};
static void on(const anyaction& act)
{
require_auth(act.from);
}
};
} /// noop
......@@ -3,10 +3,8 @@
* @copyright defined in eos/LICENSE.txt
*/
#include <proxy/proxy.hpp>
#include <eosio.system/eosio.system.hpp>
#include <eosiolib/transaction.hpp>
#include <eosiolib/currency.hpp>
#include <eosio.token/eosio.token.hpp>
namespace proxy {
using namespace eosio;
......@@ -52,7 +50,7 @@ namespace proxy {
configs::store(code_config, self);
transaction out;
out.actions.emplace_back(permission_level{self, N(active)}, N(currency), N(transfer), new_transfer);
out.actions.emplace_back(permission_level{self, N(active)}, N(eosio.token), N(transfer), new_transfer);
out.delay_sec = code_config.delay;
out.send(id, self);
}
......@@ -96,13 +94,10 @@ extern "C" {
if ( code == N(eosio)) {
if (action == N(onerror)) {
apply_onerror(receiver, deferred_transaction::from_current_action());
} if( action == N(transfer) ) {
// Comment this out for now so that the contract compiles, this will change with refactoring to use eosio.token
// apply_transfer(receiver, code, unpack_action_data<eosiosystem::contract<N(eosio.system)>::currency::transfer_memo>());
}
} else if ( code == N(currency) ) {
} else if ( code == N(eosio.token) ) {
if( action == N(transfer) ) {
apply_transfer(receiver, code, unpack_action_data<eosio::currency::transfer>());
apply_transfer(receiver, code, unpack_action_data<eosio::token::transfer_args>());
}
} else if (code == receiver ) {
if ( action == N(setowner)) {
......
......@@ -2,6 +2,8 @@
* @file
* @copyright defined in eos/LICENSE.txt
*/
#pragma once
#include <eosiolib/eosio.hpp>
namespace proxy {
......
......@@ -136,7 +136,6 @@
#include <stdexcept>
*/
//include <eosiolib/eos.hpp>
#include <eosiolib/token.hpp>
#include <eosiolib/dispatcher.hpp>
using namespace eosio;
......@@ -159,9 +158,6 @@ namespace stltest {
class contract {
public:
typedef eosio::token<N(mycurrency),S(4,MYCUR)> token_type;
static const uint64_t code = token_type::code;
static const uint64_t symbol = token_type::symbol;
static const uint64_t sent_table_name = N(sent);
static const uint64_t received_table_name = N(received);
......
......@@ -6,5 +6,3 @@ add_library( txn_test_gen_plugin
target_link_libraries( txn_test_gen_plugin appbase fc http_plugin chain_plugin )
target_include_directories( txn_test_gen_plugin PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" )
target_include_directories( txn_test_gen_plugin PUBLIC ${CMAKE_BINARY_DIR}/contracts )
add_dependencies( txn_test_gen_plugin currency )
......@@ -23,8 +23,8 @@
#include <WASM/WASM.h>
#include <Runtime/Runtime.h>
#include <currency/currency.wast.hpp>
#include <currency/currency.abi.hpp>
#include <eosio.token/eosio.token.wast.hpp>
#include <eosio.token/eosio.token.abi.hpp>
namespace eosio { namespace detail {
struct txn_test_gen_empty {};
......@@ -74,10 +74,10 @@ struct txn_test_gen_plugin_impl {
void create_test_accounts(const std::string& init_name, const std::string& init_priv_key) {
name newaccountA("txn.test.a");
name newaccountB("txn.test.b");
name newaccountC("currency");
name newaccountC("eosio.token");
name creator(init_name);
contracts::abi_def currency_abi_def = fc::json::from_string(currency_abi).as<contracts::abi_def>();
contracts::abi_def eosio_token_abi_def = fc::json::from_string(eosio_token_abi).as<contracts::abi_def>();
chain_controller& cc = app().get_plugin<chain_plugin>().chain();
chain::chain_id_type chainid;
......@@ -112,7 +112,7 @@ struct txn_test_gen_plugin_impl {
trx.actions.emplace_back(vector<chain::permission_level>{{creator,"active"}}, contracts::newaccount{creator, newaccountB, owner_auth, active_auth, recovery_auth});
}
//create "currency" account
//create "eosio.token" account
{
auto owner_auth = eosio::chain::authority{1, {{txn_text_receiver_C_pub_key, 1}}, {}};
auto active_auth = eosio::chain::authority{1, {{txn_text_receiver_C_pub_key, 1}}, {}};
......@@ -127,11 +127,11 @@ struct txn_test_gen_plugin_impl {
cc.push_transaction(packed_transaction(trx));
}
//set currency contract & initialize it
//set eosio.token contract & initialize it
{
signed_transaction trx;
vector<uint8_t> wasm = wast_to_wasm(std::string(currency_wast));
vector<uint8_t> wasm = wast_to_wasm(std::string(eosio_token_wast));
contracts::setcode handler;
handler.account = newaccountC;
......@@ -142,42 +142,42 @@ struct txn_test_gen_plugin_impl {
{
contracts::setabi handler;
handler.account = newaccountC;
handler.abi = currency_abi_def;
handler.abi = eosio_token_abi_def;
trx.actions.emplace_back( vector<chain::permission_level>{{newaccountC,"active"}}, handler);
}
abi_serializer currency_serializer(currency_abi_def);
abi_serializer eosio_token_serializer(eosio_token_abi_def);
{
action act;
act.account = N(currency);
act.account = N(eosio.token);
act.name = N(create);
act.authorization = vector<permission_level>{{newaccountC,config::active_name}};
act.data = currency_serializer.variant_to_binary("create", fc::json::from_string("{\"issuer\":\"currency\",\"maximum_supply\":\"1000000000.0000 CUR\", \"can_freeze\":0, \"can_recall\":0, \"can_whitelist\":0}}"));
act.data = eosio_token_serializer.variant_to_binary("create", fc::json::from_string("{\"issuer\":\"eosio.token\",\"maximum_supply\":\"1000000000.0000 CUR\", \"can_freeze\":0, \"can_recall\":0, \"can_whitelist\":0}}"));
trx.actions.push_back(act);
}
{
action act;
act.account = N(currency);
act.account = N(eosio.token);
act.name = N(issue);
act.authorization = vector<permission_level>{{newaccountC,config::active_name}};
act.data = currency_serializer.variant_to_binary("issue", fc::json::from_string("{\"to\":\"currency\",\"quantity\":\"600.0000 CUR\",\"memo\":\"\"}"));
act.data = eosio_token_serializer.variant_to_binary("issue", fc::json::from_string("{\"to\":\"eosio.token\",\"quantity\":\"600.0000 CUR\",\"memo\":\"\"}"));
trx.actions.push_back(act);
}
{
action act;
act.account = N(currency);
act.account = N(eosio.token);
act.name = N(transfer);
act.authorization = vector<permission_level>{{newaccountC,config::active_name}};
act.data = currency_serializer.variant_to_binary("transfer", fc::json::from_string("{\"from\":\"currency\",\"to\":\"txn.test.a\",\"quantity\":\"200.0000 CUR\",\"memo\":\"\"}"));
act.data = eosio_token_serializer.variant_to_binary("transfer", fc::json::from_string("{\"from\":\"eosio.token\",\"to\":\"txn.test.a\",\"quantity\":\"200.0000 CUR\",\"memo\":\"\"}"));
trx.actions.push_back(act);
}
{
action act;
act.account = N(currency);
act.account = N(eosio.token);
act.name = N(transfer);
act.authorization = vector<permission_level>{{newaccountC,config::active_name}};
act.data = currency_serializer.variant_to_binary("transfer", fc::json::from_string("{\"from\":\"currency\",\"to\":\"txn.test.b\",\"quantity\":\"200.0000 CUR\",\"memo\":\"\"}"));
act.data = eosio_token_serializer.variant_to_binary("transfer", fc::json::from_string("{\"from\":\"eosio.token\",\"to\":\"txn.test.b\",\"quantity\":\"200.0000 CUR\",\"memo\":\"\"}"));
trx.actions.push_back(act);
}
......@@ -202,15 +202,15 @@ struct txn_test_gen_plugin_impl {
running = true;
//create the actions here
act_a_to_b.account = N(currency);
act_a_to_b.account = N(eosio.token);
act_a_to_b.name = N(transfer);
act_a_to_b.authorization = vector<permission_level>{{name("txn.test.a"),config::active_name}};
act_a_to_b.data = currency_serializer.variant_to_binary("transfer", fc::json::from_string(fc::format_string("{\"from\":\"txn.test.a\",\"to\":\"txn.test.b\",\"quantity\":\"1.0000 CUR\",\"memo\":\"${l}\"}", fc::mutable_variant_object()("l", salt))));
act_a_to_b.data = eosio_token_serializer.variant_to_binary("transfer", fc::json::from_string(fc::format_string("{\"from\":\"txn.test.a\",\"to\":\"txn.test.b\",\"quantity\":\"1.0000 CUR\",\"memo\":\"${l}\"}", fc::mutable_variant_object()("l", salt))));
act_b_to_a.account = N(currency);
act_b_to_a.account = N(eosio.token);
act_b_to_a.name = N(transfer);
act_b_to_a.authorization = vector<permission_level>{{name("txn.test.b"),config::active_name}};
act_b_to_a.data = currency_serializer.variant_to_binary("transfer", fc::json::from_string(fc::format_string("{\"from\":\"txn.test.b\",\"to\":\"txn.test.a\",\"quantity\":\"1.0000 CUR\",\"memo\":\"${l}\"}", fc::mutable_variant_object()("l", salt))));
act_b_to_a.data = eosio_token_serializer.variant_to_binary("transfer", fc::json::from_string(fc::format_string("{\"from\":\"txn.test.b\",\"to\":\"txn.test.a\",\"quantity\":\"1.0000 CUR\",\"memo\":\"${l}\"}", fc::mutable_variant_object()("l", salt))));
timer_timeout = period;
batch = batch_size/2;
......@@ -310,7 +310,7 @@ struct txn_test_gen_plugin_impl {
int32_t txn_reference_block_lag;
abi_serializer currency_serializer = fc::json::from_string(currency_abi).as<contracts::abi_def>();
abi_serializer eosio_token_serializer = fc::json::from_string(eosio_token_abi).as<contracts::abi_def>();
};
txn_test_gen_plugin::txn_test_gen_plugin() {}
......
......@@ -28,7 +28,7 @@ target_include_directories( chain_test PUBLIC ${CMAKE_BINARY_DIR}/contracts ${CM
target_include_directories( chain_test PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/wasm_tests )
target_include_directories( chain_test PUBLIC ${CMAKE_SOURCE_DIR}/plugins/net_plugin/include )
target_include_directories( chain_test PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include )
add_dependencies(chain_test asserter test_api test_api_mem test_api_db test_api_multi_index exchange currency proxy identity identity_test stltest infinite eosio.system eosio.token eosio.bios test.inline multi_index_test noop dice eosio.msig)
add_dependencies(chain_test asserter test_api test_api_mem test_api_db test_api_multi_index exchange proxy identity identity_test stltest infinite eosio.system eosio.token eosio.bios test.inline multi_index_test noop dice eosio.msig)
#
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/p2p_tests/sync/test.sh ${CMAKE_CURRENT_BINARY_DIR}/p2p_tests/sync/test.sh COPYONLY)
......
此差异已折叠。
......@@ -393,9 +393,9 @@ try:
if hashNum != 0:
errorExit("FAILURE - get code currency failed", raw=True)
contractDir="contracts/currency"
wastFile="contracts/currency/currency.wast"
abiFile="contracts/currency/currency.abi"
contractDir="contracts/eosio.token"
wastFile="contracts/eosio.token/eosio.token.wast"
abiFile="contracts/eosio.token/eosio.token.abi"
Print("Publish contract")
trans=node.publishContract(currencyAccount.name, contractDir, wastFile, abiFile, waitForTransBlock=True)
if trans is None:
......
......@@ -6,8 +6,8 @@
#include <eosio/testing/tester.hpp>
#include <eosio/chain/contracts/abi_serializer.hpp>
#include <currency/currency.wast.hpp>
#include <currency/currency.abi.hpp>
#include <eosio.token/eosio.token.wast.hpp>
#include <eosio.token/eosio.token.abi.hpp>
#include <proxy/proxy.wast.hpp>
#include <proxy/proxy.abi.hpp>
......@@ -36,7 +36,7 @@ class currency_tester : public TESTER {
string action_type_name = abi_ser.get_action_type(name);
action act;
act.account = N(currency);
act.account = N(eosio.token);
act.name = name;
act.authorization = vector<permission_level>{{signer, config::active_name}};
act.data = abi_ser.variant_to_binary(action_type_name, data);
......@@ -49,18 +49,18 @@ class currency_tester : public TESTER {
}
asset get_balance(const account_name& account) const {
return get_currency_balance(N(currency), symbol(SY(4,CUR)), account);
return get_currency_balance(N(eosio.token), symbol(SY(4,CUR)), account);
}
currency_tester()
:TESTER(),abi_ser(json::from_string(currency_abi).as<abi_def>())
:TESTER(),abi_ser(json::from_string(eosio_token_abi).as<abi_def>())
{
create_account( N(currency));
set_code( N(currency), currency_wast );
create_account( N(eosio.token));
set_code( N(eosio.token), eosio_token_wast );
auto result = push_action(N(currency), N(create), mutable_variant_object()
("issuer", "currency")
auto result = push_action(N(eosio.token), N(create), mutable_variant_object()
("issuer", eosio_token)
("maximum_supply", "1000000000.0000 CUR")
("can_freeze", 0)
("can_recall", 0)
......@@ -68,8 +68,8 @@ class currency_tester : public TESTER {
);
wdump((result));
result = push_action(N(currency), N(issue), mutable_variant_object()
("to", "currency")
result = push_action(N(eosio.token), N(issue), mutable_variant_object()
("to", eosio_token)
("quantity", "1000000.0000 CUR")
("memo", "gggggggggggg")
);
......@@ -77,16 +77,18 @@ class currency_tester : public TESTER {
produce_block();
}
abi_serializer abi_ser;
abi_serializer abi_ser;
static const std::string eosio_token;
};
const std::string currency_tester::eosio_token = name(N(eosio.token)).to_string();
BOOST_AUTO_TEST_SUITE(currency_tests)
BOOST_AUTO_TEST_CASE( bootstrap ) try {
auto expected = asset::from_string( "1000000.0000 CUR" );
currency_tester t;
auto actual = t.get_currency_balance(N(currency), expected.get_symbol(), N(currency));
auto actual = t.get_currency_balance(N(eosio.token), expected.get_symbol(), N(eosio.token));
BOOST_REQUIRE_EQUAL(expected, actual);
} FC_LOG_AND_RETHROW() /// test_api_bootstrap
......@@ -95,8 +97,8 @@ BOOST_FIXTURE_TEST_CASE( test_transfer, currency_tester ) try {
// make a transfer from the contract to a user
{
auto trace = push_action(N(currency), N(transfer), mutable_variant_object()
("from", "currency")
auto trace = push_action(N(eosio.token), N(transfer), mutable_variant_object()
("from", eosio_token)
("to", "alice")
("quantity", "100.0000 CUR")
("memo", "fund Alice")
......@@ -112,15 +114,15 @@ BOOST_FIXTURE_TEST_CASE( test_transfer, currency_tester ) try {
BOOST_FIXTURE_TEST_CASE( test_duplicate_transfer, currency_tester ) {
create_accounts( {N(alice)} );
auto trace = push_action(N(currency), N(transfer), mutable_variant_object()
("from", "currency")
auto trace = push_action(N(eosio.token), N(transfer), mutable_variant_object()
("from", eosio_token)
("to", "alice")
("quantity", "100.0000 CUR")
("memo", "fund Alice")
);
BOOST_CHECK_THROW(push_action(N(currency), N(transfer), mutable_variant_object()
("from", "currency")
BOOST_CHECK_THROW(push_action(N(eosio.token), N(transfer), mutable_variant_object()
("from", eosio_token)
("to", "alice")
("quantity", "100.0000 CUR")
("memo", "fund Alice")),
......@@ -137,8 +139,8 @@ BOOST_FIXTURE_TEST_CASE( test_addtransfer, currency_tester ) try {
// make a transfer from the contract to a user
{
auto trace = push_action(N(currency), N(transfer), mutable_variant_object()
("from", "currency")
auto trace = push_action(N(eosio.token), N(transfer), mutable_variant_object()
("from", eosio_token)
("to", "alice")
("quantity", "100.0000 CUR")
("memo", "fund Alice")
......@@ -152,8 +154,8 @@ BOOST_FIXTURE_TEST_CASE( test_addtransfer, currency_tester ) try {
// make a transfer from the contract to a user
{
auto trace = push_action(N(currency), N(transfer), mutable_variant_object()
("from", "currency")
auto trace = push_action(N(eosio.token), N(transfer), mutable_variant_object()
("from", eosio_token)
("to", "alice")
("quantity", "10.0000 CUR")
("memo", "add Alice")
......@@ -172,8 +174,8 @@ BOOST_FIXTURE_TEST_CASE( test_overspend, currency_tester ) try {
// make a transfer from the contract to a user
{
auto trace = push_action(N(currency), N(transfer), mutable_variant_object()
("from", "currency")
auto trace = push_action(N(eosio.token), N(transfer), mutable_variant_object()
("from", eosio_token)
("to", "alice")
("quantity", "100.0000 CUR")
("memo", "fund Alice")
......@@ -206,8 +208,8 @@ BOOST_FIXTURE_TEST_CASE( test_fullspend, currency_tester ) try {
// make a transfer from the contract to a user
{
auto trace = push_action(N(currency), N(transfer), mutable_variant_object()
("from", "currency")
auto trace = push_action(N(eosio.token), N(transfer), mutable_variant_object()
("from", eosio_token)
("to", "alice")
("quantity", "100.0000 CUR")
("memo", "fund Alice")
......@@ -399,8 +401,8 @@ BOOST_FIXTURE_TEST_CASE( test_proxy, currency_tester ) try {
// for now wasm "time" is in seconds, so we have to truncate off any parts of a second that may have applied
fc::time_point expected_delivery(fc::seconds(control->head_block_time().sec_since_epoch()) + fc::seconds(10));
{
auto trace = push_action(N(currency), N(transfer), mutable_variant_object()
("from", "currency")
auto trace = push_action(N(eosio.token), N(transfer), mutable_variant_object()
("from", eosio_token)
("to", "proxy")
("quantity", "5.0000 CUR")
("memo", "fund Proxy")
......@@ -453,8 +455,8 @@ BOOST_FIXTURE_TEST_CASE( test_deferred_failure, currency_tester ) try {
// for now wasm "time" is in seconds, so we have to truncate off any parts of a second that may have applied
fc::time_point expected_delivery(fc::seconds(control->head_block_time().sec_since_epoch()) + fc::seconds(10));
auto trace = push_action(N(currency), N(transfer), mutable_variant_object()
("from", "currency")
auto trace = push_action(N(eosio.token), N(transfer), mutable_variant_object()
("from", eosio_token)
("to", "proxy")
("quantity", "5.0000 CUR")
("memo", "fund Proxy")
......@@ -516,5 +518,4 @@ BOOST_FIXTURE_TEST_CASE( test_deferred_failure, currency_tester ) try {
} FC_LOG_AND_RETHROW() /// test_currency
BOOST_AUTO_TEST_SUITE_END()
......@@ -4,8 +4,8 @@
#include <eosio/chain/contracts/abi_serializer.hpp>
#include <eosio/chain/symbol.hpp>
#include <currency/currency.wast.hpp>
#include <currency/currency.abi.hpp>
#include <eosio.token/eosio.token.wast.hpp>
#include <eosio.token/eosio.token.abi.hpp>
#include <exchange/exchange.wast.hpp>
#include <exchange/exchange.abi.hpp>
......@@ -79,7 +79,7 @@ class exchange_tester : public TESTER {
}
asset get_balance(const account_name& account) const {
return get_currency_balance(N(currency), symbol(SY(4,CUR)), account);
return get_currency_balance(N(eosio.token), symbol(SY(4,CUR)), account);
}
exchange_state get_market_state( account_name exchange, symbol sym ) {
......@@ -154,7 +154,7 @@ class exchange_tester : public TESTER {
void deploy_currency( account_name ac ) {
create_account( ac );
set_code( ac, currency_wast );
set_code( ac, eosio_token_wast /*currency_wast*/ );
}
void deploy_exchange( account_name ac ) {
......@@ -243,20 +243,20 @@ class exchange_tester : public TESTER {
create_account( N(trader) );
deploy_exchange( N(exchange) );
deploy_currency( N(currency) );
deploy_currency( N(eosio.token) );
create_currency( N(currency), N(currency), A(1000000.00 USD) );
create_currency( N(currency), N(currency), A(1000000.00 BTC) );
create_currency( N(eosio.token), N(eosio.token), A(1000000.00 USD) );
create_currency( N(eosio.token), N(eosio.token), A(1000000.00 BTC) );
issue( N(currency), N(currency), N(dan), A(1000.00 USD) );
issue( N(currency), N(currency), N(dan), A(1000.00 BTC) );
issue( N(eosio.token), N(eosio.token), N(dan), A(1000.00 USD) );
issue( N(eosio.token), N(eosio.token), N(dan), A(1000.00 BTC) );
deposit( N(exchange), N(dan), extended_asset( A(500.00 USD), N(currency) ) );
deposit( N(exchange), N(dan), extended_asset( A(500.00 BTC), N(currency) ) );
deposit( N(exchange), N(dan), extended_asset( A(500.00 USD), N(eosio.token) ) );
deposit( N(exchange), N(dan), extended_asset( A(500.00 BTC), N(eosio.token) ) );
create_exchange( N(exchange), N(dan),
extended_asset( A(400.00 USD), N(currency) ),
extended_asset( A(400.00 BTC), N(currency) ),
extended_asset( A(400.00 USD), N(eosio.token) ),
extended_asset( A(400.00 BTC), N(eosio.token) ),
A(10000000.00 EXC) );
produce_block();
......@@ -270,9 +270,9 @@ BOOST_AUTO_TEST_SUITE(exchange_tests)
BOOST_AUTO_TEST_CASE( bootstrap ) try {
auto expected = asset::from_string( "1000000.0000 CUR" );
exchange_tester t;
t.create_currency( N(currency), N(currency), expected );
t.issue( N(currency), N(currency), N(currency), expected );
auto actual = t.get_currency_balance(N(currency), expected.get_symbol(), N(currency));
t.create_currency( N(eosio.token), N(eosio.token), expected );
t.issue( N(eosio.token), N(eosio.token), N(eosio.token), expected );
auto actual = t.get_currency_balance(N(eosio.token), expected.get_symbol(), N(eosio.token));
BOOST_REQUIRE_EQUAL(expected, actual);
} FC_LOG_AND_RETHROW() /// test_api_bootstrap
......@@ -281,38 +281,38 @@ BOOST_AUTO_TEST_CASE( exchange_create ) try {
auto expected = asset::from_string( "1000000.0000 CUR" );
exchange_tester t;
t.issue( N(currency), N(currency), N(trader), A(2000.00 BTC) );
t.issue( N(currency), N(currency), N(trader), A(2000.00 USD) );
t.issue( N(eosio.token), N(eosio.token), N(trader), A(2000.00 BTC) );
t.issue( N(eosio.token), N(eosio.token), N(trader), A(2000.00 USD) );
t.deposit( N(exchange), N(trader), extended_asset( A(1500.00 USD), N(currency) ) );
t.deposit( N(exchange), N(trader), extended_asset( A(1500.00 BTC), N(currency) ) );
t.deposit( N(exchange), N(trader), extended_asset( A(1500.00 USD), N(eosio.token) ) );
t.deposit( N(exchange), N(trader), extended_asset( A(1500.00 BTC), N(eosio.token) ) );
auto trader_ex_usd = t.get_exchange_balance( N(exchange), N(currency), symbol(2,"USD"), N(trader) );
auto trader_ex_btc = t.get_exchange_balance( N(exchange), N(currency), symbol(2,"BTC"), N(trader) );
auto dan_ex_usd = t.get_exchange_balance( N(exchange), N(currency), symbol(2,"USD"), N(dan) );
auto dan_ex_btc = t.get_exchange_balance( N(exchange), N(currency), symbol(2,"BTC"), N(dan) );
auto trader_ex_usd = t.get_exchange_balance( N(exchange), N(eosio.token), symbol(2,"USD"), N(trader) );
auto trader_ex_btc = t.get_exchange_balance( N(exchange), N(eosio.token), symbol(2,"BTC"), N(trader) );
auto dan_ex_usd = t.get_exchange_balance( N(exchange), N(eosio.token), symbol(2,"USD"), N(dan) );
auto dan_ex_btc = t.get_exchange_balance( N(exchange), N(eosio.token), symbol(2,"BTC"), N(dan) );
auto dan_ex_exc = t.get_exchange_balance( N(exchange), N(exchange), symbol(2,"EXC"), N(dan) );
wdump((dan_ex_exc));
auto result = t.trade( N(exchange), N(trader), symbol(2,"EXC"),
extended_asset( A(10.00 BTC), N(currency) ),
extended_asset( A(0.01 USD), N(currency) ) );
extended_asset( A(10.00 BTC), N(eosio.token) ),
extended_asset( A(0.01 USD), N(eosio.token) ) );
for( const auto& at : result.action_traces )
ilog( "\r${s}", ("s",at.console) );
trader_ex_usd = t.get_exchange_balance( N(exchange), N(currency), symbol(2,"USD"), N(trader) );
trader_ex_btc = t.get_exchange_balance( N(exchange), N(currency), symbol(2,"BTC"), N(trader) );
trader_ex_usd = t.get_exchange_balance( N(exchange), N(eosio.token), symbol(2,"USD"), N(trader) );
trader_ex_btc = t.get_exchange_balance( N(exchange), N(eosio.token), symbol(2,"BTC"), N(trader) );
wdump((trader_ex_btc.quantity));
wdump((trader_ex_usd.quantity));
result = t.trade( N(exchange), N(trader), symbol(2,"EXC"),
extended_asset( A(9.75 USD), N(currency) ),
extended_asset( A(0.01 BTC), N(currency) ) );
extended_asset( A(9.75 USD), N(eosio.token) ),
extended_asset( A(0.01 BTC), N(eosio.token) ) );
trader_ex_usd = t.get_exchange_balance( N(exchange), N(currency), symbol(2,"USD"), N(trader) );
trader_ex_btc = t.get_exchange_balance( N(exchange), N(currency), symbol(2,"BTC"), N(trader) );
trader_ex_usd = t.get_exchange_balance( N(exchange), N(eosio.token), symbol(2,"USD"), N(trader) );
trader_ex_btc = t.get_exchange_balance( N(exchange), N(eosio.token), symbol(2,"BTC"), N(trader) );
for( const auto& at : result.action_traces )
ilog( "\r${s}", ("s",at.console) );
......@@ -333,19 +333,19 @@ BOOST_AUTO_TEST_CASE( exchange_lend ) try {
exchange_tester t;
t.create_account( N(lender) );
t.issue( N(currency), N(currency), N(lender), A(2000.00 BTC) );
t.issue( N(currency), N(currency), N(lender), A(2000.00 USD) );
t.issue( N(eosio.token), N(eosio.token), N(lender), A(2000.00 BTC) );
t.issue( N(eosio.token), N(eosio.token), N(lender), A(2000.00 USD) );
t.deposit( N(exchange), N(lender), extended_asset( A(1500.00 USD), N(currency) ) );
t.deposit( N(exchange), N(lender), extended_asset( A(1500.00 BTC), N(currency) ) );
t.deposit( N(exchange), N(lender), extended_asset( A(1500.00 USD), N(eosio.token) ) );
t.deposit( N(exchange), N(lender), extended_asset( A(1500.00 BTC), N(eosio.token) ) );
auto lender_ex_usd = t.get_exchange_balance( N(exchange), N(currency), symbol(2,"USD"), N(lender) );
auto lender_ex_btc = t.get_exchange_balance( N(exchange), N(currency), symbol(2,"BTC"), N(lender) );
auto lender_ex_usd = t.get_exchange_balance( N(exchange), N(eosio.token), symbol(2,"USD"), N(lender) );
auto lender_ex_btc = t.get_exchange_balance( N(exchange), N(eosio.token), symbol(2,"BTC"), N(lender) );
t.lend( N(exchange), N(lender), extended_asset( A(1000.00 USD), N(currency) ), symbol(2,"EXC") );
t.lend( N(exchange), N(lender), extended_asset( A(1000.00 USD), N(eosio.token) ), symbol(2,"EXC") );
lender_ex_usd = t.get_exchange_balance( N(exchange), N(currency), symbol(2,"USD"), N(lender) );
lender_ex_btc = t.get_exchange_balance( N(exchange), N(currency), symbol(2,"BTC"), N(lender) );
lender_ex_usd = t.get_exchange_balance( N(exchange), N(eosio.token), symbol(2,"USD"), N(lender) );
lender_ex_btc = t.get_exchange_balance( N(exchange), N(eosio.token), symbol(2,"BTC"), N(lender) );
wdump((lender_ex_btc.quantity));
wdump((lender_ex_usd.quantity));
......@@ -358,7 +358,7 @@ BOOST_AUTO_TEST_CASE( exchange_lend ) try {
wdump((t.get_market_state( N(exchange), symbol(2,"EXC") ) ));
t.unlend( N(exchange), N(lender), lentshares, extended_symbol{ symbol(2,"USD"), N(currency)}, symbol(2,"EXC") );
t.unlend( N(exchange), N(lender), lentshares, extended_symbol{ symbol(2,"USD"), N(eosio.token)}, symbol(2,"EXC") );
lentshares = t.get_lent_shares( N(exchange), symbol(2,"EXC"), N(lender), true );
wdump((lentshares));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册