Skip to content

Commit

Permalink
Merge pull request EOSIO#94 from enumivo/staging
Browse files Browse the repository at this point in the history
token to coin
  • Loading branch information
Enumivo authored May 14, 2018
2 parents 511e1de + bb42754 commit a812290
Show file tree
Hide file tree
Showing 33 changed files with 442 additions and 442 deletions.
54 changes: 27 additions & 27 deletions EXCHANGE_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ a couple of minutes, but either way nodeos will keep you posted on the status.

## Initial Condition
```
./cleos get currency balance eosio.token scott EOS
./cleos get currency balance enumivo.coin scott EOS
900.0000 EOS
```

Expand All @@ -60,30 +60,30 @@ We will now deposit some funds to exchange:
```
./cleos transfer scott exchange "1.0000 EOS"
executed transaction: 5ec797175dd24612acd8fc5a8685fa44caa8646cec0a87b12568db22a3df02fb 256 bytes 8k cycles
# eosio.token <= eosio.token::transfer {"from":"scott","to":"exchange","quantity":"1.0000 EOS","memo":""}
# enumivo.coin <= enumivo.coin::transfer {"from":"scott","to":"exchange","quantity":"1.0000 EOS","memo":""}
>> transfer
# scott <= eosio.token::transfer {"from":"scott","to":"exchange","quantity":"1.0000 EOS","memo":""}
# exchange <= eosio.token::transfer {"from":"scott","to":"exchange","quantity":"1.0000 EOS","memo":""}
# scott <= enumivo.coin::transfer {"from":"scott","to":"exchange","quantity":"1.0000 EOS","memo":""}
# exchange <= enumivo.coin::transfer {"from":"scott","to":"exchange","quantity":"1.0000 EOS","memo":""}
warning: transaction executed locally, but may not be confirmed by the network yet
```

This output indicates that the action "eosio.token::transfer" was delivered to 3 accounts/contracts, (eosio.token, scott, and exchange).
This output indicates that the action "enumivo.coin::transfer" was delivered to 3 accounts/contracts, (enumivo.coin, scott, and exchange).
The eosio token standard requires that both the sender and receiver account/contract be notified of all transfer actions so those
accounts can run custom logic. At this time neither `scott` nor `exchange` has any contact set, but the transaction log
still notes that they were notified.


## Polling Account History
The account history consists of all actions which were either authorized by the account or received by the account. Since the
exchange received the `eosio.token::transfer` action it is listed in the history. If you are using the console confirmed and
exchange received the `enumivo.coin::transfer` action it is listed in the history. If you are using the console confirmed and
irreversible transactions are printed in "green" while unconfirmed transactions are printed in "yellow". Without color you
can tell whether a transaction is confirmed or not by the first character, '#' for irreversible and '?' for potentially reversable.

```
./cleos get actions exchange
# seq when contract::action => receiver trx id... args
================================================================================================================
# 0 2018-04-29T01:09:45.000 eosio.token::transfer => exchange 5ec79717... {"from":"scott","to":"exchange","quantity":"1.0000 EOS","mem...
# 0 2018-04-29T01:09:45.000 enumivo.coin::transfer => exchange 5ec79717... {"from":"scott","to":"exchange","quantity":"1.0000 EOS","mem...
```

