-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathairdrops.cpp
More file actions
39 lines (38 loc) · 1.41 KB
/
airdrops.cpp
File metadata and controls
39 lines (38 loc) · 1.41 KB
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
34
35
36
37
38
39
#include "createescrow.hpp"
#include "lib/common.h"
#include "models/registry.h"
namespace createescrow
{
/*
* Called when a new user account is created
* Transfers the dapp tokens to the new account created
*/
void create_escrow::airdrop(string dapp, name account)
{
registry::Registry dapps(_self, _self.value);
auto iterator = dapps.find(common::toUUID(dapp));
if (iterator != dapps.end())
dapps.modify(iterator, same_payer, [&](auto &row) {
// check if the dapp has opted for airdrop
if (row.airdrop->contract != name(""))
{
if (row.airdrop->balance.amount > 0)
{
asset tokens = row.airdrop->amount;
auto memo = "airdrop " + tokens.to_string() + " to " + account.to_string();
action(
permission_level{_self, "active"_n},
row.airdrop->contract,
name("transfer"),
make_tuple(_self, account, tokens, memo))
.send();
row.airdrop->balance -= tokens;
}
else
{
check(false, ("Not enough " + row.airdrop->balance.symbol.code().to_string() + " with createescrow to airdrop for"+ row.dapp +"app").c_str());
}
}
});
}
} // namespace createescrow