forked from GetScatter/CreateBridge
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathairdrops.cpp
More file actions
37 lines (32 loc) · 1.35 KB
/
airdrops.cpp
File metadata and controls
37 lines (32 loc) · 1.35 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
#include "lib/common.h"
#include "models/registry.h"
class airdrops {
public:
name createbridge = common::createbridge;
/*
* Called when a new user account is created
* Transfers the dapp tokens to the new account created
*/
void airdrop(string dapp, name account){
registry::Registry dapps(createbridge, createbridge.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->tokens.amount > 0){
asset tokens = row.airdrop->limit;
auto memo = "airdrop " + tokens.to_string() + " to " + account.to_string();
action(
permission_level{ createbridge, "active"_n },
row.airdrop->contract,
name("transfer"),
make_tuple(createbridge, account, tokens, memo)
).send();
row.airdrop->tokens -= tokens;
} else {
eosio_assert(false,("Not enough " + row.airdrop->tokens.symbol.code().to_string() + " with createbridge to airdrop.").c_str());
}
}
});
}
};