github.com/mysteriumnetwork/node@v0.0.0-20240516044423-365054f76801/identity/registry/affiliator.go (about) 1 /* 2 * Copyright (C) 2019 The "MysteriumNetwork/node" Authors. 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 package registry 19 20 import ( 21 "fmt" 22 "math/big" 23 24 "github.com/pkg/errors" 25 26 "github.com/mysteriumnetwork/node/requests" 27 ) 28 29 // Affiliator allows for convenient calls to the affiliator service 30 type Affiliator struct { 31 httpClient *requests.HTTPClient 32 endpointAddress string 33 } 34 35 // NewAffiliator creates and returns new Affiliator instance 36 func NewAffiliator(httpClient *requests.HTTPClient, endpointAddress string) *Affiliator { 37 return &Affiliator{ 38 httpClient: httpClient, 39 endpointAddress: endpointAddress, 40 } 41 } 42 43 // RegistrationTokenReward returns the amount of MYST rewarder for token used. 44 func (t *Affiliator) RegistrationTokenReward(token string) (*big.Int, error) { 45 req, err := requests.NewGetRequest(t.endpointAddress, fmt.Sprintf("register-reward/token/%s", token), nil) 46 if err != nil { 47 return nil, errors.Wrap(err, "failed to get token reward amount") 48 } 49 50 var resp struct { 51 Reward string `json:"reward"` 52 } 53 54 err = t.httpClient.DoRequestAndParseResponse(req, &resp) 55 if err != nil { 56 return nil, errors.Wrap(err, "failed to get token reward amount") 57 } 58 reward, _ := new(big.Int).SetString(resp.Reward, 10) 59 60 return reward, err 61 }