Do a few more transfers:
Expand All @@ -92,9 +92,9 @@ Do a few more transfers:
./cleos get actions exchange
# seq when contract::action => receiver trx id... args
================================================================================================================
# 0 2018-04-29T01:09:45.000 eosio.token::transfer => exchange 5ec79717... {"from":"scott","to":"exchange","quantity":"1.0000 EOS","mem...
# 1 2018-04-29T01:16:25.000 eosio.token::transfer => exchange 2269828c... {"from":"scott","to":"exchange","quantity":"1.0000 EOS","mem...
? 2 2018-04-29T01:19:54.000 eosio.token::transfer => exchange 213f3797... {"from":"scott","to":"exchange","quantity":"1.0000 EOS","mem...
# 0 2018-04-29T01:09:45.000 enumivo.coin::transfer => exchange 5ec79717... {"from":"scott","to":"exchange","quantity":"1.0000 EOS","mem...
# 1 2018-04-29T01:16:25.000 enumivo.coin::transfer => exchange 2269828c... {"from":"scott","to":"exchange","quantity":"1.0000 EOS","mem...
? 2 2018-04-29T01:19:54.000 enumivo.coin::transfer => exchange 213f3797... {"from":"scott","to":"exchange","quantity":"1.0000 EOS","mem...
```

The last transfer is still pending, waiting on irreversibility.
Expand Down Expand Up @@ -126,7 +126,7 @@ To get only the last action you would do the following...
./cleos get actions exchange -1 -1
# seq when contract::action => receiver trx id... args
================================================================================================================
# 2 2018-04-29T01:19:54.000 eosio.token::transfer => exchange 213f3797... {"from":"scott","to":"exchange","quantity":"1.0000 EOS","mem...
# 2 2018-04-29T01:19:54.000 enumivo.coin::transfer => exchange 213f3797... {"from":"scott","to":"exchange","quantity":"1.0000 EOS","mem...
```

This says go to the last sequence number (indicated by pos = -1) and then fetch "1" item prior to it (offset = -1). This should
Expand All @@ -144,7 +144,7 @@ We pass pos=1 and offset=0 to get the range [1,1+0] or [1,1].
./cleos get actions exchange 1 0
# seq when contract::action => receiver trx id... args
================================================================================================================
# 1 2018-04-29T01:16:25.000 eosio.token::transfer => exchange 2269828c... {"from":"scott","to":"exchange","quantity":"1.0000 EOS","mem...
# 1 2018-04-29T01:16:25.000 enumivo.coin::transfer => exchange 2269828c... {"from":"scott","to":"exchange","quantity":"1.0000 EOS","mem...
```

We can call this in a loop procesing each confirmed action (those starting with #) until we either run out of items or
Expand Down Expand Up @@ -184,7 +184,7 @@ Here is the JSON returned when querying sequence 2.
]
},
"act": {
"account": "eosio.token",
"account": "enumivo.coin",
"name": "transfer",
"authorization": [{
"actor": "scott",
Expand Down Expand Up @@ -217,7 +217,7 @@ Given this JSON, an action is irreversible (final) if `"block_num" < "last_irrev
You can identify irreversible deposits by the following:

```
actions[0].action_trace.act.account == "eosio.token" &&
actions[0].action_trace.act.account == "enumivo.coin" &&
actions[0].action_trace.act.name == "transfer" &&
actions[0].action_trace.act.data.quantity == "X.0000 EOS" &&
actions[0].action_trace.to == "exchange" &&
Expand All @@ -236,7 +236,7 @@ other contracts with "transfer" actions that "notify" your account. If you do no
then you may process "false deposits".

```
actions[0].action_trace.act.account == "eosio.token" &&
actions[0].action_trace.act.account == "enumivo.coin" &&
actions[0].action_trace.receipt.receiver == "exchange"
```

Expand All @@ -245,7 +245,7 @@ then you may process "false deposits".
Now that we have received 3 deposits we should see that the exchange has a balance of 3.0000 EOS.

```
./cleos get currency balance eosio.token exchange EOS
./cleos get currency balance enumivo.coin exchange EOS
3.0000 EOS
```

Expand All @@ -262,32 +262,32 @@ Lets assume scott wants to withdraw `1.0000 EOS`:
```
./cleos transfer exchange scott "1.0000 EOS"
executed transaction: 93e785202e7502bb1383ad10e786cc20f7dd738d3fd3da38712b3fb38fb9af26 256 bytes 8k cycles
# eosio.token <= eosio.token::transfer {"from":"exchange","to":"scott","quantity":"1.0000 EOS","memo":""}
# enumivo.coin <= enumivo.coin::transfer {"from":"exchange","to":"scott","quantity":"1.0000 EOS","memo":""}
>> transfer
# exchange <= eosio.token::transfer {"from":"exchange","to":"scott","quantity":"1.0000 EOS","memo":""}
# scott <= eosio.token::transfer {"from":"exchange","to":"scott","quantity":"1.0000 EOS","memo":""}
# exchange <= enumivo.coin::transfer {"from":"exchange","to":"scott","quantity":"1.0000 EOS","memo":""}
# scott <= enumivo.coin::transfer {"from":"exchange","to":"scott","quantity":"1.0000 EOS","memo":""}
warning: transaction executed locally, but may not be confirmed by the network yet
```

At this stage your local `nodeos` client accepted the transaction and likely broadcast it to the broader network.

Now we can get the history and see that there are "3" new actions listed all with trx id `93e78520...` which is what
our transfer command returned to us. Because `exchange` authorized the transaction it is informed of all accounts which
processed and accepted the 'transfer'. In this case the 'eosio.token' contract processed it and updated balances, the
processed and accepted the 'transfer'. In this case the 'enumivo.coin' contract processed it and updated balances, the
sender ('exchange') processed it and so did the receiver ('scott') and all 3 contracts/accounts approved it and/or performed
state transitions based upon the action.

```
./cleos get actions exchange -1 -8
# seq when contract::action => receiver trx id... args
================================================================================================================
# 0 2018-04-29T01:09:45.000 eosio.token::transfer => exchange 5ec79717... {"from":"scott","to":"exchange","quantity":"1.0000 EOS","mem...
# 1 2018-04-29T01:16:25.000 eosio.token::transfer => exchange 2269828c... {"from":"scott","to":"exchange","quantity":"1.0000 EOS","mem...
# 2 2018-04-29T01:19:54.000 eosio.token::transfer => exchange 213f3797... {"from":"scott","to":"exchange","quantity":"1.0000 EOS","mem...
# 3 2018-04-29T01:53:57.000 eosio.token::transfer => exchange 8b7766ac... {"from":"scott","to":"exchange","quantity":"1.0000 EOS","mem...
# 4 2018-04-29T01:54:17.500 eosio.token::transfer => eosio.token 93e78520... {"from":"exchange","to":"scott","quantity":"1.0000 EOS","mem...
# 5 2018-04-29T01:54:17.500 eosio.token::transfer => exchange 93e78520... {"from":"exchange","to":"scott","quantity":"1.0000 EOS","mem...
# 6 2018-04-29T01:54:17.500 eosio.token::transfer => scott 93e78520... {"from":"exchange","to":"scott","quantity":"1.0000 EOS","mem...
# 0 2018-04-29T01:09:45.000 enumivo.coin::transfer => exchange 5ec79717... {"from":"scott","to":"exchange","quantity":"1.0000 EOS","mem...
# 1 2018-04-29T01:16:25.000 enumivo.coin::transfer => exchange 2269828c... {"from":"scott","to":"exchange","quantity":"1.0000 EOS","mem...
# 2 2018-04-29T01:19:54.000 enumivo.coin::transfer => exchange 213f3797... {"from":"scott","to":"exchange","quantity":"1.0000 EOS","mem...
# 3 2018-04-29T01:53:57.000 enumivo.coin::transfer => exchange 8b7766ac... {"from":"scott","to":"exchange","quantity":"1.0000 EOS","mem...
# 4 2018-04-29T01:54:17.500 enumivo.coin::transfer => enumivo.coin 93e78520... {"from":"exchange","to":"scott","quantity":"1.0000 EOS","mem...
# 5 2018-04-29T01:54:17.500 enumivo.coin::transfer => exchange 93e78520... {"from":"exchange","to":"scott","quantity":"1.0000 EOS","mem...
# 6 2018-04-29T01:54:17.500 enumivo.coin::transfer => scott 93e78520... {"from":"exchange","to":"scott","quantity":"1.0000 EOS","mem...
```

By processing the history we can also be informed when our transaction was confirmed. In practice it may be useful to embed an exchange-specify memo
Expand Down
2 changes: 1 addition & 1 deletion contracts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ add_subdirectory(enumivolib)
add_subdirectory(musl)
add_subdirectory(libc++)
add_subdirectory(simple.token)
add_subdirectory(eosio.token)
add_subdirectory(enumivo.coin)
add_subdirectory(enumivo.msig)
add_subdirectory(multi_index_test)
add_subdirectory(eosio.system)
Expand Down
16 changes: 8 additions & 8 deletions contracts/dice/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ Example game session using cleos
cleos set contract eosio build/contracts/enumivo.bios -p eosio
````

##### Ceate eosio.token account
##### Ceate enumivo.coin account
````bash
cleos create account eosio eosio.token EOS7ijWCBmoXBi3CgtK7DJxentZZeTkeUnaSDvyro9dq7Sd1C3dC4 EOS7ijWCBmoXBi3CgtK7DJxentZZeTkeUnaSDvyro9dq7Sd1C3dC4
cleos create account eosio enumivo.coin EOS7ijWCBmoXBi3CgtK7DJxentZZeTkeUnaSDvyro9dq7Sd1C3dC4 EOS7ijWCBmoXBi3CgtK7DJxentZZeTkeUnaSDvyro9dq7Sd1C3dC4
````

##### Set eosio.token contract to eosio.token account
##### Set enumivo.coin contract to enumivo.coin account
````bash
cleos set contract eosio.token build/contracts/eosio.token -p eosio.token
cleos set contract enumivo.coin build/contracts/enumivo.coin -p enumivo.coin
````

##### Create dice account
Expand All @@ -78,7 +78,7 @@ cleos set contract dice build/contracts/dice -p dice

##### Create native EOS token
````bash
cleos push action eosio.token create '[ "eosio", "1000000000.0000 EOS", 0, 0, 0]' -p eosio.token
cleos push action enumivo.coin create '[ "eosio", "1000000000.0000 EOS", 0, 0, 0]' -p enumivo.coin
````

##### Create alice account
Expand All @@ -93,12 +93,12 @@ cleos create account eosio bob EOS7ijWCBmoXBi3CgtK7DJxentZZeTkeUnaSDvyro9dq7Sd1C

##### Issue 1000 EOS to alice
````bash
cleos push action eosio.token issue '[ "alice", "1000.0000 EOS", "" ]' -p eosio
cleos push action enumivo.coin issue '[ "alice", "1000.0000 EOS", "" ]' -p eosio
````

##### Issue 1000 EOS to bob
````bash
cleos push action eosio.token issue '[ "bob", "1000.0000 EOS", "" ]' -p eosio
cleos push action enumivo.coin issue '[ "bob", "1000.0000 EOS", "" ]' -p eosio
````

##### Allow dice contract to make transfers on alice behalf (deposit)
Expand Down Expand Up @@ -263,7 +263,7 @@ cleos push action dice withdraw '[ "alice", "103.0000 EOS" ]' -p alice

##### Balance of alice after withdraw
````bash
cleos get currency balance eosio.token alice eos
cleos get currency balance enumivo.coin alice eos
1003.0000 EOS
````

4 changes: 2 additions & 2 deletions contracts/dice/dice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ class dice : public eosio::contract {

action(
permission_level{ from, N(active) },
N(eosio.token), N(transfer),
N(enumivo.coin), N(transfer),
std::make_tuple(from, _self, quantity, std::string(""))
).send();

Expand All @@ -252,7 +252,7 @@ class dice : public eosio::contract {

action(
permission_level{ _self, N(active) },
N(eosio.token), N(transfer),
N(enumivo.coin), N(transfer),
std::make_tuple(_self, to, quantity, std::string(""))
).send();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
file(GLOB ABI_FILES "*.abi")
configure_file("${ABI_FILES}" "${CMAKE_CURRENT_BINARY_DIR}" COPYONLY)

add_wast_executable(TARGET eosio.token
add_wast_executable(TARGET enumivo.coin
INCLUDE_FOLDERS "${STANDARD_INCLUDE_FOLDERS}"
LIBRARIES libc++ libc enumivolib
DESTINATION_FOLDER ${CMAKE_CURRENT_BINARY_DIR}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @copyright defined in eos/LICENSE.txt
*/

#include <eosio.token/eosio.token.hpp>
#include <enumivo.coin/enumivo.coin.hpp>

namespace eosio {

Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions contracts/enumivo.msig/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ Execute a proposal
Cleos usage example.

Prerequisites:
- eosio.token contract installed to eosio.token accountm, enumivo.msig contract installed on enumivo.msig account which is a priviliged account.
- enumivo.coin contract installed to enumivo.coin accountm, enumivo.msig contract installed on enumivo.msig account which is a priviliged account.
- account 'treasury' is the issuer of EOS token.
- account 'tester' exists.
- keys to accounts 'treasury' and 'tester' imported into local wallet, the wallet is unlocked.

One user creates a proposal:
````
$ cleos multisig propose test '[{"actor": "treasury", "permission": "active"}]' '[{"actor": "treasury", "permission": "active"}]' eosio.token issue '{"to": "tester", "quantity": "1000.0000 EOS", "memo": ""}' -p tester
$ cleos multisig propose test '[{"actor": "treasury", "permission": "active"}]' '[{"actor": "treasury", "permission": "active"}]' enumivo.coin issue '{"to": "tester", "quantity": "1000.0000 EOS", "memo": ""}' -p tester
executed transaction: e26f3a3a7cba524a7b15a0b6c77c7daa73d3ba9bf84e83f9c2cdf27fcb183d61 336 bytes 107520 cycles
# enumivo.msig <= enumivo.msig::propose {"proposer":"tester","proposal_name":"test","requested":[{"actor":"treasury","permission":"active"}]...
````
Expand All @@ -79,7 +79,7 @@ $ cleos multisig review tester test -p treasury
"delay_sec": 0,
"context_free_actions": [],
"actions": [{
"account": "eosio.token",
"account": "enumivo.coin",
"name": "issue",
"authorization": [{
"actor": "treasury",
Expand Down
2 changes: 1 addition & 1 deletion contracts/eosio.system/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ configure_file("${ABI_FILES}" "${CMAKE_CURRENT_BINARY_DIR}" COPYONLY)

add_wast_executable(TARGET eosio.system
INCLUDE_FOLDERS ${STANDARD_INCLUDE_FOLDERS}
LIBRARIES libc++ libc enumivolib eosio.token
LIBRARIES libc++ libc enumivolib enumivo.coin
DESTINATION_FOLDER ${CMAKE_CURRENT_BINARY_DIR}
)
2 changes: 1 addition & 1 deletion contracts/eosio.system/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Indicates that a particular account wishes to become a producer

## eosio.system::withdraw account
- this action can only be triggered by eosio.system via a deferred transaction generated by unstake
- this will generate an inline eosio.token::transfer call from=eosio.system to=account and amount equal to the next withdraw increment
- this will generate an inline enumivo.coin::transfer call from=eosio.system to=account and amount equal to the next withdraw increment
- this will generate another deferred withdraw to continue the process if there are still withdraws to be made


Expand Down
10 changes: 5 additions & 5 deletions contracts/eosio.system/delegate_bandwidth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <enumivolib/privileged.h>
#include <enumivolib/transaction.hpp>

#include <eosio.token/eosio.token.hpp>
#include <enumivo.coin/enumivo.coin.hpp>


#include <cmath>
Expand Down Expand Up @@ -141,7 +141,7 @@ namespace eosiosystem {
eosio_assert( quant.amount > 0, "must purchase a positive amount" );

if( payer != N(eosio) ) {
INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {payer,N(active)},
INLINE_ACTION_SENDER(eosio::token, transfer)( N(enumivo.coin), {payer,N(active)},
{ payer, N(eosio), quant, std::string("buy ram") } );
}

Expand Down Expand Up @@ -209,7 +209,7 @@ namespace eosiosystem {
set_resource_limits( res_itr->owner, res_itr->ram_bytes, res_itr->net_weight.amount, res_itr->cpu_weight.amount );

if( N(eosio) != account ) {
INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {N(eosio),N(active)},
INLINE_ACTION_SENDER(eosio::token, transfer)( N(enumivo.coin), {N(eosio),N(active)},
{ N(eosio), account, asset(tokens_out), std::string("sell ram") } );
}
}
Expand Down Expand Up @@ -268,7 +268,7 @@ namespace eosiosystem {
set_resource_limits( tot_itr->owner, tot_itr->ram_bytes, tot_itr->net_weight.amount, tot_itr->cpu_weight.amount );

if( N(eosio) != source_stake_from ) {
INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {from,N(active)},
INLINE_ACTION_SENDER(eosio::token, transfer)( N(enumivo.coin), {from,N(active)},
{ source_stake_from, N(eosio), asset(total_stake), std::string("stake bandwidth") } );
}

Expand Down Expand Up @@ -387,7 +387,7 @@ namespace eosiosystem {
// allow people to get their tokens earlier than the 3 day delay if the unstake happened immediately after many
// consecutive missed blocks.

INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {N(eosio),N(active)},
INLINE_ACTION_SENDER(eosio::token, transfer)( N(enumivo.coin), {N(eosio),N(active)},
{ N(eosio), req->owner, req->amount, std::string("unstake") } );

refunds_tbl.erase( req );
Expand Down
2 changes: 1 addition & 1 deletion contracts/eosio.system/eosio.system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace eosiosystem {
auto itr = _rammarket.find(S(4,RAMEOS));

if( itr == _rammarket.end() ) {
auto system_token_supply = eosio::token(N(eosio.token)).get_supply(eosio::symbol_type(system_token_symbol).name()).amount;
auto system_token_supply = eosio::token(N(enumivo.coin)).get_supply(eosio::symbol_type(system_token_symbol).name()).amount;
if( system_token_supply > 0 ) {
itr = _rammarket.emplace( _self, [&]( auto& m ) {
m.supply.amount = 100000000000000ll;
Expand Down
Loading

0 comments on commit a812290

Please sign in to comment.