liquid_feedback_frontend

annotate 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
rev   line source
bsw@1850 1 function _G.sync_token()
bsw@1850 2 local request = [[
bsw@1850 3 {
bsw@1850 4 "query": "query balanceNotificationMany($tokenSymbol: String) {
bsw@1850 5 balanceNotificationMany(filter: { token_symbol: $tokenSymbol }) {
bsw@1850 6 _id
bsw@1850 7 account_pk
bsw@1850 8 name
bsw@1850 9 token_symbol
bsw@1850 10 amount
bsw@1850 11 contractAddress
bsw@1850 12 owner
bsw@1850 13 }
bsw@1850 14 }",
bsw@1850 15 "variables": {
bsw@1850 16 "tokenSymbol": "]] .. config.token.token_name .. [["
bsw@1850 17 }
bsw@1850 18 }
bsw@1850 19 ]]
bsw@1850 20
bsw@1850 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)
bsw@1850 22
bsw@1850 23 local data = json.import(output)
bsw@1850 24
bsw@1850 25 local privileges = Privilege:new_selector()
bsw@1850 26 :add_where{ "unit_id = ?", config.token.unit_id }
bsw@1850 27 :exec()
bsw@1850 28
bsw@1850 29 for i, privilege in ipairs(privileges) do
bsw@1850 30 privilege:destroy()
bsw@1850 31 end
bsw@1850 32
bsw@1850 33 for i, entry in ipairs(data.data.balanceNotificationMany) do
bsw@1850 34 print(entry.account_pk, entry.amount)
bsw@1850 35 local member = Member:new_selector()
bsw@1850 36 :join("member_profile", nil, "member_profile.member_id = member.id")
bsw@1850 37 :add_where{ "member_profile.profile->>'" .. config.token.key_profile_field .."' = ?", entry.account_pk }
bsw@1850 38 :optional_object_mode()
bsw@1850 39 :exec()
bsw@1850 40 print(member.name)
bsw@1850 41 if member then
bsw@1850 42 local privilege = Privilege:new()
bsw@1850 43 privilege.unit_id = config.token.unit_id
bsw@1850 44 privilege.member_id = member.id
bsw@1850 45 privilege.initiative_right = true
bsw@1850 46 privilege.voting_right = true
bsw@1850 47 privilege.weight = entry.amount
bsw@1850 48 privilege:save()
bsw@1850 49 end
bsw@1850 50 end
bsw@1850 51
bsw@1850 52 end

Impressum / About Us