liquid_feedback_frontend

view lib/token/sync.lua @ 1850:accb808d5b4a

Added token based voting
author bsw
date Tue Mar 22 10:19:22 2022 +0100 (2022-03-22)
parents
children a01d5c0604de
line source
1 function _G.sync_token()
2 local request = [[
3 {
4 "query": "query balanceNotificationMany($tokenSymbol: String) {
5 balanceNotificationMany(filter: { token_symbol: $tokenSymbol }) {
6 _id
7 account_pk
8 name
9 token_symbol
10 amount
11 contractAddress
12 owner
13 }
14 }",
15 "variables": {
16 "tokenSymbol": "]] .. config.token.token_name .. [["
17 }
18 }
19 ]]
21 local output, err, status = extos.pfilter(request, "curl", "--insecure", "-X", "POST", "-H", "Content-Type: application/json", "-H", "X-REQUEST-TYPE: GraphQL", "-d", "@-", config.token.graphql_url)
23 local data = json.import(output)
25 local privileges = Privilege:new_selector()
26 :add_where{ "unit_id = ?", config.token.unit_id }
27 :exec()
29 for i, privilege in ipairs(privileges) do
30 privilege:destroy()
31 end
33 for i, entry in ipairs(data.data.balanceNotificationMany) do
34 print(entry.account_pk, entry.amount)
35 local member = Member:new_selector()
36 :join("member_profile", nil, "member_profile.member_id = member.id")
37 :add_where{ "member_profile.profile->>'" .. config.token.key_profile_field .."' = ?", entry.account_pk }
38 :optional_object_mode()
39 :exec()
40 print(member.name)
41 if member then
42 local privilege = Privilege:new()
43 privilege.unit_id = config.token.unit_id
44 privilege.member_id = member.id
45 privilege.initiative_right = true
46 privilege.voting_right = true
47 privilege.weight = entry.amount
48 privilege:save()
49 end
50 end
52 end

Impressum / About Us