forked from stableex/sx.flash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcallback.cpp
33 lines (25 loc) · 960 Bytes
/
callback.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <eosio/eosio.hpp>
#include <eosio/asset.hpp>
#include <eosio.token/eosio.token.hpp>
#include "../flash.sx.hpp"
using namespace eosio;
using namespace std;
class [[eosio::contract("callback")]] example : public contract {
public:
using contract::contract;
[[eosio::action]]
void init( const name receiver, const asset quantity )
{
sx::flash::borrow_action borrow( "flash.sx"_n, { get_self(), "active"_n });
borrow.send( receiver, extended_asset{quantity, "eosio.token"_n}, "callback memo", get_self() );
}
[[eosio::on_notify("flash.sx::callback")]]
void on_callback( const name code, const name receiver, const extended_asset amount, const asset fee, const string memo, const name notifier )
{
// do actions before sending funds back
// PLACE YOUR CODE HERE
// repay flashloan
token::transfer_action transfer( amount.contract, { receiver, "active"_n });
transfer.send( receiver, code, amount.quantity + fee, memo );
}
};