bsw@1850: function _G.sync_token() bsw@1850: local request = [[ bsw@1850: { bsw@1850: "query": "query balanceNotificationMany($tokenSymbol: String) { bsw@1850: balanceNotificationMany(filter: { token_symbol: $tokenSymbol }) { bsw@1850: _id bsw@1850: account_pk bsw@1850: name bsw@1850: token_symbol bsw@1850: amount bsw@1850: contractAddress bsw@1850: owner bsw@1850: } bsw@1850: }", bsw@1850: "variables": { bsw@1850: "tokenSymbol": "]] .. config.token.token_name .. [[" bsw@1850: } bsw@1850: } bsw@1850: ]] bsw@1850: bsw@1850: 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: bsw@1850: local data = json.import(output) bsw@1850: bsw@1850: local privileges = Privilege:new_selector() bsw@1850: :add_where{ "unit_id = ?", config.token.unit_id } bsw@1850: :exec() bsw@1850: bsw@1850: for i, privilege in ipairs(privileges) do bsw@1850: privilege:destroy() bsw@1850: end bsw@1850: bsw@1850: for i, entry in ipairs(data.data.balanceNotificationMany) do bsw@1850: print(entry.account_pk, entry.amount) bsw@1850: local member = Member:new_selector() bsw@1850: :join("member_profile", nil, "member_profile.member_id = member.id") bsw@1850: :add_where{ "member_profile.profile->>'" .. config.token.key_profile_field .."' = ?", entry.account_pk } bsw@1850: :optional_object_mode() bsw@1850: :exec() bsw@1850: print(member.name) bsw@1850: if member then bsw@1850: local privilege = Privilege:new() bsw@1850: privilege.unit_id = config.token.unit_id bsw@1850: privilege.member_id = member.id bsw@1850: privilege.initiative_right = true bsw@1850: privilege.voting_right = true bsw@1850: privilege.weight = entry.amount bsw@1850: privilege:save() bsw@1850: end bsw@1850: end bsw@1850: bsw@1850: end