liquid_feedback_frontend

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/lib/token/sync.lua	Tue Mar 22 10:19:22 2022 +0100
     1.3 @@ -0,0 +1,52 @@
     1.4 +function _G.sync_token()
     1.5 +  local request = [[
     1.6 +    {
     1.7 +      "query": "query balanceNotificationMany($tokenSymbol: String) {
     1.8 +        balanceNotificationMany(filter: { token_symbol: $tokenSymbol }) {
     1.9 +            _id
    1.10 +            account_pk
    1.11 +            name
    1.12 +            token_symbol
    1.13 +            amount
    1.14 +            contractAddress
    1.15 +            owner
    1.16 +        }
    1.17 +      }",
    1.18 +      "variables": {
    1.19 +        "tokenSymbol": "]] .. config.token.token_name .. [["
    1.20 +      }
    1.21 +    }
    1.22 +  ]]
    1.23 +
    1.24 +  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)
    1.25 +
    1.26 +  local data = json.import(output)
    1.27 +
    1.28 +  local privileges = Privilege:new_selector()
    1.29 +    :add_where{ "unit_id = ?", config.token.unit_id }
    1.30 +    :exec()
    1.31 +
    1.32 +  for i, privilege in ipairs(privileges) do
    1.33 +    privilege:destroy()
    1.34 +  end
    1.35 +
    1.36 +  for i, entry in ipairs(data.data.balanceNotificationMany) do
    1.37 +    print(entry.account_pk, entry.amount)
    1.38 +    local member = Member:new_selector()
    1.39 +      :join("member_profile", nil, "member_profile.member_id = member.id")
    1.40 +      :add_where{ "member_profile.profile->>'" .. config.token.key_profile_field .."' = ?", entry.account_pk }
    1.41 +      :optional_object_mode()
    1.42 +      :exec()
    1.43 +    print(member.name)
    1.44 +    if member then
    1.45 +      local privilege = Privilege:new()
    1.46 +      privilege.unit_id = config.token.unit_id
    1.47 +      privilege.member_id = member.id
    1.48 +      privilege.initiative_right = true
    1.49 +      privilege.voting_right = true
    1.50 +      privilege.weight = entry.amount
    1.51 +      privilege:save()
    1.52 +    end
    1.53 +  end
    1.54 +
    1.55 +end
    1.56 \ No newline at end of file

Impressum / About Us