github.com/mysteriumnetwork/node@v0.0.0-20240516044423-365054f76801/tequilapi/contract/terms.go (about) 1 /* 2 * Copyright (C) 2020 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 contract 19 20 import ( 21 "github.com/mysteriumnetwork/node/config" 22 "github.com/mysteriumnetwork/terms/terms-go" 23 ) 24 25 // TermsRequest object is accepted by terms endpoints. 26 // swagger:model TermsRequest 27 type TermsRequest struct { 28 // example: false 29 AgreedProvider *bool `json:"agreed_provider,omitempty"` 30 // example: false 31 AgreedConsumer *bool `json:"agreed_consumer,omitempty"` 32 // example: 0.0.27 33 AgreedVersion string `json:"agreed_version,omitempty"` 34 } 35 36 // TermsResponse object is returned by terms endpoints. 37 // swagger:model TermsResponse 38 type TermsResponse struct { 39 // example: false 40 AgreedProvider bool `json:"agreed_provider"` 41 // example: false 42 AgreedConsumer bool `json:"agreed_consumer"` 43 // example: 0.0.27 44 AgreedVersion string `json:"agreed_version"` 45 // example: 0.0.27 46 CurrentVersion string `json:"current_version"` 47 } 48 49 const ( 50 // TermsConsumerAgreed is the key which is used to store terms agreement 51 // for consumer features. 52 // This key can also be used to address the value directly in the config. 53 TermsConsumerAgreed = "terms.consumer-agreed" 54 55 // TermsProviderAgreed is the key which is used to store terms agreement 56 // for provider features. 57 // This key can also be used to address the value directly in the config. 58 TermsProviderAgreed = "terms.provider-agreed" 59 60 // TermsVersion is the key which is used to store terms agreement 61 // version for both provider and consumer. 62 // This key can also be used to address the value directly in the config. 63 TermsVersion = "terms.version" 64 ) 65 66 // NewTermsResp builds and returns terms agreement response. 67 func NewTermsResp() *TermsResponse { 68 return &TermsResponse{ 69 AgreedProvider: config.Current.GetBool(TermsProviderAgreed), 70 AgreedConsumer: config.Current.GetBool(TermsConsumerAgreed), 71 AgreedVersion: config.Current.GetString(TermsVersion), 72 CurrentVersion: terms.TermsVersion, 73 } 74 } 75 76 // ToMap turns a TermsRequest in to an iterable map which 77 // can be mapped directly to a user config. 78 func (t *TermsRequest) ToMap() map[string]interface{} { 79 give := map[string]interface{}{} 80 if t.AgreedConsumer != nil { 81 give[TermsConsumerAgreed] = *t.AgreedConsumer 82 } 83 84 if t.AgreedProvider != nil { 85 give[TermsProviderAgreed] = *t.AgreedProvider 86 } 87 give[TermsVersion] = t.AgreedVersion 88 89 return give 90 }