This article is supported by the "block chain Workshop" Quality content program, and more on the depth of the block chain, please click on "Block Chain workshop".
Please note that this article is in the EOS DAWN 2.0 tokens.
Exchange intelligence contracts simulate the functions of the exchange, support the recharge of EOS and currency, and support the sale between EOS and currency.
It is noteworthy that the transfer of currency token to the exchange was made using the currency intelligent contract that we talked about in the previous session, because currency token was issued by currency intelligent contract and it was necessary to manage currency token transfer. Recharge EOS: Recharge The EOS to the exchange.
$ eosc Push Message eos transfer ' {from ': "Inita", "to": "Exchange", "Amount": "Memo": "Imtoken"} '--scope Inita, Exchange--permission Inita@active
Tips: Recharge only requires personal account authorization to present EOS: From the exchange of EOS.
$ eosc Push Message eos transfer ' {in ': ' Exchange ', ' to ': ' Inita ', ' Amount ': "Memo": "Binance"} '--scope Exchange, Inita--permission exchange@active--permission inita@active
Tips: Need Exchange account and personal account authorization to recharge Currency: Recharge to the exchange currency
$ EOSC Push Message currency transfer ' {from ': ' Inita ', ' to ': ' Exchange ', ' Quantity ': '--scope inita,exchange-- Permission Inita@active
Currency: Bring the present currency to the Exchange
$ EOSC Push Message currency transfer ' {from ': ' Exchange ', ' to ': ' Inita ', ' Quantity ': '--scope inita,exchange-- Permission Exchange@active inita@active
It is worth noting that the format of the above commands depends on the Currency.abi that have been deployed. Because Exchange smart contracts use the currency namespace in currency.hpp when transferring currency.
If the format of the Currency.abi transfer is this
{
' name ': ' Transfer ', '
base ': ',
' fields ': {
' from ': ' account_name ',
' to ': ' account_name ',
' quantity ': ' Currency_tokens '
}
}
Then the above recharge order needs to read:
$ EOSC Push Message currency transfer ' {from ': ' Inita ', ' to ': ' Exchange ', ' quantity ': {' quantity ':} '--scope Inita, Exchange--permission Inita@active
The present order should read:
$ EOSC Push Message currency transfer ' {from ': ' Exchange ', ' to ': ' Inita ', ' quantity ': {' quantity ':} '--scope Inita, Exchange--permission exchange@active inita@active
The reasons for the amendment refer to my last article, "The currency of the EOS smart contract."
If, according to the code provided by the EOS official, the bill or the sale cannot succeed, a few changes are needed:
1, modify EXCHANGE.HPP bids, asks the definition of the two table, the 4th parameter is originally bids/asks, need to change to bid/ask, otherwise it will be an error
TABLE2 (bids,exchange,exchange,bid,bid,bids_by_id,order_id,bids_by_price,price);
TABLE2 (Asks,exchange,exchange,ask,ask,asks_by_id,order_id,asks_by_price,price);
2, modify the/USR/LOCAL/INCLUDE/EOSLIB/TOKEN.HPP struct price operator *,
Friend Basetoken operator * (const quotetoken& B, const price& q) {
Eosio::p rint ("B:", B, "\ n");
Eosio::p rint ("operator*", uint128 (b.quantity), "*", uint128 (Q.base_per_quote), "/", precision, "\ n");
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));
Return Basetoken (uint64_t (b.quantity * q.base_per_quote));
}
It is worth noting that the price structure has 2 constructors, and the Exchange Smart contract uses the first constructor, and if the 2nd constructor is used, the upper * operator does not need to be modified.
/**
* Default constructor.
* Initialize Base per quote to be 1.
* @brief Default constructor.
*/Price
(): Base_per_quote (1ul) {}
/**
* Construction to 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 * *
(basetoken base, Quotetoken quote) {
assert (Base >= Basetoken (1ul), "Invalid Price");
Assert (Quote >= Quotetoken (1ul), "Invalid Price");
Base_per_quote = base.quantity;
Base_per_quote *= Precision;
Base_per_quote/= quote.quantity;
}
So you can pay the bill or sell the bill. under the bill:
$ EOSC Push message exchange buy ' {buyer ': {' name ': ' Inita ', ' Number ': 5}, ' At_price ': ' 1 ', ' Quantity ': 5, ' Expiration ': ' 2018-04-14t08:53:41 "," Fill_or_kill ":" 0 "} '-S exchange,inita-p inita@active
Sell Orders:
$ EOSC Push message exchange sell ' {seller ': {' name ': ' INITB ', ' Number ': 5}, ' At_price ': ' 1 ', ' Quantity ': 5, ' Expiration ': ' 2018-04-14t08:53:41 "," Fill_or_kill ":" 0 "} '-S exchange,initb-p initb@active
Cancel the bill:
$ EOSC Push Message exchange cancelbuy ' {' name ': ' Inita ', ' Number ': 5} '-S inita,exchange-p inita@active
Cancellation of sales orders:
$ EOSC Push Message exchange Cancelsell ' {' name ': ' INITB ', ' Number ': 5} '-S initb,exchange-p initb@active